def __scan_util_br(self, br_index, vmap): gen_log.debug(vmap) br = InstructionFactory.parse(self.commands[br_index]) br.refresh_variable(vmap) if not br.isdirect(): gen_log.debug(br.cmp) result = self.is_cmp_valid(br.cmp) first_result = None second_result = None if result[0]: cmp_result = self.is_cmp_true(result[1], result[2], result[3]) if cmp_result: first_label = br.first_label temp_map = copy.deepcopy(vmap) first_result = self.__scan_instructs_left(first_label, temp_map) else: second_label = br.second_label temp_map = copy.deepcopy(vmap) second_result = self.__scan_instructs_left(second_label, temp_map) else: # Deal with different branches first_label = br.first_label second_label = br.second_label temp_map = copy.deepcopy(vmap) first_result = self.__scan_instructs_left(first_label, temp_map) temp_map = copy.deepcopy(vmap) second_result = self.__scan_instructs_left(second_label, temp_map) if first_result: print(first_result + "," + br.cmp) if second_result: # print(second_result + "," + self.reverse_cmp_condition(br.cmp)) # TODO Adjust to support more than two branches print(second_result) else: return self.__scan_instructs_left(br.target, vmap)
def is_cmp_valid(cmp_str): for cmp in CMP_LIST: if cmp in cmp_str: parts = cmp_str.split(cmp) left = parts[0] right = parts[1] if left.isdecimal() and right.isdecimal(): # Result like this is disgusting, but it just works return [True, cmp, left, right] return [False, cmp, left, right] gen_log.debug("There is no match cmp in " + cmp_str) return [False, None, None, None]
def __scan_util_br(self, br_index, vmap): gen_log.debug(vmap) br = InstructionFactory.parse(self.commands[br_index]) br.refresh_variable(vmap) if not br.isdirect(): gen_log.debug(br.cmp) result = self.is_cmp_valid(br.cmp) first_result = None second_result = None if result[0]: cmp_result = self.is_cmp_true(result[1], result[2], result[3]) if cmp_result: first_label = br.first_label temp_map = copy.deepcopy(vmap) first_result = self.__scan_instructs_left( first_label, temp_map) else: second_label = br.second_label temp_map = copy.deepcopy(vmap) second_result = self.__scan_instructs_left( second_label, temp_map) else: # Deal with different branches first_label = br.first_label second_label = br.second_label temp_map = copy.deepcopy(vmap) first_result = self.__scan_instructs_left( first_label, temp_map) temp_map = copy.deepcopy(vmap) second_result = self.__scan_instructs_left( second_label, temp_map) if first_result: print(first_result + "," + br.cmp) if second_result: # print(second_result + "," + self.reverse_cmp_condition(br.cmp)) # TODO Adjust to support more than two branches print(second_result) else: return self.__scan_instructs_left(br.target, vmap)