Implement post_decrement
This commit is contained in:
parent
abfd8d3647
commit
fbeb22df5a
16
tools/cc.py
16
tools/cc.py
@ -386,6 +386,14 @@ class Incr(UnOp):
|
||||
f'add {self.dest}, {self.operand}, {sc0}',
|
||||
f'or {self.operand}, {self.dest}, {self.dest}']
|
||||
|
||||
class Decr(UnOp):
|
||||
scratch_need = 1
|
||||
def synth(self, scratches):
|
||||
sc0 = scratches[0]
|
||||
return [f'set {sc0}, 1',
|
||||
f'sub {self.dest}, {self.operand}, {sc0}',
|
||||
f'or {self.operand}, {self.dest}, {self.dest}']
|
||||
|
||||
|
||||
class NotOp(UnOp):
|
||||
def synth(self, scratches):
|
||||
@ -853,6 +861,14 @@ class CcInterp(lark.visitors.Interpreter):
|
||||
self.cur_fun.deferred_ops.append(Incr(self.cur_fun, [reg, reg]))
|
||||
self.cur_fun.deferred_ops.append(Store(self.cur_fun, [reg, var]))
|
||||
|
||||
def post_decrement(self, tree):
|
||||
self.visit_children(tree)
|
||||
tree.op = Reg(tree.children[0].op.out)
|
||||
var = tree.children[0].var
|
||||
reg = tree.op.out
|
||||
self.cur_fun.deferred_ops.append(Decr(self.cur_fun, [reg, reg]))
|
||||
self.cur_fun.deferred_ops.append(Store(self.cur_fun, [reg, var]))
|
||||
|
||||
pre_increment = _unary_op(Incr)
|
||||
bool_not = _unary_op(BoolNot)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user