Skip to content

Commit

Permalink
Rename CollectTerms to CollapseNestedConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
rihi committed Sep 20, 2023
1 parent 182913a commit 9207491
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from decompiler.structures.pseudo.operations import COMMUTATIVE_OPERATIONS


class CollectTerms(SimplificationRule):
class CollapseNestedConstants(SimplificationRule):
"""
This rule walks the dafaflow tree and collects and folds constants in commutative operations.
The first constant of the tree is replaced with the folded result and all remaining constants are replaced with the identity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decompiler.backend.cexpressiongenerator import CExpressionGenerator
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_add_neg import CollapseAddNeg
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_constants import CollapseConstants
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collect_terms import CollectTerms
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_nested_constants import CollapseNestedConstants
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.positive_constants import PositiveConstants
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.rule import SimplificationRule
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.simplify_redundant_reference import SimplifyRedundantReference
Expand Down Expand Up @@ -161,7 +161,7 @@ def _get_instructions(self, task: DecompilerTask) -> list[Instruction]:
SimplifyTrivialLogicArithmetic(),
SimplifyTrivialShift(),
CollapseConstants(),
CollectTerms(),
CollapseNestedConstants(),
]
_post_rules: list[SimplificationRule] = [
CollapseAddNeg(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collect_terms import CollectTerms
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_nested_constants import CollapseNestedConstants
from decompiler.structures.pseudo import BinaryOperation, Constant, Expression, Integer, Operation, OperationType, Variable
from decompiler.structures.visitors.substitute_visitor import SubstituteVisitor

Expand Down Expand Up @@ -132,7 +132,7 @@ def _bit_or(e0: Expression, e1: Expression) -> BinaryOperation:
],
)
def test_collect_terms(operation: Operation, possible_results: set[Expression]):
collect_terms = CollectTerms()
collect_terms = CollapseNestedConstants()

for i in range(100):
substitutions = collect_terms.apply(operation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_constants import CollapseConstants
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collect_terms import CollectTerms
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.collapse_nested_constants import CollapseNestedConstants
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.rule import SimplificationRule
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.simplify_trivial_arithmetic import SimplifyTrivialArithmetic
from decompiler.pipeline.controlflowanalysis.expression_simplification.rules.sub_to_add import SubToAdd
Expand Down Expand Up @@ -59,7 +59,7 @@ def _v_i32(name: str) -> Variable:
Assignment(_v_i32("a"), _c_i32(5))
),
(
[SubToAdd(), CollectTerms(), SimplifyTrivialArithmetic()],
[SubToAdd(), CollapseNestedConstants(), SimplifyTrivialArithmetic()],
Assignment(_v_i32("a"), _sub(_add(_v_i32("a"), _c_i32(5)), _c_i32(5))),
Assignment(_v_i32("a"), _v_i32("a"))
),
Expand Down

0 comments on commit 9207491

Please sign in to comment.