Change shiftNumberOnStack to bits

This commit is contained in:
Alex Beregszaszi 2016-11-30 10:03:26 +00:00
parent c7ae042114
commit 8fd1d4167d
3 changed files with 13 additions and 13 deletions

View File

@ -371,10 +371,10 @@ void CompilerUtils::combineExternalFunctionType(bool _leftAligned)
m_context << u256(0xffffffffUL) << Instruction::AND << Instruction::SWAP1; m_context << u256(0xffffffffUL) << Instruction::AND << Instruction::SWAP1;
if (!_leftAligned) if (!_leftAligned)
m_context << ((u256(1) << 160) - 1) << Instruction::AND; m_context << ((u256(1) << 160) - 1) << Instruction::AND;
leftShiftNumberOnStack(u256(1) << 32); leftShiftNumberOnStack(32);
m_context << Instruction::OR; m_context << Instruction::OR;
if (_leftAligned) if (_leftAligned)
leftShiftNumberOnStack(u256(1) << 64); leftShiftNumberOnStack(64);
} }
void CompilerUtils::pushCombinedFunctionEntryLabel(Declaration const& _function) 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 // conversion from bytes to integer. no need to clean the high bit
// only to shift right because of opposite alignment // only to shift right because of opposite alignment
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType); 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) if (targetIntegerType.numBits() < typeOnStack.numBytes() * 8)
convertType(IntegerType(typeOnStack.numBytes() * 8), _targetType, _cleanupNeeded); convertType(IntegerType(typeOnStack.numBytes() * 8), _targetType, _cleanupNeeded);
} }
@ -476,7 +476,7 @@ void CompilerUtils::convertType(
if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack)) if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack))
if (targetBytesType.numBytes() * 8 > typeOnStack->numBits()) if (targetBytesType.numBytes() * 8 > typeOnStack->numBits())
cleanHigherOrderBits(*typeOnStack); cleanHigherOrderBits(*typeOnStack);
leftShiftNumberOnStack(u256(1) << (256 - targetBytesType.numBytes() * 8)); leftShiftNumberOnStack(256 - targetBytesType.numBytes() * 8);
} }
else if (targetTypeCategory == Type::Category::Enum) 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; bool leftAligned = _type.category() == Type::Category::FixedBytes;
// add leading or trailing zeros by dividing/multiplying depending on alignment // 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); rightShiftNumberOnStack(shiftFactor, false);
if (leftAligned) if (leftAligned)
leftShiftNumberOnStack(shiftFactor); leftShiftNumberOnStack(shiftFactor);
@ -1007,14 +1007,14 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack)
m_context << ((u256(1) << _typeOnStack.numBits()) - 1) << Instruction::AND; 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) unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords)

View File

@ -177,10 +177,10 @@ public:
static unsigned sizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes); static unsigned sizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes);
/// Helper function to shift top value on the stack to the left. /// 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. /// 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. /// Appends code that computes tha Keccak-256 hash of the topmost stack element of 32 byte type.
void computeHashStatic(); void computeHashStatic();

View File

@ -526,7 +526,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
if (m_context.runtimeContext()) if (m_context.runtimeContext())
// We have a runtime context, so we need the creation part. // We have a runtime context, so we need the creation part.
utils().rightShiftNumberOnStack(u256(1) << 32, false); utils().rightShiftNumberOnStack(32, false);
else else
// Extract the runtime part. // Extract the runtime part.
m_context << ((u256(1) << 32) - 1) << Instruction::AND; m_context << ((u256(1) << 32) - 1) << Instruction::AND;
@ -1269,7 +1269,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
m_context.appendConditionalInvalid(); m_context.appendConditionalInvalid();
m_context << Instruction::BYTE; m_context << Instruction::BYTE;
utils().leftShiftNumberOnStack(u256(1) << (256 - 8)); utils().leftShiftNumberOnStack(256 - 8);
} }
else if (baseType.category() == Type::Category::TypeType) else if (baseType.category() == Type::Category::TypeType)
{ {