mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Provide interface for calls in JSON and some other formatting changes.
This commit is contained in:
parent
7594813e1e
commit
ad4b027781
39
main.cpp
39
main.cpp
@ -26,12 +26,13 @@
|
|||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
#include <libdevcore/CommonData.h>
|
#include <libdevcore/CommonData.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
|
#include <libevmcore/Instruction.h>
|
||||||
#include <libsolidity/Scanner.h>
|
#include <libsolidity/Scanner.h>
|
||||||
#include <libsolidity/Parser.h>
|
#include <libsolidity/Parser.h>
|
||||||
#include <libsolidity/ASTPrinter.h>
|
#include <libsolidity/ASTPrinter.h>
|
||||||
#include <libsolidity/NameAndTypeResolver.h>
|
#include <libsolidity/NameAndTypeResolver.h>
|
||||||
#include <libsolidity/Exceptions.h>
|
#include <libsolidity/Exceptions.h>
|
||||||
#include <libsolidity/Compiler.h>
|
#include <libsolidity/CompilerStack.h>
|
||||||
#include <libsolidity/SourceReferenceFormatter.h>
|
#include <libsolidity/SourceReferenceFormatter.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -85,48 +86,34 @@ int main(int argc, char** argv)
|
|||||||
else
|
else
|
||||||
sourceCode = asString(dev::contents(infile));
|
sourceCode = asString(dev::contents(infile));
|
||||||
|
|
||||||
ASTPointer<ContractDefinition> ast;
|
CompilerStack compiler;
|
||||||
shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(sourceCode));
|
|
||||||
Parser parser;
|
|
||||||
bytes instructions;
|
|
||||||
Compiler compiler;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ast = parser.parse(scanner);
|
compiler.compile(sourceCode, optimize);
|
||||||
|
|
||||||
NameAndTypeResolver resolver;
|
|
||||||
resolver.resolveNamesAndTypes(*ast.get());
|
|
||||||
|
|
||||||
cout << "Syntax tree for the contract:" << endl;
|
|
||||||
dev::solidity::ASTPrinter printer(ast, sourceCode);
|
|
||||||
printer.print(cout);
|
|
||||||
|
|
||||||
compiler.compileContract(*ast);
|
|
||||||
instructions = compiler.getAssembledBytecode(optimize);
|
|
||||||
}
|
}
|
||||||
catch (ParserError const& exception)
|
catch (ParserError const& exception)
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Parser error", *scanner);
|
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Parser error", compiler.getScanner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (DeclarationError const& exception)
|
catch (DeclarationError const& exception)
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Declaration error", *scanner);
|
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Declaration error", compiler.getScanner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (TypeError const& exception)
|
catch (TypeError const& exception)
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Type error", *scanner);
|
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Type error", compiler.getScanner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (CompilerError const& exception)
|
catch (CompilerError const& exception)
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Compiler error", *scanner);
|
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Compiler error", compiler.getScanner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (InternalCompilerError const& exception)
|
catch (InternalCompilerError const& exception)
|
||||||
{
|
{
|
||||||
cerr << "Internal compiler error: " << boost::diagnostic_information(exception) << endl;
|
SourceReferenceFormatter::printExceptionInformation(cerr, exception, "Internal compiler error", compiler.getScanner());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (Exception const& exception)
|
catch (Exception const& exception)
|
||||||
@ -140,11 +127,15 @@ int main(int argc, char** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cout << "Syntax tree for the contract:" << endl;
|
||||||
|
ASTPrinter printer(compiler.getAST(), sourceCode);
|
||||||
|
printer.print(cout);
|
||||||
cout << "EVM assembly:" << endl;
|
cout << "EVM assembly:" << endl;
|
||||||
compiler.streamAssembly(cout);
|
compiler.streamAssembly(cout);
|
||||||
cout << "Opcodes:" << endl;
|
cout << "Opcodes:" << endl;
|
||||||
cout << eth::disassemble(instructions) << endl;
|
cout << eth::disassemble(compiler.getBytecode()) << endl;
|
||||||
cout << "Binary: " << toHex(instructions) << endl;
|
cout << "Binary: " << toHex(compiler.getBytecode()) << endl;
|
||||||
|
cout << "Interface specification: " << compiler.getInterface() << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user