def make_il(self, il_code, symbol_table, c): """Make code for this node.""" left = self.left.make_il(il_code, symbol_table, c) right = self.right.make_il(il_code, symbol_table, c) if self._check_type(left, right): left, right = arith_convert(left, right, il_code) if left.literal and right.literal: # If NotImplementedError is raised, continue with execution. try: val = self._arith_const( shift_into_range(left.literal.val, left.ctype), shift_into_range(right.literal.val, right.ctype), left.ctype) out = ILValue(left.ctype) il_code.register_literal_var(out, val) return out except NotImplementedError: pass return self._arith(left, right, il_code) else: return self._nonarith(left, right, il_code)
def make_il(self, il_code, symbol_table, c): """Make code for this node.""" left = self.left.make_il(il_code, symbol_table, c) right = self.right.make_il(il_code, symbol_table, c) if self._check_type(left, right): left, right = arith_convert(left, right, il_code) if left.literal and right.literal: # If NotImplementedError is raised, continue with execution. try: val = self._arith_const( shift_into_range(left.literal.val, left.ctype), shift_into_range(right.literal.val, right.ctype), left.ctype) out = ILValue(left.ctype) il_code.register_literal_var(out, val) return out except NotImplementedError: pass return self._arith(left, right, il_code) else: return self._nonarith(left, right, il_code)
def make_il(self, il_code, symbol_table, c): """Make code for this node.""" expr = self.expr.make_il(il_code, symbol_table, c) if not self._check_type(expr): err = f"{self.descrip} requires {self.opnd_descrip} type operand" raise CompilerError(err, self.expr.r) # perform integer promotion if expr.ctype.size < 4: expr = set_type(expr, ctypes.integer, il_code) if self.cmd: out = ILValue(expr.ctype) # perform constant folding if expr.literal: val = self._arith_const(expr.literal.val, expr.ctype) val = shift_into_range(val, expr.ctype) il_code.register_literal_var(out, val) else: il_code.add(self.cmd(out, expr)) return out return expr
def make_il(self, il_code, symbol_table, c): """Make code for this node.""" expr = self.expr.make_il(il_code, symbol_table, c) if not self._check_type(expr): err = f"{self.descrip} requires {self.opnd_descrip} type operand" raise CompilerError(err, self.expr.r) # perform integer promotion if expr.ctype.size < 4: expr = set_type(expr, ctypes.integer, il_code) if self.cmd: out = ILValue(expr.ctype) # perform constant folding if expr.literal: val = self._arith_const(expr.literal.val, expr.ctype) val = shift_into_range(val, expr.ctype) il_code.register_literal_var(out, val) else: il_code.add(self.cmd(out, expr)) return out return expr
def _arith_const(self, expr, ctype): return ~shift_into_range(expr, ctype)
def _arith_const(self, left, right, ctype): return shift_into_range(int(left / right), ctype)
def _arith_const(self, left, right, ctype): return shift_into_range(int(left / right), ctype)
def _arith_const(self, expr, ctype): return ~shift_into_range(expr, ctype)