diff options
author | Christian <c@ethdev.com> | 2014-12-09 01:19:25 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-09 01:19:25 +0800 |
commit | 9b68033efc40b11b7778fbdb43325ba4ad196f1c (patch) | |
tree | 96542ba6e7f087a92919de14bd0eaac8cb991ac8 /Compiler.cpp | |
parent | cd5f4958613ab131980c4b15563ad9d0017d8d5c (diff) | |
download | dexon-solidity-9b68033efc40b11b7778fbdb43325ba4ad196f1c.tar.gz dexon-solidity-9b68033efc40b11b7778fbdb43325ba4ad196f1c.tar.zst dexon-solidity-9b68033efc40b11b7778fbdb43325ba4ad196f1c.zip |
Cleanup before return.
Diffstat (limited to 'Compiler.cpp')
-rw-r--r-- | Compiler.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index 66d938d1..7e0f4ca1 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -195,13 +195,9 @@ bool Compiler::visit(FunctionDefinition& _function) // stack upon entry: [return address] [arg0] [arg1] ... [argn] // reserve additional slots: [retarg0] ... [retargm] [localvar0] ... [localvarp] - unsigned const numArguments = _function.getParameters().size(); - unsigned const numReturnValues = _function.getReturnParameters().size(); - unsigned const numLocalVariables = _function.getLocalVariables().size(); - - for (ASTPointer<VariableDeclaration> const& variable: _function.getParameters()) + for (ASTPointer<VariableDeclaration const> const& variable: _function.getParameters()) m_context.addVariable(*variable); - for (ASTPointer<VariableDeclaration> const& variable: _function.getReturnParameters()) + for (ASTPointer<VariableDeclaration const> const& variable: _function.getReturnParameters()) m_context.addAndInitializeVariable(*variable); for (VariableDeclaration const* localVariable: _function.getLocalVariables()) m_context.addAndInitializeVariable(*localVariable); @@ -216,12 +212,22 @@ bool Compiler::visit(FunctionDefinition& _function) // Note that the fact that the return arguments are of increasing index is vital for this // algorithm to work. + unsigned argumentsSize = 0; + for (ASTPointer<VariableDeclaration const> const& variable: _function.getParameters()) + argumentsSize += variable->getType()->getSizeOnStack(); + unsigned returnValuesSize = 0; + for (ASTPointer<VariableDeclaration const> const& variable: _function.getReturnParameters()) + returnValuesSize += variable->getType()->getSizeOnStack(); + unsigned localVariablesSize = 0; + for (VariableDeclaration const* localVariable: _function.getLocalVariables()) + localVariablesSize += localVariable->getType()->getSizeOnStack(); + vector<int> stackLayout; - stackLayout.push_back(numReturnValues); // target of return address - stackLayout += vector<int>(numArguments, -1); // discard all arguments - for (unsigned i = 0; i < numReturnValues; ++i) + stackLayout.push_back(returnValuesSize); // target of return address + stackLayout += vector<int>(argumentsSize, -1); // discard all arguments + for (unsigned i = 0; i < returnValuesSize; ++i) stackLayout.push_back(i); - stackLayout += vector<int>(numLocalVariables, -1); + stackLayout += vector<int>(localVariablesSize, -1); while (stackLayout.back() != int(stackLayout.size() - 1)) if (stackLayout.back() < 0) |