diff options
author | chriseth <chris@ethereum.org> | 2018-07-12 19:01:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 19:01:15 +0800 |
commit | 576f3ef18c47c13b92e5b604d19f99018b0300b0 (patch) | |
tree | 3cf2e9c41606f6c2a599621297a8155e097333dc /libsolidity/codegen/CompilerContext.cpp | |
parent | c438b73f689b904152f4b8b636579317fb55e60a (diff) | |
parent | a18a475b1a6ba1ebcf235f322dec0e7ff3d3dcb0 (diff) | |
download | dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar.gz dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar.bz2 dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar.lz dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar.xz dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.tar.zst dexon-solidity-576f3ef18c47c13b92e5b604d19f99018b0300b0.zip |
Merge pull request #4083 from ethereum/variable_stack_slot
[BREAKING] Allocate local variables according to their scope
Diffstat (limited to 'libsolidity/codegen/CompilerContext.cpp')
-rw-r--r-- | libsolidity/codegen/CompilerContext.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index a35eea73..3b1b4ec0 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -127,10 +127,14 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent) { solAssert(m_asm->deposit() >= 0 && unsigned(m_asm->deposit()) >= _offsetToCurrent, ""); + unsigned sizeOnStack = _declaration.annotation().type->sizeOnStack(); + // Variables should not have stack size other than [1, 2], + // but that might change when new types are introduced. + solAssert(sizeOnStack == 1 || sizeOnStack == 2, ""); m_localVariables[&_declaration].push_back(unsigned(m_asm->deposit()) - _offsetToCurrent); } -void CompilerContext::removeVariable(VariableDeclaration const& _declaration) +void CompilerContext::removeVariable(Declaration const& _declaration) { solAssert(m_localVariables.count(&_declaration) && !m_localVariables[&_declaration].empty(), ""); m_localVariables[&_declaration].pop_back(); @@ -138,6 +142,25 @@ void CompilerContext::removeVariable(VariableDeclaration const& _declaration) m_localVariables.erase(&_declaration); } +void CompilerContext::removeVariablesAboveStackHeight(unsigned _stackHeight) +{ + vector<Declaration const*> toRemove; + for (auto _var: m_localVariables) + { + solAssert(!_var.second.empty(), ""); + solAssert(_var.second.back() <= stackHeight(), ""); + if (_var.second.back() >= _stackHeight) + toRemove.push_back(_var.first); + } + for (auto _var: toRemove) + removeVariable(*_var); +} + +unsigned CompilerContext::numberOfLocalVariables() const +{ + return m_localVariables.size(); +} + eth::Assembly const& CompilerContext::compiledContract(const ContractDefinition& _contract) const { auto ret = m_compiledContracts.find(&_contract); |