diff options
| author | Ivan “CLOVIS” Canet <ivan.canet@gmail.com> | 2022-03-15 14:35:13 +0100 |
|---|---|---|
| committer | Ivan “CLOVIS” Canet <ivan.canet@gmail.com> | 2022-03-15 14:35:13 +0100 |
| commit | e71c3152d1e57a95b5243e7d4c814eed4bad870a (patch) | |
| tree | 03580c2c18f002146bde0013e4d84ff4910d416d /example/expression/simplification_add.py | |
| parent | b9ecc43cf5ae1583cb9a1e053bac5be2e6c68aa0 (diff) | |
| download | focaccia-miasm-e71c3152d1e57a95b5243e7d4c814eed4bad870a.tar.gz focaccia-miasm-e71c3152d1e57a95b5243e7d4c814eed4bad870a.zip | |
Fixed no-op in example/expression/simplification_add
Previously, the test would not do anything, as the simplification added in the test is already a part of the default enabled simplifications: ``` Without adding the simplification: a + a + a = a * 0x3 After adding the simplification: a + a + a = a * 0x3 ``` This also meant that editing the added simplification would have no effect (since the expression was already modified by the default simplifier, it would never match the custom one). This commit replaces `expr_simp` by a newly-created `simp` that doesn't have any simplifications enabled, so the one added by the test has an impact.
Diffstat (limited to 'example/expression/simplification_add.py')
| -rw-r--r-- | example/expression/simplification_add.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/example/expression/simplification_add.py b/example/expression/simplification_add.py index ff28d56e..c24c15e3 100644 --- a/example/expression/simplification_add.py +++ b/example/expression/simplification_add.py @@ -1,7 +1,11 @@ from __future__ import print_function + import miasm.expression.expression as m2_expr -from miasm.expression.simplifications import expr_simp -from pdb import pm +from miasm.expression.simplifications import ExpressionSimplifier + +# Creates an expression simplifier that (by default) applies no simplifications. +# Other instances with simplifications enabled by default can be found in `expressions/simplifications.py`. +simp = ExpressionSimplifier() print(""" Expression simplification demo: Adding a simplification: @@ -10,6 +14,7 @@ a + a + a == a * 3 More detailed examples can be found in miasm/expression/simplification*. """) + # Define the simplification method ## @expr_simp is the current expression simplifier instance ## (for recursive simplifications) @@ -31,17 +36,17 @@ def simp_add_mul(expr_simp, expr): # Do not simplify return expr + a = m2_expr.ExprId('a', 32) base_expr = a + a + a print("Without adding the simplification:") -print("\t%s = %s" % (base_expr, expr_simp(base_expr))) +print("\t%s = %s" % (base_expr, simp(base_expr))) # Enable pass -expr_simp.enable_passes({m2_expr.ExprOp: [simp_add_mul]}) +simp.enable_passes({m2_expr.ExprOp: [simp_add_mul]}) print("After adding the simplification:") -print("\t%s = %s" % (base_expr, expr_simp(base_expr))) +print("\t%s = %s" % (base_expr, simp(base_expr))) -# Automatic fail -assert(expr_simp(base_expr) == m2_expr.ExprOp("*", a, - m2_expr.ExprInt(3, a.size))) +assert simp(base_expr) == m2_expr.ExprOp("*", a, + m2_expr.ExprInt(3, a.size)) |