Skip to content

Commit f762968

Browse files
authored
Merge pull request #902 from kr-sc/kr-sc/fix-register-definitions-prefixes
Fix macro generation
2 parents 95b06b0 + 44b8d86 commit f762968

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

registers.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,26 +386,17 @@ def prototype(self):
386386
def body(self):
387387
return self.expression
388388

389-
def sympy_to_c(expression, sym_to_c = lambda s: "(" + str(s) + ")"):
389+
def sympy_to_c(expression, sym_to_c = lambda s: f"({s})", unsigned=True):
390390
"""Implement our own string function, so we can replace 2** with 1<<."""
391-
stc = lambda x : sympy_to_c(x, sym_to_c)
391+
stc = lambda x : sympy_to_c(x, sym_to_c, unsigned)
392392
if isinstance(expression, str):
393393
return expression
394394
if isinstance(expression, sympy.Number):
395-
if (expression >= 2**32):
396-
return "0x%xULL" % expression
397-
elif (expression >= 2**31):
398-
return "0x%xU" % expression
399-
elif (expression >= 10):
400-
return "0x%x" % expression
401-
elif (expression > -10):
402-
return "%d" % expression
403-
elif (expression > -2**31):
404-
return "-0x%x" % -expression
405-
elif (expression > -2**32):
406-
return "-0x%xU" % -expression
395+
suffix = "ULL" if unsigned else ""
396+
if (expression < 10 and expression > -10):
397+
return "%d%s" % (expression, suffix)
407398
else:
408-
return "-0x%xULL" % -expression
399+
return "%#0x%s" % (expression, suffix)
409400
elif isinstance(expression, sympy.Symbol):
410401
return sym_to_c(expression)
411402
elif isinstance(expression, sympy.Add):
@@ -502,7 +493,7 @@ def print_cgetters( registers_list, fd_h, fd_c):
502493
fd_h.write(Register.c_field_list_type())
503494
fd_h.write(Register.c_info_type())
504495

505-
to_c = lambda string: sympy_to_c(sympy.simplify(string), lambda s: f"context.{s}.value")
496+
to_c = lambda string: sympy_to_c(sympy.simplify(string), lambda s: f"context.{s}.value", False)
506497
is_valid = lambda s: f"context.{s}.is_set"
507498

508499
for r in all_regs:

0 commit comments

Comments
 (0)