aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp38
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp8
-rw-r--r--libsolidity/codegen/LValue.cpp4
3 files changed, 42 insertions, 8 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 36ed480e..a2c44cd3 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -345,10 +345,11 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
break;
case Type::Category::Integer:
case Type::Category::Contract:
- case Type::Category::IntegerConstant:
+ case Type::Category::NumberConstant:
+ case Type::Category::FixedPoint:
if (targetTypeCategory == Type::Category::FixedBytes)
{
- solAssert(stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::IntegerConstant,
+ solAssert(stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::NumberConstant,
"Invalid conversion to FixedBytesType requested.");
// conversion from bytes to string. no need to clean the high bit
// only to shift left because of opposite alignment
@@ -361,15 +362,31 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
else if (targetTypeCategory == Type::Category::Enum)
// just clean
convertType(_typeOnStack, *_typeOnStack.mobileType(), true);
+ else if (targetTypeCategory == Type::Category::FixedPoint)
+ {
+ solAssert(
+ stackTypeCategory == Type::Category::Integer ||
+ stackTypeCategory == Type::Category::NumberConstant ||
+ stackTypeCategory == Type::Category::FixedPoint,
+ "Invalid conversion to FixedMxNType requested."
+ );
+ //shift all integer bits onto the left side of the fixed type
+ FixedPointType const& targetFixedPointType = dynamic_cast<FixedPointType const&>(_targetType);
+ if (auto typeOnStack = dynamic_cast<IntegerType const*>(&_typeOnStack))
+ if (targetFixedPointType.integerBits() > typeOnStack->numBits())
+ cleanHigherOrderBits(*typeOnStack);
+ //need m_context call here
+
+ }
else
{
solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, "");
IntegerType addressType(0, IntegerType::Modifier::Address);
IntegerType const& targetType = targetTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_targetType) : addressType;
- if (stackTypeCategory == Type::Category::IntegerConstant)
+ if (stackTypeCategory == Type::Category::NumberConstant)
{
- IntegerConstantType const& constType = dynamic_cast<IntegerConstantType const&>(_typeOnStack);
+ ConstantNumberType const& constType = dynamic_cast<ConstantNumberType const&>(_typeOnStack);
// We know that the stack is clean, we only have to clean for a narrowing conversion
// where cleanup is forced.
if (targetType.numBits() < constType.integerType()->numBits() && _cleanupNeeded)
@@ -419,6 +436,19 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
);
break;
}
+ /*case Type::Category::Fixed:
+ {
+ if (targetTypeCategory == Type::Category::Integer)
+ {
+ //need some guidance here
+ }
+ else if (targetTypeCategory == Type::Category::FixedBytes)
+ {
+ //need some guidance here
+ }
+ else
+ //need some guidance here
+ }*/
case Type::Category::Array:
{
solAssert(targetTypeCategory == stackTypeCategory, "");
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index ab02e0b5..14bc0855 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -285,7 +285,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
// the operator should know how to convert itself and to which types it applies, so
// put this code together with "Type::acceptsBinary/UnaryOperator" into a class that
// represents the operator
- if (_unaryOperation.annotation().type->category() == Type::Category::IntegerConstant)
+ if (_unaryOperation.annotation().type->category() == Type::Category::NumberConstant)
{
m_context << _unaryOperation.annotation().type->literalValue(nullptr);
return false;
@@ -360,7 +360,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
if (c_op == Token::And || c_op == Token::Or) // special case: short-circuiting
appendAndOrOperatorCode(_binaryOperation);
- else if (commonType.category() == Type::Category::IntegerConstant)
+ else if (commonType.category() == Type::Category::NumberConstant)
m_context << commonType.literalValue(nullptr);
else
{
@@ -370,7 +370,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
// for commutative operators, push the literal as late as possible to allow improved optimization
auto isLiteral = [](Expression const& _e)
{
- return dynamic_cast<Literal const*>(&_e) || _e.annotation().type->category() == Type::Category::IntegerConstant;
+ return dynamic_cast<Literal const*>(&_e) || _e.annotation().type->category() == Type::Category::NumberConstant;
};
bool swap = m_optimize && Token::isCommutativeOp(c_op) && isLiteral(rightExpression) && !isLiteral(leftExpression);
if (swap)
@@ -1225,7 +1225,7 @@ void ExpressionCompiler::endVisit(Literal const& _literal)
switch (type->category())
{
- case Type::Category::IntegerConstant:
+ case Type::Category::NumberConstant:
case Type::Category::Bool:
m_context << type->literalValue(&_literal);
break;
diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp
index fcadd2ff..7d9fa4c8 100644
--- a/libsolidity/codegen/LValue.cpp
+++ b/libsolidity/codegen/LValue.cpp
@@ -186,6 +186,7 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
)
m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND;
+ //need something here for Fixed...guidance would be nice
else
m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND;
}
@@ -240,6 +241,9 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
<< Instruction::MUL
<< Instruction::DIV;
m_context << Instruction::MUL << Instruction::OR;
+ //else if (m_dataType->category() == Type::Category::Fixed)
+ //trying to figure out what this does...going to require some more assistance
+ m_context << Instruction::MUL << eth::Instruction::OR;
// stack: value storage_ref updated_value
m_context << Instruction::SWAP1 << Instruction::SSTORE;
if (_move)