diff options
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 10 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerUtils.h | 6 |
2 files changed, 16 insertions, 0 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index a105036f..1da21607 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -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); diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index 0ee053a9..278f9302 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -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(); |