From 428ee1460a8ef1b0804b197a840eced881c6b46a Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 19 Jun 2020 15:14:37 +0100 Subject: [PATCH] add in really bad hack which calls trunc_div or trunc_mod https://bugs.libre-soc.org/show_bug.cgi?id=324#c16 --- src/soc/decoder/pseudo/parser.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/soc/decoder/pseudo/parser.py b/src/soc/decoder/pseudo/parser.py index 161a793b..dae0e4e8 100644 --- a/src/soc/decoder/pseudo/parser.py +++ b/src/soc/decoder/pseudo/parser.py @@ -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): -- 2.30.2