Skip to content

Commit

Permalink
Used InsertionOrderedSet to store undefined variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhartmann committed Jan 9, 2024
1 parent ea80464 commit 3f2b02b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions decompiler/pipeline/preprocessing/missing_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from decompiler.structures.pseudo.instructions import Assignment, Instruction, Phi, Relation
from decompiler.structures.pseudo.operations import Call, ListOperation, OperationType, UnaryOperation
from decompiler.task import DecompilerTask
from decompiler.util.insertion_ordered_set import InsertionOrderedSet
from networkx import DiGraph

from .util import _init_basicblocks_of_definition, _init_basicblocks_usages_variable, _init_maps
Expand Down Expand Up @@ -129,7 +130,7 @@ def insert_missing_definitions(self):
- Depending whether the memory-changing instruction changes the aliased-variable we insert the definition as an assignment
(no change) or a relation (change).
"""
undefined_variables: Set[Variable] = self._get_undefined_variables()
undefined_variables: InsertionOrderedSet[Variable] = self._get_undefined_variables()
variable_copies: _VariableCopyPool = _VariableCopyPool(undefined_variables | self._def_map.defined_variables)
variable_copies.sort_copies_of(*undefined_variables)

Expand All @@ -143,13 +144,13 @@ def insert_missing_definitions(self):
self._insert_definition_if_undefined(variable, previous_ssa_labels, undefined_variables)
previous_ssa_labels.add(variable.ssa_label)

def _get_undefined_variables(self) -> Set[Variable]:
def _get_undefined_variables(self) -> InsertionOrderedSet[Variable]:
"""
Compute the set of undefined variables.
-> We assume that every aliased variable has to be defined for every memory version.
"""
undefined_variables = self._use_map.used_variables - self._def_map.defined_variables
undefined_variables: InsertionOrderedSet[Variable] = self._use_map.used_variables - self._def_map.defined_variables
all_variables = self._use_map.used_variables | self._def_map.defined_variables
aliased_variables = {variable for variable in all_variables if variable.is_aliased}

Expand All @@ -160,7 +161,9 @@ def _get_undefined_variables(self) -> Set[Variable]:
undefined_variables.add(aliased_variable)
return undefined_variables

def _insert_definition_if_undefined(self, variable: Variable, previous_ssa_labels: Set[int], undefined_variables: Set[Variable]):
def _insert_definition_if_undefined(
self, variable: Variable, previous_ssa_labels: Set[int], undefined_variables: InsertionOrderedSet[Variable]
):
"""Insert definition for the given variable if it is undefined or raises an error when it is a not an aliased variable."""
if variable in undefined_variables:
if not variable.is_aliased:
Expand Down

0 comments on commit 3f2b02b

Please sign in to comment.