def update_lvalue(new_ir, node, local_variables_instances, all_local_variables_instances, state_variables_instances, all_state_variables_instances): if isinstance(new_ir, OperationWithLValue): lvalue = new_ir.lvalue update_through_ref = False if isinstance(new_ir, (Assignment, Binary)): if isinstance(lvalue, ReferenceVariable): update_through_ref = True while isinstance(lvalue, ReferenceVariable): lvalue = lvalue.points_to if isinstance(lvalue, (LocalIRVariable, StateIRVariable)): if isinstance(lvalue, LocalIRVariable): new_var = LocalIRVariable(lvalue) new_var.index = all_local_variables_instances[ lvalue.name].index + 1 all_local_variables_instances[lvalue.name] = new_var local_variables_instances[lvalue.name] = new_var else: new_var = StateIRVariable(lvalue) new_var.index = all_state_variables_instances[ lvalue.canonical_name].index + 1 all_state_variables_instances[lvalue.canonical_name] = new_var state_variables_instances[lvalue.canonical_name] = new_var if update_through_ref: phi_operation = Phi(new_var, {node}) phi_operation.rvalues = [lvalue] node.add_ssa_ir(phi_operation) if not isinstance(new_ir.lvalue, ReferenceVariable): new_ir.lvalue = new_var else: to_update = new_ir.lvalue while isinstance(to_update.points_to, ReferenceVariable): to_update = to_update.points_to to_update.points_to = new_var
def initiate_all_local_variables_instances(nodes, local_variables_instances, all_local_variables_instances): for node in nodes: if node.variable_declaration: new_var = LocalIRVariable(node.variable_declaration) if new_var.name in all_local_variables_instances: new_var.index = all_local_variables_instances[new_var.name].index + 1 local_variables_instances[node.variable_declaration.name] = new_var all_local_variables_instances[node.variable_declaration.name] = new_var