[opengtl-commits] [555] * install KernelsCollection.h

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


Revision: 555
Author:   cyrille
Date:     2008-12-20 11:55:02 +0100 (Sat, 20 Dec 2008)

Log Message:
-----------
* install KernelsCollection.h
* set the Kernel/Library name as namespace

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/KernelsCollection.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-12-20 10:55:02 UTC (rev 555)
@@ -45,7 +45,14 @@
 
 # Install target
 install(TARGETS OpenShiva  DESTINATION ${LIB_INSTALL_DIR} )
-install( FILES Kernel.h Metadata.h Library.h LibrariesManager.h Version.h DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
+install( FILES
+  Kernel.h
+  KernelsCollection.h
+  Library.h
+  LibrariesManager.h
+  Metadata.h
+  Version.h
+  DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
 
 # Create and install pc file
 configure_file("OpenShiva.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/OpenShiva.pc" @ONLY)

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-12-20 10:55:02 UTC (rev 555)
@@ -51,6 +51,7 @@
   Parser* parser;
   int channelsNb;
   bool isKernel;
+  bool isStdLibrary;
   std::map< GTLCore::String, GTLCore::Value > parameters;
 };
 
@@ -73,8 +74,14 @@
   return d->isKernel;
 }
 
-bool Compiler::compile(bool _loadStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace, const std::map< GTLCore::String, GTLCore::Value >& parameters)
+bool Compiler::isStdLib() const
 {
+  return d->isStdLibrary;
+}
+
+bool Compiler::compile(bool _isStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace, const std::map< GTLCore::String, GTLCore::Value >& parameters)
+{
+  d->isStdLibrary = _isStdLibrary;
   SHIVA_DEBUG("Compile: " << _kernelName << " : " << _sourceCode);
   // Initialise the module structure
   SHIVA_ASSERT( d->module == 0 );
@@ -113,7 +120,7 @@
   createStdLibFunction( "floor", "floorf", GTLCore::Type::Float, 1, GTLCore::Type::Float);
   createStdLibFunction( "fmod", "fmodf", GTLCore::Type::Float, 2, GTLCore::Type::Float, GTLCore::Type::Float);
   
-  if( _loadStdLibrary)
+  if( not d->isStdLibrary)
   { // of course you don't want to import the standard library when building the standard library
     importModule("shivastdlib");
   }
@@ -150,6 +157,7 @@
   {
     delete function;
   }*/
+  SHIVA_DEBUG("Namespace = " << d->parser->nameSpace() );
   delete d->lexer;
   d->lexer = 0;
   delete d->parser;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-12-20 10:55:02 UTC (rev 555)
@@ -39,10 +39,11 @@
     public:
       Compiler( bool _isKernel, int _channelsNb );
       ~Compiler();
-      bool compile(bool _loadStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace, const std::map< GTLCore::String, GTLCore::Value >& parameters );
+      bool compile(bool _isStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace, const std::map< GTLCore::String, GTLCore::Value >& parameters );
       bool importModule(const GTLCore::String& name);
       virtual GTLCore::TypesManager* typesManager();
       bool isKernel() const;
+      bool isStdLib() const;
       const std::map< GTLCore::String, GTLCore::Value >& parameters() const;
     public:
       GTLCore::AST::Expression* standardConstant( const GTLCore::String& _name );

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-12-20 10:55:02 UTC (rev 555)
@@ -83,7 +83,7 @@
   // Create the generateEvaluatePixeles LLVM function
   d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( this, Library::d->count_channels_generic );
   // Call evaluateDepends as needed
-  GTLCore::Function* evaluateDependentsFunc = Library::d->m_moduleData->function( "MyKernel", "evaluateDependents");
+  GTLCore::Function* evaluateDependentsFunc = Library::d->m_moduleData->function( name(), "evaluateDependents");
   if( evaluateDependentsFunc )
   {
 
@@ -127,7 +127,7 @@
 int Kernel::runTest() const
 {
   SHIVA_ASSERT( isCompiled() );
-  const GTLCore::Function* f = Library::d->m_moduleData->function( "MyKernel", "runTest");
+  const GTLCore::Function* f = Library::d->m_moduleData->function( name(), "runTest");
   SHIVA_ASSERT( f );
   GTLCore::Value v = f->call( std::vector< GTLCore::Value >() );
   return v.asInt32();
@@ -135,12 +135,12 @@
 
 bool Kernel::hasTestFunction() const
 {
-  return Library::d->m_moduleData->function( "MyKernel", "runTest");
+  return Library::d->m_moduleData->function( name(), "runTest");
 }
 
 GTLCore::Region Kernel::needed( GTLCore::Region output_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
 {
-  GTLCore::Function* neededFunction = Library::d->m_moduleData->function( "MyKernel", "needed");
+  GTLCore::Function* neededFunction = Library::d->m_moduleData->function( name(),"needed");
   RegionWrap* (*func)( RegionWrap*, int, ArrayWrap* ) = ( RegionWrap* (*)( RegionWrap*, int, ArrayWrap* ) )GTLCore::VirtualMachine::instance()->getPointerToFunction( neededFunction, 3);
   RegionWrap* rwrap = (*func)( regionToRegionWrap( output_region ), input_index, regionListToArrayWrap( input_DOD ) );
   
@@ -151,12 +151,12 @@
 
 bool Kernel::hasNeededFunction() const
 {
-  return Library::d->m_moduleData->function( "MyKernel", "needed");
+  return Library::d->m_moduleData->function( name(), "needed");
 }
 
 GTLCore::Region Kernel::changed( GTLCore::Region changed_input_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
 {
-  GTLCore::Function* changedFunction = Library::d->m_moduleData->function( "MyKernel", "changed");
+  GTLCore::Function* changedFunction = Library::d->m_moduleData->function( name(), "changed");
   RegionWrap* (*func)( RegionWrap*, int, ArrayWrap* ) = ( RegionWrap* (*)( RegionWrap*, int, ArrayWrap* ) )GTLCore::VirtualMachine::instance()->getPointerToFunction( changedFunction, 3);
   RegionWrap* rwrap = (*func)( regionToRegionWrap( changed_input_region ), input_index, regionListToArrayWrap( input_DOD ) );
   
@@ -167,12 +167,12 @@
 
 bool Kernel::hasChangedFunction() const
 {
-  return Library::d->m_moduleData->function( "MyKernel", "changed");
+  return Library::d->m_moduleData->function( name(), "changed");
 }
 
 GTLCore::Region Kernel::generated()
 {
- GTLCore::Function* f = Library::d->m_moduleData->function( "MyKernel", "generated");
+ GTLCore::Function* f = Library::d->m_moduleData->function( name(), "generated");
  SHIVA_ASSERT( f );
 
  RegionWrap* (*func)() = (RegionWrap* (*)())GTLCore::VirtualMachine::instance()->getPointerToFunction( f, 0 );
@@ -185,5 +185,5 @@
 
 bool Kernel::hasGeneratedFunction() const
 {
-  return Library::d->m_moduleData->function( "MyKernel", "generated");
+  return Library::d->m_moduleData->function( name(), "generated");
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/KernelsCollection.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/KernelsCollection.cpp	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/KernelsCollection.cpp	2008-12-20 10:55:02 UTC (rev 555)
@@ -46,6 +46,7 @@
     if( GTLCore::String( path.getSuffix() ).toLower() == "shiva" )
     {
       Kernel* kernel = new Kernel( channelsNb );
+      kernel->loadFromFile( path.c_str() );
       kernels.push_back( kernel );
     }
   }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2008-12-20 10:55:02 UTC (rev 555)
@@ -176,7 +176,7 @@
   Compiler c( d->isKernel,  d->count_channels_generic );
   Wrapper::fillTypesManager( d->m_moduleData, d->m_moduleData->typesManager(), c.convertCenter() , d->count_channels_generic );
   GTLCore::String nameSpace;
-  bool result = c.compile( not d->isStandardLibrary, d->source, d->name, d->m_moduleData, nameSpace, d->parameters );
+  bool result = c.compile( d->isStandardLibrary, d->source, d->name, d->m_moduleData, nameSpace, d->parameters );
 
   if(result)
   {
@@ -185,9 +185,9 @@
     d->m_moduleData->doLink();
     d->moduleProvider = new llvm::ExistingModuleProvider( d->m_moduleData->llvmModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );
+    d->name = nameSpace;
     postCompilation();
-    d->name = nameSpace;
-
+    SHIVA_ASSERT( d->isStandardLibrary or d->name != "" );
   } else {
     d->compiled = false;
     cleanup();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-12-20 10:52:53 UTC (rev 554)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-12-20 10:55:02 UTC (rev 555)
@@ -122,6 +122,13 @@
     if( isOfType( currentToken(), GTLCore::Token::IDENTIFIER ) )
     {
       d->kernelName = currentToken().string;
+      SHIVA_ASSERT( d->kernelName != "" );
+      SHIVA_DEBUG( d->compiler->isStdLib() << " " << d->kernelName );
+      if( not d->compiler->isStdLib() )
+      {
+        setNameSpace( d->kernelName );
+        SHIVA_ASSERT( d->kernelName == nameSpace() );
+      }
       getNextToken();
       if( isOfType( currentToken(), GTLCore::Token::STARTBRACE ) )
       {


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