mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[libsolidity] interface/CompilerStack.h: Remove m_evmAssemblyJson.
This commit is contained in:
parent
4f76877753
commit
5c9c88ccc9
@ -410,7 +410,7 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
|
|||||||
m_sources[path] = std::move(source);
|
m_sources[path] = std::move(source);
|
||||||
}
|
}
|
||||||
m_stackState = ParsedAndImported;
|
m_stackState = ParsedAndImported;
|
||||||
m_importedSources = true;
|
m_importedSourceType = ImportedSourceType::SolidityAST;
|
||||||
|
|
||||||
storeContractDefinitions();
|
storeContractDefinitions();
|
||||||
}
|
}
|
||||||
@ -418,11 +418,12 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
|
|||||||
void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> const& _sources)
|
void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> const& _sources)
|
||||||
{
|
{
|
||||||
solAssert(_sources.size() == 1, "");
|
solAssert(_sources.size() == 1, "");
|
||||||
solAssert(m_sources.empty(), "");
|
solAssert(m_sourceJsons.empty(), "");
|
||||||
solAssert(m_sourceOrder.empty(), "");
|
solAssert(m_sourceOrder.empty(), "");
|
||||||
if (m_stackState != Empty)
|
if (m_stackState != Empty)
|
||||||
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
|
solThrow(CompilerError, "Must call importEvmAssemblyJson only before the SourcesSet state.");
|
||||||
|
|
||||||
|
m_sourceJsons = _sources;
|
||||||
Json::Value jsonValue = _sources.begin()->second;
|
Json::Value jsonValue = _sources.begin()->second;
|
||||||
if (jsonValue.isMember("sourceList"))
|
if (jsonValue.isMember("sourceList"))
|
||||||
for (auto const& item: jsonValue["sourceList"])
|
for (auto const& item: jsonValue["sourceList"])
|
||||||
@ -432,8 +433,8 @@ void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> con
|
|||||||
m_sources.emplace(std::make_pair(item.asString(), source));
|
m_sources.emplace(std::make_pair(item.asString(), source));
|
||||||
m_sourceOrder.push_back(&m_sources[item.asString()]);
|
m_sourceOrder.push_back(&m_sources[item.asString()]);
|
||||||
}
|
}
|
||||||
m_evmAssemblyJson[_sources.begin()->first] = std::move(jsonValue);
|
m_sourceJsons[_sources.begin()->first] = std::move(jsonValue);
|
||||||
m_importedSources = true;
|
m_importedSourceType = ImportedSourceType::EvmAssemblyJson;
|
||||||
m_stackState = SourcesSet;
|
m_stackState = SourcesSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,7 +627,7 @@ bool CompilerStack::parseAndAnalyze(State _stopAfter)
|
|||||||
{
|
{
|
||||||
m_stopAfter = _stopAfter;
|
m_stopAfter = _stopAfter;
|
||||||
|
|
||||||
if (!m_evmAssemblyJson.empty())
|
if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool success = parse();
|
bool success = parse();
|
||||||
@ -678,13 +679,12 @@ bool CompilerStack::compile(State _stopAfter)
|
|||||||
// Only compile contracts individually which have been requested.
|
// Only compile contracts individually which have been requested.
|
||||||
map<ContractDefinition const*, shared_ptr<Compiler const>> otherCompilers;
|
map<ContractDefinition const*, shared_ptr<Compiler const>> otherCompilers;
|
||||||
|
|
||||||
if (!m_evmAssemblyJson.empty())
|
if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson)
|
||||||
{
|
{
|
||||||
solAssert(m_importedSources, "");
|
solAssert(m_sourceJsons.size() == 1, "");
|
||||||
solAssert(m_evmAssemblyJson.size() == 1, "");
|
|
||||||
|
|
||||||
string const evmSourceName = m_evmAssemblyJson.begin()->first;
|
string const evmSourceName = m_sourceJsons.begin()->first;
|
||||||
Json::Value const evmJson = m_evmAssemblyJson.begin()->second;
|
Json::Value const evmJson = m_sourceJsons.begin()->second;
|
||||||
|
|
||||||
// todo: remove code duplication.
|
// todo: remove code duplication.
|
||||||
evmasm::Assembly::OptimiserSettings optimiserSettings{false, false, false, false, false, false, m_evmVersion, 0};
|
evmasm::Assembly::OptimiserSettings optimiserSettings{false, false, false, false, false, false, m_evmVersion, 0};
|
||||||
@ -697,7 +697,7 @@ bool CompilerStack::compile(State _stopAfter)
|
|||||||
optimiserSettings.expectedExecutionsPerDeployment = m_optimiserSettings.expectedExecutionsPerDeployment;
|
optimiserSettings.expectedExecutionsPerDeployment = m_optimiserSettings.expectedExecutionsPerDeployment;
|
||||||
optimiserSettings.evmVersion = m_evmVersion;
|
optimiserSettings.evmVersion = m_evmVersion;
|
||||||
|
|
||||||
m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON(m_evmAssemblyJson[evmSourceName]);
|
m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON(m_sourceJsons[evmSourceName]);
|
||||||
if (m_optimiserSettings.enabled)
|
if (m_optimiserSettings.enabled)
|
||||||
m_contracts[evmSourceName].evmAssembly->optimise(optimiserSettings);
|
m_contracts[evmSourceName].evmAssembly->optimise(optimiserSettings);
|
||||||
m_contracts[evmSourceName].object = m_contracts[evmSourceName].evmAssembly->assemble();
|
m_contracts[evmSourceName].object = m_contracts[evmSourceName].evmAssembly->assemble();
|
||||||
@ -991,21 +991,15 @@ vector<string> CompilerStack::sourceNames() const
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, unsigned> CompilerStack::sourceIndices(bool _includeInternalSources /* = true */) const
|
map<string, unsigned> CompilerStack::sourceIndices() const
|
||||||
{
|
{
|
||||||
map<string, unsigned> indices;
|
map<string, unsigned> indices;
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
if (m_evmAssemblyJson.empty())
|
for (auto const& s: m_sources)
|
||||||
{
|
if (s.first != CompilerContext::yulUtilityFileName())
|
||||||
for (auto const& s: m_sources)
|
|
||||||
indices[s.first] = index++;
|
indices[s.first] = index++;
|
||||||
solAssert(!indices.count(CompilerContext::yulUtilityFileName()), "");
|
if (indices.find(CompilerContext::yulUtilityFileName()) == indices.end())
|
||||||
if (_includeInternalSources)
|
indices[CompilerContext::yulUtilityFileName()] = index++;
|
||||||
indices[CompilerContext::yulUtilityFileName()] = index++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (auto const& s: m_sourceOrder)
|
|
||||||
indices[s->charStream->source()] = index++;
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1543,7 +1537,22 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
|
|||||||
{
|
{
|
||||||
Json::Value meta{Json::objectValue};
|
Json::Value meta{Json::objectValue};
|
||||||
meta["version"] = 1;
|
meta["version"] = 1;
|
||||||
meta["language"] = m_importedSources ? "SolidityAST" : "Solidity";
|
string sourceType;
|
||||||
|
switch (m_importedSourceType)
|
||||||
|
{
|
||||||
|
case ImportedSourceType::None:
|
||||||
|
sourceType = "Solidity";
|
||||||
|
break;
|
||||||
|
case ImportedSourceType::SolidityAST:
|
||||||
|
sourceType = "SolidityAST";
|
||||||
|
break;
|
||||||
|
case ImportedSourceType::EvmAssemblyJson:
|
||||||
|
sourceType = "EvmAssemblyJson";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
solAssert(false);
|
||||||
|
}
|
||||||
|
meta["language"] = sourceType;
|
||||||
meta["compiler"]["version"] = VersionStringStrict;
|
meta["compiler"]["version"] = VersionStringStrict;
|
||||||
|
|
||||||
/// All the source files (including self), which should be included in the metadata.
|
/// All the source files (including self), which should be included in the metadata.
|
||||||
|
@ -117,6 +117,12 @@ public:
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ImportedSourceType {
|
||||||
|
None,
|
||||||
|
SolidityAST,
|
||||||
|
EvmAssemblyJson
|
||||||
|
};
|
||||||
|
|
||||||
/// Creates a new compiler stack.
|
/// Creates a new compiler stack.
|
||||||
/// @param _readFile callback used to read files for import statements. Must return
|
/// @param _readFile callback used to read files for import statements. Must return
|
||||||
/// and must not emit exceptions.
|
/// and must not emit exceptions.
|
||||||
@ -244,7 +250,7 @@ public:
|
|||||||
|
|
||||||
/// @returns a mapping assigning each source name its index inside the vector returned
|
/// @returns a mapping assigning each source name its index inside the vector returned
|
||||||
/// by sourceNames().
|
/// by sourceNames().
|
||||||
std::map<std::string, unsigned> sourceIndices(bool _includeInternalSources = true) const;
|
std::map<std::string, unsigned> sourceIndices() const;
|
||||||
|
|
||||||
/// @returns the previously used character stream, useful for counting lines during error reporting.
|
/// @returns the previously used character stream, useful for counting lines during error reporting.
|
||||||
langutil::CharStream const& charStream(std::string const& _sourceName) const override;
|
langutil::CharStream const& charStream(std::string const& _sourceName) const override;
|
||||||
@ -502,7 +508,6 @@ private:
|
|||||||
std::map<std::string const, Source> m_sources;
|
std::map<std::string const, Source> m_sources;
|
||||||
// if imported, store AST-JSONS for each filename
|
// if imported, store AST-JSONS for each filename
|
||||||
std::map<std::string, Json::Value> m_sourceJsons;
|
std::map<std::string, Json::Value> m_sourceJsons;
|
||||||
std::map<std::string, Json::Value> m_evmAssemblyJson;
|
|
||||||
std::vector<std::string> m_unhandledSMTLib2Queries;
|
std::vector<std::string> m_unhandledSMTLib2Queries;
|
||||||
std::map<util::h256, std::string> m_smtlib2Responses;
|
std::map<util::h256, std::string> m_smtlib2Responses;
|
||||||
std::shared_ptr<GlobalContext> m_globalContext;
|
std::shared_ptr<GlobalContext> m_globalContext;
|
||||||
@ -516,7 +521,7 @@ private:
|
|||||||
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
|
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
|
||||||
bool m_parserErrorRecovery = false;
|
bool m_parserErrorRecovery = false;
|
||||||
State m_stackState = Empty;
|
State m_stackState = Empty;
|
||||||
bool m_importedSources = false;
|
ImportedSourceType m_importedSourceType = ImportedSourceType::None;
|
||||||
/// Whether or not there has been an error during processing.
|
/// Whether or not there has been an error during processing.
|
||||||
/// If this is true, the stack will refuse to generate code.
|
/// If this is true, the stack will refuse to generate code.
|
||||||
bool m_hasError = false;
|
bool m_hasError = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user