mirror of
https://github.com/cea-sec/miasm
synced 2026-06-21 13:48:18 +00:00
Add cond CC flag simplification
This commit is contained in:
@@ -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],
|
||||
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user