[opengtl-commits] [259] display some debug when calling a function to check parameters ( instead of just hiting the not informative assert in llvm)

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


Revision: 259
Author:   cyrille
Date:     2008-06-29 10:47:12 +0200 (Sun, 29 Jun 2008)

Log Message:
-----------
display some debug when calling a function to check parameters (instead of just hiting the not informative assert in llvm)

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


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-29 08:46:23 UTC (rev 258)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-29 08:47:12 UTC (rev 259)
@@ -141,6 +141,7 @@
 
 llvm::Value* CodeGenerator::convertValueTo(llvm::BasicBlock* _currentBlock, llvm::Value* _value, const Type* _valueType, const Type* _targetType)
 {
+  GTL_DEBUG("Convert value " << *_value << " from " << *_valueType << " to " << *_targetType);
   llvm::Constant* _constant = dynamic_cast<llvm::Constant*>(_value);
   if(_constant)
   {
@@ -612,15 +613,35 @@
         value = (*it)->generateValue(_gc, bb).value();
       }
       GTL_ASSERT( value );
+      GTL_DEBUG( "param's type = " << *oparam_it->type()->d->type() << " value = " << *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 );
     }
     
   }
+  
+#ifndef _NDEBUG_
+  {
+    const llvm::FunctionType *FTy =
+      llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(llvmFunction->getType())->getElementType());
+    
+    GTL_ASSERT( convertedParams.size() == FTy->getNumParams() or
+            (FTy->isVarArg() and convertedParams.size() > FTy->getNumParams()) );
+    
+    for (unsigned i = 0; i < convertedParams.size(); ++i) {
+      if( i < FTy->getNumParams() and (FTy->getParamType(i) != convertedParams[i]->getType()) )
+      {
+        GTL_DEBUG( "Wrong parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << convertedParams[i] << " => " << *convertedParams[i]->getType() );
+      } else {
+        GTL_DEBUG( "Parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << convertedParams[i]->getType() << " => " << *convertedParams[i]->getType() );
+      }
+    }
+  }
+#endif
+  
   llvm::CallInst *CallFunc = new llvm::CallInst(llvmFunction, convertedParams.begin(), convertedParams.end(), "", bb);
   CallFunc->setTailCall();
   return GTLCore::ExpressionResult( CallFunc );


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