add in really bad hack which calls trunc_div or trunc_mod
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 14:14:37 +0000 (15:14 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 14:14:37 +0000 (15:14 +0100)
https://bugs.libre-soc.org/show_bug.cgi?id=324#c16

src/soc/decoder/pseudo/parser.py

index 161a793b2360512107aae8bb643f3dc5ef2474af..dae0e4e8df4c8ae0726cc216f3cda1e30235d299 100644 (file)
@@ -603,6 +603,23 @@ class PowerParser:
             elif p[2] == '||':
                 l = check_concat(p[1]) + check_concat(p[3])
                 p[0] = ast.Call(ast.Name("concat", ast.Load()), l, [])
+            elif p[2] in ['/', '%']:
+                # bad hack: if % or / used anywhere other than div/mod ops,
+                # do % or /.  however if the argument names are "dividend"
+                # we must call the special trunc_div and trunc_rem functions
+                l, r = p[1], p[3]
+                # actual call will be "dividend / divisor" - just check
+                # LHS name
+                if isinstance(l, ast.Name) and l.id == 'dividend':
+                    if p[2] == '/':
+                        fn = 'trunc_div'
+                    else:
+                        fn = 'trunc_mod'
+                    # return "function trunc_xxx(l, r)"
+                    p[0] =  ast.Call(ast.Name(fn, ast.Load()), (l, r), [])
+                else:
+                    # return "l {binop} r"
+                    p[0] = ast.BinOp(p[1], binary_ops[p[2]], p[3])
             elif p[2] in ['<', '>', '=', '<=', '>=', '!=']:
                 p[0] = binary_ops[p[2]]((p[1], p[3]))
             elif identify_sint_mul_pattern(p):