More uses of shift helper

This commit is contained in:
Alex Beregszaszi 2017-02-12 14:48:46 +00:00
parent 8fd1d4167d
commit 68b0ac4fdd

View File

@ -353,13 +353,16 @@ void CompilerUtils::splitExternalFunctionType(bool _leftAligned)
// address (right aligned), function identifier (right aligned)
if (_leftAligned)
{
m_context << Instruction::DUP1 << (u256(1) << (64 + 32)) << Instruction::SWAP1 << Instruction::DIV;
m_context << Instruction::DUP1;
rightShiftNumberOnStack(64 + 32, false);
// <input> <address>
m_context << Instruction::SWAP1 << (u256(1) << 64) << Instruction::SWAP1 << Instruction::DIV;
m_context << Instruction::SWAP1;
rightShiftNumberOnStack(64, false);
}
else
{
m_context << Instruction::DUP1 << (u256(1) << 32) << Instruction::SWAP1 << Instruction::DIV;
m_context << Instruction::DUP1;
rightShiftNumberOnStack(32, false);
m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1;
}
m_context << u256(0xffffffffUL) << Instruction::AND;
@ -383,11 +386,12 @@ void CompilerUtils::pushCombinedFunctionEntryLabel(Declaration const& _function)
// If there is a runtime context, we have to merge both labels into the same
// stack slot in case we store it in storage.
if (CompilerContext* rtc = m_context.runtimeContext())
{
leftShiftNumberOnStack(32);
m_context <<
(u256(1) << 32) <<
Instruction::MUL <<
rtc->functionEntryLabel(_function).toSubAssemblyTag(m_context.runtimeSub()) <<
Instruction::OR;
}
}
void CompilerUtils::convertType(
@ -1029,7 +1033,7 @@ unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords)
convertType(_type, _type, true);
if (numBytes != 32 && !leftAligned && !_padToWords)
// shift the value accordingly before storing
m_context << (u256(1) << ((32 - numBytes) * 8)) << Instruction::MUL;
leftShiftNumberOnStack((32 - numBytes) * 8);
}
return numBytes;
}