aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerUtils.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-11-17 22:15:00 +0800
committerchriseth <c@ethdev.com>2015-11-26 20:10:12 +0800
commit879844dd0a9137602373c8f67f283a5895913732 (patch)
treeea084fcbf268c0a1644f62364c6d9713ed119604 /libsolidity/codegen/CompilerUtils.cpp
parentbf55aa6ae2b9aeec09bb8cf1e3715afd7dd59b7e (diff)
downloaddexon-solidity-879844dd0a9137602373c8f67f283a5895913732.tar.gz
dexon-solidity-879844dd0a9137602373c8f67f283a5895913732.tar.zst
dexon-solidity-879844dd0a9137602373c8f67f283a5895913732.zip
Code generation for creating arrays.
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 2ebf5b64..357013e6 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -266,6 +266,19 @@ void CompilerUtils::encodeToMemory(
popStackSlots(argSize + dynPointers + 1);
}
+void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type)
+{
+ auto repeat = m_context.newTag();
+ m_context << repeat;
+ pushZeroValue(*_type.baseType());
+ storeInMemoryDynamic(*_type.baseType());
+ m_context << eth::Instruction::SWAP1 << u256(1) << eth::Instruction::SWAP1;
+ m_context << eth::Instruction::SUB << eth::Instruction::SWAP1;
+ m_context << eth::Instruction::DUP2;
+ m_context.appendConditionalJumpTo(repeat);
+ m_context << eth::Instruction::SWAP1 << eth::Instruction::POP;
+}
+
void CompilerUtils::memoryCopy()
{
// Stack here: size target source
@@ -646,15 +659,8 @@ void CompilerUtils::pushZeroValue(Type const& _type)
{
m_context << arrayType->length() << eth::Instruction::SWAP1;
// stack: items_to_do memory_pos
- auto repeat = m_context.newTag();
- m_context << repeat;
- pushZeroValue(*arrayType->baseType());
- storeInMemoryDynamic(*arrayType->baseType());
- m_context << eth::Instruction::SWAP1 << u256(1) << eth::Instruction::SWAP1;
- m_context << eth::Instruction::SUB << eth::Instruction::SWAP1;
- m_context << eth::Instruction::DUP2;
- m_context.appendConditionalJumpTo(repeat);
- m_context << eth::Instruction::SWAP1 << eth::Instruction::POP;
+ zeroInitialiseMemoryArray(*arrayType);
+ // stack: updated_memory_pos
}
}
else