diff --git a/tools/cc.py b/tools/cc.py index 50047cc..6a17b16 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -469,6 +469,7 @@ MulOp = make_cpu_bin_op('mul') AndOp = make_cpu_bin_op('and') OrOp = make_cpu_bin_op('or') XorOp = make_cpu_bin_op('xor') +ShrOp = make_cpu_bin_op('shr') # 2nd operand needs to be a literal class ShlOp(BinOp): scratch_need = 2 @@ -1270,6 +1271,17 @@ class CcInterp(lark.visitors.Interpreter): neq = _binary_op(NeqOp) eq = _combo(bool_not, 'neq') + def shr(self, tree): + self.visit(tree.children[0]) + left = tree.children[0].op.out + assert tree.children[1].data == 'literal' + right = tree.children[1].children[0] + dest = self.cur_fun.regs.take() + tree.op = ShrOp(self.cur_fun, [dest, left, right]) + self._synth(tree.op) + self.cur_fun.regs.give(left) + tree.type = tree.children[0].type # because uhm reasons + def _assign(self, left, right): self._log(f'assigning {left} = {right}') self.cur_fun.regs.assign(left, right)