[opengtl-commits] [205] * rename OpenShiva::Type to OpenShiva::Wrapper

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


Revision: 205
Author:   cyrille
Date:     2008-06-20 22:45:35 +0200 (Fri, 20 Jun 2008)

Log Message:
-----------
* rename OpenShiva::Type to OpenShiva::Wrapper
* finish evaluatePixeles

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Function.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h

Removed Paths:
-------------
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Function.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Function.h	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Function.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -29,8 +29,8 @@
 }
 
 namespace OpenShiva {
-  class Types;
   class CodeGenerator;
+  class Wrapper;
 }
 
 namespace GTLCore {
@@ -53,7 +53,7 @@
       friend class ParserBase;
       friend class OpenCTL::Compiler;
       friend class OpenCTL::Program;
-      friend class OpenShiva::Types;
+      friend class OpenShiva::Wrapper;
       friend class CodeGenerator;
       friend class OpenShiva::CodeGenerator;
       friend class VirtualMachine;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -31,7 +31,8 @@
 }
 
 namespace OpenShiva {
-  class Types;
+  class CodeGenerator;
+  class Wrapper;
 }
 
 namespace GTLCore {
@@ -55,7 +56,8 @@
     friend class OpenCTL::Program;
     friend class CodeGenerator;
     friend class VariableNG;
-    friend class OpenShiva::Types;
+    friend class OpenShiva::CodeGenerator;
+    friend class OpenShiva::Wrapper;
     friend class ParserBase;
     friend class Function;
     friend class TypeManager;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -24,13 +24,13 @@
 #include <GTLCore/Type.h>
 
 namespace OpenShiva {
-  class Types;
+  class Wrapper;
 }
 
 namespace GTLCore {
   class TypeManager {
     friend class ParserBase;
-    friend class OpenShiva::Types;
+    friend class OpenShiva::Wrapper;
     public:
       TypeManager();
       ~TypeManager();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-20 20:45:35 UTC (rev 205)
@@ -11,7 +11,7 @@
   CodeGenerator_p.cpp
   Lexer_p.cpp
   Parser_p.cpp
-  Types_p.cpp
+  Wrapper_p.cpp
 # Wrap
   wrappers/ImageWrap_p.cpp
   wrappers/PixelWrap_p.cpp

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -35,11 +35,13 @@
 #include "GTLCore/GenerationContext_p.h"
 #include "GTLCore/ModuleData_p.h"
 #include "GTLCore/Parameter.h"
+#include "GTLCore/PixelDescription.h"
 #include "GTLCore/Type.h"
 #include "GTLCore/TypeManager_p.h"
 #include "GTLCore/Value.h"
 #include "GTLCore/VariableNG_p.h"
 
+#include "Wrapper_p.h"
 #include "wrappers/PixelWrap_p.h"
 
 #include "Debug.h"
@@ -49,9 +51,8 @@
 
 int CodeGenerator::s_evaluatePixelesId = 0;
 
-llvm::BasicBlock* CodeGenerator::memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size )
+llvm::Function* CodeGenerator::createMemCpyFunction( llvm::Module* _module )
 {
-  // Initialise llvm_memcpy_i32
   // TODO that stuff was copied from a llvmgcc output, can't we use memcpy intrinsinc ?
   std::vector<const llvm::Type*> memcpyTyArgs;
   memcpyTyArgs.push_back(llvm::PointerType::get(llvm::IntegerType::get(8), 0));
@@ -61,7 +62,7 @@
   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", _gc.llvmModule()); // (external, no body)
+      memcpyTy, llvm::GlobalValue::ExternalLinkage, "llvm.memcpy.i32", _module); // (external, no body)
   func_llvm_memcpy_i32->setCallingConv(llvm::CallingConv::C);
   
   const llvm::ParamAttrsList *func_llvm_memcpy_i32_PAL = 0;
@@ -73,7 +74,13 @@
     func_llvm_memcpy_i32_PAL = llvm::ParamAttrsList::get(Attrs);
   }
   func_llvm_memcpy_i32->setParamAttrs(func_llvm_memcpy_i32_PAL);
+  return func_llvm_memcpy_i32;
+}
 
+llvm::BasicBlock* CodeGenerator::memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size )
+{
+  // Initialise llvm_memcpy_i32
+  llvm::Function* func_llvm_memcpy_i32 = createMemCpyFunction( _gc.llvmModule() );
   // Access to the data pointer for the _pixel
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
@@ -98,8 +105,13 @@
   return _currentBlock;
 }
 
-llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData)
+llvm::BasicBlock* CodeGenerator::pixelToMem( GTLCore::GenerationContext& /*_gc*/, llvm::BasicBlock* _currentBlock, llvm::Value* /*_pixel*/, llvm::Value* /*_dataPointer*/, int /*_size*/ )
 {
+  return _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)
+{
   GTLCore::CodeGenerator codeGenerator( _moduleData );
   
   // Pseudo-code explaining step-by-step what an evaluatePixeles function does :
@@ -128,10 +140,10 @@
   
   // Create the function
   std::vector<const llvm::Type*> params;
-  params.push_back( llvm::PointerType::get( llvm::Type::Int32Ty, 0 ) );
-  params.push_back( llvm::PointerType::get( llvm::Type::Int32Ty, 0 ) );
+  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 ) );
-  params.push_back( llvm::PointerType::get( llvm::Type::Int8Ty, 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;
   llvm::Function* func = codeGenerator.createFunction( definitionType, "evaluatePixeles" + GTLCore::String::number(evaluatePixelesId));
@@ -153,7 +165,7 @@
 //     llvm::Value* arg_sources = arg_it;
     //   void* _result = fourth arg;
     ++arg_it;
-//     llvm::Value* arg_result = arg_it;
+    llvm::Value* arg_result = arg_it;
   // Construct the "conditions" of the first loop
     // int j = 0;
     GTLCore::VariableNG* incJ = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
@@ -184,14 +196,20 @@
         new llvm::CallInst( llvmEPFunction, evaluatePixel_params.begin(), evaluatePixel_params.end(), "", firstBlockILoop );
         // Synchronize the output pixel with input
         // Call image_wrap_data on the result to get the pointer on destination data
+        std::vector<llvm::Value*> image_wrap_data_params;
+        image_wrap_data_params.push_back( arg_result );
+        image_wrap_data_params.push_back( incI->get( generationContext, firstBlockILoop ) );
+        image_wrap_data_params.push_back( incJ->get( generationContext, firstBlockILoop ) );
+         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::BasicBlock* lastBlockJLoop = GTLCore::CodeGenerator::createIterationForStatement( generationContext, firstBlockJLoop, incI, arg_width, GTLCore::Type::Integer32, firstBlockILoop, firstBlockILoop);
+      llvm::BasicBlock* lastBlockJLoop = GTLCore::CodeGenerator::createIterationForStatement( generationContext, firstBlockJLoop, incI, arg_width, GTLCore::Type::Integer32, firstBlockILoop, lastBlockILoop);
     // }
     llvm::BasicBlock* lastBlock = GTLCore::CodeGenerator::createIterationForStatement( generationContext, initialBlock, incJ, arg_height, GTLCore::Type::Integer32, firstBlockJLoop, lastBlockJLoop);
     new llvm::ReturnInst(lastBlock);
   // Cleanup
-  delete resultVar;
+//   delete resultVar;
   delete incJ;
-  delete incI;
+//   delete incI;
   return func;
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -25,6 +25,7 @@
 namespace llvm {
   class BasicBlock;
   class Function;
+  class Module;
   class Value;
 }
 
@@ -33,6 +34,7 @@
   class GenerationContext;
   class ModuleData;
   class Type;
+  class PixelDescription;
 }
 
 namespace OpenShiva {
@@ -45,8 +47,10 @@
        */
       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);
+      static llvm::Function* generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
     private:
+      static llvm::Function* createMemCpyFunction( llvm::Module* _module );
+    private:
       static int s_evaluatePixelesId;
   };
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -37,7 +37,8 @@
 #include "Debug.h"
 #include "CodeGenerator_p.h"
 #include "Compiler_p.h"
-#include "Types_p.h"
+#include "Wrapper_p.h"
+#include "wrappers/ImageWrap_p.h"
 
 using namespace OpenShiva;
 
@@ -142,7 +143,7 @@
   if(d->source.empty()) return;
   cleanup();
   d->moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
-  Types::fillTypeManager( d->moduleData->llvmModule(), d->moduleData->typeManager(), d->pixelDescription, d->referenceDepth );
+  Wrapper::fillTypeManager( d->moduleData->llvmModule(), d->moduleData->typeManager(), d->pixelDescription, d->referenceDepth );
   Compiler c;
   GTLCore::String nameSpace;
   bool result = c.compile( d->source, d->name, d->moduleData, nameSpace );
@@ -152,7 +153,7 @@
     d->compiled = true;
     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 ); // TODO call with correct types
+    d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( std::vector<const GTLCore::Type*>(), d->moduleData->typeManager()->getStructure("image1"), this, d->moduleData, d->pixelDescription ); // TODO call with correct types
     d->name = nameSpace;
   } else {
     cleanup();
@@ -166,7 +167,9 @@
   SHIVA_ASSERT( d->evaluatePixelesFunction );
   void (*func)( int, int, void**, void*) = ( void(*)(int, int, void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
   SHIVA_ASSERT(func);
-  (*func)( 200, 300, 0, (void*)_outputImage); // TODO s/200/width s/300/height
+  ImageWrap owrap;
+  owrap.image = _outputImage;
+  (*func)( 200, 300, 0, (void*)&owrap); // TODO s/200/width s/300/height
 }
 
 int Kernel::runTest() const

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -23,7 +23,6 @@
 
 #include "Compiler_p.h"
 #include "Lexer_p.h"
-#include "Types_p.h"
 
 #include <GTLCore/AST/Statement.h>
 #include <GTLCore/AST/Tree.h>

Deleted: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -1,155 +0,0 @@
-/*
- *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "Types_p.h"
-
-#include <map>
-#include <vector>
-
-#include "GTLCore/Function_p.h"
-#include "GTLCore/Macros.h"
-#include "GTLCore/Parameter.h"
-#include "GTLCore/PixelDescription.h"
-#include "GTLCore/Type.h"
-#include "GTLCore/Type_p.h"
-#include "GTLCore/TypeManager.h"
-#include "GTLCore/TypeManager_p.h"
-#include "GTLCore/Value.h"
-
-
-#include "Debug.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 Types::Private
-{
-  static std::vector<GTLCore::Type::StructDataMember> s_imageDataMembers;
-};
-
-std::vector<GTLCore::Type::StructDataMember> Types::Private::s_imageDataMembers;
-
-void Types::fillTypeManager( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  )
-{
-  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 );
-}
-
-void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription)
-{
-  SHIVA_ASSERT(_pixelDescription.bitsSize() % 8 == 0);
-  std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-  createPixelType(_module, _typeManager, "", pixelDataMembers, _pixelDescription.bitsSize() / 8 );
-}
-
-void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, 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 )
-  {
-    size_vector *= 2;
-  }
-  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", _typeManager->getVector( _referenceDepth, _channels) ) );
-  // Create the generic part of the pixel type
-  createPixelType(_module, _typeManager, GTLCore::String::number( _channels ), pixelDataMembers, _channels * _referenceDepth->bitsSize() / 8 );
-}
-
-void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize )
-{
-  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) );
-  
-  _typeManager->d->createStructure( "pixel" + _suffix, _pixelDataMembers );
-}
-
-void Types::createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager )
-{
-  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) );
-  regionDataMembers.push_back( GTLCore::Type::StructDataMember( "width", GTLCore::Type::Float ) );
-  regionDataMembers.push_back( GTLCore::Type::StructDataMember( "height", GTLCore::Type::Float ) );
-  const GTLCore::Type* type = _typeManager->d->createStructure( "region", regionDataMembers);
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "left", "region_wrap_left", GTLCore::Type::Float, 1,
-                GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "right", "region_wrap_right", GTLCore::Type::Float, 1,
-                GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "bottom", "region_wrap_bottom", GTLCore::Type::Float, 1,
-                GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "top", "region_wrap_top", GTLCore::Type::Float, 1,
-                GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "intersect", "region_wrap_intersect", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "union", "region_wrap_union", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "outset", "region_wrap_outset", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
-  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
-          GTLCore::Function::Private::createExternalFunction(
-                _module, "inset", "region_wrap_inset", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
-}
-
-
-STATIC_INITIALISATION(OpenShivaTypes)
-{
-
-  { // Image
-    Types::Private::s_imageDataMembers.push_back( GTLCore::Type::StructDataMember( "image", GTLCore::Type::Pointer) );
-  }
-  { // Region
-    // Structure
-    // Members
-//     Types::Private::s_regionFunctionMembers.push_back( createTypeMember("intersect", "", 
-  }
-  { // Pixel
-    // struct { float x, float y, vecX data; }
-//     Types::Private::s_pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "pixel", GTLCore::Type::Pointer, -1) );
-  }
-}

Deleted: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -1,65 +0,0 @@
-/*
- *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _OPENSHIVA_TYPES_P_H_
-#define _OPENSHIVA_TYPES_P_H_
-
-#include "GTLCore/Type_p.h"
-
-namespace llvm {
-  class Module;
-}
-
-namespace GTLCore {
-  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 Types {
-    public:
-      static void fillTypeManager( llvm::Module* _module, GTLCore::TypeManager*, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  );
-    public:
-      struct Private;
-    private:
-      static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
-      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 );
-  };
-}
-
-
-#endif

Copied: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp (from rev 203, trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp)
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -0,0 +1,169 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "Wrapper_p.h"
+
+#include <map>
+#include <vector>
+
+#include <llvm/DerivedTypes.h>
+#include <llvm/Function.h>
+
+#include "GTLCore/Function_p.h"
+#include "GTLCore/Macros.h"
+#include "GTLCore/Parameter.h"
+#include "GTLCore/PixelDescription.h"
+#include "GTLCore/Type.h"
+#include "GTLCore/Type_p.h"
+#include "GTLCore/TypeManager.h"
+#include "GTLCore/TypeManager_p.h"
+#include "GTLCore/Value.h"
+
+
+#include "Debug.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 Wrapper::Private
+{
+  static std::vector<GTLCore::Type::StructDataMember> s_imageDataMembers;
+};
+
+std::vector<GTLCore::Type::StructDataMember> Wrapper::Private::s_imageDataMembers;
+
+void Wrapper::fillTypeManager( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  )
+{
+  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 );
+}
+
+void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription)
+{
+  SHIVA_ASSERT(_pixelDescription.bitsSize() % 8 == 0);
+  std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
+  createPixelType(_module, _typeManager, "", pixelDataMembers, _pixelDescription.bitsSize() / 8 );
+}
+
+void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, 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 )
+  {
+    size_vector *= 2;
+  }
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", _typeManager->getVector( _referenceDepth, _channels) ) );
+  // Create the generic part of the pixel type
+  createPixelType(_module, _typeManager, GTLCore::String::number( _channels ), pixelDataMembers, _channels * _referenceDepth->bitsSize() / 8 );
+}
+
+void Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize )
+{
+  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) );
+  
+  _typeManager->d->createStructure( "pixel" + _suffix, _pixelDataMembers );
+}
+
+void Wrapper::createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager )
+{
+  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) );
+  regionDataMembers.push_back( GTLCore::Type::StructDataMember( "width", GTLCore::Type::Float ) );
+  regionDataMembers.push_back( GTLCore::Type::StructDataMember( "height", GTLCore::Type::Float ) );
+  const GTLCore::Type* type = _typeManager->d->createStructure( "region", regionDataMembers);
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "left", "region_wrap_left", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "right", "region_wrap_right", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "bottom", "region_wrap_bottom", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "top", "region_wrap_top", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "intersect", "region_wrap_intersect", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "union", "region_wrap_union", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "outset", "region_wrap_outset", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "inset", "region_wrap_inset", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
+}
+
+llvm::Function* Wrapper::image_wrap_dataFunction( llvm::Module* _module, const GTLCore::Type* _imageType )
+{
+  std::vector<const llvm::Type*> functionArgs;
+  functionArgs.push_back(llvm::PointerType::get( _imageType->d->type(), 0));
+  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);
+  GTL_DEBUG( *functionTy );
+  return new llvm::Function( functionTy, llvm::GlobalValue::ExternalLinkage, "image_wrap_data", _module);
+}
+
+
+STATIC_INITIALISATION(OpenShivaTypes)
+{
+
+  { // Image
+    Wrapper::Private::s_imageDataMembers.push_back( GTLCore::Type::StructDataMember( "image", GTLCore::Type::Pointer) );
+  }
+  { // 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) );
+  }
+}

Copied: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h (from rev 203, trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h)
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	2008-06-20 20:45:35 UTC (rev 205)
@@ -0,0 +1,67 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPENSHIVA_WRAPPER_P_H_
+#define _OPENSHIVA_WRAPPER_P_H_
+
+#include "GTLCore/Type_p.h"
+
+namespace llvm {
+  class Function;
+  class Module;
+}
+
+namespace GTLCore {
+  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 Wrapper {
+    public:
+      static void fillTypeManager( llvm::Module* _module, GTLCore::TypeManager*, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  );
+      static llvm::Function* image_wrap_dataFunction( llvm::Module* _module, const GTLCore::Type* _imageType );
+    public:
+      struct Private;
+    private:
+      static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
+      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 );
+  };
+}
+
+
+#endif

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp	2008-06-20 20:45:35 UTC (rev 205)
@@ -21,10 +21,13 @@
 
 #include "AbstractImage.h"
 
+#include "../Debug.h"
+
 extern "C" {
 
 char* image_wrap_data( ImageWrap* _imageWrap, int _x, int _y )
 {
+//   GTL_DEBUG( _x << " " << _y );
   return _imageWrap->image->data(_x, _y);
 }
 

Modified: trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	2008-06-19 19:27:31 UTC (rev 204)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	2008-06-20 20:45:35 UTC (rev 205)
@@ -2,7 +2,7 @@
 {
   void evaluatePixel(out pixel result)
   {
-    for(int i = 0; i < result.size; ++i )
+//    for(int i = 0; i < result.size; ++i )
     {
 //      result[i] = 0.5;
     }


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