aboutsummaryrefslogtreecommitdiffstats
path: root/Assembly.cpp
diff options
context:
space:
mode:
authorLiana Husikyan <liana@ethdev.com>2015-05-15 18:23:13 +0800
committerLiana Husikyan <liana@ethdev.com>2015-06-01 19:06:12 +0800
commit25205cb05b068e0ec116bdc3f8230f9f2f2159f0 (patch)
tree7f59715c530d13cb9e17a16ce3060df1445c65d2 /Assembly.cpp
parent7f55e26eb8fd9c321c679f7e4c758070b8d670c1 (diff)
downloaddexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar.gz
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar.bz2
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar.lz
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar.xz
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.tar.zst
dexon-solidity-25205cb05b068e0ec116bdc3f8230f9f2f2159f0.zip
added error jump instead of STOP instraction in case of exception
Diffstat (limited to 'Assembly.cpp')
-rw-r--r--Assembly.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/Assembly.cpp b/Assembly.cpp
index 5cf3b787..f492260a 100644
--- a/Assembly.cpp
+++ b/Assembly.cpp
@@ -127,7 +127,10 @@ ostream& Assembly::streamAsm(ostream& _out, string const& _prefix, StringMap con
_out << " PUSH \"" << m_strings.at((h256)i.data()) << "\"";
break;
case PushTag:
- _out << " PUSH [tag" << dec << i.data() << "]";
+ if (i.data() == 0)
+ _out << " PUSH [ErrorTag]";
+ else
+ _out << " PUSH [tag" << dec << i.data() << "]";
break;
case PushSub:
_out << " PUSH [$" << h256(i.data()).abridged() << "]";
@@ -207,6 +210,10 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
createJsonValue("PUSH tag", i.getLocation().start, i.getLocation().end, m_strings.at((h256)i.data())));
break;
case PushTag:
+ if (i.data() == 0)
+ collection.append(
+ createJsonValue("PUSH [ErrorTag]", i.getLocation().start, i.getLocation().end, ""));
+
collection.append(
createJsonValue("PUSH [tag]", i.getLocation().start, i.getLocation().end, string(i.data())));
break;
@@ -226,7 +233,7 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
collection.append(
createJsonValue("tag", i.getLocation().start, i.getLocation().end, string(i.data())));
collection.append(
- createJsonValue("JUMDEST", i.getLocation().start, i.getLocation().end));
+ createJsonValue("JUMPDEST", i.getLocation().start, i.getLocation().end));
break;
case PushData:
collection.append(createJsonValue("PUSH data", i.getLocation().start, i.getLocation().end, toStringInHex(i.data())));
@@ -387,6 +394,11 @@ bytes Assembly::assemble() const
// m_data must not change from here on
for (AssemblyItem const& i: m_items)
+ {
+ // store position of the invalid jump destination
+ if (i.type() != Tag && tagPos[0] == 0)
+ tagPos[0] = ret.size();
+
switch (i.type())
{
case Operation:
@@ -448,17 +460,23 @@ bytes Assembly::assemble() const
}
case Tag:
tagPos[(unsigned)i.data()] = ret.size();
+ assertThrow(i.data() != 0, AssemblyException, "");
ret.push_back((byte)Instruction::JUMPDEST);
break;
default:
BOOST_THROW_EXCEPTION(InvalidOpcode());
}
-
+ }
for (auto const& i: tagRef)
{
bytesRef r(ret.data() + i.first, bytesPerTag);
- //@todo in the failure case, we could use the position of the invalid jumpdest
- toBigEndian(i.second < tagPos.size() ? tagPos[i.second] : (1 << (8 * bytesPerTag)) - 1, r);
+ auto tag = i.second;
+ if (tag >= tagPos.size())
+ tag = 0;
+ if (tag == 0)
+ assertThrow(tagPos[tag] != 0, AssemblyException, "");
+
+ toBigEndian(tagPos[tag], r);
}
if (!m_data.empty())