[opengtl-commits] [163] use Type::isSigned when converting numbers |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 163
Author: cyrille
Date: 2008-05-02 20:44:00 +0200 (Fri, 02 May 2008)
Log Message:
-----------
use Type::isSigned when converting numbers
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/tests/stdlib/constants.ctl
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
Modified: trunk/OpenGTL/OpenCTL/tests/stdlib/constants.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/stdlib/constants.ctl 2008-05-02 17:03:47 UTC (rev 162)
+++ trunk/OpenGTL/OpenCTL/tests/stdlib/constants.ctl 2008-05-02 18:44:00 UTC (rev 163)
@@ -1,17 +1,18 @@
+import "TestFramework";
+
int main()
{
- assert(M_PI > 3.141592);
- assert(M_PI < 3.141593);
- assert(M_E > 2.718281);
- assert(M_E < 2.718282);
- assert(FLT_MAX > 3.4028e38);
- assert(FLT_MAX < 3.4029e38);
- assert(FLT_MIN > 1.1754e-38);
- assert(FLT_MIN < 1.1755e-38);
- assert(INT_MAX == 2147483647 );
-// assert(INT_MIN == -2147483648); // TODO: for some reason on x86-32 integer saturates to -2147483647 while INT_MIN is correctly set at -2147483648
+ int errorCount = 0;
+ checkNearEqual(M_PI, 3.141592, errorCount);
+ checkNearEqual(M_E, 2.718281, errorCount);
+ check(FLT_MAX > 3.4028e38, errorCount);
+ check(FLT_MAX < 3.4029e38, errorCount);
+ check(FLT_MIN > 1.1754e-38, errorCount);
+ check(FLT_MIN < 1.1755e-38, errorCount);
+ checkIntEqual(INT_MAX, 2147483647, errorCount );
+// checkIntEqual(INT_MIN, -2147483648, errorCount ); // TODO: for some reason on x86-32 integer saturates to -2147483647 while INT_MIN is correctly set at -2147483648
assert(isinf_f(FLT_POS_INF));
assert(isinf_f(FLT_NEG_INF));
- return 0;
+ return errorCount;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-05-02 17:03:47 UTC (rev 162)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-05-02 18:44:00 UTC (rev 163)
@@ -212,16 +212,8 @@
}
GTL_ASSERT(_targetType->data()->type()->isFirstClassType());
GTL_ASSERT(_value->getType()->isFirstClassType());
- if( _value->getType()->isInteger() and _targetType->data()->type()->isInteger())
- { // Cast integers between integers
- return llvm::CastInst::createIntegerCast(_value, _targetType->data()->type(), false, "", _currentBlock);
- } else if( _value->getType()->isFloatingPoint() and _targetType->data()->type()->isFloatingPoint() )
- { // Cast floats between floats
- return llvm::CastInst::createFPCast(_value, _targetType->data()->type(), "", _currentBlock);
- } else { // Other casts
- return llvm::CastInst::create(
- llvm::CastInst::getCastOpcode(_value, true, _targetType->data()->type(), true), _value, _targetType->data()->type(), "", _currentBlock ); // TODO support for unsigned
- }
+ return llvm::CastInst::create(
+ llvm::CastInst::getCastOpcode(_value, _valueType->isSigned(), _targetType->data()->type(), _targetType->isSigned()), _value, _targetType->data()->type(), "", _currentBlock );
}
llvm::Constant* CodeGenerator::convertConstantTo(llvm::Constant* _constant, const Type* _constantType, const Type* _targetType)
@@ -233,26 +225,8 @@
}
GTL_ASSERT(_targetType->data()->type()->isFirstClassType());
GTL_ASSERT(_constant->getType()->isFirstClassType());
- if( _constant->getType()->isInteger() and _targetType->data()->type()->isInteger())
- { // Cast integers between integers
- if( _constant->getType()->getPrimitiveSizeInBits() > _targetType->data()->type()->getPrimitiveSizeInBits() )
- {
- return llvm::ConstantExpr::getTrunc(_constant, _targetType->data()->type());
- } else {
- return llvm::ConstantExpr::getZExt(_constant, _targetType->data()->type());
- }
- } else if( _constant->getType()->isFloatingPoint() and _targetType->data()->type()->isFloatingPoint() )
- { // Cast floats between floats
- if( _constant->getType()->getPrimitiveSizeInBits() > _targetType->data()->type()->getPrimitiveSizeInBits() )
- {
- return llvm::ConstantExpr::getFPTrunc(_constant, _targetType->data()->type());
- } else {
- return llvm::ConstantExpr::getFPExtend(_constant, _targetType->data()->type());
- }
- } else { // Other casts
- return llvm::ConstantExpr::getCast(
- (unsigned)llvm::CastInst::getCastOpcode(_constant, true, _targetType->data()->type(), true), _constant, _targetType->data()->type() ); // TODO support for unsigned
- }
+ return llvm::ConstantExpr::getCast(
+ (unsigned)llvm::CastInst::getCastOpcode(_constant, _constantType->isSigned(), _targetType->data()->type(), _targetType->isSigned()), _constant, _targetType->data()->type() );
}
@@ -599,7 +573,7 @@
return Type::UnsignedInteger32;
} else if( type1 == Type::Boolean or type2 == Type::Boolean )
{
- return Type::UnsignedInteger32;
+ return Type::Boolean;
}
GTL_DEBUG("Select type failed : "<< *type1 << " " << *type2 );
return 0;