fixup! [libevmasm] Add support to import evm assembly json.

This commit is contained in:
Kamil Śliwak 2023-04-20 19:22:27 +02:00 committed by Alexander Arlt
parent 108490e630
commit 5c43d9e3f7
3 changed files with 29 additions and 14 deletions

View File

@ -442,17 +442,15 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
void CompilerStack::importFromEVMAssemblyStack(std::string const& _sourceName, std::string const& _source) void CompilerStack::importFromEVMAssemblyStack(std::string const& _sourceName, std::string const& _source)
{ {
solRequire(m_stackState == Empty, CompilerError, ""); solRequire(m_stackState == Empty, CompilerError, "");
m_evmAssemblyStack = std::make_unique<evmasm::EVMAssemblyStack>(m_evmVersion); m_evmAssemblyStack = make_unique<evmasm::EVMAssemblyStack>(m_evmVersion);
Json::Value evmAsmJson; Json::Value evmAsmJson;
if (m_evmAssemblyStack->parseAndAnalyze(_sourceName, _source)) if (m_evmAssemblyStack->parseAndAnalyze(_sourceName, _source))
{ {
m_evmAssemblyStack->assemble(); m_evmAssemblyStack->assemble();
string const name{m_evmAssemblyStack->name()}; string const name{m_evmAssemblyStack->name()};
Json::Value const& json = m_evmAssemblyStack->json();
m_sourceJsons[name] = json;
Contract& contract = m_contracts[name]; Contract& contract = m_contracts[name];
contract.evmAssembly = m_evmAssemblyStack->evmAssembly(); contract.evmAssembly = m_evmAssemblyStack->evmAssembly();
contract.evmRuntimeAssembly= m_evmAssemblyStack->evmRuntimeAssembly(); contract.evmRuntimeAssembly = m_evmAssemblyStack->evmRuntimeAssembly();
contract.object = m_evmAssemblyStack->object(); contract.object = m_evmAssemblyStack->object();
contract.runtimeObject = m_evmAssemblyStack->runtimeObject(); contract.runtimeObject = m_evmAssemblyStack->runtimeObject();
@ -739,7 +737,7 @@ bool CompilerStack::compile(State _stopAfter)
{ {
if ( if (
SourceLocation const* sourceLocation = SourceLocation const* sourceLocation =
boost::get_error_info<langutil::errinfo_sourceLocation>(_unimplementedError) boost::get_error_info<langutil::errinfo_sourceLocation>(_unimplementedError)
) )
{ {
string const* comment = _unimplementedError.comment(); string const* comment = _unimplementedError.comment();
@ -981,8 +979,8 @@ Json::Value CompilerStack::assemblyJSON(string const& _contractName) const
Contract const& currentContract = contract(_contractName); Contract const& currentContract = contract(_contractName);
if (currentContract.evmAssembly) if (currentContract.evmAssembly)
{ {
std::vector<std::string> sources = sourceNames(); vector<string> sources = sourceNames();
if (std::find(sources.begin(), sources.end(), CompilerContext::yulUtilityFileName()) == sources.end()) if (find(sources.begin(), sources.end(), CompilerContext::yulUtilityFileName()) == sources.end())
sources.emplace_back(CompilerContext::yulUtilityFileName()); sources.emplace_back(CompilerContext::yulUtilityFileName());
currentContract.evmAssembly->setSourceList(sources); currentContract.evmAssembly->setSourceList(sources);
return currentContract.evmAssembly->assemblyJSON(); return currentContract.evmAssembly->assemblyJSON();
@ -993,6 +991,9 @@ Json::Value CompilerStack::assemblyJSON(string const& _contractName) const
vector<string> CompilerStack::sourceNames() const vector<string> CompilerStack::sourceNames() const
{ {
if (m_evmAssemblyStack)
return m_evmAssemblyStack->evmAssembly()->sourceList();
return ranges::to<vector>(m_sources | ranges::views::keys); return ranges::to<vector>(m_sources | ranges::views::keys);
} }

View File

@ -940,7 +940,8 @@ void CommandLineInterface::handleCombinedJSON()
); );
if (m_options.compiler.combinedJsonRequests->funDebugRuntime && m_compiler->compilationSuccessful()) if (m_options.compiler.combinedJsonRequests->funDebugRuntime && m_compiler->compilationSuccessful())
contractData[g_strFunDebugRuntime] = StandardCompiler::formatFunctionDebugData( contractData[g_strFunDebugRuntime] = StandardCompiler::formatFunctionDebugData(
m_compiler->runtimeObject(contractName).functionDebugData); m_compiler->runtimeObject(contractName).functionDebugData
);
if (m_options.compiler.combinedJsonRequests->signatureHashes) if (m_options.compiler.combinedJsonRequests->signatureHashes)
contractData[g_strSignatureHashes] = m_compiler->interfaceSymbols(contractName)["methods"]; contractData[g_strSignatureHashes] = m_compiler->interfaceSymbols(contractName)["methods"];
if (m_options.compiler.combinedJsonRequests->natspecDev) if (m_options.compiler.combinedJsonRequests->natspecDev)
@ -950,8 +951,8 @@ void CommandLineInterface::handleCombinedJSON()
} }
bool needsSourceList = m_options.compiler.combinedJsonRequests->ast || bool needsSourceList = m_options.compiler.combinedJsonRequests->ast ||
m_options.compiler.combinedJsonRequests->srcMap || m_options.compiler.combinedJsonRequests->srcMap ||
m_options.compiler.combinedJsonRequests->srcMapRuntime; m_options.compiler.combinedJsonRequests->srcMapRuntime;
if (needsSourceList) if (needsSourceList)
{ {
// Indices into this array are used to abbreviate source names in source locations. // Indices into this array are used to abbreviate source names in source locations.
@ -1212,7 +1213,7 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
shared_ptr<evmasm::Assembly> assembly{stack.assembleEVMWithDeployed().first}; shared_ptr<evmasm::Assembly> assembly{stack.assembleEVMWithDeployed().first};
if (assembly) if (assembly)
{ {
std::function<map<string, unsigned>(yul::Object const&)> collectSourceIndices = function<map<string, unsigned>(yul::Object const&)> collectSourceIndices =
[&](yul::Object const& _object) -> map<string, unsigned> { [&](yul::Object const& _object) -> map<string, unsigned> {
map<string, unsigned> sourceIndices; map<string, unsigned> sourceIndices;
if (_object.debugData && _object.debugData->sourceNames.has_value()) if (_object.debugData && _object.debugData->sourceNames.has_value())

View File

@ -30,6 +30,8 @@
#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>
#include <range/v3/range/conversion.hpp> #include <range/v3/range/conversion.hpp>
#include <fmt/format.h>
using namespace std; using namespace std;
using namespace solidity::langutil; using namespace solidity::langutil;
@ -1049,7 +1051,11 @@ void CommandLineParser::processArgs()
if (!option.second.defaulted() && !supportedByEvmAsmJsonImport.count(option.first)) if (!option.second.defaulted() && !supportedByEvmAsmJsonImport.count(option.first))
solThrow( solThrow(
CommandLineValidationError, CommandLineValidationError,
"Option --" + option.first + " is not supported with --"+g_strImportEvmAssemblerJson+"." fmt::format(
"Option --{} is not supported with --{}.",
g_strCombinedJson,
g_strImportEvmAssemblerJson
)
); );
} }
@ -1419,7 +1425,8 @@ void CommandLineParser::processArgs()
solAssert( solAssert(
m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::Compiler ||
m_options.input.mode == InputMode::CompilerWithASTImport || m_options.input.mode == InputMode::CompilerWithASTImport ||
m_options.input.mode == InputMode::EVMAssemblerJSON); m_options.input.mode == InputMode::EVMAssemblerJSON
);
} }
void CommandLineParser::parseCombinedJsonOption() void CommandLineParser::parseCombinedJsonOption()
@ -1456,7 +1463,13 @@ void CommandLineParser::parseCombinedJsonOption()
if (m_options.compiler.combinedJsonRequests.value().*invalidOption) if (m_options.compiler.combinedJsonRequests.value().*invalidOption)
solThrow( solThrow(
CommandLineValidationError, CommandLineValidationError,
"Invalid option to --" + g_strCombinedJson + ": " + CombinedJsonRequests::componentName(invalidOption) + " for --" + g_strImportEvmAssemblerJson); fmt::format(
"Invalid option to --{}: {} for --{}",
g_strCombinedJson,
CombinedJsonRequests::componentName(invalidOption),
g_strImportEvmAssemblerJson
)
);
} }
} }