[opengtl-commits] [253] * the shiva interpreter get an option to display the llvm assembly code after the call to evaluatePixeles

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


Revision: 253
Author:   cyrille
Date:     2008-06-27 22:37:36 +0200 (Fri, 27 Jun 2008)

Log Message:
-----------
* the shiva interpreter get an option to display the llvm assembly code after the call to evaluatePixeles
* add two fields to ImageWrap, two "virtual" functions to convert to/from vectors/memory
* generate the converter function (only works in the case of float images currently)
* cleanup in Kernel, since inside a Shiva kernel, image are allways float, removes from the API the possibility to choose the type of the pixel

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
    trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-27 20:37:36 UTC (rev 253)
@@ -26,6 +26,7 @@
 #include <llvm/DerivedTypes.h>
 #include <llvm/Function.h>
 #include <llvm/Instructions.h>
+#include <llvm/Module.h>
 #include <llvm/Value.h>
 #include <llvm/ParameterAttributes.h>
 
@@ -62,8 +63,8 @@
   memcpyTyArgs.push_back(llvm::IntegerType::get(32));
   llvm::FunctionType* memcpyTy = llvm::FunctionType::get( llvm::Type::VoidTy, memcpyTyArgs, false);
   
-  llvm::Function* func_llvm_memcpy_i32 = new llvm::Function(
-      memcpyTy, llvm::GlobalValue::ExternalLinkage, "llvm.memcpy.i32", _module); // (external, no body)
+  llvm::Function* func_llvm_memcpy_i32 = (llvm::Function*)_module->getOrInsertFunction(
+      "llvm.memcpy.i32", memcpyTy); // (external, no body)
   func_llvm_memcpy_i32->setCallingConv(llvm::CallingConv::C);
   
   const llvm::ParamAttrsList *func_llvm_memcpy_i32_PAL = 0;
@@ -104,6 +105,7 @@
 
 llvm::Value* CodeGenerator::callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n )
 {
+  GTL_DEBUG( "memcpy( dst = " << *_dst << ", src = " << *_src << ", _n = " << *_n );
   // Initialise llvm_memcpy_i32
   llvm::Function* func_llvm_memcpy_i32 = createMemCpyFunction( _gc.llvmModule() );
   // Set parameters
@@ -119,23 +121,29 @@
   return callMemCpy;
 }
 
-llvm::BasicBlock* CodeGenerator::memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size )
+llvm::BasicBlock* CodeGenerator::memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, llvm::Value* _image )
 {
   // Access to the data pointer for the _pixel
-  llvm::Value* _pointerToPixelVectorU8 = accessPixelDataAsU8Ptr( _gc, _currentBlock, _pixel );
-  // Call llvm.memcpy.i32
-  callMemcpy( _gc, _currentBlock, _pointerToPixelVectorU8, _dataPointer, GTLCore::CodeGenerator::integerToConstant( _size ) );
+  llvm::Value* _pointerToPixelVector = accessPixelDataPtr( _gc, _currentBlock, _pixel );
   
+  std::vector<llvm::Value*> arguments;
+  arguments.push_back( _pointerToPixelVector );
+  arguments.push_back( _dataPointer );
+  callVirtualMember( _gc, _currentBlock, _image, ImageWrap::INDEX_MEM_TO_VEC, arguments);
+  
   return _currentBlock;
 }
 
-llvm::BasicBlock* CodeGenerator::pixelToMem( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _dataPointer, int _size )
+llvm::BasicBlock* CodeGenerator::pixelToMem( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _dataPointer, llvm::Value* _image )
 {
   // Access to the data pointer for the _pixel
-  llvm::Value* _pointerToPixelVectorU8 = accessPixelDataAsU8Ptr( _gc, _currentBlock, _pixel );
-  // Call llvm.memcpy.i32
-  callMemcpy( _gc, _currentBlock, _dataPointer, _pointerToPixelVectorU8,  GTLCore::CodeGenerator::integerToConstant( _size ) );
-
+  llvm::Value* _pointerToPixelVector = accessPixelDataPtr( _gc, _currentBlock, _pixel );
+  
+  std::vector<llvm::Value*> arguments;
+  arguments.push_back( _dataPointer );
+  arguments.push_back( _pointerToPixelVector );
+  callVirtualMember( _gc, _currentBlock, _image, ImageWrap::INDEX_VEC_TO_MEM, arguments);
+  
   return _currentBlock;
 }
 
@@ -157,7 +165,7 @@
         _currentBlock );
 }
 
-llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription)
+llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels)
 {
   GTLCore::CodeGenerator codeGenerator( _moduleData );
   
@@ -191,7 +199,10 @@
   params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::Type::Int32Ty );
-  params.push_back( llvm::PointerType::get( llvm::PointerType::get( llvm::Type::Int8Ty, 0 ), 0 ) );
+  SHIVA_ASSERT( _moduleData->typeManager()->getStructure( "image" ) );
+  params.push_back( 
+          llvm::PointerType::get( 
+                   llvm::PointerType::get( _moduleData->typeManager()->getStructure( "image" )->d->type(), 0 ), 0 ) );
   params.push_back( llvm::PointerType::get( _moduleData->typeManager()->getStructure( "image" )->d->type(), 0 ) );
   llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, false );
   int evaluatePixelesId = ++CodeGenerator::s_evaluatePixelesId;
@@ -233,24 +244,10 @@
     std::vector<llvm::Value*> evaluatePixel_params;
     for(unsigned int i = 0; i < countArguments - 1; ++i )
     {
-      const GTLCore::Type* parameterType = ePFunction->parameters()[i].type();
-      // Allocate an ImageWrap structure
-      llvm::Value* val = new llvm::AllocaInst( parameterType->d->type(),
-                                               GTLCore::CodeGenerator::integerToConstant(1),
-                                               "", initialBlock);
-      // Add it to the list of parameters
-      evaluatePixel_params.push_back( val );
-      // Set the image field of the structure
-      std::vector<llvm::Value*> indexesImageWrap;
-      indexesImageWrap.push_back( generationContext.codeGenerator()->integerToConstant(0));
-      indexesImageWrap.push_back( generationContext.codeGenerator()->integerToConstant(ImageWrap::INDEX_IMAGE));
-      new llvm::StoreInst(
-            new llvm::LoadInst(
+      evaluatePixel_params.push_back(
+          new llvm::LoadInst(
               new llvm::GetElementPtrInst( arg_sources, GTLCore::CodeGenerator::integerToConstant( i ), "", initialBlock ),
-              "", initialBlock ),
-            new llvm::GetElementPtrInst( val, indexesImageWrap.begin(), indexesImageWrap.end(), "", initialBlock ),
-            "",
-            initialBlock );
+              "", initialBlock ) );
     }
     evaluatePixel_params.push_back( resultVar->pointer() );
     SHIVA_ASSERT( evaluatePixel_params.size() == countArguments );
@@ -291,8 +288,8 @@
         image_wrap_data_params.push_back( arg_result );
         image_wrap_data_params.push_back( iVal );
         image_wrap_data_params.push_back( jVal );
-         llvm::Value* pointer =  new llvm::CallInst( Wrapper::image_wrap_dataFunction( _moduleData->llvmModule(), _moduleData->typeManager()->getStructure( "image" ) ), image_wrap_data_params.begin(), image_wrap_data_params.end(), "", firstBlockILoop );
-        llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(), pointer, _pixelDescription.bitsSize() / 8 );
+         llvm::Value* pointer =  new llvm::CallInst( Wrapper::image_wrap_dataFunction( _moduleData->llvmModule(), _moduleData->typeManager()->getStructure( "image" ) ), image_wrap_data_params.begin(), image_wrap_data_params.end(), "", firstBlockILoop ); // TODO get the real type of the output image (even if it doesn't matter much currently)
+        llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(), pointer, arg_result );
       // }
       
       llvm::BasicBlock* lastBlockJLoop = GTLCore::CodeGenerator::createIterationForStatement( generationContext, firstBlockJLoop, incI, arg_width, GTLCore::Type::Integer32, firstBlockILoop, lastBlockILoop);
@@ -307,3 +304,210 @@
   delete incI;
   return func;
 }
+
+int memToVecId = 0;
+
+llvm::Function* CodeGenerator::generateMemToVec( Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription )
+{
+  int channelsNb = _pixelDescription.channels();
+  // Check if all channels are floats
+  bool allFloat = true;
+  for( int i = 0; i < channelsNb; ++i)
+  {
+    if( _pixelDescription.channelTypes()[i]->dataType() != GTLCore::Type::FLOAT )
+    {
+      allFloat = false;
+      break;
+    }
+  }
+  //
+  // If all channels are float, then do a direct memcpy.
+  // Otherwise do a conversion to a float array and memcpy it.
+  //
+  //  template<bool _TAllFloat_, int _TChannels_>
+  //  void memToVec( vec4* _dst, char* _imgData)
+  //  {
+  //    char *src;
+  //    if( _TAllFloat_ )
+  //    {
+  //      src = _imgData;
+  //    } else {
+  //      src = float[ _TChannels_ ];
+  //      for(int i = 0; i < _TChannels; ++i)
+  //      {
+  //        convert( i, _imgData, src );
+  //      }
+  //    }
+  //    memcpy( (char*)result, src, _TChannels * 4 );
+  //  }
+  
+  GTLCore::CodeGenerator codeGenerator( _moduleData );
+
+  llvm::Function* func = codeGenerator.createFunction( 
+      Wrapper::image_wrap_mem_to_vec_float_type( _moduleData->typeManager(), _pixelDescription.channels()) ,
+      "image_wrap_memToVec" + GTLCore::String::number( ++memToVecId) );
+  // Initialise a generation context
+  GTLCore::GenerationContext generationContext( &codeGenerator, func, 0, _moduleData );
+  
+  // Get the args.
+    llvm::Function::arg_iterator arg_it = func->arg_begin();
+    //   vec4* _dst = first arg;
+    llvm::Value* arg_dst = arg_it;
+    //   char* _imgData= second arg;
+    ++arg_it;
+    llvm::Value* arg_imgData = arg_it;
+    
+  // {
+    llvm::BasicBlock* currentBlock = new llvm::BasicBlock;
+    func->getBasicBlockList().push_back( currentBlock );
+  //    char *src;
+    llvm::Value* srcPtr = 0;
+    
+  //    if( _TAllFloat_ )
+    if( allFloat )
+  //    {
+    {
+  //      src = _imgData;
+      srcPtr = arg_imgData;
+  //    } else {
+    } else {
+  //      src = (char*)new float[ _TChannels_ ];
+      srcPtr = new llvm::AllocaInst( llvm::IntegerType::get(8),
+                    GTLCore::CodeGenerator::integerToConstant( 32 * channelsNb / 4 ),
+                    "", currentBlock );
+  //      for(int i = 0; i < _TChannels; ++i)
+  //      {
+  //        convert( i, _imgData, src );
+  //      }
+      GTL_ABORT("unimplemented");
+  //    }
+    }
+    GTL_ASSERT( srcPtr );
+  //    memcpy( (char*)result, src, _TChannels * 4 );
+    callMemcpy( generationContext, currentBlock, 
+                GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_dst),
+                srcPtr, GTLCore::CodeGenerator::integerToConstant( 4 * channelsNb ) );
+  //  }
+    new llvm::ReturnInst( currentBlock );
+  return func;
+}
+
+int vecToMemId = 0;
+
+llvm::Function* CodeGenerator::generateVecToMem( Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription )
+{
+  int channelsNb = _pixelDescription.channels();
+  // Check if all channels are floats
+  bool allFloat = true;
+  for( int i = 0; i < channelsNb; ++i)
+  {
+    if( _pixelDescription.channelTypes()[i]->dataType() != GTLCore::Type::FLOAT )
+    {
+      allFloat = false;
+      break;
+    }
+  }
+  //
+  // If all channels are float, then do a direct memcpy.
+  // Otherwise do a memcpy to a float array and a conversion from it.
+  //
+  //  template<bool _TAllFloat_, int _TChannels_>
+  //  void vecToMem( char* _imgData, vec4* _src, )
+  //  {
+  //    char *dst;
+  //    if( _TAllFloat_ )
+  //    {
+  //      dst = _imgData;
+  //    } else {
+  //      dst = float[ _TChannels_ ];
+  //    }
+  //    memcpy( dst, (char*)_src, _TChannels * sizeof(float) );
+  //    if( not _TAllFloat_ )
+  //    {
+  //      for(int i = 0; i < _TChannels; ++i)
+  //      {
+  //        convert( i, dst, _imgData );
+  //      }
+  //    }
+  //  }
+  
+  GTLCore::CodeGenerator codeGenerator( _moduleData );
+  
+  llvm::Function* func = codeGenerator.createFunction( 
+      Wrapper::image_wrap_vec_float_to_mem_type( _moduleData->typeManager(), _pixelDescription.channels()) ,
+      "image_wrap_vecToMem" + GTLCore::String::number( ++vecToMemId) );
+  // Initialise a generation context
+  GTLCore::GenerationContext generationContext( &codeGenerator, func, 0, _moduleData );
+  
+  // Get the args.
+    llvm::Function::arg_iterator arg_it = func->arg_begin();
+    //   char* _imgData = first arg;
+    llvm::Value* arg_imgData = arg_it;
+    //   vec4* _src = second arg;
+    ++arg_it;
+    llvm::Value* arg_src = arg_it;
+    
+  // {
+    llvm::BasicBlock* currentBlock = new llvm::BasicBlock;
+    func->getBasicBlockList().push_back( currentBlock );
+  //    char *src;
+    llvm::Value* dstPtr = 0;
+  //    if( _TAllFloat_ )
+    if( allFloat )
+  //    {
+    {
+  //      src = _imgData;
+      dstPtr = arg_imgData;
+  //    } else {
+    } else {
+  //      src = (char*)new float[ _TChannels_ ];
+      dstPtr = new llvm::AllocaInst( llvm::IntegerType::get(8),
+                    GTLCore::CodeGenerator::integerToConstant( 32 * channelsNb / 4 ),
+                    "", currentBlock );
+  //    }
+    }
+    GTL_ASSERT( dstPtr );
+  //    memcpy( dst, (char*)_src, _TChannels * sizeof(float) );
+    callMemcpy( generationContext, currentBlock, dstPtr,
+                GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_src),
+                GTLCore::CodeGenerator::integerToConstant( 4 * channelsNb ) );
+    
+    if( not allFloat )
+    {
+  //      for(int i = 0; i < _TChannels; ++i)
+  //      {
+  //        convert( i, dst, _imgData );
+  //      }
+      GTL_ABORT("unimplemented");
+    }
+  //  }
+    new llvm::ReturnInst( currentBlock );
+  return func;
+}
+
+llvm::Value* CodeGenerator::callVirtualMember( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int _member_index , std::vector<llvm::Value*> _arguments)
+{
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(_member_index));
+  
+  llvm::Value* funcPtr = new llvm::LoadInst( new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock ), "" , _currentBlock);
+  return new llvm::CallInst( funcPtr, _arguments.begin(), _arguments.end(), "", _currentBlock );
+}
+
+int imageSampleNearestId = 0;
+
+llvm::Function* CodeGenerator::generateImageSampleNearest(GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType )
+{
+  //  pixelX sampleNearest( ImageWrap self, float2 pt )
+  //  {
+  //    int x = pt[0] + 0.5;
+  //    int y = pt[1] + 0.5;
+  //    pixelX px = memToPixel( image_wrap_data(self, x, y ) );
+  //    px.x = pt[0];
+  //    px.y = pt[1];
+  //    return px;
+  //  }
+  
+  return 0;
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -48,12 +48,18 @@
       /**
        * Copy a pixel from memory to the vector.
        */
-      static llvm::BasicBlock* memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size );
-      static llvm::BasicBlock* pixelToMem( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _dataPointer, int _size );
-      static llvm::Function* generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
+      static llvm::BasicBlock* memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, llvm::Value* _image );
+      static llvm::BasicBlock* pixelToMem( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _dataPointer, llvm::Value* _image );
+      static llvm::Function* generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels );
+      static llvm::Function* generateMemToVec( Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
+      static llvm::Function* generateVecToMem( Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
       /**
-       * @return a pointer to the data pointer of a pixel
+       * Generate a sample nearest function.
        */
+      llvm::Function* generateImageSampleNearest(GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, const GTLCore::Type* _type );
+      /**
+       * @return a pointer to the data pointer of a pixel (as a pointer to a vector of float)
+       */
       static llvm::Value* accessPixelDataPtr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel);
       /**
        * @return a pointer to the data pointer of a pixel cast to a (float*)
@@ -64,6 +70,10 @@
       static llvm::Value* accessPixelDataAsU8Ptr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel);
       static llvm::Value* callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n );
       static void setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _iVal, llvm::Value* _jVal );
+      /**
+       * Call a "virtual" member of a structure, aka, a member with a pointer.
+       */
+      static llvm::Value* callVirtualMember( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int _member_index , std::vector<llvm::Value*> arguments);
     private:
       static int s_evaluatePixelesId;
   };

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-27 20:37:36 UTC (rev 253)
@@ -44,9 +44,6 @@
 using namespace OpenShiva;
 
 struct Kernel::Private {
-  Private( const GTLCore::PixelDescription& _pixelDescription) : pixelDescription(_pixelDescription)
-  {
-  }
   GTLCore::String name;
   GTLCore::String source;
   bool enableHydraCompatibility;
@@ -54,48 +51,29 @@
   std::list<GTLCore::ErrorMessage> compilationErrors;
   llvm::ModuleProvider* moduleProvider;
   GTLCore::ModuleData* moduleData;
-  const GTLCore::PixelDescription pixelDescription;
-  const GTLCore::Type* referenceDepth;
   llvm::Function* evaluatePixelesFunction;
+  int count_channels_generic;
+  Wrapper* wrapper;
 };
 
-Kernel::Kernel(const GTLCore::String& _name) : d(new Private(GTLCore::PixelDescription( GTLCore::Type::Float, 4 )) )
+Kernel::Kernel(const GTLCore::String& _name, int _channelsNb ) : d(new Private )
 {
-  init(_name, GTLCore::Type::Float );
-}
-
-Kernel::Kernel(const GTLCore::String& _name, const GTLCore::Type* _referenceDepth, int _channelsNb ) : d(new Private(GTLCore::PixelDescription( _referenceDepth, _channelsNb )))
-{
-  init(_name, _referenceDepth );
-}
-
-Kernel::Kernel(const GTLCore::String& _name, const GTLCore::PixelDescription& _pixelDescription ) : d(new Private(_pixelDescription))
-{
-  init(_name, _pixelDescription.channelTypes()[0] );
-}
-
-Kernel::Kernel(const GTLCore::String& _name, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth ) : d(new Private(_pixelDescription))
-{
-  init(_name, _referenceDepth );
-}
-
-Kernel::~Kernel()
-{
-  cleanup();
-  delete d;
-}
-
-void Kernel::init(const GTLCore::String& _name, const GTLCore::Type* _referenceDepth )
-{
   d->name = _name;
   d->compiled = false;
   d->enableHydraCompatibility = false;
   d->moduleProvider = 0;
   d->moduleData = 0;
-  d->referenceDepth = _referenceDepth;
+  d->count_channels_generic = _channelsNb;
   d->evaluatePixelesFunction = 0;
+  d->wrapper = 0;
 }
 
+Kernel::~Kernel()
+{
+  cleanup();
+  delete d;
+}
+
 void Kernel::cleanup()
 {
   if(d->moduleProvider)
@@ -105,6 +83,7 @@
     d->moduleProvider = 0;
   }
   delete d->moduleData;
+  delete d->wrapper;
   d->moduleData = 0;
   d->evaluatePixelesFunction = 0; // It's deleted by the moduleData
 }
@@ -145,7 +124,7 @@
   if(d->source.empty()) return;
   cleanup();
   d->moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
-  Wrapper::fillTypeManager( d->moduleData->llvmModule(), d->moduleData->typeManager(), d->pixelDescription, d->referenceDepth );
+  Wrapper::fillTypeManager( d->moduleData->llvmModule(), d->moduleData->typeManager(), d->count_channels_generic );
   Compiler c;
   GTLCore::String nameSpace;
   bool result = c.compile( d->source, d->name, d->moduleData, nameSpace );
@@ -153,9 +132,14 @@
   if(result)
   {
     d->compiled = true;
+    // Register the compiled module in the virtual machine
     d->moduleProvider = new llvm::ExistingModuleProvider( d->moduleData->llvmModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );
-    d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( std::vector<const GTLCore::Type*>(), d->moduleData->typeManager()->getStructure("image1"), this, d->moduleData, d->pixelDescription ); // TODO call with correct types
+    
+    // Create a wrapper
+    d->wrapper = new Wrapper(this, d->moduleData);
+    // Create the generateEvaluatePixeles LLVM function
+    d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( std::vector<const GTLCore::Type*>(), d->moduleData->typeManager()->getStructure("image"), this, d->moduleData, d->count_channels_generic ); // TODO call with correct types
     d->name = nameSpace;
   } else {
     cleanup();
@@ -167,9 +151,9 @@
 void Kernel::evaluatePixeles( const GTLCore::Region& _region, const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const
 {
   SHIVA_ASSERT( d->evaluatePixelesFunction );
-  void (*func)( int, int, int, int, const void**, void*) = ( void(*)(int, int, int, int, const void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
-  SHIVA_ASSERT(func);
   
+  // Wrap input images
+  SHIVA_ASSERT( d->wrapper );
   const void** inputImages = new const void*[ _inputImages.size() ];
   int i = 0;
   for( std::list< AbstractImage* >::const_iterator it = _inputImages.begin();
@@ -178,10 +162,15 @@
     inputImages[i] = (const void*)*it;
   }
   
-  ImageWrap owrap;
-  owrap.image = _outputImage;
-  (*func)( _region.x(), _region.y(), _region.width(), _region.height(), inputImages, (void*)&owrap); // TODO s/200/width s/300/height
+  // Wrap output image
+  ImageWrap* owrap = d->wrapper->wrapImage( _outputImage );
+  
+  // Call function
+  void (*func)( int, int, int, int, const void**, void*) = ( void(*)(int, int, int, int, const void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
+  SHIVA_ASSERT(func);
+  (*func)( _region.x(), _region.y(), _region.width(), _region.height(), inputImages, owrap); // TODO s/200/width s/300/height
   delete[] inputImages;
+  delete owrap;
 }
 
 int Kernel::runTest() const

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -24,8 +24,6 @@
 
 namespace GTLCore {
   class ErrorMessage;
-  class Type;
-  class PixelDescription;
   class Region;
 }
 
@@ -41,13 +39,9 @@
    */
   class Kernel {
     public:
-      Kernel(const GTLCore::String& _name );
-      Kernel(const GTLCore::String& _name, const GTLCore::Type* _referenceDepth, int _channelsNb );
-      Kernel(const GTLCore::String& _name, const GTLCore::PixelDescription& _pixelDescription );
-      Kernel(const GTLCore::String& _name, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth );
+      Kernel(const GTLCore::String& _name, int _channelsNb = 4 );
       ~Kernel();
     private:
-      void init(const GTLCore::String& _name, const GTLCore::Type* _referenceDepth );
       void cleanup();
     public:
       /**

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-27 20:37:36 UTC (rev 253)
@@ -35,83 +35,105 @@
 #include "GTLCore/TypeManager.h"
 #include "GTLCore/TypeManager_p.h"
 #include "GTLCore/Value.h"
+#include "GTLCore/VirtualMachine_p.h"
 
+#include "AbstractImage.h"
+#include "CodeGenerator_p.h"
 #include "Debug.h"
 #include "PixelVisitor_p.h"
 
+#include "wrappers/ImageWrap_p.h"
+
 using namespace OpenShiva;
 
-typedef std::vector< const GTLCore::Type* > vTypes;
-typedef std::map< const GTLCore::Type*, vTypes> typeToVTypes;
-typedef std::map< GTLCore::PixelDescription, vTypes > pdToVTypes;
+struct WrappedFunctions {
+  void* memToVec;
+  void* vecToMem;
+};
 
-struct Wrapper::Private
-{
-  static std::vector<GTLCore::Type::StructDataMember> s_imageDataMembers;
+typedef std::map< GTLCore::PixelDescription, WrappedFunctions > pdToWF;
+typedef pdToWF::iterator pdToWF_it;
+typedef pdToWF::const_iterator pdToWF_cit;
+
+struct Wrapper::Private {
+  pdToWF imageFunctions;
+  Kernel* kernel;
+  GTLCore::ModuleData* moduleData;
 };
 
-std::vector<GTLCore::Type::StructDataMember> Wrapper::Private::s_imageDataMembers;
+Wrapper::Wrapper(Kernel* _kernel, GTLCore::ModuleData* _moduleData) : d(new Private)
+{
+  d->kernel = _kernel;
+  d->moduleData = _moduleData;
+}
 
-void Wrapper::fillTypeManager( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  )
+Wrapper::~Wrapper()
 {
-  SHIVA_DEBUG("fillTypeManager");
-  for( int i = 1; i <= 5; ++i)
-  {
-    // Create Image type
-    _typeManager->d->createStructure( 
-            "image" + GTLCore::String::number( i ), Private::s_imageDataMembers );
-    createPixelType( _module, _typeManager, i, _referenceDepth );
-  }
-  _typeManager->d->createStructure( "image", Private::s_imageDataMembers );
-  createPixelType( _module, _typeManager, _pixelDescription);
-  createRegionType( _module, _typeManager );
+  delete d;
 }
 
-void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription)
+ImageWrap* Wrapper::wrapImage(AbstractImage* _abstractImage)
 {
-  if( _pixelDescription.sameTypeChannels() )
+  ImageWrap* owrap = new ImageWrap;
+  owrap->image = _abstractImage;
+  pdToWF_it it = d->imageFunctions.find( _abstractImage->pixelDescription() );
+  if( it == d->imageFunctions.end() )
   {
-    createPixelType(_module, _typeManager, "", _pixelDescription.channels(), _pixelDescription.channelTypes()[0]);
+    // Wrap functions doesn't exist yet, generate them
+    WrappedFunctions wf;
+    wf.memToVec = GTLCore::VirtualMachine::instance()->getPointerToFunction(
+        CodeGenerator::generateMemToVec( d->kernel, d->moduleData, _abstractImage->pixelDescription()  ) );
+    wf.vecToMem = GTLCore::VirtualMachine::instance()->getPointerToFunction(
+        CodeGenerator::generateVecToMem( d->kernel, d->moduleData, _abstractImage->pixelDescription()  ) );
+    d->imageFunctions[ _abstractImage->pixelDescription() ] = wf;
+    owrap->memToVec = wf.memToVec;
+    owrap->vecToMem = wf.vecToMem;
   } else {
-    SHIVA_ASSERT(_pixelDescription.bitsSize() % 8 == 0);
-    std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-    createPixelType(_module, _typeManager, "", pixelDataMembers, _pixelDescription.bitsSize() / 8 );
-    SHIVA_ABORT("Unimplemented");
+    // Use allready existing wrap function
+    owrap->memToVec = it->second.memToVec;
+    owrap->vecToMem = it->second.vecToMem;
   }
+  return owrap;
 }
 
-void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, int _channels, const GTLCore::Type* _referenceDepth )
+void Wrapper::fillTypeManager( llvm::Module* _module, GTLCore::TypeManager* _typeManager, int _channels )
 {
-  createPixelType( _module, _typeManager, GTLCore::String::number( _channels ), _channels, _referenceDepth );
-}
-
-void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels, const GTLCore::Type* _referenceDepth )
-{
-  SHIVA_ASSERT(_referenceDepth->bitsSize() % 8 == 0);
-  std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-  // Compute the size of the vector
-  int size_vector = 1;
-  while( size_vector < _channels )
+  SHIVA_DEBUG("fillTypeManager");
+  for( int i = 1; i <= 5; ++i)
   {
-    size_vector *= 2;
+    // Create Image type
+    createImageType( _module, _typeManager, GTLCore::String::number( i ), i );
+    createPixelType( _module, _typeManager, GTLCore::String::number( i ), i );
   }
-  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", _typeManager->getVector( _referenceDepth, _channels) ) );
-  // Create the generic part of the pixel type
-  createPixelType(_module, _typeManager, _suffix, pixelDataMembers, _channels * _referenceDepth->bitsSize() / 8 );
+  createImageType( _module, _typeManager, "", _channels );
+  createPixelType( _module, _typeManager, "", _channels );
+  createRegionType( _module, _typeManager );
 }
 
-void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize )
+void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels )
 {
-  SHIVA_DEBUG("createPixelType of size " << _pixelSize);
-  _pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
-  _pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
+  //---------------------- WARNING ----------------------//
+  // Whenever the following structure is edited,         //
+  // it's llvm declaration must be changed too in        //
+  // struct PixelWrap !                                  //
+  //---------------------- WARNING ----------------------//
+  std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", vectorType( _typeManager, _channels ) ) );
   
-  const GTLCore::Type* type = _typeManager->d->createStructure( "pixel" + _suffix, _pixelDataMembers );
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
+  
+  const GTLCore::Type* type = _typeManager->d->createStructure( "pixel" + _suffix, pixelDataMembers );
   type->d->setVisitor( PixelVisitor::instance() );
 }
 
 void Wrapper::createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager )
 {
+  //---------------------- WARNING ----------------------//
+  // Whenever the following structure is edited,         //
+  // it's llvm declaration must be changed too in        //
+  // struct RegionWrap !                                 //
+  //---------------------- WARNING ----------------------//
   std::vector<GTLCore::Type::StructDataMember> regionDataMembers;
   regionDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
   regionDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
@@ -159,23 +181,60 @@
   functionArgs.push_back(llvm::IntegerType::get(32));
   functionArgs.push_back(llvm::IntegerType::get(32));
   llvm::FunctionType* functionTy = llvm::FunctionType::get( llvm::PointerType::get(llvm::IntegerType::get(8), 0), functionArgs, false);
-  SHIVA_DEBUG( *functionTy );
   return new llvm::Function( functionTy, llvm::GlobalValue::ExternalLinkage, "image_wrap_data", _module);
 }
 
+llvm::FunctionType* Wrapper::image_wrap_sample_nearest( GTLCore::TypeManager* _typeManager, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType )
+{
+  std::vector<const llvm::Type*> functionArgs;
+  functionArgs.push_back( _imageType->d->pointerType() );
+  functionArgs.push_back( _typeManager->getVector( GTLCore::Type::Float, 2 )->d->type() );
+  return llvm::FunctionType::get( _pixelType->d->pointerType() , functionArgs, false);
+}
 
-STATIC_INITIALISATION(OpenShivaTypes)
+llvm::FunctionType* Wrapper::image_wrap_mem_to_vec_float_type( GTLCore::TypeManager* _typeManager, int _channels )
 {
-  { // Image
-    Wrapper::Private::s_imageDataMembers.push_back( GTLCore::Type::StructDataMember( "image", GTLCore::Type::Pointer) );
+  std::vector<const llvm::Type*> functionArgs;
+  functionArgs.push_back( llvm::PointerType::get( vectorType( _typeManager, _channels)->d->type(), 0) );
+  functionArgs.push_back( llvm::PointerType::get( llvm::IntegerType::get(8), 0));
+  return llvm::FunctionType::get( llvm::Type::VoidTy, functionArgs, false);
+}
+
+llvm::FunctionType* Wrapper::image_wrap_vec_float_to_mem_type( GTLCore::TypeManager* _typeManager, int _channels )
+{
+  std::vector<const llvm::Type*> functionArgs;
+  functionArgs.push_back( llvm::PointerType::get( llvm::IntegerType::get(8), 0));
+  functionArgs.push_back( llvm::PointerType::get( vectorType( _typeManager, _channels)->d->type(), 0) );
+  return llvm::FunctionType::get( llvm::Type::VoidTy, functionArgs, false);
+}
+
+void Wrapper::createImageType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels )
+{
+  //---------------------- WARNING ----------------------//
+  // Whenever the following structure is edited,         //
+  // it's llvm declaration must be changed too in        //
+  // struct ImageWrap !                                  //
+  //---------------------- WARNING ----------------------//
+  std::vector<GTLCore::Type::StructDataMember> imageDataMembers;
+  imageDataMembers.push_back( GTLCore::Type::StructDataMember( "image", GTLCore::Type::Pointer) );
+  imageDataMembers.push_back( GTLCore::Type::StructDataMember(
+        "memToVec",
+        GTLCore::Type::Private::createArbitraryType(
+            llvm::PointerType::get( image_wrap_mem_to_vec_float_type( _typeManager, _channels ), 0 ) ) ) );
+  imageDataMembers.push_back( GTLCore::Type::StructDataMember(
+        "vecToMem",
+        GTLCore::Type::Private::createArbitraryType(
+            llvm::PointerType::get( image_wrap_vec_float_to_mem_type( _typeManager, _channels ), 0 ) ) ) );
+  *_typeManager->d->createStructure( "image" + _suffix, imageDataMembers )->d->type();
+}
+
+const GTLCore::Type* Wrapper::vectorType( GTLCore::TypeManager* _typeManager, int _channels )
+{
+  // Compute the size of the vector
+  int size_vector = 1;
+  while( size_vector < _channels )
+  {
+    size_vector *= 2;
   }
-  { // Region
-    // Structure
-    // Members
-//     Wrapper::Private::s_regionFunctionMembers.push_back( createTypeMember("intersect", "", 
-  }
-  { // Pixel
-    // struct { float x, float y, vecX data; }
-//     Wrapper::Private::s_pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "pixel", GTLCore::Type::Pointer, -1) );
-  }
+  return _typeManager->getVector( GTLCore::Type::Float, size_vector);
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -22,45 +22,51 @@
 
 #include "GTLCore/Type_p.h"
 
+struct ImageWrap;
+
 namespace llvm {
   class Function;
+  class FunctionType;
   class Module;
 }
 
 namespace GTLCore {
+  class ModuleData;
+  class PixelDescription;
   class TypeManager;
-  class PixelDescription;
 }
 
 namespace OpenShiva {
   class AbstractImage;
-  namespace InternalStructure {
-    //---------------------- WARNING ----------------------//
-    // Whenever one of the following structures is edited, //
-    // it's llvm declaration must be changed too in        //
-    // Types_p.cpp !                                       //
-    //---------------------- WARNING ----------------------//
-    struct ImageWrap {
-      AbstractImage* image;
-    };
-    struct PixelWrap {
-    };
-  }
+  class Kernel;
+  /**
+   * @internal
+   * This class allows all informations related to wrapped types of OpenShiva : imageX, pixelX and
+   * region.
+   * @ingroup OpenShiva
+   */
   class Wrapper {
     public:
-      static void fillTypeManager( llvm::Module* _module, GTLCore::TypeManager*, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  );
+      Wrapper(Kernel* _kernel, GTLCore::ModuleData* _moduleData);
+      ~Wrapper();
+      ImageWrap* wrapImage(AbstractImage* _abstractImage);
+    private:
+      struct Private;
+      Private* const d;
+    public:
+      static void fillTypeManager( llvm::Module* _module, GTLCore::TypeManager*, int _channels );
       static llvm::Function* image_wrap_dataFunction( llvm::Module* _module, const GTLCore::Type* _imageType );
-    public:
-      struct Private;
+      static llvm::FunctionType* image_wrap_sample_nearest( GTLCore::TypeManager* _typeManager, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType );
+      static llvm::FunctionType* image_wrap_mem_to_vec_float_type( GTLCore::TypeManager* _typeManager, int _channels );
+      static llvm::FunctionType* image_wrap_vec_float_to_mem_type( GTLCore::TypeManager* _typeManager, int _channels );
+      /**
+       * @return the vectory type associated to that number of _channels
+       */
+      static const GTLCore::Type* vectorType( GTLCore::TypeManager* _typeManager, int _channels );
     private:
       static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
-      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels, const GTLCore::Type* _referenceDepth );
-      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, int _channels, const GTLCore::Type* _referenceDepth );
-      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription);
-      /**
-       * @param _pixelSize size of one pixel in bytes
-       */
-      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize );
+      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels );
+      static void createImageType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels );
   };
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -27,12 +27,16 @@
 //---------------------- WARNING ----------------------//
 // Whenever the following structure is edited,         //
 // it's llvm declaration must be changed too in        //
-// Types_p.cpp !                                       //
+// Wrapper::createImageType !                          //
 //---------------------- WARNING ----------------------//
 struct ImageWrap {
   OpenShiva::AbstractImage* image;
+  void* memToVec;
+  void* vecToMem;
   enum ImageIndexes {
     INDEX_IMAGE = 0,
+    INDEX_MEM_TO_VEC = 1,
+    INDEX_VEC_TO_MEM = 2
   };
 };
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -23,7 +23,7 @@
 //---------------------- WARNING ----------------------//
 // Whenever the following structure is edited,         //
 // it's llvm declaration must be changed too in        //
-// Types_p.cpp !                                       //
+// Wrapper::createPixelType !                          //
 //---------------------- WARNING ----------------------//
 struct PixelWrap {
   void* data;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-06-27 20:37:36 UTC (rev 253)
@@ -23,9 +23,8 @@
 //---------------------- WARNING ----------------------//
 // Whenever the following structure is edited,         //
 // it's llvm declaration must be changed too in        //
-// Types_p.cpp !                                       //
+// Wrapper::createRegionType !                         //
 //---------------------- WARNING ----------------------//
-
 struct RegionWrap {
   float x, y, width, height;
 };

Modified: trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-06-27 20:34:14 UTC (rev 252)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-06-27 20:37:36 UTC (rev 253)
@@ -45,6 +45,7 @@
   std::cout << "Usage : shiva [option] fileName.shiva [input0.png input1.png ...] output.png" << std::endl;
   std::cout << std::endl;
   std::cout << "Options : " << std::endl;
+  std::cout << "  -S --asm-source         print the assembly source code generated after the execution of the kernel" << std::endl;
 //   std::cout << "  -L --module-dir   add a location where to find modules" << std::endl;
   std::cout << std::endl;
   std::cout << "  -h --help               print this message" << std::endl;
@@ -56,6 +57,7 @@
 {
   GTLCore::String fileName = "";
   GTLCore::String output = "";
+  bool showAssembly = false;
   for(int ai = 1; ai < argc; ai++)
   {
     if(ARG_IS("-h","--help"))
@@ -66,6 +68,8 @@
     {
       printVersion();
       return EXIT_SUCCESS;
+    } else if(ARG_IS("-S","--asm-source")) {
+      showAssembly = true;
     } else if(ARG_IS("-L", "--module-dir")) {
       if( ai == argc )
       {
@@ -105,8 +109,8 @@
       source += "\n";
       std::getline(in,str);
     }
-    GTLCore::PixelDescription pixel( GTLCore::Type::Float, 1 );
-    OpenShiva::Kernel p(fileName, pixel);
+    GTLCore::PixelDescription pixel( GTLCore::Type::Float, 4 );
+    OpenShiva::Kernel p(fileName, 1);
     p.setSource( source );
     p.compile();
     if(not p.isCompiled())
@@ -118,6 +122,10 @@
     memset( image.data(0, 0), 1, 200 * 300 );
     p.evaluatePixeles( GTLCore::Region(0,0, 200, 300), std::list<OpenShiva::AbstractImage*>(), &image );
     std::cout << *((float*)image.data( 0, 0));
+    if( showAssembly )
+    {
+      std::cout << p.asmSourceCode();
+    }
   }
   return EXIT_SUCCESS;
 }


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