From d2301739260f3d8bc5b83d6ab4ecbb1e8db1d014 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 11 Jan 2024 00:09:37 +0300 Subject: [PATCH] oppc/code: support simple constant unary exprs --- src/openpower/oppc/__main__.py | 2 +- src/openpower/oppc/pc_code.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index 91f5d4ba..fcc0e8f1 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -53,7 +53,7 @@ for path in []: # glob.glob(f"{find_wiki_dir()}/../isa/*.mdwn"): raise exc code = """ -a <- 0b0 +a <- ¬(RA) """ tree = parser.parse(code=code) print(tree) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 143a0055..74604f45 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -68,6 +68,27 @@ class CodeVisitor(pc_util.Visitor): yield node if isinstance(node.value, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.value)].append(node.value) + stmt = "".join([ + str(self[node.op]), + f"oppc_reg_fetch({str(self[node.value])})", + ]) + else: + stmt = "".join([ + str(self[node.op]), + f"({str(self[node.value])})", + ]) + self[node].emit(stmt=stmt) + + @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub) + def Op(self, node): + yield node + mapping = { + pc_ast.Not: "~", + pc_ast.Add: "+", + pc_ast.Sub: "-", + } + stmt = mapping[node.__class__] + self[node].emit(stmt=stmt) @pc_util.Hook(pc_ast.BinLiteral, pc_ast.DecLiteral, pc_ast.HexLiteral) def Integer(self, node): @@ -99,6 +120,10 @@ class CodeVisitor(pc_util.Visitor): self.__decls[str(node)].append(node) self[node].emit(stmt=str(node)) + @pc_util.Hook(pc_ast.Node) + def Node(self, node): + raise NotImplementedError(type(node)) + def code(name, root): yield from CodeVisitor(name=name, root=root) -- 2.30.2