aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm/Assembly.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libevmasm/Assembly.cpp')
-rw-r--r--libevmasm/Assembly.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index b71bc80c..c2eaa1ca 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -41,10 +41,19 @@ void Assembly::append(Assembly const& _a)
auto newDeposit = m_deposit + _a.deposit();
for (AssemblyItem i: _a.m_items)
{
- if (i.type() == Tag || i.type() == PushTag)
+ switch (i.type())
+ {
+ case Tag:
+ case PushTag:
i.setData(i.data() + m_usedTags);
- else if (i.type() == PushSub || i.type() == PushSubSize)
+ break;
+ case PushSub:
+ case PushSubSize:
i.setData(i.data() + m_subs.size());
+ break;
+ default:
+ break;
+ }
append(i);
}
m_deposit = newDeposit;
@@ -69,6 +78,21 @@ void Assembly::append(Assembly const& _a, int _deposit)
append(Instruction::POP);
}
+AssemblyItem const& Assembly::append(AssemblyItem const& _i)
+{
+ assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
+ m_deposit += _i.deposit();
+ m_items.push_back(_i);
+ if (m_items.back().location().isEmpty() && !m_currentSourceLocation.isEmpty())
+ m_items.back().setLocation(m_currentSourceLocation);
+ return back();
+}
+
+void Assembly::injectStart(AssemblyItem const& _i)
+{
+ m_items.insert(m_items.begin(), _i);
+}
+
unsigned Assembly::bytesRequired(unsigned subTagSize) const
{
for (unsigned tagSize = subTagSize; true; ++tagSize)
@@ -264,7 +288,7 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const
createJsonValue("PUSH [ErrorTag]", i.location().start, i.location().end, ""));
else
collection.append(
- createJsonValue("PUSH [tag]", i.location().start, i.location().end, string(i.data())));
+ createJsonValue("PUSH [tag]", i.location().start, i.location().end, dev::toString(i.data())));
break;
case PushSub:
collection.append(
@@ -290,7 +314,7 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const
break;
case Tag:
collection.append(
- createJsonValue("tag", i.location().start, i.location().end, string(i.data())));
+ createJsonValue("tag", i.location().start, i.location().end, dev::toString(i.data())));
collection.append(
createJsonValue("JUMPDEST", i.location().start, i.location().end));
break;
@@ -323,16 +347,6 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const
return root;
}
-AssemblyItem const& Assembly::append(AssemblyItem const& _i)
-{
- assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
- m_deposit += _i.deposit();
- m_items.push_back(_i);
- if (m_items.back().location().isEmpty() && !m_currentSourceLocation.isEmpty())
- m_items.back().setLocation(m_currentSourceLocation);
- return back();
-}
-
AssemblyItem Assembly::namedTag(string const& _name)
{
assertThrow(!_name.empty(), AssemblyException, "Empty named tag.");
@@ -348,11 +362,6 @@ AssemblyItem Assembly::newPushLibraryAddress(string const& _identifier)
return AssemblyItem(PushLibraryAddress, h);
}
-void Assembly::injectStart(AssemblyItem const& _i)
-{
- m_items.insert(m_items.begin(), _i);
-}
-
Assembly& Assembly::optimise(bool _enable, EVMVersion _evmVersion, bool _isCreation, size_t _runs)
{
OptimiserSettings settings;
@@ -617,8 +626,8 @@ LinkerObject const& Assembly::assemble() const
}
if (!m_subs.empty() || !m_data.empty() || !m_auxiliaryData.empty())
- // Append a STOP just to be sure.
- ret.bytecode.push_back(0);
+ // Append an INVALID here to help tests find miscompilation.
+ ret.bytecode.push_back(byte(Instruction::INVALID));
for (size_t i = 0; i < m_subs.size(); ++i)
{