aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia/optimiser
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-06 19:20:00 +0800
committerchriseth <chris@ethereum.org>2018-02-07 05:51:30 +0800
commitc961a3079dda8735363872cdb84c489d61846003 (patch)
tree8048fd3fbdd4f14031255344bfa1375a18d83e0f /libjulia/optimiser
parent5523296eaa68a591a331d9b75dc19cf11d1c538e (diff)
downloaddexon-solidity-c961a3079dda8735363872cdb84c489d61846003.tar.gz
dexon-solidity-c961a3079dda8735363872cdb84c489d61846003.tar.zst
dexon-solidity-c961a3079dda8735363872cdb84c489d61846003.zip
Turn simplification rule tuple into struct.
Diffstat (limited to 'libjulia/optimiser')
-rw-r--r--libjulia/optimiser/ExpressionSimplifier.cpp4
-rw-r--r--libjulia/optimiser/SimplificationRules.cpp10
-rw-r--r--libjulia/optimiser/SimplificationRules.h9
3 files changed, 12 insertions, 11 deletions
diff --git a/libjulia/optimiser/ExpressionSimplifier.cpp b/libjulia/optimiser/ExpressionSimplifier.cpp
index bdcf3168..3d471cb3 100644
--- a/libjulia/optimiser/ExpressionSimplifier.cpp
+++ b/libjulia/optimiser/ExpressionSimplifier.cpp
@@ -43,8 +43,8 @@ void ExpressionSimplifier::visit(Expression& _expression)
// Do not apply the rule if it removes non-constant parts of the expression.
// TODO: The check could actually be less strict than "movable".
// We only require "Does not cause side-effects".
- if (std::get<2>(*match) && !MovableChecker(_expression).movable())
+ if (match->removesNonConstants && !MovableChecker(_expression).movable())
return;
- _expression = std::get<1>(*match)().toExpression(locationOf(_expression));
+ _expression = match->action().toExpression(locationOf(_expression));
}
}
diff --git a/libjulia/optimiser/SimplificationRules.cpp b/libjulia/optimiser/SimplificationRules.cpp
index 234efea0..a439caef 100644
--- a/libjulia/optimiser/SimplificationRules.cpp
+++ b/libjulia/optimiser/SimplificationRules.cpp
@@ -34,7 +34,7 @@ using namespace dev;
using namespace dev::julia;
-tuple<Pattern, function<Pattern()>, bool> const* SimplificationRules::findFirstMatch(Expression const& _expr)
+SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch(Expression const& _expr)
{
if (_expr.type() != typeid(FunctionalInstruction))
return nullptr;
@@ -45,21 +45,21 @@ tuple<Pattern, function<Pattern()>, bool> const* SimplificationRules::findFirstM
for (auto const& rule: rules.m_rules[byte(instruction.instruction)])
{
rules.resetMatchGroups();
- if (std::get<0>(rule).matches(_expr))
+ if (rule.pattern.matches(_expr))
return &rule;
}
return nullptr;
}
-void SimplificationRules::addRules(vector<tuple<Pattern, function<Pattern()>, bool>> const& _rules)
+void SimplificationRules::addRules(vector<SimplificationRule<Pattern>> const& _rules)
{
for (auto const& r: _rules)
addRule(r);
}
-void SimplificationRules::addRule(tuple<Pattern, function<Pattern()>, bool> const& _rule)
+void SimplificationRules::addRule(SimplificationRule<Pattern> const& _rule)
{
- m_rules[byte(std::get<0>(_rule).instruction())].push_back(_rule);
+ m_rules[byte(_rule.pattern.instruction())].push_back(_rule);
}
SimplificationRules::SimplificationRules()
diff --git a/libjulia/optimiser/SimplificationRules.h b/libjulia/optimiser/SimplificationRules.h
index 96f3de21..68b640b1 100644
--- a/libjulia/optimiser/SimplificationRules.h
+++ b/libjulia/optimiser/SimplificationRules.h
@@ -21,6 +21,7 @@
#pragma once
#include <libevmasm/ExpressionClasses.h>
+#include <libevmasm/SimplificationRule.h>
#include <libjulia/ASTDataForward.h>
@@ -48,16 +49,16 @@ public:
/// @returns a pointer to the first matching pattern and sets the match
/// groups accordingly.
- static std::tuple<Pattern, std::function<Pattern()>, bool> const* findFirstMatch(Expression const& _expr);
+ static SimplificationRule<Pattern> const* findFirstMatch(Expression const& _expr);
private:
- void addRules(std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> const& _rules);
- void addRule(std::tuple<Pattern, std::function<Pattern()>, bool> const& _rule);
+ void addRules(std::vector<SimplificationRule<Pattern>> const& _rules);
+ void addRule(SimplificationRule<Pattern> const& _rule);
void resetMatchGroups() { m_matchGroups.clear(); }
std::map<unsigned, Expression const*> m_matchGroups;
- std::vector<std::tuple<Pattern, std::function<Pattern()>, bool>> m_rules[256];
+ std::vector<SimplificationRule<Pattern>> m_rules[256];
};
enum class PatternKind