Skip to content

Commit

Permalink
Preprocessing methods with sub objects
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Jan 20, 2025
1 parent ae272cd commit 993c583
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/cfg_methods/constants_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def insert_variables_for_constants(cfg: CFG) -> None:

insert_constants_block_list(cfg_function.blocks, constants_per_block)

sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()
if sub_object is not None:
insert_variables_for_constants(sub_object)

Expand Down
4 changes: 2 additions & 2 deletions src/cfg_methods/function_inlining.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def inline_functions(cfg: CFG) -> None:

for object_id, cfg_object in cfg.objectCFG.items():
inline_functions_cfg_object(cfg_object, cfg_object2modify[object_id])
sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
inline_functions(sub_object)
Expand All @@ -58,7 +58,7 @@ def generate_function2information(cfg: CFG) -> Dict[function_name_T, function2ca
generate_function2blocks_block_list(cfg_function.blocks, function_names, current_object2call_info)

function2blocks[object_id] = current_object2call_info
sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
function2blocks.update(generate_function2information(sub_object))
Expand Down
2 changes: 1 addition & 1 deletion src/cfg_methods/jump_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def insert_jumps_tags_cfg(cfg: CFG) -> Dict[cfg_object_T, Dict[block_id_T, int]]

combined_tags[object_id] = tags_object

sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
tags_sub_object = insert_jumps_tags_cfg(sub_object)
Expand Down
4 changes: 2 additions & 2 deletions src/cfg_methods/sub_block_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def split_blocks_cfg(cfg: CFG, tags_object: Dict[cfg_object_T, Dict[block_id_T,
for function_name, cfg_function in cfg_object.functions.items():
modify_block_list_split(cfg_function.blocks, function_names, tag_dict)

sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
split_blocks_cfg(sub_object, tags_object)
Expand Down Expand Up @@ -103,7 +103,7 @@ def combine_remove_blocks_cfg(cfg: CFG):
for function_name, cfg_function in cfg_object.functions.items():
combine_remove_blocks_block_list(cfg_function.blocks, function_names)

sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
combine_remove_blocks_cfg(sub_object)
Expand Down
2 changes: 1 addition & 1 deletion src/cfg_methods/variable_renaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def rename_variables_cfg(cfg: CFG) -> None:
for cfg_function in cfg_object.functions.values():
free_index = new_variables_function(cfg_function, free_index)

sub_object = cfg.get_subobject()
sub_object = cfg_object.get_subobject()

if sub_object is not None:
rename_variables_cfg(sub_object)
Expand Down
13 changes: 9 additions & 4 deletions src/liveness/liveness_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,19 @@ def dot_from_analysis_cfg(cfg: CFG, final_dir: Path = Path(".")) -> Dict[str, Di
return results


def dot_from_analysis(cfg: CFG, final_dir: Path = Path("."), position: int = 0) -> Dict[str, Dict[str, LivenessAnalysisInfo]]:
def dot_from_analysis(cfg: CFG, final_dir: Path = Path("."), positions: List[str] = None) -> Dict[str, Dict[str, LivenessAnalysisInfo]]:
"""
Returns the information from the liveness analysis and also stores a dot file for each analyzed structure
in "final_dir"
"""
sub_cfg = final_dir.joinpath(f"{position}")
if positions is None:
positions = ["0"]

sub_cfg = final_dir.joinpath(f"{'_'.join(positions)}")
sub_cfg.mkdir(exist_ok=True, parents=True)
# It only analyzes the code from one CFG level
analysis_cfg = dot_from_analysis_cfg(cfg, sub_cfg)
if cfg.subObjects is not None:
analysis_cfg.update(dot_from_analysis(cfg.subObjects, final_dir, position + 1))
for idx, cfg_object in enumerate(cfg.objectCFG.values()):
if cfg_object.subObject is not None:
analysis_cfg.update(dot_from_analysis(cfg_object.subObject, final_dir, positions + [str(i)]))
return analysis_cfg
4 changes: 2 additions & 2 deletions src/parser/cfg_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def __init__(self, name, blocks):
self.subObject: Optional['CFG'] = None

def set_subobject(self, subobject: 'CFG'):
self.subObjects = subobject
self.subObject = subobject

def get_subobject(self) -> 'CFG':
return self.subObjects
return self.subObject

def add_function(self, function:CFGFunction) -> None:
function_name = function.get_name()
Expand Down

0 comments on commit 993c583

Please sign in to comment.