From f6ed29b88b0a721984173df04f04ad4c48d8711d Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 4 Dec 2018 18:57:07 +0100 Subject: Extend abstract assembly to be able to handle sub-objects. --- libsolidity/codegen/AsmCodeGen.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'libsolidity/codegen/AsmCodeGen.cpp') diff --git a/libsolidity/codegen/AsmCodeGen.cpp b/libsolidity/codegen/AsmCodeGen.cpp index 4ca0c4e2..dfcc900b 100644 --- a/libsolidity/codegen/AsmCodeGen.cpp +++ b/libsolidity/codegen/AsmCodeGen.cpp @@ -27,10 +27,13 @@ #include #include +#include #include #include +#include + #include #include @@ -131,6 +134,39 @@ void EthAssemblyAdapter::appendAssemblySize() m_assembly.appendProgramSize(); } +pair, AbstractAssembly::SubID> EthAssemblyAdapter::createSubAssembly() +{ + shared_ptr assembly{make_shared()}; + auto sub = m_assembly.newSub(assembly); + return {make_shared(*assembly), size_t(sub.data())}; +} + +void EthAssemblyAdapter::appendDataOffset(AbstractAssembly::SubID _sub) +{ + auto it = m_dataHashBySubId.find(_sub); + if (it == m_dataHashBySubId.end()) + m_assembly.pushSubroutineOffset(size_t(_sub)); + else + m_assembly << eth::AssemblyItem(eth::PushData, it->second); +} + +void EthAssemblyAdapter::appendDataSize(AbstractAssembly::SubID _sub) +{ + auto it = m_dataHashBySubId.find(_sub); + if (it == m_dataHashBySubId.end()) + m_assembly.pushSubroutineSize(size_t(_sub)); + else + m_assembly << u256(m_assembly.data(h256(it->second)).size()); +} + +AbstractAssembly::SubID EthAssemblyAdapter::appendData(bytes const& _data) +{ + eth::AssemblyItem pushData = m_assembly.newData(_data); + SubID subID = m_nextDataCounter++; + m_dataHashBySubId[subID] = pushData.data(); + return subID; +} + EthAssemblyAdapter::LabelID EthAssemblyAdapter::assemblyTagToIdentifier(eth::AssemblyItem const& _tag) { u256 id = _tag.data(); -- cgit v1.2.3