Skip to content

Commit dcb697f

Browse files
committed
[libevmasm] loadFromAssemblyJSON: optionally load from sourceList.
1 parent c822263 commit dcb697f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

libevmasm/Assembly.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,21 @@ bool Assembly::addAssemblyItemsFromJSON(Json::Value const& _code)
518518
return true;
519519
}
520520

521-
bool Assembly::loadFromAssemblyJSON(Json::Value const& _json)
521+
bool Assembly::loadFromAssemblyJSON(Json::Value const& _json, bool _loadSources /* = true */)
522522
{
523523
if (!_json[".code"].isArray())
524524
return false;
525525
bool result{true};
526+
527+
if (_loadSources)
528+
{
529+
vector<string> sourceList;
530+
if (_json.isMember("sourceList"))
531+
for (auto const& it: _json["sourceList"])
532+
sourceList.emplace_back(it.asString());
533+
setSources(sourceList);
534+
}
535+
526536
addAssemblyItemsFromJSON(_json[".code"]);
527537
if (_json[".auxdata"].isString())
528538
this->m_auxiliaryData = fromHex(_json[".auxdata"].asString());
@@ -538,7 +548,7 @@ bool Assembly::loadFromAssemblyJSON(Json::Value const& _json)
538548
{
539549
shared_ptr<Assembly> subassembly = make_shared<Assembly>();
540550
subassembly->setSources(this->sources());
541-
result &= subassembly->loadFromAssemblyJSON(code);
551+
result &= subassembly->loadFromAssemblyJSON(code, false);
542552
this->m_subs.emplace_back(subassembly);
543553
}
544554
}

libevmasm/Assembly.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <sstream>
4040
#include <memory>
4141
#include <map>
42+
#include <utility>
4243

4344
namespace solidity::evmasm
4445
{
@@ -159,7 +160,7 @@ class Assembly
159160
bool _includeSourceList = true
160161
) const;
161162

162-
bool loadFromAssemblyJSON(Json::Value const& _json);
163+
bool loadFromAssemblyJSON(Json::Value const& _json, bool _loadSources = true);
163164

164165
/// Mark this assembly as invalid. Calling ``assemble`` on it will throw.
165166
void markAsInvalid() { m_invalid = true; }
@@ -168,7 +169,7 @@ class Assembly
168169
size_t encodeSubPath(std::vector<size_t> const& _subPath);
169170

170171
void setSources(std::vector<std::shared_ptr<std::string const>> _sources) {
171-
m_sources = _sources;
172+
m_sources = std::move(_sources);
172173
}
173174

174175
void setSources(std::vector<std::string> const& _sources) {

libsolidity/interface/CompilerStack.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,20 +685,14 @@ bool CompilerStack::compile(State _stopAfter)
685685
optimiserSettings.runJumpdestRemover = m_optimiserSettings.runJumpdestRemover;
686686
optimiserSettings.runPeephole = m_optimiserSettings.runPeephole;
687687

688-
vector<string> sourceList;
689-
if (m_evmAssemblyJson[evmAssemblyJsonSource].isMember("sourceList"))
690-
for (auto const& it: m_evmAssemblyJson[evmAssemblyJsonSource]["sourceList"])
691-
sourceList.emplace_back(it.asString());
692-
693688
m_contracts[evmAssemblyJsonSource].evmAssembly = make_shared<evmasm::Assembly>(evmAssemblyJsonSource);
694-
m_contracts[evmAssemblyJsonSource].evmAssembly->setSources(sourceList);
695689
m_contracts[evmAssemblyJsonSource].evmAssembly->loadFromAssemblyJSON(m_evmAssemblyJson[evmAssemblyJsonSource]);
696690
m_contracts[evmAssemblyJsonSource].evmAssembly->optimise(optimiserSettings);
697691
m_contracts[evmAssemblyJsonSource].object = m_contracts[evmAssemblyJsonSource].evmAssembly->assemble();
698692

699693
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly = make_shared<evmasm::Assembly>(evmAssemblyJsonSource);
700-
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->setSources(sourceList);
701-
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->loadFromAssemblyJSON(m_evmAssemblyJson[evmAssemblyJsonSource][".data"]["0"]);
694+
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->setSources(m_contracts[evmAssemblyJsonSource].evmAssembly->sources());
695+
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->loadFromAssemblyJSON(m_evmAssemblyJson[evmAssemblyJsonSource][".data"]["0"], false);
702696
m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->optimise(optimiserSettings);
703697
m_contracts[evmAssemblyJsonSource].runtimeObject = m_contracts[evmAssemblyJsonSource].evmRuntimeAssembly->assemble();
704698
}

0 commit comments

Comments
 (0)