[opengtl-commits] [377] introduce a counter field in the structure, to count how many time a structure is used, if it reaches 0, then it should be freeed

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


Revision: 377
Author:   cyrille
Date:     2008-09-07 22:01:24 +0200 (Sun, 07 Sep 2008)

Log Message:
-----------
introduce a counter field in the structure, to count how many time a structure is used, if it reaches 0, then it should be freeed

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
    trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -39,6 +39,7 @@
 #include "GTLCore/ModuleData_p.h"
 #include "Debug.h"
 #include "GTLCore/VirtualMachine_p.h"
+#include "GTLCore/Optimiser_p.h"
 
 // LLVM
 #include <llvm/DerivedTypes.h>
@@ -337,15 +338,10 @@
       OCTL_DEBUG("return;");
       llvm::ReturnInst::Create(finBlock);
       OCTL_DEBUG(*d->module);
-      // Optimize, FIXME: use GTLCore's optimizer
+      // Optimize
       OCTL_DEBUG("Optimize");
-      llvm::PassManager Passes;
-      // Add in the passes we want to execute
-      Passes.add(new llvm::TargetData(d->module));
-      // Verify we start with valid
-      Passes.add(llvm::createVerifierPass());
-      // Run
-      Passes.run(*d->module);
+      GTLCore::Optimiser::instance()->d->passManager()->run( *d->module );
+      
       // Register module in the VM
       d->moduleProvider = new llvm::ExistingModuleProvider( d->module );
       GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -32,6 +32,8 @@
 #include "../Type_p.h"
 #include "../Utils_p.h"
 
+#include "../wrappers/StructWrap.h"
+
 using namespace GTLCore::AST;
 
 //------------------- AccessorExpression -------------------//
@@ -89,7 +91,9 @@
 
 StructAccessorExpression::StructAccessorExpression(AccessorExpression* _parent, unsigned int _index) : m_parent(_parent), m_index(_index)
 {
-  GTL_ASSERT( m_index < m_parent->type()->structDataMembers()->size());
+#ifndef NDEBUG
+  m_parent->type()->structDataMember( m_index ); // let the assert be triggered inside Type::structDataMember
+#endif
 }
 
 StructAccessorExpression::~StructAccessorExpression()
@@ -102,7 +106,7 @@
   GTL_DEBUG("StructAccessorExpression::pointer");
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
-  indexes.push_back( _gc.codeGenerator()->integerToConstant(m_index));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(m_index + STRUCT_FIRST_ELEMENT));
   return llvm::GetElementPtrInst::Create( m_parent->pointer( _gc, _bb) , indexes.begin(), indexes.end(), "", _bb);
 }
 
@@ -113,7 +117,7 @@
 
 const GTLCore::Type* StructAccessorExpression::type() const
 {
-  return (*m_parent->type()->structDataMembers())[ m_index].type();
+  return m_parent->type()->structDataMember(m_index).type();
 }
 
 void StructAccessorExpression::markAsReturnExpression()

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -98,9 +98,10 @@
   } else if( m_type->dataType() == Type::STRUCTURE )
   {
     std::vector<llvm::Constant*> members;
+    members.push_back( CodeGenerator::integerToConstant( 0 ) ); // GC constant
     for( uint i = 0; i < m_expressions.size(); ++i)
     {
-      members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _bb).constant(), m_expressions[i]->type(), (*m_type->structDataMembers())[i].type() ) );
+      members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _bb).constant(), m_expressions[i]->type(), m_type->structDataMember(i).type() ) );
     }
     const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->d->type() );
     return GTLCore::ExpressionResult(

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -37,6 +37,7 @@
 #include "ModuleData_p.h"
 
 #include "AST/AccessorExpression.h"
+#include "wrappers/ArrayWrap.h"
 
 #define UNIFORMIZE_TYPES( _v1_, _v2_) \
   GTL_ASSERT( _v1_.value() ); \
@@ -571,7 +572,7 @@
   GTL_DEBUG( *_pointer << " " << *_index );
   std::vector<llvm::Value*> indexes;
   indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); // Access the size of the array
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_DATA)); // Access the data of the array
   
   // Select the pointer
   llvm::Value* iptr = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -332,11 +332,14 @@
 #include <llvm/Function.h>
 #include <llvm/Type.h>
 
-void compareFunctionParameters( llvm::Function* func, const std::vector<llvm::Value*>& params  )
+void compareFunctionParameters( llvm::Value* func, const std::vector<llvm::Value*>& params  )
 {
+  GTL_ASSERT(func);
   const llvm::FunctionType *FTy =
     llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(func->getType())->getElementType());
   
+  GTL_DEBUG(  *FTy );
+  
   GTL_ASSERT( params.size() == FTy->getNumParams() or
           (FTy->isVarArg() and params.size() > FTy->getNumParams()) );
   
@@ -345,7 +348,7 @@
     {
       GTL_DEBUG( "Wrong parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << params[i] << " => " << *params[i]->getType() );
     } else {
-      GTL_DEBUG( "Parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << params[i]->getType() << " => " << *params[i]->getType() );
+      GTL_DEBUG( "Parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " and got " << params[i]->getType() << " => " << *params[i]->getType() );
     }
   }
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -103,7 +103,7 @@
   class Value;
 }
              
-void compareFunctionParameters( llvm::Function* func, const std::vector<llvm::Value*>& params  );
+void compareFunctionParameters( llvm::Value* func, const std::vector<llvm::Value*>& params  );
 
 #define GTL_COMPARE_FUNCTION_PARAMETERS( _FUNC_, _PARAMS_ ) \
   compareFunctionParameters( _FUNC_, _PARAMS_ );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -22,6 +22,7 @@
 
 namespace OpenCTL {
   class Compiler;
+  class Program;
 }
 
 namespace OpenShiva {
@@ -31,6 +32,7 @@
 namespace GTLCore {
   class Optimiser{
     friend class OpenCTL::Compiler;
+    friend class OpenCTL::Program;
     friend class OpenShiva::Compiler;
     private:
       Optimiser();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -226,6 +226,7 @@
 {
   GTL_ASSERT( _type );
   GTL_ASSERT( d->currentToken.type == Token::STARTBRACE );
+  GTL_DEBUG( *_type );
   getNextToken(); // Eat '{'
   std::vector< AST::Expression* > expressions_;
   int index = 0;
@@ -240,11 +241,13 @@
         type = _type->embeddedType();
       } else if( _type->dataType() == Type::STRUCTURE )
       {
-        type = (*_type->structDataMembers())[index].type();
+        type = _type->structDataMember(index).type();
       }
       GTL_ASSERT( type );
+      GTL_DEBUG( index << " " <<  *type );
       if( type->dataType() != Type::STRUCTURE and type->dataType() != Type::ARRAY )
       {
+        GTL_DEBUG("unexpected");
         reportUnexpected( d->currentToken );
         return 0;
       }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -114,7 +114,12 @@
 {
   init(STRUCTURE);
   d->structName = _structName;
-  d->structDataMembers = new std::vector<StructDataMember>( _members );
+  d->structDataMembers = new std::vector<StructDataMember>( );
+  // Add the Garbage Collector field
+  d->structDataMembers->push_back( StructDataMember( "", GTLCore::Type::Integer32 ) );
+  // Add members
+  d->structDataMembers->insert( d->structDataMembers->end(), _members.begin(), _members.end() );
+  // Init the llvm type
   std::vector< const llvm::Type * > types;
   for(std::vector<StructDataMember>::iterator it = d->structDataMembers->begin();
       it != d->structDataMembers->end(); ++it)
@@ -187,16 +192,33 @@
   return d->structName;
 }
 
-const std::vector<Type::StructDataMember>* Type::structDataMembers() const
+const Type::StructDataMember& Type::structDataMember(std::size_t index) const
 {
-  return d->structDataMembers;
+  GTL_ASSERT(d->structDataMembers);
+  GTL_ASSERT( index < countStructDataMembers( ) );
+  return (*d->structDataMembers)[index + 1];
 }
 
-const std::vector<Type::StructFunctionMember>* Type::structFunctionMembers() const
+std::size_t Type::countStructDataMembers( ) const
 {
-  return d->structFunctionMembers;
+  if( d->structDataMembers )
+  {
+    return d->structDataMembers->size() - 1;
+  } else {
+    return 0;
+  }
 }
 
+// const std::vector<Type::StructDataMember>* Type::structDataMembers() const
+// {
+//   return d->structDataMembers;
+// }
+
+// const std::vector<Type::StructFunctionMember>* Type::structFunctionMembers() const
+// {
+//   return d->structFunctionMembers;
+// }
+
 int Type::bitsSize() const
 {
   switch( dataType() )

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -171,11 +171,13 @@
        * @return the name of the structure
        */
       const GTLCore::String& structName() const;
+      const Type::StructDataMember& structDataMember(std::size_t index) const;
+      std::size_t countStructDataMembers( ) const;
       /**
        * @return a vector of the struct members, or 0 if not a structure
        */
-      const std::vector<Type::StructDataMember>* structDataMembers() const;
-      const std::vector<Type::StructFunctionMember>* structFunctionMembers() const;
+//       const std::vector<Type::StructDataMember>* structDataMembers() const;
+//       const std::vector<Type::StructFunctionMember>* structFunctionMembers() const;
       /**
        * @return the size of this type in bytes (or -1 for structures and arrays)
        */

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -24,6 +24,7 @@
 #include "Parameter.h"
 #include "ScopedName.h"
 #include "Visitor_p.h"
+#include "wrappers/StructWrap.h"
 
 using namespace GTLCore;
 
@@ -172,7 +173,7 @@
   {
     if( it->name() == name)
     {
-      return count;
+      return count - STRUCT_FIRST_ELEMENT;
     }
   }
   return -1;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -39,6 +39,7 @@
 #include "Utils_p.h"
 
 #include "AST/Expression.h"
+#include "wrappers/ArrayWrap.h"
 
 using namespace GTLCore;
 
@@ -214,13 +215,14 @@
   GTL_DEBUG( *_size );
   std::vector<llvm::Value*> indexes;
   indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_SIZE)); // Access the size of the array
   { // Init the size
+    GTL_DEBUG( *_pointer );
     llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
     new llvm::StoreInst(_generationContext.codeGenerator()->convertValueTo( _currentBlock, _size, Type::Integer32, Type::Integer32 ), ptr, "", _currentBlock);
   }
   // Allocate the Array
-  indexes[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
+  indexes[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_DATA);
   {
     llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
     llvm::Value* array = 0;
@@ -241,7 +243,7 @@
 {
   std::vector<llvm::Value*> indexes;
   indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_SIZE)); // Access the size of the array
   llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", currentBlock);
   return new llvm::LoadInst( ptr, "", currentBlock);
 }
@@ -287,7 +289,7 @@
   } else {
     std::vector<llvm::Value*> indexes;
     indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-    indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
+    indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_SIZE)); // Access the size of the array
     // Init the size
     llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
     new llvm::StoreInst( GTLCore::CodeGenerator::integerToConstant( 0 ), ptr, "", _currentBlock);
@@ -400,7 +402,7 @@
 {
   std::vector<llvm::Value*> indexes;
   indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, _index));
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, _index + STRUCT_FIRST_ELEMENT ));
   return llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
 }
 
@@ -417,9 +419,9 @@
 llvm::BasicBlock* StructureVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _value, const Type* _valueType, bool _allocatedInMemory ) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
-  for(uint i = 0; i < _pointerType->structDataMembers()->size(); ++i)
+  for(uint i = 0; i < _pointerType->countStructDataMembers(); ++i)
   {
-    const Type* type = (*_pointerType->structDataMembers())[i].type();
+    const Type* type = _pointerType->structDataMember(i).type();
     llvm::Value* nptrToOwnMember = pointerToValue(_generationContext, _currentBlock, _pointer, i);
     llvm::Value* nptrToValueMember = pointerToValue( _generationContext, _currentBlock, _value, i);
     const Visitor* visitor = Visitor::getVisitorFor( type );
@@ -432,17 +434,17 @@
 llvm::BasicBlock* StructureVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
-  const std::vector<Type::StructDataMember>* sm = _pointerType->structDataMembers();
   
-  for( uint i = 0; i < sm->size(); ++i)
+  for( uint i = 0; i < _pointerType->countStructDataMembers(); ++i)
   {
     std::list< llvm::Value* > sizes;
-    for(std::list<int>::const_iterator it = (*sm)[i].initialSizes().begin();
-        it != (*sm)[i].initialSizes().end(); ++it)
+    const Type::StructDataMember& sdm = _pointerType->structDataMember(i);
+    for(std::list<int>::const_iterator it = sdm.initialSizes().begin();
+        it != sdm.initialSizes().end(); ++it)
     {
       sizes.push_back( _generationContext.codeGenerator()->integerToConstant( *it ) );
     }
-    const Type* type = (*sm)[i].type();
+    const Type* type = sdm.type();
     const Visitor* visitor = Visitor::getVisitorFor( type );
     _currentBlock = visitor->initialise( _generationContext, _currentBlock,
                             pointerToValue( _generationContext, _currentBlock, _pointer, i ),
@@ -455,11 +457,10 @@
 {
   if( _pointer == _donttouch ) return _currentBlock;
   GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
-  const std::vector<Type::StructDataMember>* sm = _pointerType->structDataMembers();
   
-  for( uint i = 0; i < sm->size(); ++i)
+  for( uint i = 0; i < _pointerType->countStructDataMembers(); ++i)
   {
-    const Type* type = (*sm)[i].type();
+    const Type* type = _pointerType->structDataMember(i).type();
     const Visitor* visitor = Visitor::getVisitorFor( type );
     _currentBlock = visitor->cleanUp( _generationContext, _currentBlock, pointerToValue( _generationContext, _currentBlock, _pointer, i ), type, _donttouch, _allocatedInMemory );
   }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -27,7 +27,7 @@
       GTLTEST_CHECK_EQUAL(Type::Float->dataType(), Type::FLOAT);
       GTLTEST_CHECK_EQUAL(Type::Float->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::Float->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::Float->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Float->countStructDataMembers(), 0);
     }
 };
 
@@ -41,27 +41,27 @@
       GTLTEST_CHECK_EQUAL(Type::Integer8->dataType(), Type::INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::Integer8->bitsSize(), 8);
       GTLTEST_CHECK_EQUAL(Type::Integer8->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::Integer8->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer8->countStructDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->dataType(), Type::UNSIGNED_INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->bitsSize(), 8);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->countStructDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer16->dataType(), Type::INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::Integer16->bitsSize(), 16);
       GTLTEST_CHECK_EQUAL(Type::Integer16->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::Integer16->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer16->countStructDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->dataType(), Type::UNSIGNED_INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->bitsSize(), 16);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->countStructDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer32->dataType(), Type::INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::Integer32->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::Integer32->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::Integer32->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer32->countStructDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->dataType(), Type::UNSIGNED_INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->embeddedType(), 0);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->structDataMembers(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->countStructDataMembers(), 0);
     }
 };
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -25,10 +25,14 @@
  * @ingroup GTLCore
  * @internal
  */
+//   STRUCT_HEADER
 struct ArrayWrap {
-  STRUCT_HEADER
   int size;
   void* data;
+  enum ArrayIndexes {
+    POS_SIZE = 0, // STRUCT_FIRST_ELEMENT,
+    POS_DATA = 1 // STRUCT_FIRST_ELEMENT + 1,
+  };
 };
 
 template<class _T_>

Modified: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -20,10 +20,10 @@
 #ifndef _STRUCT_WRAP_H_
 #define _STRUCT_WRAP_H_
 
-#define STRUCT_HEADER
-  // int count;
+#define STRUCT_HEADER \
+  int count;
 
-#define STRUCT_FIRST_ELEMENT 0
+#define STRUCT_FIRST_ELEMENT 1
 
 
 #endif

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -86,7 +86,7 @@
   SHIVA_DEBUG( *_pixel );
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
-  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_DATA));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::POS_DATA ));
   return llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock );
 }
 
@@ -161,10 +161,10 @@
   
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
-  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_COORD));
-  new llvm::StoreInst( result,
-        llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock ),
-        "", _currentBlock );
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::POS_COORD ));
+  llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock );
+  SHIVA_DEBUG( *_pixel << " " << *ptr << " " << *result);
+  new llvm::StoreInst( result, ptr, "", _currentBlock );
 }
 
 llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels)
@@ -543,9 +543,12 @@
 {
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
-  indexes.push_back( _gc.codeGenerator()->integerToConstant(_member_index));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(_member_index + STRUCT_FIRST_ELEMENT));
+  GTL_DEBUG( "Call " << _member_index << " on " << *_pointer );
   
   llvm::Value* funcPtr = new llvm::LoadInst( llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock ), "" , _currentBlock);
+  GTL_DEBUG( *funcPtr );
+  GTL_COMPARE_FUNCTION_PARAMETERS( funcPtr, _arguments );
   return llvm::CallInst::Create( funcPtr, _arguments.begin(), _arguments.end(), "", _currentBlock );
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp	2008-09-07 20:01:24 UTC (rev 377)
@@ -27,6 +27,7 @@
 
 #include "CodeGenerator_p.h"
 #include "Debug.h"
+#include "wrappers/PixelWrap_p.h"
 
 using namespace OpenShiva;
 
@@ -70,6 +71,6 @@
 
 bool PixelConvertExpressionFactory::canConvertBetween( const GTLCore::Type* srcType, const GTLCore::Type* dstType) const
 {
-  return (srcType->dataType() == GTLCore::Type::STRUCTURE and srcType->structName().startWith( "pixel" ) and (*srcType->structDataMembers())[0].type() == dstType )
-      or (dstType->dataType() == GTLCore::Type::STRUCTURE and dstType->structName().startWith( "pixel" ) and (*dstType->structDataMembers())[0].type() == srcType );
+  return (srcType->dataType() == GTLCore::Type::STRUCTURE and srcType->structName().startWith( "pixel" ) and srcType->structDataMember(PixelWrap::INDEX_DATA).type() == dstType )
+      or (dstType->dataType() == GTLCore::Type::STRUCTURE and dstType->structName().startWith( "pixel" ) and dstType->structDataMember(PixelWrap::INDEX_DATA).type() == srcType );
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -37,10 +37,15 @@
   void* memToVec;
   void* vecToMem;
   enum ImageIndexes {
-    INDEX_IMAGE = STRUCT_FIRST_ELEMENT,
-    INDEX_MEM_TO_VEC = STRUCT_FIRST_ELEMENT + 1,
-    INDEX_VEC_TO_MEM = STRUCT_FIRST_ELEMENT + 2
+    INDEX_IMAGE = 0,
+    INDEX_MEM_TO_VEC = 1,
+    INDEX_VEC_TO_MEM = 2
   };
+  enum ImagePoses {
+    POS_IMAGE = STRUCT_FIRST_ELEMENT + INDEX_IMAGE,
+    POS_MEM_TO_VEC = STRUCT_FIRST_ELEMENT + INDEX_MEM_TO_VEC,
+    POS_VEC_TO_MEM = STRUCT_FIRST_ELEMENT + INDEX_VEC_TO_MEM
+  };
 };
 
 extern "C" {

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-09-07 08:58:56 UTC (rev 376)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-09-07 20:01:24 UTC (rev 377)
@@ -32,9 +32,13 @@
   void* data;
   void* coord;
   enum PixelIndexes {
-    INDEX_DATA = STRUCT_FIRST_ELEMENT,
-    INDEX_COORD = STRUCT_FIRST_ELEMENT + 1
+    INDEX_DATA = 0,
+    INDEX_COORD = 1
   };
+  enum PixelPoses {
+    POS_DATA = STRUCT_FIRST_ELEMENT + INDEX_DATA,
+    POS_COORD = STRUCT_FIRST_ELEMENT + INDEX_COORD
+  };
 };
 
 #endif


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