Move stack height to generation phase.

This commit is contained in:
chriseth 2017-06-14 00:01:06 +02:00
parent 45d96959f8
commit c554145f4d
3 changed files with 9 additions and 11 deletions

View File

@ -64,8 +64,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
for (auto const& variable: _varDecl.variables) for (auto const& variable: _varDecl.variables)
{ {
auto& var = boost::get<Scope::Variable>(m_scope->identifiers.at(variable.name)); auto& var = boost::get<Scope::Variable>(m_scope->identifiers.at(variable.name));
var.stackHeight = height++; m_context->variableStackHeights[&var] = height++;
var.active = true;
} }
checkStackHeight(&_varDecl); checkStackHeight(&_varDecl);
} }
@ -288,8 +287,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
for (auto const& v: _function.arguments | boost::adaptors::reversed) for (auto const& v: _function.arguments | boost::adaptors::reversed)
{ {
auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name)); auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name));
var.stackHeight = height++; m_context->variableStackHeights[&var] = height++;
var.active = true;
} }
m_assembly.setSourceLocation(_function.location); m_assembly.setSourceLocation(_function.location);
@ -311,8 +309,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
for (auto const& v: _function.returns) for (auto const& v: _function.returns)
{ {
auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name)); auto& var = boost::get<Scope::Variable>(varScope->identifiers.at(v.name));
var.stackHeight = height++; m_context->variableStackHeights[&var] = height++;
var.active = true;
// Preset stack slots for return variables to zero. // Preset stack slots for return variables to zero.
m_assembly.appendConstant(u256(0)); 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 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)) if (heightDiff <= (_forSwap ? 1 : 0) || heightDiff > (_forSwap ? 17 : 16))
{ {
solUnimplemented( solUnimplemented(

View File

@ -81,8 +81,10 @@ public:
protected: protected:
struct Context struct Context
{ {
std::map<solidity::assembly::Scope::Label const*, AbstractAssembly::LabelID> labelIDs; using Scope = solidity::assembly::Scope;
std::map<solidity::assembly::Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs; std::map<Scope::Label const*, AbstractAssembly::LabelID> labelIDs;
std::map<Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs;
std::map<Scope::Variable const*, int> variableStackHeights;
}; };
CodeTransform( CodeTransform(

View File

@ -67,8 +67,6 @@ struct Scope
struct Variable 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. /// Used during analysis to check whether we already passed the declaration inside the block.
/// @todo move there. /// @todo move there.
bool active = false; bool active = false;