aboutsummaryrefslogtreecommitdiffstats
path: root/Compiler.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-15 19:59:17 +0800
committerChristian <c@ethdev.com>2014-12-15 20:05:18 +0800
commit40f7c32e57cf8b09d45f52935b8726f5baef5358 (patch)
treeffd8a95576fd6ab0deec5246c474b07aa27b6792 /Compiler.cpp
parent2f64c56ef3a49f7551a708f63c4ed836efce7b73 (diff)
downloaddexon-solidity-40f7c32e57cf8b09d45f52935b8726f5baef5358.tar.gz
dexon-solidity-40f7c32e57cf8b09d45f52935b8726f5baef5358.tar.zst
dexon-solidity-40f7c32e57cf8b09d45f52935b8726f5baef5358.zip
Packing and unpacking of constructor arguments.
Diffstat (limited to 'Compiler.cpp')
-rw-r--r--Compiler.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index 48d8be88..f2877c1c 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -77,12 +77,21 @@ void Compiler::packIntoContractCreator(ContractDefinition const& _contract,
{
eth::AssemblyItem returnTag = m_context.pushNewTag();
m_context.addFunction(*constructor); // note that it cannot be called due to syntactic reasons
- // copy constructor arguments
- //@todo ask assembly for the size of the current program
+ // copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
+ unsigned argumentSize = 0;
+ for (ASTPointer<VariableDeclaration> const& var: constructor->getParameters())
+ argumentSize += var->getType()->getCalldataEncodedSize();
+ if (argumentSize > 0)
+ {
+ m_context << u256(argumentSize);
+ m_context.appendProgramSize();
+ m_context << u256(1); // copy it to byte one as expected for ABI calls
+ m_context << eth::Instruction::CODECOPY;
+ appendCalldataUnpacker(*constructor, true);
+ }
//@todo calling other functions inside the constructor should either trigger a parse error
//or we should copy them here (register them above and call "accept") - detecting which
// functions are referenced / called needs to be done in a recursive way.
- appendCalldataUnpacker(*constructor, true);
m_context.appendJumpTo(m_context.getFunctionEntryLabel(*constructor));
constructor->accept(*this);
m_context << returnTag;
@@ -135,7 +144,6 @@ unsigned Compiler::appendCalldataUnpacker(FunctionDefinition const& _function, b
{
// We do not check the calldata size, everything is zero-padded.
unsigned dataOffset = 1;
-
//@todo this can be done more efficiently, saving some CALLDATALOAD calls
for (ASTPointer<VariableDeclaration> const& var: _function.getParameters())
{