mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move exception handlers from CommandLineInterface to main()
This commit is contained in:
parent
298af55cc5
commit
e13dc5084d
@ -699,30 +699,6 @@ bool CommandLineInterface::compile()
|
|||||||
formatter.printExceptionInformation(_exception, "Compiler error");
|
formatter.printExceptionInformation(_exception, "Compiler error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (InternalCompilerError const& _exception)
|
|
||||||
{
|
|
||||||
serr() <<
|
|
||||||
"Internal compiler error during compilation:" <<
|
|
||||||
endl <<
|
|
||||||
boost::diagnostic_information(_exception);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (UnimplementedFeatureError const& _exception)
|
|
||||||
{
|
|
||||||
serr() <<
|
|
||||||
"Unimplemented feature:" <<
|
|
||||||
endl <<
|
|
||||||
boost::diagnostic_information(_exception);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (smtutil::SMTLogicError const& _exception)
|
|
||||||
{
|
|
||||||
serr() <<
|
|
||||||
"SMT logic error during analysis:" <<
|
|
||||||
endl <<
|
|
||||||
boost::diagnostic_information(_exception);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (Error const& _error)
|
catch (Error const& _error)
|
||||||
{
|
{
|
||||||
if (_error.type() == Error::Type::DocstringParsingError)
|
if (_error.type() == Error::Type::DocstringParsingError)
|
||||||
@ -735,23 +711,6 @@ bool CommandLineInterface::compile()
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception const& _exception)
|
|
||||||
{
|
|
||||||
serr() << "Exception during compilation: " << boost::diagnostic_information(_exception) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception during compilation" << (
|
|
||||||
_e.what() ? ": " + string(_e.what()) : "."
|
|
||||||
) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception during compilation." << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1016,32 +975,11 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
|
|||||||
m_options.optimiserSettings()
|
m_options.optimiserSettings()
|
||||||
);
|
);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!stack.parseAndAnalyze(src.first, src.second))
|
if (!stack.parseAndAnalyze(src.first, src.second))
|
||||||
successful = false;
|
successful = false;
|
||||||
else
|
else
|
||||||
stack.optimize();
|
stack.optimize();
|
||||||
}
|
}
|
||||||
catch (Exception const& _exception)
|
|
||||||
{
|
|
||||||
serr() << "Exception in assembler: " << boost::diagnostic_information(_exception) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
serr() <<
|
|
||||||
"Unknown exception during compilation" <<
|
|
||||||
(_e.what() ? ": " + string(_e.what()) : ".") <<
|
|
||||||
endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception in assembler." << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto const& sourceAndStack: assemblyStacks)
|
for (auto const& sourceAndStack: assemblyStacks)
|
||||||
{
|
{
|
||||||
@ -1073,30 +1011,9 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
|
|||||||
sout() << stack.print() << endl;
|
sout() << stack.print() << endl;
|
||||||
|
|
||||||
if (_language != yul::AssemblyStack::Language::Ewasm && _targetMachine == yul::AssemblyStack::Machine::Ewasm)
|
if (_language != yul::AssemblyStack::Language::Ewasm && _targetMachine == yul::AssemblyStack::Machine::Ewasm)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
stack.translate(yul::AssemblyStack::Language::Ewasm);
|
stack.translate(yul::AssemblyStack::Language::Ewasm);
|
||||||
stack.optimize();
|
stack.optimize();
|
||||||
}
|
|
||||||
catch (Exception const& _exception)
|
|
||||||
{
|
|
||||||
serr() << "Exception in assembler: " << boost::diagnostic_information(_exception) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
serr() <<
|
|
||||||
"Unknown exception during compilation" <<
|
|
||||||
(_e.what() ? ": " + string(_e.what()) : ".") <<
|
|
||||||
endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception in assembler." << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sout() << endl << "==========================" << endl;
|
sout() << endl << "==========================" << endl;
|
||||||
sout() << endl << "Translated source:" << endl;
|
sout() << endl << "Translated source:" << endl;
|
||||||
@ -1104,28 +1021,8 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
|
|||||||
}
|
}
|
||||||
|
|
||||||
yul::MachineAssemblyObject object;
|
yul::MachineAssemblyObject object;
|
||||||
try
|
|
||||||
{
|
|
||||||
object = stack.assemble(_targetMachine);
|
object = stack.assemble(_targetMachine);
|
||||||
object.bytecode->link(m_options.linker.libraries);
|
object.bytecode->link(m_options.linker.libraries);
|
||||||
}
|
|
||||||
catch (Exception const& _exception)
|
|
||||||
{
|
|
||||||
serr() << "Exception while assembling: " << boost::diagnostic_information(_exception) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception during compilation" << (
|
|
||||||
_e.what() ? ": " + string(_e.what()) : "."
|
|
||||||
) << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
serr() << "Unknown exception while assembling." << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sout() << endl << "Binary representation:" << endl;
|
sout() << endl << "Binary representation:" << endl;
|
||||||
if (object.bytecode)
|
if (object.bytecode)
|
||||||
|
@ -22,11 +22,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <solc/CommandLineInterface.h>
|
#include <solc/CommandLineInterface.h>
|
||||||
|
|
||||||
|
#include <liblangutil/Exceptions.h>
|
||||||
|
|
||||||
#include <boost/exception/all.hpp>
|
#include <boost/exception/all.hpp>
|
||||||
|
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace solidity;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The equivalent of setlocale(LC_ALL, "C") is called before any user code is run.
|
The equivalent of setlocale(LC_ALL, "C") is called before any user code is run.
|
||||||
@ -53,24 +58,52 @@ static void setDefaultOrCLocale()
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
setDefaultOrCLocale();
|
|
||||||
solidity::frontend::CommandLineInterface cli(cin, cout, cerr);
|
|
||||||
if (!cli.parseArguments(argc, argv))
|
|
||||||
return 1;
|
|
||||||
if (!cli.readInputFiles())
|
|
||||||
return 1;
|
|
||||||
if (!cli.processInput())
|
|
||||||
return 1;
|
|
||||||
bool success = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
success = cli.actOnInput();
|
setDefaultOrCLocale();
|
||||||
|
solidity::frontend::CommandLineInterface cli(cin, cout, cerr);
|
||||||
|
bool success =
|
||||||
|
cli.parseArguments(argc, argv) &&
|
||||||
|
cli.readInputFiles() &&
|
||||||
|
cli.processInput() &&
|
||||||
|
cli.actOnInput();
|
||||||
|
|
||||||
|
return success ? 0 : 1;
|
||||||
|
}
|
||||||
|
catch (smtutil::SMTLogicError const& _exception)
|
||||||
|
{
|
||||||
|
cerr << "SMT logic error:" << endl;
|
||||||
|
cerr << boost::diagnostic_information(_exception);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (langutil::UnimplementedFeatureError const& _exception)
|
||||||
|
{
|
||||||
|
cerr << "Unimplemented feature:" << endl;
|
||||||
|
cerr << boost::diagnostic_information(_exception);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (langutil::InternalCompilerError const& _exception)
|
||||||
|
{
|
||||||
|
cerr << "Internal compiler error:" << endl;
|
||||||
|
cerr << boost::diagnostic_information(_exception);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
catch (boost::exception const& _exception)
|
catch (boost::exception const& _exception)
|
||||||
{
|
{
|
||||||
cerr << "Exception during output generation: " << boost::diagnostic_information(_exception) << endl;
|
cerr << "Uncaught exception:" << endl;
|
||||||
success = false;
|
cerr << boost::diagnostic_information(_exception) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (std::exception const& _exception)
|
||||||
|
{
|
||||||
|
cerr << "Uncaught exception:" << endl;
|
||||||
|
cerr << boost::diagnostic_information(_exception) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
cerr << "Uncaught exception" << endl;
|
||||||
|
cerr << boost::current_exception_diagnostic_information() << endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user