diff options
author | Christian <c@ethdev.com> | 2014-10-30 08:20:32 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-10-30 08:25:42 +0800 |
commit | 877aa91c57bb9cda410a7b521ed3b7630b5ae2dc (patch) | |
tree | e2cb3cd5c6f7f36828d72e13be628bde75800648 | |
parent | 03a6cf0e81407df00742fe42929bdbdca89473c7 (diff) | |
download | dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar.gz dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar.bz2 dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar.lz dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar.xz dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.tar.zst dexon-solidity-877aa91c57bb9cda410a7b521ed3b7630b5ae2dc.zip |
Contract compiler and also add ExpressionStatement to AST.
ExpressionStatement functions as glue between Statements and Expressions.
This way it is possible to detect when the border between statements and
expressions is crossed while walking the AST. Note that ExpressionStatement is
not the only border, almost every statement can contains expressions.
-rw-r--r-- | main.cpp | 41 |
1 files changed, 4 insertions, 37 deletions
@@ -55,35 +55,6 @@ void version() exit(0); } - -/// Helper class that extracts the first expression in an AST. -class FirstExpressionExtractor: private ASTVisitor -{ -public: - FirstExpressionExtractor(ASTNode& _node): m_expression(nullptr) { _node.accept(*this); } - Expression* getExpression() const { return m_expression; } -private: - virtual bool visit(Expression& _expression) override { return checkExpression(_expression); } - virtual bool visit(Assignment& _expression) override { return checkExpression(_expression); } - virtual bool visit(UnaryOperation& _expression) override { return checkExpression(_expression); } - virtual bool visit(BinaryOperation& _expression) override { return checkExpression(_expression); } - virtual bool visit(FunctionCall& _expression) override { return checkExpression(_expression); } - virtual bool visit(MemberAccess& _expression) override { return checkExpression(_expression); } - virtual bool visit(IndexAccess& _expression) override { return checkExpression(_expression); } - virtual bool visit(PrimaryExpression& _expression) override { return checkExpression(_expression); } - virtual bool visit(Identifier& _expression) override { return checkExpression(_expression); } - virtual bool visit(ElementaryTypeNameExpression& _expression) override { return checkExpression(_expression); } - virtual bool visit(Literal& _expression) override { return checkExpression(_expression); } - bool checkExpression(Expression& _expression) - { - if (m_expression == nullptr) - m_expression = &_expression; - return false; - } -private: - Expression* m_expression; -}; - int main(int argc, char** argv) { string infile; @@ -143,13 +114,10 @@ int main(int argc, char** argv) dev::solidity::ASTPrinter printer(ast, sourceCode); printer.print(cout); - FirstExpressionExtractor extractor(*ast); - - CompilerContext context; - ExpressionCompiler compiler(context); + bytes instructions; try { - compiler.compile(*extractor.getExpression()); + instructions = Compiler::compile(*ast); } catch (CompilerError const& exception) { @@ -157,10 +125,9 @@ int main(int argc, char** argv) return -1; } - bytes instructions = compiler.getAssembledBytecode(); - - cout << "Bytecode for the first expression: " << endl; + cout << "EVM assembly: " << endl; cout << eth::disassemble(instructions) << endl; + cout << "Binary: " << toHex(instructions) << endl; return 0; } |