diff options
author | chriseth <chris@ethereum.org> | 2018-02-06 19:20:00 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-02-07 05:51:30 +0800 |
commit | c961a3079dda8735363872cdb84c489d61846003 (patch) | |
tree | 8048fd3fbdd4f14031255344bfa1375a18d83e0f /libevmasm/RuleList.h | |
parent | 5523296eaa68a591a331d9b75dc19cf11d1c538e (diff) | |
download | dexon-solidity-c961a3079dda8735363872cdb84c489d61846003.tar.gz dexon-solidity-c961a3079dda8735363872cdb84c489d61846003.tar.zst dexon-solidity-c961a3079dda8735363872cdb84c489d61846003.zip |
Turn simplification rule tuple into struct.
Diffstat (limited to 'libevmasm/RuleList.h')
-rw-r--r-- | libevmasm/RuleList.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index f8a6ce73..2312d673 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -25,6 +25,7 @@ #include <functional> #include <libevmasm/Instruction.h> +#include <libevmasm/SimplificationRule.h> #include <libdevcore/CommonData.h> @@ -45,12 +46,10 @@ template <class S> S modWorkaround(S const& _a, S const& _b) /// @returns a list of simplification rules given certain match placeholders. /// A, B and C should represent constants, X and Y arbitrary expressions. -/// The third element in the tuple is a boolean flag that indicates whether -/// any non-constant elements in the pattern are removed by applying it. /// The simplifications should neven change the order of evaluation of -/// arbitrary operations, though. +/// arbitrary operations. template <class Pattern> -std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> simplificationRuleList( +std::vector<SimplificationRule<Pattern>> simplificationRuleList( Pattern A, Pattern B, Pattern C, @@ -58,8 +57,8 @@ std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> simplificationR Pattern Y ) { - std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> rules; - rules += std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>>{ + std::vector<SimplificationRule<Pattern>> rules; + rules += std::vector<SimplificationRule<Pattern>>{ // arithmetics on constants {{Instruction::ADD, {A, B}}, [=]{ return A.d() + B.d(); }, false}, {{Instruction::MUL, {A, B}}, [=]{ return A.d() * B.d(); }, false}, @@ -196,7 +195,7 @@ std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> simplificationR // xa can be (X, A) or (A, X) for (auto xa: {std::vector<Pattern>{X, A}, std::vector<Pattern>{A, X}}) { - rules += std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>>{{ + rules += std::vector<SimplificationRule<Pattern>>{{ // (X+A)+B -> X+(A+B) {op, {{op, xa}, B}}, [=]() -> Pattern { return {op, {X, fun(A.d(), B.d())}}; }, @@ -221,7 +220,7 @@ std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> simplificationR } // move constants across subtractions - rules += std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>>{ + rules += std::vector<SimplificationRule<Pattern>>{ { // X - A -> X + (-A) {Instruction::SUB, {X, A}}, |