diff options
author | Paweł Bylica <pawel.bylica@imapp.pl> | 2015-03-12 20:39:40 +0800 |
---|---|---|
committer | Paweł Bylica <pawel.bylica@imapp.pl> | 2015-03-12 20:39:40 +0800 |
commit | 8181792a6ad37fa1b7d5961ac67cdcfee494ad4f (patch) | |
tree | 6f6f560f08dd548ae5c939b5fbf3efa7b0c358a9 | |
parent | 5ae0a975b373eb19aeb5eb7a17ccf46f3b63f56a (diff) | |
parent | 51258f300209a563cc5d1739504c1e87537ddff6 (diff) | |
download | dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar.gz dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar.bz2 dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar.lz dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar.xz dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.tar.zst dexon-solidity-8181792a6ad37fa1b7d5961ac67cdcfee494ad4f.zip |
Merge remote-tracking branch 'upstream/develop' into evmjit
-rw-r--r-- | Compiler.cpp | 3 | ||||
-rw-r--r-- | Compiler.h | 4 | ||||
-rw-r--r-- | CompilerContext.cpp | 7 | ||||
-rw-r--r-- | CompilerContext.h | 4 | ||||
-rw-r--r-- | ExpressionCompiler.cpp | 17 | ||||
-rw-r--r-- | GlobalContext.cpp | 1 | ||||
-rw-r--r-- | Parser.h | 2 |
7 files changed, 30 insertions, 8 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index 7ff846bd..dc6e2c5a 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -378,8 +378,9 @@ bool Compiler::visit(FunctionDefinition const& _function) m_context.removeVariable(*localVariable); m_context.adjustStackOffset(-(int)c_returnValuesSize); + if (!_function.isConstructor()) - m_context << eth::Instruction::JUMP; + m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction); return false; } @@ -94,8 +94,8 @@ private: std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement eth::AssemblyItem m_returnTag; ///< tag to jump to for a "return" statement unsigned m_modifierDepth = 0; - FunctionDefinition const* m_currentFunction; - unsigned m_stackCleanupForReturn; ///< this number of stack elements need to be removed before jump to m_returnTag + FunctionDefinition const* m_currentFunction = nullptr; + unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag // arguments for base constructors, filled in derived-to-base order std::map<FunctionDefinition const*, std::vector<ASTPointer<Expression>> const*> m_baseArguments; }; diff --git a/CompilerContext.cpp b/CompilerContext.cpp index 1dea62e9..f2bb1de2 100644 --- a/CompilerContext.cpp +++ b/CompilerContext.cpp @@ -177,6 +177,13 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati return it->second; } +CompilerContext& CompilerContext::appendJump(eth::AssemblyItem::JumpType _jumpType) +{ + eth::AssemblyItem item(eth::Instruction::JUMP); + item.setJumpType(_jumpType); + return *this << item; +} + void CompilerContext::resetVisitedNodes(ASTNode const* _node) { stack<ASTNode const*> newStack; diff --git a/CompilerContext.h b/CompilerContext.h index 4d63d8ba..76923a77 100644 --- a/CompilerContext.h +++ b/CompilerContext.h @@ -91,7 +91,7 @@ public: /// Appends a JUMP to a new tag and @returns the tag eth::AssemblyItem appendJumpToNew() { return m_asm.appendJump().tag(); } /// Appends a JUMP to a tag already on the stack - CompilerContext& appendJump() { return *this << eth::Instruction::JUMP; } + CompilerContext& appendJump(eth::AssemblyItem::JumpType _jumpType = eth::AssemblyItem::JumpType::Ordinary); /// Appends a JUMP to a specific tag CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJump(_tag); return *this; } /// Appends pushing of a new tag and @returns the new tag. @@ -120,7 +120,7 @@ public: eth::Assembly const& getAssembly() const { return m_asm; } /// @arg _sourceCodes is the map of input files to source code strings - void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const { m_asm.streamRLP(_stream, "", _sourceCodes); } + void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const { m_asm.stream(_stream, "", _sourceCodes); } bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); } diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index b02aecf5..12926112 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -108,7 +108,8 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& retSizeOnStack = returnType->getSizeOnStack(); } solAssert(retSizeOnStack <= 15, "Stack too deep."); - m_context << eth::dupInstruction(retSizeOnStack + 1) << eth::Instruction::JUMP; + m_context << eth::dupInstruction(retSizeOnStack + 1); + m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction); } void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded) @@ -405,7 +406,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) } _functionCall.getExpression().accept(*this); - m_context.appendJump(); + m_context.appendJump(eth::AssemblyItem::JumpType::IntoFunction); m_context << returnLabel; unsigned returnParametersSize = CompilerUtils::getSizeOnStack(function.getReturnParameterTypes()); @@ -825,10 +826,20 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier) Declaration const* declaration = _identifier.getReferencedDeclaration(); if (MagicVariableDeclaration const* magicVar = dynamic_cast<MagicVariableDeclaration const*>(declaration)) { - if (magicVar->getType()->getCategory() == Type::Category::Contract) + switch (magicVar->getType()->getCategory()) + { + case Type::Category::Contract: // "this" or "super" if (!dynamic_cast<ContractType const&>(*magicVar->getType()).isSuper()) m_context << eth::Instruction::ADDRESS; + break; + case Type::Category::Integer: + // "now" + m_context << eth::Instruction::TIMESTAMP; + break; + default: + break; + } } else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration)) m_context << m_context.getVirtualFunctionEntryLabel(*functionDef).pushTag(); diff --git a/GlobalContext.cpp b/GlobalContext.cpp index 60de5105..411e99ab 100644 --- a/GlobalContext.cpp +++ b/GlobalContext.cpp @@ -37,6 +37,7 @@ GlobalContext::GlobalContext(): m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)), make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message)), make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)), + make_shared<MagicVariableDeclaration>("now", make_shared<IntegerType>(256)), make_shared<MagicVariableDeclaration>("suicide", make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)), make_shared<MagicVariableDeclaration>("sha3", @@ -34,6 +34,8 @@ class Scanner; class Parser { public: + Parser() {} + ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner); std::shared_ptr<std::string const> const& getSourceName() const; |