diff options
author | Christian <c@ethdev.com> | 2014-12-08 23:56:41 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-08 23:56:41 +0800 |
commit | cd5f4958613ab131980c4b15563ad9d0017d8d5c (patch) | |
tree | 7e9f4ef84501756e20a042ffd3a24b9802735ead /CompilerContext.cpp | |
parent | 57e6827cb57708ed8f687bf9b0a304b1481cf742 (diff) | |
download | dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar.gz dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar.bz2 dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar.lz dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar.xz dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.tar.zst dexon-solidity-cd5f4958613ab131980c4b15563ad9d0017d8d5c.zip |
Register variably-sized variables on stack.
Diffstat (limited to 'CompilerContext.cpp')
-rw-r--r-- | CompilerContext.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/CompilerContext.cpp b/CompilerContext.cpp index b89a8e5b..fa18520d 100644 --- a/CompilerContext.cpp +++ b/CompilerContext.cpp @@ -41,20 +41,25 @@ void CompilerContext::addStateVariable(VariableDeclaration const& _declaration) m_stateVariablesSize += _declaration.getType()->getStorageSize(); } -void CompilerContext::initializeLocalVariables(unsigned _numVariables) +void CompilerContext::addVariable(VariableDeclaration const& _declaration) { - if (_numVariables > 0) - { + m_localVariables[&_declaration] = m_localVariablesSize; + m_localVariablesSize += _declaration.getType()->getSizeOnStack(); +} + +void CompilerContext::addAndInitializeVariable(VariableDeclaration const& _declaration) +{ + addVariable(_declaration); + + unsigned const size = _declaration.getType()->getSizeOnStack(); + for (unsigned i = 0; i < size; ++i) *this << u256(0); - for (unsigned i = 1; i < _numVariables; ++i) - *this << eth::Instruction::DUP1; - m_asm.adjustDeposit(-_numVariables); - } + m_asm.adjustDeposit(-size); } bool CompilerContext::isLocalVariable(Declaration const* _declaration) const { - return std::find(m_localVariables.begin(), m_localVariables.end(), _declaration) != m_localVariables.end(); + return m_localVariables.count(_declaration) > 0; } eth::AssemblyItem CompilerContext::getFunctionEntryLabel(FunctionDefinition const& _function) const @@ -67,10 +72,10 @@ eth::AssemblyItem CompilerContext::getFunctionEntryLabel(FunctionDefinition cons unsigned CompilerContext::getBaseStackOffsetOfVariable(Declaration const& _declaration) const { - auto res = find(begin(m_localVariables), end(m_localVariables), &_declaration); + auto res = m_localVariables.find(&_declaration); if (asserts(res != m_localVariables.end())) BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Variable not found on stack.")); - return unsigned(end(m_localVariables) - res - 1); + return m_localVariablesSize - res->second - 1; } unsigned CompilerContext::baseToCurrentStackOffset(unsigned _baseOffset) const |