diff options
author | Peter Wu <lekensteyn@gmail.com> | 2011-11-27 14:20:41 +0000 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2011-11-27 14:20:41 +0000 |
commit | 2224c3d82acc392bd380de352305a6da6cebf274 (patch) | |
tree | 57413a8ea70b39c4721cc8710508a898f807a6b0 | |
parent | d511864f8ad4094e0a96bbae384ee0913538aa36 (diff) | |
download | pp2cc-2224c3d82acc392bd380de352305a6da6cebf274.tar.gz |
Fix function calls yielding 'None' as register where 'R0' should be placed
-rwxr-xr-x | pp2cc.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -72,12 +72,31 @@ class Registers(object): return text # out of luck return None + def get_instruction(self, text): + """Retrieve the instruction from text skipping labels and comments""" + text = text.strip() + # ignore commented lines + if text.startswith(";"): + return None + # skip labels if any + text = text.upper().split(":", 1)[-1] + # the first element is assumed to be an instruction + text = text.lstrip(" ").split(" ", 1)[0] + # instructions have a length between 2 (OR) and 4 (LOAD) + if len(text) >= 2 and len(text) <= 4: + return text + return None def find_register(self, instructions_list, fatal=False): """Finds the last modified register in a list of instructions""" for line in reversed(instructions_list): reg = self.get_register(line) if reg: return reg + else: + instruction = self.get_instruction(line) + # convention: non-void functions store their result value in R0 + if instruction == "BRS": + return "R0" if fatal: raise RuntimeError("No register found in instructions list") return None |