Created
August 21, 2018 09:07
-
-
Save yannayl/534a89aa9b54e9f75bbcb23a7d6a34bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def spoils(f): | |
"""return the list of spoiled registers | |
default is r0-r3 | |
not too smart, but safe - i.e. if list of spoiled registers is smaller than 4 - it's quite safe to assume only these registers are spoiled | |
the opposite is false | |
""" | |
spoiled = ['R0', 'R1', 'R2', 'R3'] | |
if any(f.xrefs_from): | |
return spoiled | |
regs = set() | |
for l in f.lines: | |
for op in l.insn.operands: | |
regs.update(op.regs) | |
if not regs.issubset(set(spoiled + ['LR', 'PC'])): | |
return spoiled | |
if all(reg in regs for reg in spoiled): | |
return spoiled | |
return list(regs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment