oppc/code: support dynamic operands
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:09:45 +0000 (22:09 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:08 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index d490a85dbc3019d921c7b6307e5b7a1f33e69c92..123d65b33d68617ac32a45200f8aec8c26823387 100644 (file)
@@ -1,9 +1,11 @@
 import collections
 import contextlib
+import operator
 
 import openpower.oppc.pc_ast as pc_ast
 import openpower.oppc.pc_util as pc_util
 import openpower.oppc.pc_pseudocode as pc_pseudocode
+from openpower.insndb.core import DynamicOperand
 
 
 class Transient(pc_ast.Node):
@@ -47,21 +49,24 @@ class CodeVisitor(pc_util.Visitor):
 
         super().__init__(root=root)
 
-        for decl in self.__decls:
+        for decl in (operand.name for operand in insn.dynamic_operands):
+            if decl not in self.__decls:
+                self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};")
+        for decl in sorted(self.__decls):
             self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};")
-        decls = sorted(filter(lambda decl: decl in insn.fields, self.__decls))
-        if decls:
-            self.__code[self.__header].emit()
-        for decl in decls:
-            bits = f"{len(insn.fields[decl])}"
+        self.__code[self.__header].emit()
+
+        for operand in insn.dynamic_operands:
+            bits = f"{len(operand.span)}"
             transient = Transient(bits=bits)
-            symbol = pc_ast.Symbol(decl)
+            symbol = pc_ast.Symbol(operand.name)
             assign = pc_ast.AssignExpr(lvalue=symbol, rvalue=transient)
             self.traverse(root=assign)
             for (level, stmt) in self[assign]:
                 self[self.__header].emit(stmt=stmt, level=level)
-            for (lbit, rbit) in enumerate(insn.fields[decl]):
-                lsymbol = pc_ast.Symbol(decl)
+
+            for (lbit, rbit) in enumerate(operand.span):
+                lsymbol = pc_ast.Symbol(operand.name)
                 rsymbol = Instruction()
                 lindex = Transient(value=str(lbit))
                 rindex = Transient(value=str(rbit))
@@ -72,8 +77,6 @@ class CodeVisitor(pc_util.Visitor):
                 for (level, stmt) in self[assign]:
                     self[self.__header].emit(stmt=stmt, level=level)
             self.__code[self.__header].emit()
-        if decls:
-            self.__code[self.__header].emit()
 
     def __iter__(self):
         yield from self[self.__header]