diff options
author | Christian <c@ethdev.com> | 2014-11-01 00:47:43 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-03 23:11:40 +0800 |
commit | 4dfd6dfa13929f31dcea889d17a6fc77137f9c67 (patch) | |
tree | c9ce6abe2c76e25025669448da6bccfc9736f0f2 /Compiler.cpp | |
parent | 643c781a6ddd4cd601b0aee5ad4d2ee0613495a0 (diff) | |
download | dexon-solidity-4dfd6dfa13929f31dcea889d17a6fc77137f9c67.tar.gz dexon-solidity-4dfd6dfa13929f31dcea889d17a6fc77137f9c67.tar.zst dexon-solidity-4dfd6dfa13929f31dcea889d17a6fc77137f9c67.zip |
Some tests and bugfixes for the compiler.
Diffstat (limited to 'Compiler.cpp')
-rw-r--r-- | Compiler.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index 7909e070..a44c177d 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -94,25 +94,20 @@ void Compiler::appendFunctionSelector(vector<ASTPointer<FunctionDefinition>> con for (pair<string, pair<FunctionDefinition const*, eth::AssemblyItem>> const& f: publicFunctions) m_context.appendJumpTo(f.second.second) << eth::Instruction::JUMPDEST; - m_context << returnTag << eth::Instruction::RETURN; + m_context << returnTag << eth::Instruction::STOP; for (pair<string, pair<FunctionDefinition const*, eth::AssemblyItem>> const& f: publicFunctions) { + FunctionDefinition const& function = *f.second.first; m_context << f.second.second; - appendFunctionCallSection(*f.second.first); - } -} - -void Compiler::appendFunctionCallSection(FunctionDefinition const& _function) -{ - eth::AssemblyItem returnTag = m_context.pushNewTag(); - appendCalldataUnpacker(_function); + eth::AssemblyItem returnTag = m_context.pushNewTag(); + appendCalldataUnpacker(function); + m_context.appendJumpTo(m_context.getFunctionEntryLabel(function)); + m_context << returnTag; - m_context.appendJumpTo(m_context.getFunctionEntryLabel(_function)); - m_context << returnTag; - - appendReturnValuePacker(_function); + appendReturnValuePacker(function); + } } void Compiler::appendCalldataUnpacker(FunctionDefinition const& _function) @@ -142,7 +137,7 @@ void Compiler::appendReturnValuePacker(FunctionDefinition const& _function) //@todo this can be also done more efficiently unsigned dataOffset = 0; vector<ASTPointer<VariableDeclaration>> const& parameters = _function.getReturnParameters(); - for (unsigned i = 0 ; i < parameters.size(); ++i) + for (unsigned i = 0; i < parameters.size(); ++i) { unsigned numBytes = parameters[i]->getType()->getCalldataEncodedSize(); if (numBytes == 0) @@ -150,11 +145,9 @@ void Compiler::appendReturnValuePacker(FunctionDefinition const& _function) << errinfo_sourceLocation(parameters[i]->getLocation()) << errinfo_comment("Type not yet supported.")); m_context << eth::dupInstruction(parameters.size() - i); - if (numBytes == 32) - m_context << u256(dataOffset) << eth::Instruction::MSTORE; - else - m_context << u256(dataOffset) << (u256(1) << ((32 - numBytes) * 8)) - << eth::Instruction::MUL << eth::Instruction::MSTORE; + if (numBytes != 32) + m_context << (u256(1) << ((32 - numBytes) * 8)) << eth::Instruction::MUL; + m_context << u256(dataOffset) << eth::Instruction::MSTORE; dataOffset += numBytes; } // note that the stack is not cleaned up here @@ -215,6 +208,7 @@ bool Compiler::visit(FunctionDefinition& _function) m_context << eth::swapInstruction(stackLayout.size() - stackLayout.back() - 1); swap(stackLayout[stackLayout.back()], stackLayout.back()); } + //@todo assert that everything is in place now m_context << eth::Instruction::JUMP; |