[opengtl-commits] [166] make ModuleData used in the generation context, break some tests

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


Revision: 166
Author:   cyrille
Date:     2008-05-19 00:32:39 +0200 (Mon, 19 May 2008)

Log Message:
-----------
make ModuleData used in the generation context, break some tests

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
    trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.h
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -62,6 +62,7 @@
   {
   }
   llvm::Module* module;
+  GTLCore::ModuleData* moduleData;
   void (*func)( const char*, char*, int);
   llvm::ModuleProvider* moduleProvider;
   GTLCore::PixelDescription srcPixelDescription;
@@ -110,16 +111,18 @@
 {
   d->func = 0;
   d->moduleProvider = 0;
+  d->moduleData = 0;
   // Clone the module
   if( module->data())
   {
     d->module = llvm::CloneModule(module->data()->llvmModule());
+    d->moduleData = new GTLCore::ModuleData( d->module );
     const GTLCore::Function* functionDef = module->function( functionName );
     if( not functionDef ) return;
     llvm::Function* function = d->module->getFunction( GTLCore::Function::Data::symbolName( GTLCore::ScopedName( "", functionName), functionDef->parameters() ) );
     if(function)
     {
-      GTLCore::CodeGenerator cg( d->module );
+      GTLCore::CodeGenerator cg( d->moduleData );
       // Initialise pixel information 
       int srcPixelSize = srcPixelDescription.bitsSize() / 8;
       OCTL_ASSERT(srcPixelDescription.bitsSize() % 8== 0);
@@ -169,7 +172,7 @@
       int programNb = ++Program::Private::s_id;
       llvm::Function* func = cg.createFunction( definitionType, "CTLProgram" + GTLCore::String::number(programNb));
       // Initialise a generation context
-      GTLCore::GenerationContext gc( &cg, func, 0, d->module );
+      GTLCore::GenerationContext gc( &cg, func, 0, d->moduleData );
       // {
       llvm::BasicBlock* initialBlock = new llvm::BasicBlock;
       func->getBasicBlockList().push_back( initialBlock );
@@ -363,7 +366,7 @@
     GTLCore::VirtualMachine::instance()->unregisterModule( d->moduleProvider);
     delete d->moduleProvider;
   }
-  delete d->module;
+  delete d->moduleData;
   delete d;
 }
 

Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -171,7 +171,7 @@
   
   // Create LLVM module
   d->module = moduleData->llvmModule();
-  d->codeGenerator = new GTLCore::CodeGenerator( d->module );
+  d->codeGenerator = new GTLCore::CodeGenerator( moduleData );
   d->moduleData = moduleData;
 
   // Create Standard Library functions
@@ -216,7 +216,7 @@
   GTLCore::AST::Tree* tree = d->parser->parse();
   if( tree and errorMessages().size() == 0)
   {
-    tree->generate( d->module, d->codeGenerator );
+    tree->generate( d->moduleData, d->codeGenerator );
     for( std::list<GTLCore::AST::FunctionDeclaration*>::const_iterator it = tree->functionsDeclarations().begin();
          it != tree->functionsDeclarations().end(); ++it)
     {

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -71,7 +71,7 @@
     arrayStruct.push_back( _gc.codeGenerator()->integerToConstant( members.size() ) );
     llvm::Constant* constant = llvm::ConstantArray::get(
                   llvm::ArrayType::get( arrayType->data()->type(), members.size()), members );
-    llvm::GlobalVariable* gvar = new llvm::GlobalVariable( constant->getType(), true, llvm::GlobalValue::ExternalLinkage, constant, "", _gc.module() );
+    llvm::GlobalVariable* gvar = new llvm::GlobalVariable( constant->getType(), true, llvm::GlobalValue::ExternalLinkage, constant, "", _gc.llvmModule() );
     
     llvm::Constant* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); // Access the structure of the array
     llvm::Constant *Ops[] = {zero, zero };

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -70,7 +70,7 @@
 GTLCore::ExpressionResult GlobalDataExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
 {
   llvm::Constant* value = m_expression->generateValue( _gc, 0 ).constant();
-  return GTLCore::ExpressionResult( new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _gc.module() ) );
+  return GTLCore::ExpressionResult( new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _gc.llvmModule() ) );
 }
 
 //------------------------------------------//

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -32,6 +32,7 @@
 #include <GTLCore/Debug.h>
 #include <GTLCore/Function_p.h>
 #include <GTLCore/Utils_p.h>
+#include <GTLCore/ModuleData_p.h>
 
 #include "Expression.h"
 #include "Statement.h"
@@ -82,10 +83,10 @@
   m_statement = statement;
 }
 
-void FunctionDeclaration::generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator)
+void FunctionDeclaration::generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator)
 {
   GTL_DEBUG("Generate function " << m_function->name() );
-  m_functionData->setModule( _module );
+  m_functionData->setModule( _module->llvmModule() );
   // Create the list of parameters as in llvm
   std::vector<const llvm::Type*> params;
   for(std::vector< Parameter >::const_iterator it = m_function->parameters().begin();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.h	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.h	2008-05-18 22:32:39 UTC (rev 166)
@@ -36,6 +36,7 @@
   class CodeGenerator;
   class Type;
   class VariableNG;
+  class ModuleData;
   namespace AST {
     class Expression;
     class Statement;
@@ -68,7 +69,7 @@
         Function* function();
         void setStatement( Statement* statement );
         const std::vector< GTLCore::VariableNG* >& parametersVariable() { return m_parametersVariable; }
-        void generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator);
+        void generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator);
       private:
         std::vector< FunctionParameter* > m_parameters;
         std::vector< GTLCore::VariableNG* > m_parametersVariable;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -219,7 +219,7 @@
   std::vector<const llvm::Type*> params;
   params.push_back( llvm::Type::Int32Ty);
   llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, true );
-  llvm::Function* func = dynamic_cast<llvm::Function*>( _context.module()->getOrInsertFunction("_Z5printiz", definitionType));
+  llvm::Function* func = dynamic_cast<llvm::Function*>( _context.llvmModule()->getOrInsertFunction("_Z5printiz", definitionType));
   
   std::vector<llvm::Value*> values;
   values.push_back( _context.codeGenerator()->integerToConstant( m_expressions.size() ));
@@ -232,7 +232,7 @@
     if( (*it)->type() == 0 )
     { // It's a string
       values.push_back( _context.codeGenerator()->integerToConstant( 3) );
-      values.push_back( new llvm::GlobalVariable( value.value()->getType(), true, llvm::GlobalValue::InternalLinkage, value.constant(), "", _context.module() ) );
+      values.push_back( new llvm::GlobalVariable( value.value()->getType(), true, llvm::GlobalValue::InternalLinkage, value.constant(), "", _context.llvmModule() ) );
     } else if( type == llvm::Type::Int32Ty )
     {
       values.push_back( _context.codeGenerator()->integerToConstant( 0) );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -30,6 +30,7 @@
 #include "GTLCore/Type_p.h"
 #include "GTLCore/VariableNG_p.h"
 #include "GTLCore/Utils_p.h"
+#include "GTLCore/ModuleData_p.h"
 
 #include "Expression.h"
 
@@ -47,12 +48,12 @@
 }
 
 
-void GlobalConstantDeclaration::generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator)
+void GlobalConstantDeclaration::generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator)
 {
   GTLCore::GenerationContext gc( _codeGenerator, 0, 0, _module);
   
   llvm::Constant* value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
-  llvm::Value* pointer = new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _module );
+  llvm::Value* pointer = new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _module->llvmModule() );
   m_variable->initialise( gc, pointer);
 }
 
@@ -97,7 +98,7 @@
 }
 
 
-void Tree::generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator)
+void Tree::generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator)
 {
   // Generate constants
   for(std::list<GlobalConstantDeclaration*>::iterator it = m_globalConstants.begin();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.h	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.h	2008-05-18 22:32:39 UTC (rev 166)
@@ -31,6 +31,7 @@
   class CodeGenerator;
   class VariableNG;
   class Type;
+  class ModuleData;
   namespace AST {
     class Expression;
     class FunctionDeclaration;
@@ -46,7 +47,7 @@
         const Expression* initialiser() const { return m_initialiser; }
         Expression* initialiser() { return m_initialiser; }
         GTLCore::VariableNG* variable() { return m_variable; }
-        void generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator);
+        void generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator);
       private:
         GTLCore::ScopedName m_name;
         Expression* m_initialiser;
@@ -66,7 +67,7 @@
         const std::list<GlobalConstantDeclaration*>& globalConstantDeclarations() const;
         void append( GlobalConstantDeclaration* constant );
         bool containsGlobalConstant( const GTLCore::ScopedName& _name ) const;
-        void generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator);
+        void generate( ModuleData* _module, GTLCore::CodeGenerator* _codeGenerator);
       private:
         std::list<FunctionDeclaration*> m_functions;
         std::list<GlobalConstantDeclaration*> m_globalConstants;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -32,6 +32,7 @@
 #include "Type_p.h"
 #include "Value.h"
 #include "VariableNG_p.h"
+#include "ModuleData_p.h"
 
 #define UNIFORMIZE_TYPES( _v1_, _v2_) \
   GTL_ASSERT( _v1_.value() ); \
@@ -82,10 +83,10 @@
 using namespace GTLCore;
 
 struct CodeGenerator::Private {
-  llvm::Module* module;
+  ModuleData* module;
 };
 
-CodeGenerator::CodeGenerator(llvm::Module* module) : d(new Private)
+CodeGenerator::CodeGenerator(ModuleData* module) : d(new Private)
 {
   d->module = module;
 }
@@ -235,7 +236,7 @@
 {
   std::vector<const llvm::Type*> llvmArguments;
   llvmArguments.push_back( llvm::Type::FloatTy );
-  llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->getOrInsertFunction( "_Z10float2halff",
+  llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->llvmModule()->getOrInsertFunction( "_Z10float2halff",
       llvm::FunctionType::get( llvm::Type::Int16Ty , llvmArguments, false ) ) );
   std::vector<llvm::Value*> convertedParams;
   convertedParams.push_back( convertValueTo( currentBlock, value, _valueType, GTLCore::Type::Float ) );
@@ -246,7 +247,7 @@
 {
   std::vector<const llvm::Type*> llvmArguments;
   llvmArguments.push_back( llvm::Type::Int16Ty );
-  llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->getOrInsertFunction( "_Z10half2floatt",
+  llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->llvmModule()->getOrInsertFunction( "_Z10half2floatt",
       llvm::FunctionType::get( llvm::Type::FloatTy , llvmArguments, false ) ) );
   std::vector<llvm::Value*> convertedParams;
   convertedParams.push_back( convertValueTo( currentBlock, value, GTLCore::Type::Half, GTLCore::Type::Integer16 ) );
@@ -315,7 +316,7 @@
 llvm::Function* CodeGenerator::createFunction( llvm::FunctionType* type, const GTLCore::String& name)
 {
   return  new llvm::Function( type, llvm::GlobalValue::InternalLinkage,
-                  name, d->module );
+                  name, d->module->llvmModule() );
 }
 
 void CodeGenerator::createIncrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var)

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-05-18 22:32:39 UTC (rev 166)
@@ -38,6 +38,7 @@
 
 namespace GTLCore {
   class ExpressionResult;
+  class ModuleData;
   class Type;
   class Value;
   class VariableNG;
@@ -54,7 +55,7 @@
       /**
        * Create a new \ref CodeGenerator for the given llvm module.
        */
-      CodeGenerator(llvm::Module* module);
+      CodeGenerator(ModuleData* module);
       ~CodeGenerator();
       /**
        * @return an integer constant

Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -19,10 +19,12 @@
 
 #include "GenerationContext_p.h"
 
+#include "ModuleData_p.h"
+
 using namespace GTLCore;
 
 GenerationContext::GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
-                    llvm::Function* _llvmFunction, Function* _function, llvm::Module* _module )
+                    llvm::Function* _llvmFunction, Function* _function, ModuleData* _module )
         : m_codeGenerator(_codeGenerator), m_llvmFunction(_llvmFunction), m_function(_function), m_module( _module)
 {
 }
@@ -42,8 +44,8 @@
   return m_function;
 }
 
-llvm::Module* GenerationContext::module()
+llvm::Module* GenerationContext::llvmModule()
 {
-  return m_module;
+  return m_module->llvmModule();
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h	2008-05-18 22:32:39 UTC (rev 166)
@@ -28,19 +28,21 @@
 namespace GTLCore {
   class CodeGenerator;
   class Function;
+  class ModuleData;
   class GenerationContext {
     public:
       GenerationContext( GTLCore::CodeGenerator* _codeGenerator, 
-                         llvm::Function* _llvmFunction, Function* _function, llvm::Module* _module );
+                         llvm::Function* _llvmFunction, Function* _function, ModuleData* _module );
       CodeGenerator* codeGenerator();
       llvm::Function* llvmFunction();
       Function* function();
-      llvm::Module* module();
+      llvm::Module* llvmModule();
+//       Module::Data* module();
     private:
       GTLCore::CodeGenerator* m_codeGenerator;
       llvm::Function* m_llvmFunction;
       Function* m_function;
-      llvm::Module* m_module;
+      ModuleData* m_module;
   };
 
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-05-18 10:53:01 UTC (rev 165)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-05-18 22:32:39 UTC (rev 166)
@@ -63,7 +63,7 @@
   // Initialise the module structure
   SHIVA_ASSERT( d->module == 0 );
   d->module = _moduleData->llvmModule();
-  d->codeGenerator = new GTLCore::CodeGenerator( d->module );
+  d->codeGenerator = new GTLCore::CodeGenerator( d->moduleData );
   d->moduleData = _moduleData;
   
   // Init the lexer
@@ -73,7 +73,7 @@
   GTLCore::AST::Tree* tree = d->parser->parse();
   if( tree and errorMessages().size() == 0)
   {
-    tree->generate( d->module, d->codeGenerator );
+    tree->generate( d->moduleData, d->codeGenerator );
     for( std::list<GTLCore::AST::FunctionDeclaration*>::const_iterator it = tree->functionsDeclarations().begin();
          it != tree->functionsDeclarations().end(); ++it)
     {


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