[evmasm] EVMAssemblyStack::parseAndAnalyze remove return code.

This commit is contained in:
Alexander Arlt 2023-04-26 22:41:54 -05:00
parent 1aac4d1a4c
commit ff05b7a485
3 changed files with 14 additions and 26 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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<evmasm::EVMAssemblyStack> 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<evmasm::EVMAssemblyStack>(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()