aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-11-30 18:03:26 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-03 06:40:47 +0800
commit8fd1d4167d2d05363ecf6af7ada42da940199900 (patch)
tree3a1765d3d4ef9efbec7e8afceaad4d41f3056a62 /libsolidity
parentc7ae042114e50ceccd2c230abf80ac7b246d0a44 (diff)
downloaddexon-solidity-8fd1d4167d2d05363ecf6af7ada42da940199900.tar.gz
dexon-solidity-8fd1d4167d2d05363ecf6af7ada42da940199900.tar.zst
dexon-solidity-8fd1d4167d2d05363ecf6af7ada42da940199900.zip
Change shiftNumberOnStack to bits
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp18
-rw-r--r--libsolidity/codegen/CompilerUtils.h4
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp4
3 files changed, 13 insertions, 13 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 4d8f32ca..8ea86684 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -371,10 +371,10 @@ void CompilerUtils::combineExternalFunctionType(bool _leftAligned)
m_context << u256(0xffffffffUL) << Instruction::AND << Instruction::SWAP1;
if (!_leftAligned)
m_context << ((u256(1) << 160) - 1) << Instruction::AND;
- leftShiftNumberOnStack(u256(1) << 32);
+ leftShiftNumberOnStack(32);
m_context << Instruction::OR;
if (_leftAligned)
- leftShiftNumberOnStack(u256(1) << 64);
+ leftShiftNumberOnStack(64);
}
void CompilerUtils::pushCombinedFunctionEntryLabel(Declaration const& _function)
@@ -425,7 +425,7 @@ void CompilerUtils::convertType(
// conversion from bytes to integer. no need to clean the high bit
// only to shift right because of opposite alignment
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
- rightShiftNumberOnStack(u256(1) << (256 - typeOnStack.numBytes() * 8), false);
+ rightShiftNumberOnStack(256 - typeOnStack.numBytes() * 8, false);
if (targetIntegerType.numBits() < typeOnStack.numBytes() * 8)
convertType(IntegerType(typeOnStack.numBytes() * 8), _targetType, _cleanupNeeded);
}
@@ -476,7 +476,7 @@ void CompilerUtils::convertType(
if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack))
if (targetBytesType.numBytes() * 8 > typeOnStack->numBits())
cleanHigherOrderBits(*typeOnStack);
- leftShiftNumberOnStack(u256(1) << (256 - targetBytesType.numBytes() * 8));
+ leftShiftNumberOnStack(256 - targetBytesType.numBytes() * 8);
}
else if (targetTypeCategory == Type::Category::Enum)
{
@@ -986,7 +986,7 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda
{
bool leftAligned = _type.category() == Type::Category::FixedBytes;
// add leading or trailing zeros by dividing/multiplying depending on alignment
- u256 shiftFactor = u256(1) << ((32 - numBytes) * 8);
+ int shiftFactor = (32 - numBytes) * 8;
rightShiftNumberOnStack(shiftFactor, false);
if (leftAligned)
leftShiftNumberOnStack(shiftFactor);
@@ -1007,14 +1007,14 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack)
m_context << ((u256(1) << _typeOnStack.numBits()) - 1) << Instruction::AND;
}
-void CompilerUtils::leftShiftNumberOnStack(u256 _shiftFactor)
+void CompilerUtils::leftShiftNumberOnStack(unsigned _bits)
{
- m_context << _shiftFactor << Instruction::MUL;
+ m_context << (u256(1) << _bits) << Instruction::MUL;
}
-void CompilerUtils::rightShiftNumberOnStack(u256 _shiftFactor, bool _isSigned)
+void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned)
{
- m_context << _shiftFactor << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV);
+ m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV);
}
unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords)
diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h
index 278f9302..fb169463 100644
--- a/libsolidity/codegen/CompilerUtils.h
+++ b/libsolidity/codegen/CompilerUtils.h
@@ -177,10 +177,10 @@ public:
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);
+ void leftShiftNumberOnStack(unsigned _bits);
/// Helper function to shift top value on the stack to the right.
- void rightShiftNumberOnStack(u256 _shiftFactor, bool _isSigned = false);
+ void rightShiftNumberOnStack(unsigned _bits, bool _isSigned = false);
/// Appends code that computes tha Keccak-256 hash of the topmost stack element of 32 byte type.
void computeHashStatic();
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index d3586443..82518e8c 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -526,7 +526,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
if (m_context.runtimeContext())
// We have a runtime context, so we need the creation part.
- utils().rightShiftNumberOnStack(u256(1) << 32, false);
+ utils().rightShiftNumberOnStack(32, false);
else
// Extract the runtime part.
m_context << ((u256(1) << 32) - 1) << Instruction::AND;
@@ -1269,7 +1269,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
m_context.appendConditionalInvalid();
m_context << Instruction::BYTE;
- utils().leftShiftNumberOnStack(u256(1) << (256 - 8));
+ utils().leftShiftNumberOnStack(256 - 8);
}
else if (baseType.category() == Type::Category::TypeType)
{