diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-14 21:49:55 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-09-18 20:28:21 +0800 |
commit | a1d73a7befd2f3d72c18d4cb539edab5111c681f (patch) | |
tree | bd440467d4d2f4d2c275b47f51057933cac2aaef /libevmasm/RuleList.h | |
parent | 06ffcd0502c1c06788bec9b1e1e4db3f7c42ed4d (diff) | |
download | dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar.gz dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar.bz2 dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar.lz dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar.xz dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.tar.zst dexon-solidity-a1d73a7befd2f3d72c18d4cb539edab5111c681f.zip |
Split simplification rules into two functions.
Diffstat (limited to 'libevmasm/RuleList.h')
-rw-r--r-- | libevmasm/RuleList.h | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 0573856b..874a8929 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -44,12 +44,11 @@ template <class S> S modWorkaround(S const& _a, S const& _b) return (S)(bigint(_a) % bigint(_b)); } -/// @returns a list of simplification rules given certain match placeholders. -/// A, B and C should represent constants, X and Y arbitrary expressions. -/// The simplifications should never change the order of evaluation of -/// arbitrary operations. +// This part of simplificationRuleList below was split out to prevent +// stack overflows in the JavaScript optimizer for emscripten builds +// that affected certain browser versions. template <class Pattern> -std::vector<SimplificationRule<Pattern>> simplificationRuleList( +std::vector<SimplificationRule<Pattern>> simplificationRuleListPart1( Pattern A, Pattern B, Pattern C, @@ -57,8 +56,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList( Pattern Y ) { - std::vector<SimplificationRule<Pattern>> rules; - rules += std::vector<SimplificationRule<Pattern>>{ + return std::vector<SimplificationRule<Pattern>> { // arithmetic on constants {{Instruction::ADD, {A, B}}, [=]{ return A.d() + B.d(); }, false}, {{Instruction::MUL, {A, B}}, [=]{ return A.d() * B.d(); }, false}, @@ -162,6 +160,22 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList( {{Instruction::OR, {X, {Instruction::NOT, {X}}}}, [=]{ return ~u256(0); }, true}, {{Instruction::OR, {{Instruction::NOT, {X}}, X}}, [=]{ return ~u256(0); }, true}, }; +} + + +// This part of simplificationRuleList below was split out to prevent +// stack overflows in the JavaScript optimizer for emscripten builds +// that affected certain browser versions. +template <class Pattern> +std::vector<SimplificationRule<Pattern>> simplificationRuleListPart2( + Pattern A, + Pattern B, + Pattern, + Pattern X, + Pattern Y +) +{ + std::vector<SimplificationRule<Pattern>> rules; // Replace MOD X, <power-of-two> with AND X, <power-of-two> - 1 for (size_t i = 0; i < 256; ++i) @@ -292,5 +306,24 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList( return rules; } +/// @returns a list of simplification rules given certain match placeholders. +/// A, B and C should represent constants, X and Y arbitrary expressions. +/// The simplifications should never change the order of evaluation of +/// arbitrary operations. +template <class Pattern> +std::vector<SimplificationRule<Pattern>> simplificationRuleList( + Pattern A, + Pattern B, + Pattern C, + Pattern X, + Pattern Y +) +{ + std::vector<SimplificationRule<Pattern>> rules; + rules += simplificationRuleListPart1(A, B, C, X, Y); + rules += simplificationRuleListPart2(A, B, C, X, Y); + return rules; +} + } } |