Add shift helper to CompilerUtils

This commit is contained in:
Alex Beregszaszi 2016-11-21 12:23:43 +00:00
parent d230048dc8
commit 0494fa98c0
2 changed files with 16 additions and 0 deletions

View File

@ -1007,6 +1007,16 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack)
m_context << ((u256(1) << _typeOnStack.numBits()) - 1) << Instruction::AND;
}
void CompilerUtils::leftShiftNumberOnStack(u256 _shiftFactor)
{
m_context << _shiftFactor << Instruction::MUL;
}
void CompilerUtils::rightShiftNumberOnStack(u256 _shiftFactor, bool _isSigned)
{
m_context << _shiftFactor << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV);
}
unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords)
{
unsigned numBytes = _type.calldataEncodedSize(_padToWords);

View File

@ -176,6 +176,12 @@ public:
static unsigned sizeOnStack(std::vector<T> const& _variables);
static unsigned sizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes);
/// Helper function to shift top value on the stack to the left.
void leftShiftNumberOnStack(u256 _shiftFactor);
/// Helper function to shift top value on the stack to the right.
void rightShiftNumberOnStack(u256 _shiftFactor, bool _isSigned = false);
/// Appends code that computes tha Keccak-256 hash of the topmost stack element of 32 byte type.
void computeHashStatic();