aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-11-21 20:23:43 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-03 06:37:47 +0800
commit0494fa98c0c973bf9e8b3dfa4873e1b5744e7715 (patch)
treefde61fef74bf4f4bc5186b1380775af0854baa14 /libsolidity
parentd230048dc8385744203528115aa9bb5c0fba4339 (diff)
downloaddexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar.gz
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar.bz2
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar.lz
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar.xz
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.tar.zst
dexon-solidity-0494fa98c0c973bf9e8b3dfa4873e1b5744e7715.zip
Add shift helper to CompilerUtils
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp10
-rw-r--r--libsolidity/codegen/CompilerUtils.h6
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();