[opengtl-commits] [455] fix initialization of static structures and vectors

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


Revision: 455
Author:   cyrille
Date:     2008-10-17 09:42:55 +0200 (Fri, 17 Oct 2008)

Log Message:
-----------
fix initialization of static structures and vectors

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-10-16 22:14:07 UTC (rev 454)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-10-17 07:42:55 UTC (rev 455)
@@ -197,6 +197,7 @@
 
 const Type::StructDataMember& Type::structDataMember(std::size_t index) const
 {
+  GTL_ASSERT(d->dataType == Type::STRUCTURE );
   GTL_ASSERT(d->structDataMembers);
   GTL_ASSERT( index < countStructDataMembers( ) );
   return (*d->structDataMembers)[index + STRUCT_FIRST_ELEMENT];

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-10-16 22:14:07 UTC (rev 454)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-10-17 07:42:55 UTC (rev 455)
@@ -501,9 +501,16 @@
   return _currentBlock;
 }
 
-llvm::Constant* VectorVisitor::createStaticVariable( llvm::Module*, const Type* type, const std::list< int>& /*_sizes*/ ) const
+llvm::Constant* VectorVisitor::createStaticVariable( llvm::Module* _module, const Type* _type, const std::list< int>& /*_sizes*/ ) const
 {
-  return llvm::ConstantVector::getAllOnesValue( dynamic_cast<const llvm::VectorType*>(type->d->type() ) );
+  GTL_ASSERT( _type->dataType() == Type::VECTOR );
+  std::vector< llvm::Constant* > constants;
+  const Visitor* visitor = Visitor::getVisitorFor( _type->embeddedType() );
+  for( std::size_t i  = 0; i < _type->vectorSize(); ++i)
+  {
+    constants.push_back( visitor->createStaticVariable( _module, _type->embeddedType(), std::list<int>() ) );
+  }
+  return llvm::ConstantVector::get( dynamic_cast<const llvm::VectorType*>(_type->d->type() ), constants);
 }
 
 //--------- StructureVisitor ---------///
@@ -631,15 +638,16 @@
   return _currentBlock;
 }
 
-llvm::Constant* StructureVisitor::createStaticVariable( llvm::Module* _module, const Type* type, const std::list< int>& /*_sizes */) const
+llvm::Constant* StructureVisitor::createStaticVariable( llvm::Module* _module, const Type* _type, const std::list< int>& /*_sizes */) const
 {
+  GTL_ASSERT( _type->dataType() == Type::STRUCTURE );
   std::vector< llvm::Constant* > initialisers;
   initialisers.push_back( CodeGenerator::integerToConstant( 1 ) );
-  for( uint i = 0; i < type->countStructDataMembers(); ++i)
+  for( uint i = 0; i < _type->countStructDataMembers(); ++i)
   {
-    const Type* type = type->structDataMember(i).type();
+    const Type* type = _type->structDataMember(i).type();
     const Visitor* visitor = Visitor::getVisitorFor( type );
-    initialisers.push_back( visitor->createStaticVariable( _module, type, type->structDataMember(i).initialSizes() ) );
+    initialisers.push_back( visitor->createStaticVariable( _module, type, _type->structDataMember(i).initialSizes() ) );
   }
-  return llvm::ConstantStruct::get( dynamic_cast<const llvm::StructType*>(type->d->type()), initialisers );
+  return llvm::ConstantStruct::get( dynamic_cast<const llvm::StructType*>(_type->d->type()), initialisers );
 }


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