Skip to content

Commit be6a359

Browse files
committed
[libsolidity] interface/CompilerStack.h: Remove m_evmAssemblyJson.
1 parent d5a08b1 commit be6a359

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

libsolidity/interface/CompilerStack.cpp

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -410,19 +410,20 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
410410
m_sources[path] = std::move(source);
411411
}
412412
m_stackState = ParsedAndImported;
413-
m_importedSources = true;
413+
m_importedSourceType = ImportedSourceType::SolidityAST;
414414

415415
storeContractDefinitions();
416416
}
417417

418418
void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> const& _sources)
419419
{
420420
solAssert(_sources.size() == 1, "");
421-
solAssert(m_sources.empty(), "");
421+
solAssert(m_sourceJsons.empty(), "");
422422
solAssert(m_sourceOrder.empty(), "");
423423
if (m_stackState != Empty)
424424
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
425425

426+
m_sourceJsons = _sources;
426427
Json::Value jsonValue = _sources.begin()->second;
427428
if (jsonValue.isMember("sourceList"))
428429
for (auto const& item: jsonValue["sourceList"])
@@ -432,8 +433,8 @@ void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> con
432433
m_sources.emplace(std::make_pair(item.asString(), source));
433434
m_sourceOrder.push_back(&m_sources[item.asString()]);
434435
}
435-
m_evmAssemblyJson[_sources.begin()->first] = std::move(jsonValue);
436-
m_importedSources = true;
436+
m_sourceJsons[_sources.begin()->first] = std::move(jsonValue);
437+
m_importedSourceType = ImportedSourceType::EvmAssemblyJson;
437438
m_stackState = SourcesSet;
438439
}
439440

@@ -626,7 +627,7 @@ bool CompilerStack::parseAndAnalyze(State _stopAfter)
626627
{
627628
m_stopAfter = _stopAfter;
628629

629-
if (!m_evmAssemblyJson.empty())
630+
if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson)
630631
return true;
631632

632633
bool success = parse();
@@ -678,13 +679,12 @@ bool CompilerStack::compile(State _stopAfter)
678679
// Only compile contracts individually which have been requested.
679680
map<ContractDefinition const*, shared_ptr<Compiler const>> otherCompilers;
680681

681-
if (!m_evmAssemblyJson.empty())
682+
if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson)
682683
{
683-
solAssert(m_importedSources, "");
684-
solAssert(m_evmAssemblyJson.size() == 1, "");
684+
solAssert(m_sourceJsons.size() == 1, "");
685685

686-
string const evmSourceName = m_evmAssemblyJson.begin()->first;
687-
Json::Value const evmJson = m_evmAssemblyJson.begin()->second;
686+
string const evmSourceName = m_sourceJsons.begin()->first;
687+
Json::Value const evmJson = m_sourceJsons.begin()->second;
688688

689689
// todo: remove code duplication.
690690
evmasm::Assembly::OptimiserSettings optimiserSettings{false, false, false, false, false, false, m_evmVersion, 0};
@@ -697,7 +697,7 @@ bool CompilerStack::compile(State _stopAfter)
697697
optimiserSettings.expectedExecutionsPerDeployment = m_optimiserSettings.expectedExecutionsPerDeployment;
698698
optimiserSettings.evmVersion = m_evmVersion;
699699

700-
m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON(m_evmAssemblyJson[evmSourceName]);
700+
m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON(m_sourceJsons[evmSourceName]);
701701
if (m_optimiserSettings.enabled)
702702
m_contracts[evmSourceName].evmAssembly->optimise(optimiserSettings);
703703
m_contracts[evmSourceName].object = m_contracts[evmSourceName].evmAssembly->assemble();
@@ -991,21 +991,15 @@ vector<string> CompilerStack::sourceNames() const
991991
return names;
992992
}
993993

994-
map<string, unsigned> CompilerStack::sourceIndices(bool _includeInternalSources /* = true */) const
994+
map<string, unsigned> CompilerStack::sourceIndices() const
995995
{
996996
map<string, unsigned> indices;
997997
unsigned index = 0;
998-
if (m_evmAssemblyJson.empty())
999-
{
1000-
for (auto const& s: m_sources)
998+
for (auto const& s: m_sources)
999+
if (s.first != CompilerContext::yulUtilityFileName())
10011000
indices[s.first] = index++;
1002-
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
1003-
if (_includeInternalSources)
1004-
indices[CompilerContext::yulUtilityFileName()] = index++;
1005-
}
1006-
else
1007-
for (auto const& s: m_sourceOrder)
1008-
indices[s->charStream->source()] = index++;
1001+
if (indices.find(CompilerContext::yulUtilityFileName()) == indices.end())
1002+
indices[CompilerContext::yulUtilityFileName()] = index++;
10091003
return indices;
10101004
}
10111005

@@ -1543,7 +1537,22 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
15431537
{
15441538
Json::Value meta{Json::objectValue};
15451539
meta["version"] = 1;
1546-
meta["language"] = m_importedSources ? "SolidityAST" : "Solidity";
1540+
string sourceType;
1541+
switch (m_importedSourceType)
1542+
{
1543+
case ImportedSourceType::None:
1544+
sourceType = "Solidity";
1545+
break;
1546+
case ImportedSourceType::SolidityAST:
1547+
sourceType = "SolidityAST";
1548+
break;
1549+
case ImportedSourceType::EvmAssemblyJson:
1550+
sourceType = "EvmAssemblyJson";
1551+
break;
1552+
default:
1553+
solAssert(false);
1554+
}
1555+
meta["language"] = sourceType;
15471556
meta["compiler"]["version"] = VersionStringStrict;
15481557

15491558
/// All the source files (including self), which should be included in the metadata.

libsolidity/interface/CompilerStack.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class CompilerStack: public langutil::CharStreamProvider
117117
None
118118
};
119119

120+
enum class ImportedSourceType {
121+
None,
122+
SolidityAST,
123+
EvmAssemblyJson
124+
};
125+
120126
/// Creates a new compiler stack.
121127
/// @param _readFile callback used to read files for import statements. Must return
122128
/// and must not emit exceptions.
@@ -244,7 +250,7 @@ class CompilerStack: public langutil::CharStreamProvider
244250

245251
/// @returns a mapping assigning each source name its index inside the vector returned
246252
/// by sourceNames().
247-
std::map<std::string, unsigned> sourceIndices(bool _includeInternalSources = true) const;
253+
std::map<std::string, unsigned> sourceIndices() const;
248254

249255
/// @returns the previously used character stream, useful for counting lines during error reporting.
250256
langutil::CharStream const& charStream(std::string const& _sourceName) const override;
@@ -502,7 +508,6 @@ class CompilerStack: public langutil::CharStreamProvider
502508
std::map<std::string const, Source> m_sources;
503509
// if imported, store AST-JSONS for each filename
504510
std::map<std::string, Json::Value> m_sourceJsons;
505-
std::map<std::string, Json::Value> m_evmAssemblyJson;
506511
std::vector<std::string> m_unhandledSMTLib2Queries;
507512
std::map<util::h256, std::string> m_smtlib2Responses;
508513
std::shared_ptr<GlobalContext> m_globalContext;
@@ -516,7 +521,7 @@ class CompilerStack: public langutil::CharStreamProvider
516521
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
517522
bool m_parserErrorRecovery = false;
518523
State m_stackState = Empty;
519-
bool m_importedSources = false;
524+
ImportedSourceType m_importedSourceType = ImportedSourceType::None;
520525
/// Whether or not there has been an error during processing.
521526
/// If this is true, the stack will refuse to generate code.
522527
bool m_hasError = false;

0 commit comments

Comments
 (0)