Fix if-else regs
This commit is contained in:
parent
64d440c94b
commit
f3928f52a4
11
tools/cc.py
11
tools/cc.py
@ -186,6 +186,15 @@ class RegBank:
|
||||
if var1 is not None:
|
||||
self.loaded(var1, reg0)
|
||||
|
||||
def snap(self):
|
||||
return dict(self.vars), dict(self.cleanup)
|
||||
|
||||
def restore(self, snap):
|
||||
self.reset()
|
||||
vardict, cleanup = snap
|
||||
for var, reg in vardict.items():
|
||||
self.loaded(var, reg, cleanup=cleanup.get(reg, None))
|
||||
|
||||
@contextlib.contextmanager
|
||||
def borrow(self, howmany):
|
||||
regs = [self.take() for i in range(howmany)]
|
||||
@ -775,8 +784,10 @@ class CcInterp(lark.visitors.Interpreter):
|
||||
has_else = len(tree.children) > 2
|
||||
op = IfOp(self.cur_fun, [tree.children[0].op.out, mark, has_else])
|
||||
self._synth(op)
|
||||
begin_vars = self.cur_fun.regs.snap()
|
||||
self.visit(tree.children[1])
|
||||
if has_else:
|
||||
self.cur_fun.regs.restore(begin_vars)
|
||||
self.cur_fun.ops.append(op.synth_else)
|
||||
self.visit(tree.children[2])
|
||||
self.cur_fun.ops.append(op.synth_endif)
|
||||
|
Loading…
Reference in New Issue
Block a user