Skip to content

Commit

Permalink
include code for considering if a push that comes from a memory guard…
Browse files Browse the repository at this point in the history
… has been generated previously
  • Loading branch information
tutugordillo committed Oct 9, 2024
1 parent 74f9c7c commit f3f9b7e
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/parser/cfg_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,32 +384,49 @@ def _build_spec_for_sequence(self, instructions, map_instructions: Dict, out_idx
jump_instr = ins
continue

# TODO: temporal fix for PUSH instructions obtained through translating "memoryguard"
elif ins.get_op_name() == "push":
in_val = int(ins.builtin_args[0])
str_in_val = hex(in_val)
push_name = "PUSH" if in_val != 0 else "PUSH0"
inst_idx = instrs_idx.get(push_name, 0)
instrs_idx[push_name] = inst_idx + 1
push_ins = build_push_spec(str_in_val, inst_idx, [ins.get_out_args()[0]])
# # TODO: temporal fix for PUSH instructions obtained through translating "memoryguard"
# elif ins.get_op_name() == "push":
# in_val = int(ins.builtin_args[0])
# str_in_val = hex(in_val)
# push_name = "PUSH" if in_val != 0 else "PUSH0"
# inst_idx = instrs_idx.get(push_name, 0)
# instrs_idx[push_name] = inst_idx + 1
# push_ins = build_push_spec(str_in_val, inst_idx, [ins.get_out_args()[0]])

map_instructions[("PUSH", tuple([str_in_val]))] = push_ins
# map_instructions[("PUSH", tuple([str_in_val]))] = push_ins

uninter_functions.append(push_ins)
# uninter_functions.append(push_ins)

map_positions_instructions[i] = push_ins["id"]
# map_positions_instructions[i] = push_ins["id"]

continue
# continue

ins_spec = map_instructions.get((ins.get_op_name().upper(), tuple(ins.get_in_args())), None)
if ins.get_op_name().startswith("push"):
ins_spec = map_instructions.get((ins.get_op_name().upper(), tuple(ins.get_builtin_args())), None)
else:
ins_spec = map_instructions.get((ins.get_op_name().upper(), tuple(ins.get_in_args())), None)

if ins_spec is None:
result, new_out_idx = ins.build_spec(new_out_idx, instrs_idx, map_instructions)

uninter_functions += result

map_positions_instructions[i] = result[-1]["id"]


elif ins.get_op_name() == "push": #it is a push value that has been already created. If it comes from a memoryguard we have to rename the previous instructions to the output of the memoryguard
out_var_list = ins_spec["outpt_sk"]
new_out_var_list = ins.get_out_args()

ins_spec["outpt_sk"] = new_out_var_list

out_var = out_var_list[0]
new_out_var = new_out_var_list[0]

candidate_instructions = filter(lambda x: out_var in x["inpt_sk"],uninter_functions)
for uninter in candidate_instructions:
pos = uninter["inpt_sk"].index(out_var)
uninter["inpt_sk"][pos] = new_out_var

assignment2stack_var = dict()
# Assignments might be generated from phi functions
for out_val, in_val in self.assignment_dict.items():
Expand Down

0 comments on commit f3f9b7e

Please sign in to comment.