Skip to content

Commit

Permalink
complete lexical environment related instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Penkace committed Jan 19, 2025
1 parent 6d9bb6a commit 7a5bf1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions ohre/abcre/dis/DisFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def get_external_module_name(
return None

def create_lexical_environment(
self, slots: int, file_class_method_name: str = "", literal_id=None) -> Union[str, None]:
self, slots: int, literal_id=None) -> Union[str, None]:
slots_number = slots
lex_env_layer = [None] * slots_number
if literal_id:
Expand All @@ -281,12 +281,16 @@ def create_lexical_environment(
variable_value = literal_value[1].replace('"', '')
else:
Log.warn(f"newlexenvwithname failed. literal id format is {literal_content[cnt]}")
variable_name = literal_content[cnt+1].strip()
lex_env_layer[i] = variable_value
variable_name = literal_content[cnt+1].strip().split(':')
if len(variable_name)==2:
variable_name = variable_name[1].replace('"','')
else:
Log.warn(f"newlexenvwithname failed. literal id format is {literal_content[cnt+1]}")
lex_env_layer[i] = f"[variable: {variable_name} value: {variable_value}]"
cnt += 2
self.lex_env.append(lex_env_layer)
self.cur_lex_level += 1
return self.cur_lex_level
return self.lex_env[-1]

def get_lex_env(
self, lexenv_layer: int, slot_index: int
Expand Down
7 changes: 4 additions & 3 deletions ohre/abcre/dis/NACtoTAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ def toTAC(self, nac: NAC, meth: AsmMethod, dis_file: DisFile) -> Union[TAC, List
return TAC.tac_assign(AsmArg.ACC(), arg_obj, log="createobjectwithbuffer d3bug")
if (nac.op == "newlexenv"):
slots = int(nac.args[0], base=16)
cur_lexenv_level = dis_file.create_lexical_environment(slots, meth.file_class_method_name)
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.LEXENV, value=cur_lexenv_level))
cur_lex_env = dis_file.create_lexical_environment(slots)
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.LEXENV, value=str(cur_lex_env)))
if (nac.op == "newlexenvwithname"):
slots = int(nac.args[0], base=16)
literal_id = nac.args[1]
cur_lexenv_level = dis_file.create_lexical_environment(slots,meth.file_class_method_name,literal_id=literal_id)
cur_lex_env = dis_file.create_lexical_environment(slots,literal_id=literal_id)
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.LEXENV, value=str(cur_lex_env)))
# === inst: object creaters # END

# === inst: object visitors # START
Expand Down

0 comments on commit 7a5bf1b

Please sign in to comment.