Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _ail_handle_Add(self, expr):
operand_0 = self._expr(expr.operands[0])
operand_1 = self._expr(expr.operands[1])
if isinstance(operand_0, Expr.Const) and isinstance(operand_1, Expr.Const):
return Expr.Const(expr.idx, None, operand_0.value + operand_1.value, expr.bits)
elif isinstance(operand_0, Expr.BasePointerOffset) and isinstance(operand_1, Expr.Const):
r = operand_0.copy()
r.offset += operand_1.value
return r
return Expr.BinaryOp(expr.idx, 'Add', [operand_0 if operand_0 is not None else expr.operands[0],
operand_1 if operand_1 is not None else expr.operands[1]
])
self._link_variables_on_expr(variable_manager, block, stmt_idx, stmt, expr.operands[0])
self._link_variables_on_expr(variable_manager, block, stmt_idx, stmt, expr.operands[1])
elif type(expr) is ailment.Expr.UnaryOp:
variables = variable_manager.find_variables_by_atom(block.addr, stmt_idx, expr)
if len(variables) == 1:
var, offset = next(iter(variables))
expr.referenced_variable = var
expr.offset = offset
else:
self._link_variables_on_expr(variable_manager, block, stmt_idx, stmt, expr.operands)
elif type(expr) is ailment.Expr.Convert:
self._link_variables_on_expr(variable_manager, block, stmt_idx, stmt, expr.operand)
elif isinstance(expr, ailment.Expr.BasePointerOffset):
variables = variable_manager.find_variables_by_atom(block.addr, stmt_idx, expr)
if len(variables) == 1:
var, offset = next(iter(variables))
expr.referenced_variable = var
expr.offset = offset