"""
+def RANGE(start, end):
+ if start > end:
+ # auto-subtract-one (sigh) due to python range
+ end -= 1
+ else:
+ # auto-add-one (sigh) due to python range
+ end += 1
+ return range(start, end)
+
+
def exts(value, bits):
sign = 1 << (bits - 1)
return (value & (sign - 1)) - (value & sign)
p[0] = ast.Break()
def p_for_stmt(self, p):
- """for_stmt : FOR atom EQ test TO test COLON suite
- | DO atom EQ test TO test COLON suite
+ """for_stmt : FOR atom EQ comparison TO comparison COLON suite
+ | DO atom EQ comparison TO comparison COLON suite
"""
start = p[4]
end = p[6]
- if start.value > end.value: # start greater than end, must go -ve
- # auto-subtract-one (sigh) due to python range
- end = ast.BinOp(p[6], ast.Add(), ast.Constant(-1))
- arange = [start, end, ast.Constant(-1)]
- else:
- # auto-add-one (sigh) due to python range
- end = ast.BinOp(p[6], ast.Add(), ast.Constant(1))
- arange = [start, end]
- it = ast.Call(ast.Name("range", ast.Load()), arange, [])
+ it = ast.Call(ast.Name("RANGE", ast.Load()), (start, end), [])
p[0] = ast.For(p[2], it, p[8], [])
def p_while_stmt(self, p):
trunc_divs, trunc_rems, MULS, DIVS, MODS,
EXTS128, undefined,
bitrev, SHL64,
+ RANGE,
)
from openpower.decoder.selectable_int import SelectableInt
from openpower.decoder.selectable_int import selectconcat as concat