Skip to content

Commit

Permalink
Replaced setter functions with substitutes
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhartmann committed Nov 16, 2023
1 parent 7799db5 commit b4cfe63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
19 changes: 11 additions & 8 deletions decompiler/pipeline/controlflowanalysis/loop_utility_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
Variable,
)
from decompiler.structures.visitors.assignment_visitor import AssignmentVisitor
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.sub_to_add import SubToAdd
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.term_order import TermOrder
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.rule import SimplificationRule


@dataclass
Expand Down Expand Up @@ -257,7 +260,7 @@ def _get_continue_nodes_with_equalizable_definition(
):
return None

_unify_binary_operation(continuation.instruction.value)
_unify_binary_operation_in_assignment(continuation.instruction)
equalizable_nodes.append(code_node)
return equalizable_nodes

Expand Down Expand Up @@ -289,14 +292,14 @@ def _count_unaryoperations_negations(expression: Expression) -> int:
return negations


def _unify_binary_operation(binaryoperation: BinaryOperation):
"""Brings a simple binary operation into a unified representation like 'var + const'."""
if not binaryoperation.operation == OperationType.plus:
binaryoperation.operation = OperationType.plus
binaryoperation.substitute(binaryoperation.right, UnaryOperation(OperationType.negate, [binaryoperation.right]))
def _unify_binary_operation_in_assignment(assignment: Assignment):
"""Brings a simple binary operation of an assignment into a unified representation like 'var = -var + const' instead of 'var = const - var'."""
if not assignment.value.operation == OperationType.plus:
assignment.substitute(assignment.value, BinaryOperation(OperationType.plus, [assignment.value.left, assignment.value.right]))
assignment.substitute(assignment.value.right, UnaryOperation(OperationType.negate, [assignment.value.right]))

if any(isinstance(operand, Constant) for operand in binaryoperation.left.subexpressions()):
binaryoperation.swap_operands()
if any(isinstance(operand, Constant) for operand in assignment.value.left.subexpressions()):
assignment.substitute(assignment.value, BinaryOperation(OperationType.plus, [assignment.value.right, assignment.value.left]))


def _substract_continuation_from_last_definition(code_node: CodeNode, continuation: AstInstruction, variable_init: AstInstruction):
Expand Down
9 changes: 0 additions & 9 deletions decompiler/structures/pseudo/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,6 @@ def right(self) -> Expression:
"""Return the right-hand-side operand."""
return self._operands[1]

@Operation.operation.setter
def operation(self, value):
"""Setter function for operation."""
self._operation = value

def copy(self) -> BinaryOperation:
"""Generate a deep copy of the current binary operation."""
return self.__class__(self._operation, [operand.copy() for operand in self._operands], self._type.copy(), self.tags)
Expand All @@ -469,10 +464,6 @@ def accept(self, visitor: DataflowObjectVisitorInterface[T]) -> T:
"""Invoke the appropriate visitor for this Operation."""
return visitor.visit_binary_operation(self)

def swap_operands(self):
"""Swaps left-hand-side with right-hand-side operand."""
self._operands[0], self._operands[1] = self._operands[1], self._operands[0]


class Call(Operation):
"""Class representing a Call operation"""
Expand Down

0 comments on commit b4cfe63

Please sign in to comment.