diff mbox series

[RFC] scripts/decodetree.py: Fix variable-length ISA

Message ID 87woktpqmr.wl-ysato@users.sourceforge.jp (mailing list archive)
State New, archived
Headers show
Series [RFC] scripts/decodetree.py: Fix variable-length ISA | expand

Commit Message

Yoshinori Sato March 20, 2019, 2:27 p.m. UTC
Hi.
I found some problem in tested RX instructions.
It is usable in RX instructions, but I think that there
is a better fix because I am not familiar with Python.

I fixed three point.
- Added ctx to !function args.
- Fixed group operaiton. varinsns required width field.
- Fixed symbol in decode_load_bytes args.

Thanks.

Comments

Richard Henderson March 21, 2019, 1:43 a.m. UTC | #1
On 3/20/19 7:27 AM, Yoshinori Sato wrote:
> Hi.
> I found some problem in tested RX instructions.
> It is usable in RX instructions, but I think that there
> is a better fix because I am not familiar with Python.

The patch itself look ok, but needs some changes.

> I fixed three point.
> - Added ctx to !function args.

This seems fine.  But it needs either

(1) A command-line option, or
(2) Changes to all existing users in the tree.

Otherwise the build breaks for the other targets.

> - Fixed group operaiton. varinsns required width field.
> - Fixed symbol in decode_load_bytes args.

Thanks.  I can fold these fixes into v2 of the varinsns patches.


r~
Yoshinori Sato March 22, 2019, 2:16 p.m. UTC | #2
On Thu, 21 Mar 2019 10:43:37 +0900,
Richard Henderson wrote:
> 
> On 3/20/19 7:27 AM, Yoshinori Sato wrote:
> > Hi.
> > I found some problem in tested RX instructions.
> > It is usable in RX instructions, but I think that there
> > is a better fix because I am not familiar with Python.
> 
> The patch itself look ok, but needs some changes.
> 
> > I fixed three point.
> > - Added ctx to !function args.
> 
> This seems fine.  But it needs either
> 
> (1) A command-line option, or
> (2) Changes to all existing users in the tree.
> 
> Otherwise the build breaks for the other targets.
> 
> > - Fixed group operaiton. varinsns required width field.
> > - Fixed symbol in decode_load_bytes args.
> 
> Thanks.  I can fold these fixes into v2 of the varinsns patches.
>

OK. Thanks.

> 
> r~
>
diff mbox series

Patch

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 150af32d65..4537fbe948 100755
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -256,7 +256,7 @@  class FunctionField:
         return self.func + '(' + str(self.base) + ')'
 
     def str_extract(self):
-        return self.func + '(' + self.base.str_extract() + ')'
+        return self.func + '(ctx, ' + self.base.str_extract() + ')'
 
     def __eq__(self, other):
         return self.func == other.func and self.base == other.base
@@ -318,7 +318,7 @@  class Format(General):
         return decode_function + '_extract_' + self.name
 
     def output_extract(self):
-        output('static void ', self.extract_name(), '(',
+        output('static void ', self.extract_name(), '(DisasContext *ctx, ',
                self.base.struct_name(), ' *a, ', insntype, ' insn)\n{\n')
         for n, f in self.fields.items():
             output('    a->', n, ' = ', f.str_extract(), ';\n')
@@ -343,7 +343,8 @@  class Pattern(General):
         arg = self.base.base.name
         output(ind, '/* ', self.file, ':', str(self.lineno), ' */\n')
         if not extracted:
-            output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n')
+            output(ind, self.base.extract_name(),
+                   '(ctx, &u.f_', arg, ', insn);\n')
         for n, f in self.fields.items():
             output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n')
         output(ind, 'if (', translate_prefix, '_', self.name,
@@ -354,14 +355,16 @@  class Pattern(General):
 class MultiPattern(General):
     """Class representing an overlapping set of instruction patterns"""
 
-    def __init__(self, lineno, pats, fixb, fixm, udfm):
+    def __init__(self, name, lineno, pats, fixb, fixm, udfm, w):
         self.file = input_file
+        self.name = name
         self.lineno = lineno
         self.pats = pats
         self.base = None
         self.fixedbits = fixb
         self.fixedmask = fixm
         self.undefmask = udfm
+        self.width = w
 
     def __str__(self):
         r = "{"
@@ -732,6 +735,7 @@  def build_multi_pattern(lineno, pats):
 
     fixedmask = insnmask
     undefmask = insnmask
+    width = 0
 
     # Collect fixed/undefmask for all of the children.
     # Move the defining lineno back to that of the first child.
@@ -740,6 +744,7 @@  def build_multi_pattern(lineno, pats):
         undefmask &= p.undefmask
         if p.lineno < lineno:
             lineno = p.lineno
+        name = p.name
 
     repeat = True
     while repeat:
@@ -753,10 +758,14 @@  def build_multi_pattern(lineno, pats):
             elif fixedbits != thisbits:
                 fixedmask &= ~(fixedbits ^ thisbits)
                 break
+            if width == 0:
+                width = p.width
+            if width != p.width:
+                error(lineno, 'width mismatch in pattern within braces')
         else:
             repeat = False
 
-    mp = MultiPattern(lineno, pats, fixedbits, fixedmask, undefmask)
+    mp = MultiPattern(name, lineno, pats, fixedbits, fixedmask, undefmask, width)
     patterns.append(mp)
 # end build_multi_pattern
 
@@ -886,7 +895,7 @@  class Tree:
         # extract the fields now.
         if not extracted and self.base:
             output(ind, self.base.extract_name(),
-                   '(&u.f_', self.base.base.name, ', insn);\n')
+                   '(ctx, &u.f_', self.base.base.name, ', insn);\n')
             extracted = True
 
         # Attempt to aid the compiler in producing compact switch statements.
@@ -985,7 +994,7 @@  class SizeTree:
         # If we need to load more bytes to test, do so now.
         if extracted < self.width:
             output(ind, 'insn = ', decode_function,
-                   '_load_bytes(s, insn, {0}, {1});\n'
+                   '_load_bytes(ctx, insn, {0}, {1});\n'
                    .format(extracted / 8, self.width / 8));
             extracted = self.width
 
@@ -1039,7 +1048,7 @@  class SizeLeaf:
         # If we need to load more bytes, do so now.
         if extracted < self.width:
             output(ind, 'insn = ', decode_function,
-                   '_load_bytes(s, insn, {0}, {1});\n'
+                   '_load_bytes(ctx, insn, {0}, {1});\n'
                    .format(extracted / 8, self.width / 8));
             extracted = self.width
         output(ind, 'return insn;\n')