[opengtl-commits] [239] * can pass the array/ struct result of a function call and global value as arguments to a function

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 239
Author:   cyrille
Date:     2008-06-26 22:19:15 +0200 (Thu, 26 Jun 2008)

Log Message:
-----------
* can pass the array/struct result of a function call and global value as arguments to a function
* fix comparison expression to work with 'signed' integers

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-26 20:12:48 UTC (rev 238)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-26 20:19:15 UTC (rev 239)
@@ -477,56 +477,62 @@
 CREATE_BINARY_INTEGER_EXPRESSION(createBitAndExpression, getAnd, createAnd )
 
 
-#define CREATE_COMPARISON_EXPRESSION(_GTL_Function_Name_, _LLVM_Int_Expr_, _LLVM_Float_Expr_ ) \
+#define CREATE_COMPARISON_EXPRESSION(_GTL_Function_Name_, _LLVM_UInt_Expr_, _LLVM_SInt_Expr_, _LLVM_Float_Expr_ ) \
   llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType) \
   { \
-    return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+    return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_UInt_Expr_, llvm::ICmpInst::_LLVM_SInt_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
   } \
   llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType) \
   { \
-    return createComparisonExpression( lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+    return createComparisonExpression( lhs, lhsType, rhs, rhsType,  llvm::ICmpInst::_LLVM_UInt_Expr_, llvm::ICmpInst::_LLVM_SInt_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
   } \
   ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
   { \
-    return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+    return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType,  llvm::ICmpInst::_LLVM_UInt_Expr_, llvm::ICmpInst::_LLVM_SInt_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
   }
 
-CREATE_COMPARISON_EXPRESSION(createEqualExpression, ICMP_EQ, FCMP_OEQ);
-CREATE_COMPARISON_EXPRESSION(createDifferentExpression, ICMP_NE, FCMP_ONE);
-CREATE_COMPARISON_EXPRESSION(createStrictInferiorExpression, ICMP_ULT, FCMP_OLT);
-CREATE_COMPARISON_EXPRESSION(createInferiorOrEqualExpression, ICMP_ULE, FCMP_OLE);
-CREATE_COMPARISON_EXPRESSION(createStrictSupperiorExpression, ICMP_UGT, FCMP_OGT);
-CREATE_COMPARISON_EXPRESSION(createSupperiorOrEqualExpression, ICMP_UGE, FCMP_OGE);
+CREATE_COMPARISON_EXPRESSION(createEqualExpression, ICMP_EQ, ICMP_EQ, FCMP_OEQ);
+CREATE_COMPARISON_EXPRESSION(createDifferentExpression, ICMP_NE, ICMP_NE, FCMP_ONE);
+CREATE_COMPARISON_EXPRESSION(createStrictInferiorExpression, ICMP_ULT, ICMP_SLT, FCMP_OLT);
+CREATE_COMPARISON_EXPRESSION(createInferiorOrEqualExpression, ICMP_ULE, ICMP_SLE, FCMP_OLE);
+CREATE_COMPARISON_EXPRESSION(createStrictSupperiorExpression, ICMP_UGT, ICMP_SGT, FCMP_OGT);
+CREATE_COMPARISON_EXPRESSION(createSupperiorOrEqualExpression, ICMP_UGE, ICMP_SGE, FCMP_OGE);
 
-llvm::Value* CodeGenerator::createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
+llvm::Value* CodeGenerator::createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred)
 {
   UNIFORMIZE_VALUE_TYPES( lhs, rhs );
   if( v1->getType()->isFloatingPoint() )
   {
     return new llvm::FCmpInst( (llvm::FCmpInst::Predicate)floatPred, v1, v2, "", currentBlock );
   } else if( v2->getType()->isInteger() ) {
-    return new llvm::ICmpInst( (llvm::ICmpInst::Predicate)integerPred, v1, v2, "", currentBlock );
+    if( rhsType->isSigned() )
+    {
+      return new llvm::ICmpInst( (llvm::ICmpInst::Predicate)signedIntegerPred, v1, v2, "", currentBlock );
+    } else {
+      return new llvm::ICmpInst( (llvm::ICmpInst::Predicate)unsignedIntegerPred, v1, v2, "", currentBlock );
+    }
   } else {
     GTL_ABORT("Invalid comparison");
     return 0;
   }
 }
 
-llvm::Constant* CodeGenerator::createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
+llvm::Constant* CodeGenerator::createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred)
 {
   UNIFORMIZE_CONSTANT_TYPES( lhs, rhs );
-  unsigned op = v1->getType()->isFloatingPoint() ? floatPred : integerPred;
+  unsigned op = v1->getType()->isFloatingPoint() ? floatPred : 
+      ( rhsType->isSigned() ? signedIntegerPred : unsignedIntegerPred);
   return (llvm::Constant*)llvm::ConstantExpr::getCompare( op, v1, v2);
 }
 
-ExpressionResult CodeGenerator::createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
+ExpressionResult CodeGenerator::createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred)
 {
   UNIFORMIZE_TYPES(lhs, rhs);
   if( v1.isConstant() and v2.isConstant() )
   {
-    return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), lhsType, v2.constant(), rhsType, integerPred, floatPred));
+    return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), lhsType, v2.constant(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred));
   } else {
-    return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), lhsType, v2.value(), rhsType, integerPred, floatPred));
+    return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), lhsType, v2.value(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred));
   }
 }
 
@@ -641,15 +647,22 @@
       llvm::Value* value = 0;
       if( (*it)->type()->dataType() == GTLCore::Type::ARRAY or (*it)->type()->dataType() == GTLCore::Type::STRUCTURE )
       {
-        AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
-        GTL_ASSERT( aexp );
-        value = aexp->pointer( _gc, bb );
+        if( AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it ) )
+        {
+          value = aexp->pointer( _gc, bb );
+        } else if( dynamic_cast<AST::FunctionCallExpression*>( *it )
+                   or dynamic_cast<AST::GlobalDataExpression*>( *it ) ) {
+            value = (*it)->generateValue(_gc, bb).value();
+        } else {
+          GTL_ABORT("Can't pass an array or a structure");
+        }
       } else {
         value = (*it)->generateValue(_gc, bb).value();
       }
       GTL_ASSERT( value );
       if( oparam_it->type()->d->type()->isFirstClassType() )
       {
+        GTL_DEBUG( "param's type = " << *oparam_it->type()->d->type() << " value = " << *value );
         value = _gc.codeGenerator()-> convertValueTo( bb, value, (*it)->type(), oparam_it->type() );
       }
       convertedParams.push_back( value );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-26 20:12:48 UTC (rev 238)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-26 20:19:15 UTC (rev 239)
@@ -241,9 +241,9 @@
     public:
       GTLCore::ExpressionResult callFunction( GenerationContext& _gc, llvm::BasicBlock* _bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& m_arguments );
     private:
-      static llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
-      static ExpressionResult createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
-      static llvm::Constant* createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
+      static llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred);
+      static ExpressionResult createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred);
+      static llvm::Constant* createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred);
     private:
       struct Private;
       Private* const d;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/