From: Dmitry Selyutin Date: Fri, 12 Jan 2024 20:16:17 +0000 (+0300) Subject: oppc/code: support if exprs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e2596e1c96ba9df7b359a442e48515bf3b62084;p=openpower-isa.git oppc/code: support if exprs --- diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index fcc0e8f1..63a03eee 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -53,7 +53,17 @@ for path in []: # glob.glob(f"{find_wiki_dir()}/../isa/*.mdwn"): raise exc code = """ -a <- ¬(RA) +src <- [0]*64 +src[64-XLEN:63] <- (RS) +result <- [0]*64 +do i = 0 to 1 + n <- i * 32 + result[n+0:n+7] <- 0 + result[n+8:n+19] <- DPD_TO_BCD(src[n+12:n+21]) + result[n+20:n+31] <- DPD_TO_BCD(src[n+22:n+31]) +RA <- result[64-XLEN:63] +if a < b then RT <- (RA) +else RT <- (RB) """ tree = parser.parse(code=code) print(tree) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index a1cd4314..f014eaf1 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -200,6 +200,23 @@ class CodeVisitor(pc_util.Visitor): self[node].emit(stmt=stmt, level=level) self[node].emit(f"}}") + @pc_util.Hook(pc_ast.IfExpr) + def IfExpr(self, node): + yield node + stmt = " ".join([ + "if", + str(self[node.test]), + "{", + ]) + self[node].emit(stmt=stmt) + for (level, stmt) in self[node.body]: + self[node].emit(stmt=stmt, level=level) + if node.orelse: + self[node].emit("} else {") + for (level, stmt) in self[node.orelse]: + self[node].emit(stmt=stmt, level=level) + self[node].emit("}") + @pc_util.Hook(pc_ast.Call.Name) def CallName(self, node): yield node