diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2020-06-25 13:41:24 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2020-06-25 13:41:24 +0200 |
| commit | ce175bb51b8d391ea0da2ef1396b79b495b8cdf5 (patch) | |
| tree | 6fa89ff7a6e0df5df12e8b7801e9cfbbf01b2aed | |
| parent | b54727ab6a8c2764fd2f2e42cb3020f41c4cb772 (diff) | |
| download | miasm-ce175bb51b8d391ea0da2ef1396b79b495b8cdf5.tar.gz miasm-ce175bb51b8d391ea0da2ef1396b79b495b8cdf5.zip | |
Add cond CC flag simplification
| -rw-r--r-- | miasm/expression/simplifications.py | 1 | ||||
| -rw-r--r-- | miasm/expression/simplifications_common.py | 20 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 25 |
3 files changed, 46 insertions, 0 deletions
diff --git a/miasm/expression/simplifications.py b/miasm/expression/simplifications.py index 3f54b158..c65b2b7b 100644 --- a/miasm/expression/simplifications.py +++ b/miasm/expression/simplifications.py @@ -86,6 +86,7 @@ class ExpressionSimplifier(ExprVisitorCallbackBottomToTop): simplifications_common.simp_cond_logic_ext, simplifications_common.simp_cond_sign_bit, simplifications_common.simp_cond_eq_1_0, + simplifications_common.simp_cond_cc_flag, ], m2_expr.ExprMem: [simplifications_common.simp_mem], diff --git a/miasm/expression/simplifications_common.py b/miasm/expression/simplifications_common.py index 932db49a..dc9fadea 100644 --- a/miasm/expression/simplifications_common.py +++ b/miasm/expression/simplifications_common.py @@ -919,6 +919,26 @@ def simp_sub_cf_zero(_, expr): return expr return ExprCond(expr.args[1], ExprInt(1, 1), ExprInt(0, 1)) +def simp_cond_cc_flag(expr_simp, expr): + """ + ExprCond(CC_><(bit), X, Y) => ExprCond(bit, X, Y) + ExprCond(CC_U>=(bit), X, Y) => ExprCond(bit, Y, X) + """ + if not expr.is_cond(): + return expr + if not expr.cond.is_op(): + return expr + expr_op = expr.cond + if expr_op.op not in ["CC_U<", "CC_U>="]: + return expr + arg = expr_op.args[0] + if arg.size != 1: + return expr + if expr_op.op == "CC_U<": + return ExprCond(arg, expr.src1, expr.src2) + if expr_op.op == "CC_U>=": + return ExprCond(arg, expr.src2, expr.src1) + return expr def simp_cmp_int(expr_simp, expr): """ diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 1f243425..c75dc0d3 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -784,6 +784,31 @@ to_test = [ ExprOp(TOK_EQUAL, a, i0) ), + + ( + ExprCond( + ExprOp("CC_U<", a[0:1]), + b, c + ), + ExprCond( + a[0:1], + b, c + ), + ), + + ( + ExprCond( + ExprOp("CC_U>=", a[0:1]), + b, c + ), + ExprCond( + a[0:1], + c, b + ), + ), + + + ] for e_input, e_check in to_test: |