oppc/code: refactor binary and unary exprs
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 f6d7b908bb644e9a594a7995c5492dc0903a067c..df5fa3195cd307b60d27c548bbfe471c9f2390e1 100644 (file)
@@ -269,7 +269,28 @@ class CodeVisitor(pc_util.Visitor):
             transient = self.transient(bits="UINT8_C(1)")
         else:
             transient = self.transient()
-        call = self.call(name=str(self[node.op]), code=[
+        calls = {
+            pc_ast.Add: "oppc_add",
+            pc_ast.Sub: "oppc_sub",
+            pc_ast.Mul: "oppc_mul",
+            pc_ast.Div: "oppc_div",
+            pc_ast.Mod: "oppc_mod",
+            pc_ast.Lt: "oppc_lt",
+            pc_ast.Le: "oppc_le",
+            pc_ast.Eq: "oppc_eq",
+            pc_ast.Ne: "oppc_ne",
+            pc_ast.LtU: "oppc_ltu",
+            pc_ast.GtU: "oppc_gtu",
+            pc_ast.Ge: "oppc_ge",
+            pc_ast.Gt: "oppc_gt",
+            pc_ast.LShift: "oppc_lshift",
+            pc_ast.RShift: "oppc_rshift",
+            pc_ast.BitAnd: "oppc_and",
+            pc_ast.BitOr: "oppc_or",
+            pc_ast.BitXor: "oppc_xor",
+            pc_ast.BitConcat: "oppc_concat",
+        }
+        call = self.call(name=calls[node.op.__class__], code=[
             self[transient],
             self[node.left],
             self[node.right],
@@ -283,8 +304,13 @@ class CodeVisitor(pc_util.Visitor):
         yield node
         if isinstance(node.value, pc_ast.IfExpr):
             self.fixup_ternary(node=node.value)
+        calls = {
+            pc_ast.Not: "oppc_not",
+            pc_ast.Add: "oppc_plus",
+            pc_ast.Sub: "oppc_minus",
+        }
         transient = self.transient()
-        call = self.call(name=str(self[node.op]), code=[
+        call = self.call(name=calls[node.op.__class__], code=[
             self[transient],
             self[node.value],
         ])
@@ -305,29 +331,6 @@ class CodeVisitor(pc_util.Visitor):
         )
     def Op(self, node):
         yield node
-        op = {
-            pc_ast.Not: "oppc_not",
-            pc_ast.Add: "oppc_add",
-            pc_ast.Sub: "oppc_sub",
-            pc_ast.Mul: "oppc_mul",
-            pc_ast.Div: "oppc_div",
-            pc_ast.Mod: "oppc_mod",
-            pc_ast.Lt: "oppc_lt",
-            pc_ast.Le: "oppc_le",
-            pc_ast.Eq: "oppc_eq",
-            pc_ast.Ne: "oppc_ne",
-            pc_ast.LtU: "oppc_ltu",
-            pc_ast.GtU: "oppc_gtu",
-            pc_ast.Ge: "oppc_ge",
-            pc_ast.Gt: "oppc_gt",
-            pc_ast.LShift: "oppc_lshift",
-            pc_ast.RShift: "oppc_rshift",
-            pc_ast.BitAnd: "oppc_and",
-            pc_ast.BitOr: "oppc_or",
-            pc_ast.BitXor: "oppc_xor",
-            pc_ast.BitConcat: "oppc_concat",
-        }[node.__class__]
-        self[node].emit(stmt=op)
 
     @pc_util.Hook(pc_ast.StringLiteral)
     def StringLiteral(self, node):