Merge pull request #1037 from chriseth/sol_bytesCalldataToMemory

Copying calldata directly to memory.
This commit is contained in:
Gav Wood 2015-02-13 11:16:09 +01:00
commit 92abc7162b

View File

@ -76,8 +76,16 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
if (_type.getCategory() == Type::Category::ByteArray) if (_type.getCategory() == Type::Category::ByteArray)
{ {
auto const& type = dynamic_cast<ByteArrayType const&>(_type); auto const& type = dynamic_cast<ByteArrayType const&>(_type);
solAssert(type.getLocation() == ByteArrayType::Location::Storage, "Non-storage byte arrays not yet implemented.");
if (type.getLocation() == ByteArrayType::Location::CallData)
{
m_context << eth::Instruction::CALLDATASIZE << u256(0) << eth::Instruction::DUP3
<< eth::Instruction::CALLDATACOPY
<< eth::Instruction::CALLDATASIZE << eth::Instruction::ADD;
}
else
{
solAssert(type.getLocation() == ByteArrayType::Location::Storage, "Memory byte arrays not yet implemented.");
m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD; m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD;
// stack here: memory_offset storage_offset length_bytes // stack here: memory_offset storage_offset length_bytes
// jump to end if length is zero // jump to end if length is zero
@ -106,6 +114,7 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
m_context.appendConditionalJumpTo(loopStart); m_context.appendConditionalJumpTo(loopStart);
m_context << loopEnd << eth::Instruction::POP << eth::Instruction::POP; m_context << loopEnd << eth::Instruction::POP << eth::Instruction::POP;
} }
}
else else
{ {
unsigned numBytes = prepareMemoryStore(_type, _padToWordBoundaries); unsigned numBytes = prepareMemoryStore(_type, _padToWordBoundaries);