add test of if elif
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Apr 2020 17:23:18 +0000 (18:23 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 2 Apr 2020 17:23:18 +0000 (18:23 +0100)
src/soc/decoder/power_pseudo.py
src/soc/decoder/pseudo/parser.py

index 76e50906311c9d1271f506a4a44d1dbf016080b8..317ab5da4e0850cb4057fcb0d8b819e1167cf698 100644 (file)
@@ -62,8 +62,16 @@ RA <- EXTZ64(n)
 print (RA)
 """
 
+cmpi = """
+if      a < EXTS(SI) then
+    c <- 0b100
+else if a > EXTS(SI) then
+    c <- 0b010
+"""
+
 #code = testreg
-code = cnttzd
+#code = cnttzd
+code = cmpi
 #code = bpermd
 
 def tolist(num):
index 8f76f32758d3ec9386ae44b36eededba87bb1622..a4663ab41dc0440fe93ccc58cf67e8df0feee92d 100644 (file)
@@ -265,10 +265,13 @@ class PowerParser:
             p[0] = ast.While(p[3], p[5], p[8])
 
     def p_if_stmt(self, p):
-        """if_stmt : IF test COLON suite ELSE COLON suite
+        """if_stmt : IF test COLON suite ELSE COLON if_stmt
+                   | IF test COLON suite ELSE COLON suite
                    | IF test COLON suite
         """
-        if len(p) == 5:
+        if len(p) == 8 and isinstance(p[7], ast.If):
+            p[0] = ast.If(p[2], p[4], [p[7]])
+        elif len(p) == 5:
             p[0] = ast.If(p[2], p[4], [])
         else:
             p[0] = ast.If(p[2], p[4], p[7])