diff options
author | chriseth <chris@ethereum.org> | 2017-06-14 06:01:06 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-06-14 06:01:06 +0800 |
commit | c554145f4d7063422a5e105e2b600b640cf3d8d1 (patch) | |
tree | 604062962d8c5f70c4eed00c5522d25905bf75b4 | |
parent | 45d96959f88e951af0e2ccf0217f19d75da66ed1 (diff) | |
download | dexon-solidity-c554145f4d7063422a5e105e2b600b640cf3d8d1.tar.gz dexon-solidity-c554145f4d7063422a5e105e2b600b640cf3d8d1.tar.zst dexon-solidity-c554145f4d7063422a5e105e2b600b640cf3d8d1.zip |
Move stack height to generation phase.
-rw-r--r-- | libjulia/backends/evm/EVMCodeTransform.cpp | 12 | ||||
-rw-r--r-- | libjulia/backends/evm/EVMCodeTransform.h | 6 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmScope.h | 2 |
3 files changed, 9 insertions, 11 deletions
diff --git a/libjulia/backends/evm/EVMCodeTransform.cpp b/libjulia/backends/evm/EVMCodeTransform.cpp index 638ff4d9..7c14eb8b 100644 --- a/libjulia/backends/evm/EVMCodeTransform.cpp +++ b/libjulia/backends/evm/EVMCodeTransform.cpp @@ -64,8 +64,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl) for (auto const& variable: _varDecl.variables) { auto& var = boost::get<Scope::Variable>(m_scope->identifiers.at(variable.name)); - var.stackHeight = height++; - var.active = true; + m_context->variableStackHeights[&var] = height++; } checkStackHeight(&_varDecl); } @@ -288,8 +287,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) for (auto const& v: _function.arguments | boost::adaptors::reversed) { auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name)); - var.stackHeight = height++; - var.active = true; + m_context->variableStackHeights[&var] = height++; } m_assembly.setSourceLocation(_function.location); @@ -311,8 +309,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) for (auto const& v: _function.returns) { auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name)); - var.stackHeight = height++; - var.active = true; + m_context->variableStackHeights[&var] = height++; // Preset stack slots for return variables to zero. m_assembly.appendConstant(u256(0)); } @@ -427,7 +424,8 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap) { - int heightDiff = m_assembly.stackHeight() - _var.stackHeight; + solAssert(m_context->variableStackHeights.count(&_var), ""); + int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var]; if (heightDiff <= (_forSwap ? 1 : 0) || heightDiff > (_forSwap ? 17 : 16)) { solUnimplemented( diff --git a/libjulia/backends/evm/EVMCodeTransform.h b/libjulia/backends/evm/EVMCodeTransform.h index 57781c91..202f5051 100644 --- a/libjulia/backends/evm/EVMCodeTransform.h +++ b/libjulia/backends/evm/EVMCodeTransform.h @@ -81,8 +81,10 @@ public: protected: struct Context { - std::map<solidity::assembly::Scope::Label const*, AbstractAssembly::LabelID> labelIDs; - std::map<solidity::assembly::Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs; + using Scope = solidity::assembly::Scope; + std::map<Scope::Label const*, AbstractAssembly::LabelID> labelIDs; + std::map<Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs; + std::map<Scope::Variable const*, int> variableStackHeights; }; CodeTransform( diff --git a/libsolidity/inlineasm/AsmScope.h b/libsolidity/inlineasm/AsmScope.h index 5e22c6e7..23cf61f2 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libsolidity/inlineasm/AsmScope.h @@ -67,8 +67,6 @@ struct Scope struct Variable { - /// Used during code generation to store the stack height. @todo move there. - int stackHeight = 0; /// Used during analysis to check whether we already passed the declaration inside the block. /// @todo move there. bool active = false; |