[opengtl-commits] [483] * add a shivastdlib implemented in shiva

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


Revision: 483
Author:   cyrille
Date:     2008-11-17 00:03:55 +0100 (Mon, 17 Nov 2008)

Log Message:
-----------
* add a shivastdlib implemented in shiva
* makes absf a function in shivastdlib.shiva

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/LibrariesManager.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-11-16 23:03:55 UTC (rev 483)
@@ -29,9 +29,8 @@
 add_definitions( "-D__STDC_LIMIT_MACROS" )
 add_definitions( -DCOUMPONENT_NAME="OpenShiva" )
 
-add_definitions( -D_OPENSHIVA_SHIVA_STD_LIB_BUILD_DIR_="${CMAKE_CURRENT_BINARY_DIR}/../ShivaStdLib/")
 add_definitions( -D_OPENSHIVA_LIB_INSTALL_="${CMAKE_INSTALL_PREFIX}/lib/")
-add_definitions( -D_OPENSHIVA_SHIVA_STD_LIB_SRC_DIR_="${CMAKE_CURRENT_SOURCE_DIR}/../ShivaStdLib/")
+add_definitions( -D_OPENSHIVA_SHIVA_STD_LIB_SRC_DIR_="${CMAKE_CURRENT_SOURCE_DIR}")
 add_definitions( -D_OPENSHIVA_SHIVA_SHARE_DIR_="${SHARE_INSTALL_DIR}/shiva" )
 
 
@@ -46,3 +45,6 @@
 configure_file("OpenShiva.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/OpenShiva.pc" @ONLY)
 
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenShiva.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)  
+
+# Install standard library
+install(FILES shivastdlib.shiva DESTINATION ${SHARE_INSTALL_DIR}/shiva )

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-11-16 23:03:55 UTC (rev 483)
@@ -71,7 +71,7 @@
   return d->isKernel;
 }
 
-bool Compiler::compile(const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace)
+bool Compiler::compile(bool _loadStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace)
 {
   SHIVA_DEBUG("Compile: " << _kernelName << " : " << _sourceCode);
   // Initialise the module structure
@@ -107,10 +107,14 @@
   createStdLibFunction( "pow", "powf", GTLCore::Type::Float, 2, GTLCore::Type::Float, GTLCore::Type::Float);
   createStdLibFunction( "pow_h", "powf", GTLCore::Type::Float, 2, GTLCore::Type::Float, GTLCore::Type::Float);
   createStdLibFunction( "sqrt", "sqrtf", GTLCore::Type::Float, 1, GTLCore::Type::Float);
-  createStdLibFunction( "fabs", "fabsf", GTLCore::Type::Float, 1, GTLCore::Type::Float);
   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)
+  { // of course you don't want to import the standard library when building the standard library
+    importModule("shivastdlib");
+  }
+
   // Init the lexer
   std::istringstream iss(_sourceCode);
   d->lexer = new Lexer( &iss );

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-11-16 23:03:55 UTC (rev 483)
@@ -36,7 +36,7 @@
     public:
       Compiler( bool _isKernel, int _channelsNb );
       ~Compiler();
-      bool compile(const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace);
+      bool compile(bool _loadStdLibrary, const GTLCore::String& _sourceCode, const GTLCore::String& _kernelName, GTLCore::ModuleData* _moduleData, GTLCore::String& _nameSpace);
       bool importModule(const GTLCore::String& name);
       virtual GTLCore::TypeManager* typeManager();
       bool isKernel() const;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/LibrariesManager.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/LibrariesManager.cpp	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/LibrariesManager.cpp	2008-11-16 23:03:55 UTC (rev 483)
@@ -41,6 +41,8 @@
 LibrariesManager::LibrariesManager() : d(new Private)
 {
   addDirectory(".");
+  addDirectory(_OPENSHIVA_SHIVA_STD_LIB_SRC_DIR_);
+  addDirectory(_OPENSHIVA_SHIVA_SHARE_DIR_);
 }
 
 void LibrariesManager::addDirectory(const GTLCore::String& directory)

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2008-11-16 23:03:55 UTC (rev 483)
@@ -56,6 +56,7 @@
   d->m_moduleData = 0;
   d->count_channels_generic = _channelsNb;
   d->isKernel = _isKernel;
+  d->isStandardLibrary = false;
 }
 
 Library::~Library()
@@ -89,6 +90,7 @@
 
 void Library::loadFromFile(const GTLCore::String& _fileName)
 {
+  d->isStandardLibrary = _fileName.endWith( "shivastdlib.shiva" );
   d->source = "";
   std::ifstream in;
   in.open(_fileName.c_str() );
@@ -118,12 +120,13 @@
   Compiler c( d->isKernel,  d->count_channels_generic );
   Wrapper::fillTypeManager( d->m_moduleData, d->m_moduleData->typeManager(), c.convertCenter() , d->count_channels_generic );
   GTLCore::String nameSpace;
-  bool result = c.compile( d->source, d->name, d->m_moduleData, nameSpace );
+  bool result = c.compile( not d->isStandardLibrary, d->source, d->name, d->m_moduleData, nameSpace );
 
   if(result)
   {
     d->compiled = true;
     // Register the compiled module in the virtual machine
+    d->m_moduleData->doLink();
     d->moduleProvider = new llvm::ExistingModuleProvider( d->m_moduleData->llvmModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );
     postCompilation();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h	2008-11-16 22:39:57 UTC (rev 482)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h	2008-11-16 23:03:55 UTC (rev 483)
@@ -44,6 +44,7 @@
     GTLCore::ModuleData* m_moduleData;
     int count_channels_generic;
     bool isKernel;
+    bool isStandardLibrary;
   };
 }
 

Added: trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva	2008-11-16 23:03:55 UTC (rev 483)
@@ -0,0 +1,27 @@
+/*
+ *  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.
+ */
+
+library stdlib
+{
+  float fabs( float v )
+  {
+    if( v < 0) return -v;
+    return v;
+  }
+}


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