diff --git a/libevmasm/EVMAssemblyStack.cpp b/libevmasm/EVMAssemblyStack.cpp index f34884f49..ff1b7c11c 100644 --- a/libevmasm/EVMAssemblyStack.cpp +++ b/libevmasm/EVMAssemblyStack.cpp @@ -30,25 +30,21 @@ using namespace std; namespace solidity::evmasm { -bool EVMAssemblyStack::parseAndAnalyze(string const& _sourceName, string const& _source) +void EVMAssemblyStack::parseAndAnalyze(string const& _sourceName, string const& _source) { solAssert(!m_evmAssembly); - m_name = _sourceName; - if (!jsonParseStrict(_source, m_json)) - return false; - + solRequire(jsonParseStrict(_source, m_json), AssemblyImportException, "Could not parse JSON file."); auto result = evmasm::Assembly::fromJSON(m_json); m_evmAssembly = result.first; m_sourceList = result.second; - - return m_evmAssembly != nullptr; + solRequire(m_evmAssembly != nullptr, AssemblyImportException, "Could not create evm assembly object."); } void EVMAssemblyStack::assemble() { - solAssert(m_evmAssembly->isCreation()); solAssert(m_evmAssembly); + solAssert(m_evmAssembly->isCreation()); solAssert(!m_evmRuntimeAssembly); m_object = m_evmAssembly->assemble(); @@ -62,7 +58,6 @@ void EVMAssemblyStack::assemble() } } - LinkerObject const& EVMAssemblyStack::object(string const& _contractName) const { solAssert(_contractName == m_name); diff --git a/libevmasm/EVMAssemblyStack.h b/libevmasm/EVMAssemblyStack.h index e9e4a9a4f..cc90486e7 100644 --- a/libevmasm/EVMAssemblyStack.h +++ b/libevmasm/EVMAssemblyStack.h @@ -35,7 +35,10 @@ class EVMAssemblyStack: public AbstractAssemblyStack public: explicit EVMAssemblyStack(langutil::EVMVersion _evmVersion): m_evmVersion(_evmVersion) {} - bool parseAndAnalyze(std::string const& _sourceName, std::string const& _source); + /// Runs parsing and analysis steps. + /// Multiple calls overwrite the previous state. + /// @throws AssemblyImportException, if JSON could not be validated. + void parseAndAnalyze(std::string const& _sourceName, std::string const& _source); void assemble(); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 5b820f988..d4fb1a622 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -765,33 +765,23 @@ void CommandLineInterface::assembleFromEvmAssemblyJson() solAssert(m_options.input.mode == InputMode::EVMAssemblerJSON); solAssert(!m_assemblyStack); solAssert(!m_evmAssemblyStack && !m_compiler); - bool importSuccessful = false; unique_ptr evmAssemblyStack; + solAssert(m_fileReader.sourceUnits().size() == 1); + auto&& [sourceUnitName, source] = *m_fileReader.sourceUnits().begin(); try { - solAssert(m_fileReader.sourceUnits().size() == 1); - auto&& [sourceUnitName, source] = *m_fileReader.sourceUnits().begin(); - evmAssemblyStack = make_unique(m_options.output.evmVersion); + evmAssemblyStack->parseAndAnalyze(sourceUnitName, source); if (m_options.output.debugInfoSelection.has_value()) evmAssemblyStack->selectDebugInfo(m_options.output.debugInfoSelection.value()); - - // TODO: Why does it report errors both with exceptions and with an error code? - // It should always throw when the operation is not successful. - importSuccessful = evmAssemblyStack->parseAndAnalyze(sourceUnitName, source); + evmAssemblyStack->assemble(); + m_evmAssemblyStack = std::move(evmAssemblyStack); + m_assemblyStack = m_evmAssemblyStack.get(); } catch (evmasm::AssemblyImportException const& _exception) { solThrow(CommandLineExecutionError, "Assembly Import Error: "s + _exception.what()); } - if (importSuccessful) - { - evmAssemblyStack->assemble(); - m_evmAssemblyStack = std::move(evmAssemblyStack); - m_assemblyStack = m_evmAssemblyStack.get(); - } - else - solThrow(CommandLineExecutionError, "Assembly Import Error: Could not create compiler object."); } void CommandLineInterface::compile()