From e6902e070e5952d7d732a537edc81331609bc55b Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 3 Dec 2014 07:46:55 +0100 Subject: [PATCH 1/2] Import directive. --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a7216e594..76d8ef6b7 100644 --- a/main.cpp +++ b/main.cpp @@ -127,7 +127,7 @@ int main(int argc, char** argv) return -1; } - cout << "Syntax tree for the contract:" << endl; + cout << "Syntax tree for the source unit:" << endl; ASTPrinter printer(compiler.getAST(), sourceCode); printer.print(cout); cout << "EVM assembly:" << endl; From aae508748e0537c1afc0d9507c427cd5ca30189a Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 3 Dec 2014 18:52:28 +0100 Subject: [PATCH 2/2] Improved external interface for multi-source and multi-contract compilation. --- main.cpp | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/main.cpp b/main.cpp index 76d8ef6b7..3284be74a 100644 --- a/main.cpp +++ b/main.cpp @@ -59,7 +59,7 @@ void version() int main(int argc, char** argv) { - string infile; + vector infiles; bool optimize = false; for (int i = 1; i < argc; ++i) { @@ -71,49 +71,52 @@ int main(int argc, char** argv) else if (arg == "-V" || arg == "--version") version(); else - infile = argv[i]; + infiles.push_back(argv[i]); } - string sourceCode; - if (infile.empty()) + map sourceCodes; + if (infiles.empty()) { string s; while (!cin.eof()) { getline(cin, s); - sourceCode.append(s); + sourceCodes[""].append(s); } } else - sourceCode = asString(dev::contents(infile)); + for (string const& infile: infiles) + sourceCodes[infile] = asString(dev::contents(infile)); CompilerStack compiler; try { - compiler.compile(sourceCode, optimize); + for (auto const& sourceCode: sourceCodes) + compiler.addSource(sourceCode.first, sourceCode.second); + compiler.compile(optimize); } catch (ParserError const& exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Parser error", compiler.getScanner()); + SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Parser error", compiler); return -1; } catch (DeclarationError const& exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Declaration error", compiler.getScanner()); + SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Declaration error", compiler); return -1; } catch (TypeError const& exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Type error", compiler.getScanner()); + SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Type error", compiler); return -1; } catch (CompilerError const& exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Compiler error", compiler.getScanner()); + SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Compiler error", compiler); return -1; } catch (InternalCompilerError const& exception) { - SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Internal compiler error", compiler.getScanner()); + SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Internal compiler error", compiler); return -1; } catch (Exception const& exception) @@ -127,15 +130,25 @@ int main(int argc, char** argv) return -1; } - cout << "Syntax tree for the source unit:" << endl; - ASTPrinter printer(compiler.getAST(), sourceCode); - printer.print(cout); - cout << "EVM assembly:" << endl; - compiler.streamAssembly(cout); - cout << "Opcodes:" << endl; - cout << eth::disassemble(compiler.getBytecode()) << endl; - cout << "Binary: " << toHex(compiler.getBytecode()) << endl; - cout << "Interface specification: " << compiler.getInterface() << endl; + cout << "Syntax trees:" << endl << endl; + for (auto const& sourceCode: sourceCodes) + { + cout << endl << "======= " << sourceCode.first << " =======" << endl; + ASTPrinter printer(compiler.getAST(sourceCode.first), sourceCode.second); + printer.print(cout); + } + vector contracts = compiler.getContractNames(); + cout << endl << "Contracts:" << endl; + for (string const& contract: contracts) + { + cout << endl << "======= " << contract << " =======" << endl + << "EVM assembly:" << endl; + compiler.streamAssembly(cout, contract); + cout << "Opcodes:" << endl + << eth::disassemble(compiler.getBytecode(contract)) << endl + << "Binary: " << toHex(compiler.getBytecode(contract)) << endl + << "Interface specification: " << compiler.getInterface(contract) << endl; + } return 0; }