|
|
@ -84,24 +84,35 @@ ExpressionClasses::Id ExpressionClasses::find( |
|
|
|
bool ExpressionClasses::knownToBeDifferent(ExpressionClasses::Id _a, ExpressionClasses::Id _b) |
|
|
|
{ |
|
|
|
// Try to simplify "_a - _b" and return true iff the value is a non-zero constant.
|
|
|
|
map<unsigned, Expression const*> matchGroups; |
|
|
|
Pattern constant(Push); |
|
|
|
constant.setMatchGroup(1, matchGroups); |
|
|
|
Id difference = find(Instruction::SUB, {_a, _b}); |
|
|
|
return constant.matches(representative(difference), *this) && constant.d() != u256(0); |
|
|
|
return knownNonZero(find(Instruction::SUB, {_a, _b})); |
|
|
|
} |
|
|
|
|
|
|
|
bool ExpressionClasses::knownToBeDifferentBy32(ExpressionClasses::Id _a, ExpressionClasses::Id _b) |
|
|
|
{ |
|
|
|
// Try to simplify "_a - _b" and return true iff the value is at least 32 away from zero.
|
|
|
|
u256 const* v = knownConstant(find(Instruction::SUB, {_a, _b})); |
|
|
|
// forbidden interval is ["-31", 31]
|
|
|
|
return v && *v + 31 > u256(62); |
|
|
|
} |
|
|
|
|
|
|
|
bool ExpressionClasses::knownZero(Id _c) |
|
|
|
{ |
|
|
|
return Pattern(u256(0)).matches(representative(_c), *this); |
|
|
|
} |
|
|
|
|
|
|
|
bool ExpressionClasses::knownNonZero(Id _c) |
|
|
|
{ |
|
|
|
return Pattern(u256(0)).matches(representative(find(Instruction::ISZERO, {_c})), *this); |
|
|
|
} |
|
|
|
|
|
|
|
u256 const* ExpressionClasses::knownConstant(Id _c) |
|
|
|
{ |
|
|
|
map<unsigned, Expression const*> matchGroups; |
|
|
|
Pattern constant(Push); |
|
|
|
constant.setMatchGroup(1, matchGroups); |
|
|
|
Id difference = find(Instruction::SUB, {_a, _b}); |
|
|
|
if (!constant.matches(representative(difference), *this)) |
|
|
|
return false; |
|
|
|
// forbidden interval is ["-31", 31]
|
|
|
|
return constant.d() + 31 > u256(62); |
|
|
|
if (!constant.matches(representative(_c), *this)) |
|
|
|
return nullptr; |
|
|
|
return &constant.d(); |
|
|
|
} |
|
|
|
|
|
|
|
string ExpressionClasses::fullDAGToString(ExpressionClasses::Id _id) const |
|
|
|