Skip to content

Commit

Permalink
check validity arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tutugordillo committed Sep 3, 2024
1 parent 03fc79e commit a0ac491
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/parser/cfg_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, identifier : str, instructions: List[CFGInstruction], type_bl
self.function_calls = set()
self.sto_dep = []
self.mem_dep = []
self.output_var_idx = 0


def get_block_id(self) -> str:
Expand Down Expand Up @@ -117,6 +118,24 @@ def process_function_calls(self, function_ids):
calls = filter(lambda x: x in function_ids, op_names)
self.function_calls = set(calls)

def check_validity_arguments(self):
'''
It checks for each instruction in the block that there is not
any previous instruction that uses as input argument the variable
that is generating as output (there is not aliasing).
'''

for i in range(len(self._instructions)):
instr = self._instructions[i]
out_var = instr.get_out_args()
if len(out_var) > 0:
out_var_set = set(out_var)
pred_inputs = map(lambda x: set(x.get_in_args()).intersection(out_var_set),self._instructions[:i+1])
candidates = list(filter(lambda x: x != set(), pred_inputs))
if len(candidates) != 0:
print("[WARNING]: Aliasing between variables!")


def _process_dependences(self, instructions, map_positions):

sto_dep = self._compute_storage_dependences(instructions)
Expand Down Expand Up @@ -416,7 +435,6 @@ def build_spec(self, block_tags_dict: Dict, block_tag_idx: int):
print("block"+str(self.block_id)+"_"+str(cont))
# print(json.dumps(r, indent=4))


else:
r = get_empty_spec()
cont+=1
Expand Down Expand Up @@ -447,10 +465,11 @@ def build_spec(self, block_tags_dict: Dict, block_tag_idx: int):

specifications["block"+str(self.block_id)+"_"+str(cont)] = r

#Just to print information if it is not a jump
if not self._jump_type in ["conditional","unconditional"]:
pass
# print("block"+str(self.block_id)+"_"+str(cont))
# print(json.dumps(r, indent=4))
print("block"+str(self.block_id)+"_"+str(cont))
print(json.dumps(r, indent=4))


else:
r = get_empty_spec()
Expand All @@ -459,8 +478,8 @@ def build_spec(self, block_tags_dict: Dict, block_tag_idx: int):
if self._jump_type in ["conditional","unconditional"]:
r, out_idx, block_tag_idx = self._include_jump_tag(r,out_idx, block_tags_dict, block_tag_idx)
specifications["block"+str(self.block_id)+"_"+str(cont)] = r
# print("block"+str(self.block_id)+"_"+str(cont))
# print(json.dumps(r, indent=4))
print("block"+str(self.block_id)+"_"+str(cont))
print(json.dumps(r, indent=4))

return specifications, block_tag_idx

Expand Down
4 changes: 3 additions & 1 deletion src/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def parse_block(block_json: Dict[str,Any]) -> Tuple[block_id_T, CFGBlock, block_


block = CFGBlock(block_id, list_cfg_instructions, block_type, assignment_dict)


block.check_validity_arguments()

if block_type == "FunctionCall":
block.set_function_call(True)

Expand Down

0 comments on commit a0ac491

Please sign in to comment.