diff options
| author | ajax <devnull@localhost> | 2014-06-12 18:40:55 +0200 |
|---|---|---|
| committer | ajax <devnull@localhost> | 2014-06-12 18:40:55 +0200 |
| commit | 0698cd3820a70182c362ba113849fe8ca5e0e032 (patch) | |
| tree | 5fd0cabf8bc3cb43a706b401906e2c49bdf127b1 | |
| parent | 8462e1b5b65b61e837e673229e1bae4dc78c7840 (diff) | |
| download | miasm-0698cd3820a70182c362ba113849fe8ca5e0e032.tar.gz miasm-0698cd3820a70182c362ba113849fe8ca5e0e032.zip | |
Simplifications_cond: Fix size issue, add constructor
I could have use a child class of ExprOp specific for conditions, but I prefer to keep a better modularity by just using "<s", "<u" as a new op I don't add the size issue in expression/expression.py (such as 'parity') because we don't want dependencies from this file to expression/simplifications_cond (for TOK_*)
Diffstat (limited to '')
| -rw-r--r-- | miasm2/expression/simplifications_cond.py | 23 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 10 |
2 files changed, 26 insertions, 7 deletions
diff --git a/miasm2/expression/simplifications_cond.py b/miasm2/expression/simplifications_cond.py index 93f28162..8f41975b 100644 --- a/miasm2/expression/simplifications_cond.py +++ b/miasm2/expression/simplifications_cond.py @@ -34,6 +34,25 @@ jok1 = m2_expr.ExprId("jok1") jok2 = m2_expr.ExprId("jok2") jok3 = m2_expr.ExprId("jok3") +# Constructors + +def __ExprOp_cond(op, arg1, arg2): + "Return an ExprOp standing for arg1 op arg2 with size to 1" + ec = m2_expr.ExprOp(op, arg1, arg2) + ec._size = 1 + return ec + + +def ExprOp_inf_signed(arg1, arg2): + "Return an ExprOp standing for arg1 <s arg2" + return __ExprOp_cond(TOK_INF_SIGNED, arg1, arg2) + + +def ExprOp_inf_unsigned(arg1, arg2): + "Return an ExprOp standing for arg1 <s arg2" + return __ExprOp_cond(TOK_INF_UNSIGNED, arg1, arg2) + + # Catching conditions forms def __check_msb(e): @@ -83,7 +102,7 @@ def expr_simp_inf_signed(expr_simp, e): sub = expr_simp(r[jok1] - r[jok2]) if new_j3 == sub: - return m2_expr.ExprOp(TOK_INF_SIGNED, r[jok1], r[jok2]) + return ExprOp_inf_signed(r[jok1], r[jok2]) else: return e @@ -107,7 +126,7 @@ def expr_simp_inf_unsigned_inversed(expr_simp, e): sub = expr_simp(r[jok1] - r[jok2]) if new_j3 == sub: - return m2_expr.ExprOp(TOK_INF_UNSIGNED, r[jok1], r[jok2]) + return ExprOp_inf_unsigned(r[jok1], r[jok2]) else: return e diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 9a4fbe8c..057ff1c7 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -4,7 +4,7 @@ from pdb import pm from miasm2.expression.expression import * from miasm2.expression.simplifications import expr_simp, ExpressionSimplifier -from miasm2.expression.simplifications_cond import TOK_INF_SIGNED, TOK_INF_UNSIGNED +from miasm2.expression.simplifications_cond import ExprOp_inf_signed, ExprOp_inf_unsigned # Define example objects a = ExprId('a') @@ -178,11 +178,11 @@ for e, e_check in to_test[:]: to_test = [ (((a - b) ^ ((a ^ b) & ((a - b) ^ a))).msb(), - ExprOp(TOK_INF_SIGNED, a, b)), + ExprOp_inf_signed(a, b)), ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b).msb(), - ExprOp(TOK_INF_UNSIGNED, a, b)), - (ExprOp(TOK_INF_UNSIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), - (ExprOp(TOK_INF_SIGNED, ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), + ExprOp_inf_unsigned(a, b)), + (ExprOp_inf_unsigned(ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), + (ExprOp_inf_signed(ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), ] expr_simp_cond = ExpressionSimplifier() |