aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm/ExpressionClasses.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-01-06 18:25:02 +0800
committerchriseth <c@ethdev.com>2017-01-13 00:52:26 +0800
commit652d8dab191fcd50ce59b049177ae3281255f309 (patch)
tree27057dd05421c22b29b0f015686e9591d8ced883 /libevmasm/ExpressionClasses.cpp
parentafad40ac5a259cf60cd2f5c8b31495f3f64f3e8e (diff)
downloaddexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar.gz
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar.bz2
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar.lz
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar.xz
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.tar.zst
dexon-solidity-652d8dab191fcd50ce59b049177ae3281255f309.zip
Optimize pattern matcher.
Diffstat (limited to 'libevmasm/ExpressionClasses.cpp')
-rw-r--r--libevmasm/ExpressionClasses.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/libevmasm/ExpressionClasses.cpp b/libevmasm/ExpressionClasses.cpp
index b903ae04..fccac1b0 100644
--- a/libevmasm/ExpressionClasses.cpp
+++ b/libevmasm/ExpressionClasses.cpp
@@ -185,7 +185,7 @@ class Rules: public boost::noncopyable
public:
Rules();
void resetMatchGroups() { m_matchGroups.clear(); }
- vector<pair<Pattern, function<Pattern()>>> rules() const { return m_rules; }
+ vector<pair<Pattern, function<Pattern()>>> const& rules() const { return m_rules; }
private:
using Expression = ExpressionClasses::Expression;
@@ -417,8 +417,7 @@ ExpressionClasses::Id ExpressionClasses::rebuildExpression(ExpressionTemplate co
Pattern::Pattern(Instruction _instruction, std::vector<Pattern> const& _arguments):
m_type(Operation),
- m_requireDataMatch(true),
- m_data(_instruction),
+ m_instruction(_instruction),
m_arguments(_arguments)
{
}
@@ -449,7 +448,10 @@ bool Pattern::matches(Expression const& _expr, ExpressionClasses const& _classes
AssemblyItem Pattern::toAssemblyItem(SourceLocation const& _location) const
{
- return AssemblyItem(m_type, m_data, _location);
+ if (m_type == Operation)
+ return AssemblyItem(m_instruction, _location);
+ else
+ return AssemblyItem(m_type, data(), _location);
}
string Pattern::toString() const
@@ -458,16 +460,16 @@ string Pattern::toString() const
switch (m_type)
{
case Operation:
- s << instructionInfo(Instruction(unsigned(m_data))).name;
+ s << instructionInfo(m_instruction).name;
break;
case Push:
- s << "PUSH " << hex << m_data;
+ s << "PUSH " << hex << data();
break;
case UndefinedItem:
s << "ANY";
break;
default:
- s << "t=" << dec << m_type << " d=" << hex << m_data;
+ s << "t=" << dec << m_type << " d=" << hex << data();
break;
}
if (!m_requireDataMatch)
@@ -489,13 +491,10 @@ bool Pattern::matchesBaseItem(AssemblyItem const* _item) const
return false;
if (m_type != _item->type())
return false;
- if (m_requireDataMatch)
- {
- if (m_type == Operation)
- return m_data == u256(byte(_item->instruction()));
- else
- return m_data == _item->data();
- }
+ else if (m_type == Operation)
+ return m_instruction == _item->instruction();
+ else if (m_requireDataMatch)
+ return data() == _item->data();
return true;
}
@@ -507,6 +506,11 @@ Pattern::Expression const& Pattern::matchGroupValue() const
return *(*m_matchGroups)[m_matchGroup];
}
+u256 const& Pattern::data() const
+{
+ assertThrow(m_data, OptimizerException, "");
+ return *m_data;
+}
ExpressionTemplate::ExpressionTemplate(Pattern const& _pattern, SourceLocation const& _location)
{