diff options
author | Peter Wu <lekensteyn@gmail.com> | 2011-11-28 22:41:00 +0000 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2011-11-28 22:41:00 +0000 |
commit | bb3c12c5c31f637642936e3177ad211fa3053e3e (patch) | |
tree | 4d9d27b7678762417f73ce4e525f76c60501141b /pp2cc.py | |
parent | 64e5f4cbc2819b7f17eab7fc84593d15887d7000 (diff) | |
download | pp2cc-bb3c12c5c31f637642936e3177ad211fa3053e3e.tar.gz |
Properly handle $F (=$FFFFF) and %1 (=-1) assembly constants
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-x | pp2cc.py | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -690,6 +690,10 @@ class Parse(object): lines.append(self.asm.noop(lbl_end, register=result_reg)) return lines def convertInteger(self, value=None, node=None): + """Returns a string of the value + + For integers, the string returned is a base-10 number modulo WORDSIZE + """ if value is None: if isinstance(node, c_ast.Constant) and node.type == "int": value = node.value @@ -704,23 +708,34 @@ class Parse(object): if "U" in value: # unsigned integer, ignore for now value = value.replace("U", "", 1) if value.startswith("0X"): - value = value[2:] - if len(value) == 5: - # highest possible value is 3FFFF, so adding a zero would not make sense - value = "$" + value - else: - value = "$0" + value + value = int(value[2:], 16) elif value.startswith("0"): # octal numbers are not understood by PP2 assembly, therefore convert it - value = str(int(value, 8)) - return value + value = int(value, 8) + else: + value = int(value) + # values are modulo WORDSIZE. If negative, the MSB is 1 + value %= pow(2, self.WORDSIZE) + return str(value) def convertStrToInteger(self, str): """Converts a PP2 assembly integer string to an integer""" str = str.upper() if str.startswith("$"): - return int(str[1:], 16) + if str.startswith("$0"): + return int(str[2:], 16) + else: + # anything with a leading 8 or higher is padded... assembler + # bug? + val = str[1:] + if int(val[1]) >= 8: + hexsize = len(hex(pow(2, self.WORDSIZE) - 1)[2:]) + val = val.rjust(hexsize, "F") + return int(val, 16) elif str.startswith("%"): - return int(str[1:], 8) + if str.startswith("%0"): + return int(str[2:], 8) + else: + return int(str[1:].rjust(self.WORDSIZE, "1"), 8) return int(str, 10) def parseConstant(self, linked_node, register="R0"): node = linked_node.node |