From 838b76f1c640a1ff426adca9c139f1c188454153 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 16 Jan 2024 22:09:45 +0300 Subject: [PATCH] oppc/code: support dynamic operands --- src/openpower/oppc/pc_code.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index d490a85d..123d65b3 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -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] -- 2.30.2