restore branch expansion for non-4502 targets

This commit is contained in:
gardners 2014-02-08 01:59:42 +10:30
parent 8152590946
commit 5c162d2407

View File

@ -618,10 +618,41 @@ class ExtendBranches(PCTracker):
arg = expr.value(env) arg = expr.value(env)
arg = arg - (env.getPC() + 2) arg = arg - (env.getPC() + 2)
if arg < -128 or arg > 127: if arg < -128 or arg > 127:
node.nodetype = "RelativeLong" if Cmd.enable_4502_exts:
if Cmd.warn_on_branch_extend: node.nodetype = "RelativeLong"
print>>sys.stderr, str(node.ppt) + ": WARNING: " \ if Cmd.warn_on_branch_extend:
"branch out of range, replacing with 16-bit relative branch" print>>sys.stderr, str(node.ppt) + ": WARNING: " \
"branch out of range, replacing with 16-bit relative branch"
else:
if opcode == 'bra':
# If BRA - BRanch Always - is out of range, it's a JMP.
node.data = ('jmp', expr, None)
node.nodetype = "Absolute"
if Cmd.warn_on_branch_extend:
print>>sys.stderr, str(node.ppt) + ": WARNING: " \
"bra out of range, replacing with jmp"
else:
# Otherwise, we replace it with a 'macro' of sorts by hand:
# $branch LOC -> $reversed_branch ^+5; JMP LOC
# We don't use temp labels here because labels need to have
# been fixed in place by this point, and JMP is always 3
# bytes long.
expansion = [IR.Node(node.ppt, "Relative",
ExtendBranches.reversed[opcode],
IR.SequenceExpr([IR.PCExpr(), "+",
IR.ConstantExpr(5)]),
None),
IR.Node(node.ppt, "Absolute", 'jmp', expr, None)]
node.nodetype = 'SEQUENCE'
node.data = expansion
if Cmd.warn_on_branch_extend:
print>>sys.stderr, str(node.ppt) + ": WARNING: " + \
opcode + " out of range, " \
"replacing with " + \
ExtendBranches.reversed[opcode] + \
"/jmp combo"
self.changed = True
node.accept(self, env)
else: else:
PCTracker.visitRelative(self, node, env) PCTracker.visitRelative(self, node, env)