From a0ac491e1519b476a15b425a389d898c0c560904 Mon Sep 17 00:00:00 2001 From: tutugordillo Date: Tue, 3 Sep 2024 11:55:59 +0200 Subject: [PATCH] check validity arguments --- src/parser/cfg_block.py | 31 +++++++++++++++++++++++++------ src/parser/parser.py | 4 +++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/parser/cfg_block.py b/src/parser/cfg_block.py index 768dd644..127dfd2c 100644 --- a/src/parser/cfg_block.py +++ b/src/parser/cfg_block.py @@ -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: @@ -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) @@ -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 @@ -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() @@ -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 diff --git a/src/parser/parser.py b/src/parser/parser.py index 4db87001..ff7128c9 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -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)