aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-10-08 00:43:01 +0800
committerGav Wood <i@gavwood.com>2014-10-08 00:43:01 +0800
commit92d9a107d711040cc34921aa6bd5f5abcf515b8c (patch)
tree57457c8f3ebafa0bf2983ab8f6a5d5bbe7ee41b5
parentf61c3232449d36cc44bcff70240f5292bf8f9f16 (diff)
downloaddexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar.gz
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar.bz2
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar.lz
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar.xz
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.tar.zst
dexon-solidity-92d9a107d711040cc34921aa6bd5f5abcf515b8c.zip
PoC-7: JUMPDEST implemented.
-rw-r--r--Assembly.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/Assembly.cpp b/Assembly.cpp
index 9b6dee94..11ee9122 100644
--- a/Assembly.cpp
+++ b/Assembly.cpp
@@ -149,6 +149,17 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItemsConstRef _i)
ostream& Assembly::streamOut(ostream& _out, string const& _prefix) const
{
+ _out << _prefix << ".pre:" << endl;
+ for (AssemblyItem const& i: m_items)
+ switch (i.m_type)
+ {
+ case PushTag:
+ _out << _prefix << " PUSH [tag" << i.m_data << "]" << endl;
+ _out << _prefix << " JUMPDEST" << endl;
+ break;
+ default:;
+ }
+
_out << _prefix << ".code:" << endl;
for (AssemblyItem const& i: m_items)
switch (i.m_type)
@@ -353,9 +364,11 @@ bytes Assembly::assemble() const
ret.reserve(totalBytes);
vector<unsigned> tagPos(m_usedTags);
map<unsigned, unsigned> tagRef;
+ map<unsigned, unsigned> pretagRef;
multimap<h256, unsigned> dataRef;
unsigned bytesPerTag = dev::bytesRequired(totalBytes);
byte tagPush = (byte)Instruction::PUSH1 - 1 + bytesPerTag;
+ bytes preret;
for (auto const& i: m_subs)
m_data[i.first] = i.second.assemble();
@@ -393,6 +406,11 @@ bytes Assembly::assemble() const
ret.push_back(tagPush);
tagRef[ret.size()] = (unsigned)i.m_data;
ret.resize(ret.size() + bytesPerTag);
+
+ preret.push_back(tagPush);
+ pretagRef[preret.size()] = (unsigned)i.m_data;
+ preret.resize(preret.size() + bytesPerTag);
+ preret.push_back((byte)Instruction::JUMPDEST);
break;
}
case PushData: case PushSub:
@@ -424,6 +442,12 @@ bytes Assembly::assemble() const
toBigEndian(tagPos[i.second], r);
}
+ for (auto const& i: pretagRef)
+ {
+ bytesRef r(preret.data() + i.first, bytesPerTag);
+ toBigEndian(tagPos[i.second], r);
+ }
+
if (m_data.size())
{
ret.push_back(0);
@@ -442,5 +466,5 @@ bytes Assembly::assemble() const
}
}
}
- return ret;
+ return preret + ret;
}