aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionClasses.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-04-30 17:40:43 +0800
committerchriseth <c@ethdev.com>2015-05-06 17:10:03 +0800
commit3ebb7d99c4e24d7bc963c419790c9f0081cc47a1 (patch)
tree9d20776d37f187127b8e9e720cbde9e2e8f6f575 /ExpressionClasses.cpp
parent9106d72a02aa52b0c48db2eef7e4f9df213500b5 (diff)
downloaddexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar.gz
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar.bz2
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar.lz
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar.xz
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.tar.zst
dexon-solidity-3ebb7d99c4e24d7bc963c419790c9f0081cc47a1.zip
More flexible way to approach unknown stack elements.
Diffstat (limited to 'ExpressionClasses.cpp')
-rw-r--r--ExpressionClasses.cpp36
1 files changed, 27 insertions, 9 deletions
diff --git a/ExpressionClasses.cpp b/ExpressionClasses.cpp
index 1e60a7fe..8d0785d3 100644
--- a/ExpressionClasses.cpp
+++ b/ExpressionClasses.cpp
@@ -37,6 +37,7 @@ using namespace dev::eth;
bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const
{
+ assertThrow(!!item && !!_other.item, OptimizerException, "");
auto type = item->type();
auto otherType = _other.item->type();
return std::tie(type, item->data(), arguments, sequenceNumber) <
@@ -78,6 +79,15 @@ ExpressionClasses::Id ExpressionClasses::find(
return exp.id;
}
+ExpressionClasses::Id ExpressionClasses::newId()
+{
+ // Note that we cannot insert it in m_expressions because this requires item to be set.
+ Expression exp;
+ exp.id = m_representatives.size();
+ m_representatives.push_back(exp);
+ return exp.id;
+}
+
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.
@@ -122,10 +132,16 @@ string ExpressionClasses::fullDAGToString(ExpressionClasses::Id _id) const
{
Expression const& expr = representative(_id);
stringstream str;
- str << dec << expr.id << ":" << *expr.item << "(";
- for (Id arg: expr.arguments)
- str << fullDAGToString(arg) << ",";
- str << ")";
+ str << dec << expr.id << ":";
+ if (expr.item)
+ {
+ str << *expr.item << "(";
+ for (Id arg: expr.arguments)
+ str << fullDAGToString(arg) << ",";
+ str << ")";
+ }
+ else
+ str << " UNIQUE";
return str.str();
}
@@ -279,7 +295,7 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr,
{
static Rules rules;
- if (_expr.item->type() != Operation)
+ if (!_expr.item || _expr.item->type() != Operation)
return -1;
for (auto const& rule: rules.rules())
@@ -337,7 +353,7 @@ void Pattern::setMatchGroup(unsigned _group, map<unsigned, Expression const*>& _
bool Pattern::matches(Expression const& _expr, ExpressionClasses const& _classes) const
{
- if (!matchesBaseItem(*_expr.item))
+ if (!matchesBaseItem(_expr.item))
return false;
if (m_matchGroup)
{
@@ -387,13 +403,15 @@ string Pattern::toString() const
return s.str();
}
-bool Pattern::matchesBaseItem(AssemblyItem const& _item) const
+bool Pattern::matchesBaseItem(AssemblyItem const* _item) const
{
if (m_type == UndefinedItem)
return true;
- if (m_type != _item.type())
+ if (!_item)
+ return false;
+ if (m_type != _item->type())
return false;
- if (m_requireDataMatch && m_data != _item.data())
+ if (m_requireDataMatch && m_data != _item->data())
return false;
return true;
}