diff options
author | chriseth <c@ethdev.com> | 2016-02-22 09:13:41 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-03-30 08:37:00 +0800 |
commit | 949b00ed591303c531ed8fa73087b710b7a554de (patch) | |
tree | 182664f2545e6211d7994ef90a1e7746d5482981 /solc/CommandLineInterface.cpp | |
parent | 8236732e9a5d2535afd3a3573a70d5aab3da3efe (diff) | |
download | dexon-solidity-949b00ed591303c531ed8fa73087b710b7a554de.tar.gz dexon-solidity-949b00ed591303c531ed8fa73087b710b7a554de.tar.zst dexon-solidity-949b00ed591303c531ed8fa73087b710b7a554de.zip |
Parsing for inline assembly.
Diffstat (limited to 'solc/CommandLineInterface.cpp')
-rw-r--r-- | solc/CommandLineInterface.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 499b1f7a..1cf87bc9 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -45,6 +45,7 @@ #include <libsolidity/interface/CompilerStack.h> #include <libsolidity/interface/SourceReferenceFormatter.h> #include <libsolidity/interface/GasEstimator.h> +#include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/formal/Why3Translator.h> using namespace std; @@ -431,6 +432,10 @@ Allowed options)", ) (g_argGas.c_str(), "Print an estimate of the maximal gas usage for each function.") ( + "assemble", + "Switch to assembly mode, ignoring all options and assumes input is assembly." + ) + ( "link", "Switch to linker mode, ignoring all options apart from --libraries " "and modify binaries in place." @@ -509,6 +514,12 @@ bool CommandLineInterface::processInput() if (!parseLibraryOption(library)) return false; + if (m_args.count("assemble")) + { + // switch to assembly mode + m_onlyAssemble = true; + return assemble(); + } if (m_args.count("link")) { // switch to linker mode @@ -574,6 +585,7 @@ bool CommandLineInterface::processInput() }; m_compiler.reset(new CompilerStack(m_args.count(g_argAddStandard) > 0, fileReader)); + auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); }; try { for (auto const& sourceCode: m_sourceCodes) @@ -593,7 +605,8 @@ bool CommandLineInterface::processInput() SourceReferenceFormatter::printExceptionInformation( cerr, *error, - (error->type() == Error::Type::Warning) ? "Warning" : "Error", *m_compiler + (error->type() == Error::Type::Warning) ? "Warning" : "Error", + scannerFromSourceName ); if (!successful) @@ -601,7 +614,7 @@ bool CommandLineInterface::processInput() } catch (CompilerError const& _exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Compiler error", *m_compiler); + SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Compiler error", scannerFromSourceName); return false; } catch (InternalCompilerError const& _exception) @@ -615,7 +628,7 @@ bool CommandLineInterface::processInput() if (_error.type() == Error::Type::DocstringParsingError) cerr << "Documentation parsing error: " << *boost::get_error_info<errinfo_comment>(_error) << endl; else - SourceReferenceFormatter::printExceptionInformation(cerr, _error, _error.typeName(), *m_compiler); + SourceReferenceFormatter::printExceptionInformation(cerr, _error, _error.typeName(), scannerFromSourceName); return false; } @@ -759,7 +772,9 @@ void CommandLineInterface::handleAst(string const& _argStr) void CommandLineInterface::actOnInput() { - if (m_onlyLink) + if (m_onlyAssemble) + return; //@TODO + else if (m_onlyLink) writeLinkedFiles(); else outputCompilationResults(); @@ -812,6 +827,31 @@ void CommandLineInterface::writeLinkedFiles() writeFile(src.first, src.second); } +bool CommandLineInterface::assemble() +{ + //@TODO later, we will use the convenience interface and should also remove the include above + bool successful = true; + ErrorList errors; + map<string, shared_ptr<Scanner>> scanners; + for (auto const& src: m_sourceCodes) + { + auto scanner = make_shared<Scanner>(CharStream(src.second), src.first); + scanners[src.first] = scanner; + InlineAssemblyParser parser(errors); + if (!parser.parse(scanner)) + successful = false; + } + for (auto const& error: errors) + SourceReferenceFormatter::printExceptionInformation( + cerr, + *error, + (error->type() == Error::Type::Warning) ? "Warning" : "Error", + [&](string const& _source) -> Scanner const& { return *scanners.at(_source); } + ); + + return successful; +} + void CommandLineInterface::outputCompilationResults() { handleCombinedJSON(); |