From 7adc4461f1fe26442b7f102373423355b3a47eb1 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:24:22 +0300 Subject: [PATCH] oppc/code: support simple conditions --- src/openpower/oppc/pc_code.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index cb7260ee..616bb6a5 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -71,7 +71,11 @@ class CodeVisitor(pc_util.Visitor): else: right = str(self[node.right]) if isinstance(node.op, (pc_ast.Add, pc_ast.Sub, - pc_ast.Mul, pc_ast.Div, pc_ast.Mod)): + pc_ast.Mul, pc_ast.Div, pc_ast.Mod, + pc_ast.Lt, pc_ast.Le, + pc_ast.Eq, pc_ast.NotEq, + pc_ast.Ge, pc_ast.Gt, + )): op = { pc_ast.Not: "~", pc_ast.Add: "+", @@ -79,6 +83,12 @@ class CodeVisitor(pc_util.Visitor): pc_ast.Mul: "*", pc_ast.Div: "/", pc_ast.Mod: "%", + pc_ast.Lt: "<", + pc_ast.Le: "<=", + pc_ast.Eq: "==", + pc_ast.NotEq: "!=", + pc_ast.Ge: ">=", + pc_ast.Gt: ">", }[node.op.__class__] stmt = " ".join([left, op, right]) self[node].emit(stmt=f"({stmt})") @@ -102,8 +112,13 @@ class CodeVisitor(pc_util.Visitor): else: raise ValueError(node) - @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub, - pc_ast.Mul, pc_ast.Div, pc_ast.Mod) + @pc_util.Hook( + pc_ast.Not, pc_ast.Add, pc_ast.Sub, + pc_ast.Mul, pc_ast.Div, pc_ast.Mod, + pc_ast.Lt, pc_ast.Le, + pc_ast.Eq, pc_ast.NotEq, + pc_ast.Ge, pc_ast.Gt, + ) def Op(self, node): yield node -- 2.30.2