[opengtl-commits] [537] make it possible to directly use vector parameters in code ( parameters are inserted as constants)

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


Revision: 537
Author:   cyrille
Date:     2008-12-10 23:37:05 +0100 (Wed, 10 Dec 2008)

Log Message:
-----------
make it possible to directly use vector parameters in code (parameters are inserted as constants)

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Library.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
    trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-12-10 22:37:05 UTC (rev 537)
@@ -58,6 +58,7 @@
 
 GTLCore::ExpressionResult CoumpoundExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
 {
+  GTL_ASSERT( _bb );
   GTL_DEBUG( *m_type << " " << m_type->dataType() << " " << Type::ARRAY << " " << Type::STRUCTURE << " " << Type::VECTOR );
   
   switch( m_type->dataType() )

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-12-10 22:37:05 UTC (rev 537)
@@ -41,7 +41,7 @@
 
 #include "AccessorExpression.h"
 #include "GarbageCollectionStatement.h"
-#include "CoumpoundExpression.h"
+#include "ConstantCoumpoundExpression.h"
 
 using namespace GTLCore::AST;
 
@@ -72,7 +72,7 @@
       {
         expressions.push_back( fromValue( val ) );
       }
-      return new AST::CoumpoundExpression( _val.type(), expressions );
+      return new AST::ConstantCoumpoundExpression( _val.type(), expressions );
     }
     default:
       return 0;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Metadata/ParameterEntry.cpp	2008-12-10 22:37:05 UTC (rev 537)
@@ -30,6 +30,7 @@
 using namespace GTLCore::Metadata;
 
 struct ParameterEntry::Private {
+  Private() : type(0) {}
   Value minimumValue;
   Value maximumValue;
   Value defaultValue;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.cpp	2008-12-10 22:37:05 UTC (rev 537)
@@ -200,12 +200,17 @@
 {
   // TODO standardConstant
   
-  // Check if it is a parameter
+/*  // Check if it is a parameter
   std::map< GTLCore::String, GTLCore::Value >::iterator it = d->parameters.find(_name);
   if( it != d->parameters.end() )
   {
     return GTLCore::AST::Expression::fromValue( it->second );
-  }
+  }*/
   
   return 0;
 }
+
+const std::map< GTLCore::String, GTLCore::Value >& Compiler::parameters() const
+{
+  return d->parameters;
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Compiler_p.h	2008-12-10 22:37:05 UTC (rev 537)
@@ -43,6 +43,7 @@
       bool importModule(const GTLCore::String& name);
       virtual GTLCore::TypeManager* typeManager();
       bool isKernel() const;
+      const std::map< GTLCore::String, GTLCore::Value >& parameters() const;
     public:
       GTLCore::AST::Expression* standardConstant( const GTLCore::String& _name );
     private:

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-12-10 22:37:05 UTC (rev 537)
@@ -49,7 +49,7 @@
        * @param indicates the number of channel for the 'pixel' and 'image' type
        */
       Kernel(int _channelsNb = 4 );
-      ~Kernel();
+      virtual ~Kernel();
     private:
       virtual void cleanup();
       virtual void postCompilation();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library.h	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library.h	2008-12-10 22:37:05 UTC (rev 537)
@@ -39,7 +39,7 @@
     friend class Kernel;
     friend class LibrariesManager;
       Library( bool _isKernel, int _channelsNb );
-      ~Library();
+      virtual ~Library();
     private:
       virtual void cleanup();
       virtual void postCompilation();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-12-10 22:37:05 UTC (rev 537)
@@ -24,12 +24,14 @@
 #include "Compiler_p.h"
 #include "Lexer_p.h"
 
+#include <GTLCore/AST/Expression.h>
 #include <GTLCore/AST/Statement.h>
 #include <GTLCore/AST/Tree.h>
 #include <GTLCore/CompilerBase_p.h>
 #include <GTLCore/Macros_p.h>
 #include <GTLCore/Type.h>
 #include <GTLCore/TypeManager.h>
+#include <GTLCore/Value.h>
 #include <GTLCore/VariableNG_p.h>
 #include <GTLCore/VariablesManager_p.h>
 
@@ -98,6 +100,20 @@
     checkNextTokenIsSemi();
     getNextToken();
   }
+  SHIVA_DEBUG("Set parameters as constants");
+  // Set parameters as constants
+  for( std::map< GTLCore::String, GTLCore::Value >::const_iterator it = d->compiler->parameters().begin();
+       it != d->compiler->parameters().end(); ++it )
+  {
+    GTLCore::ScopedName scopedName( nameSpace(), it->first );
+    AST::GlobalConstantDeclaration* gcd = new AST::GlobalConstantDeclaration(
+        scopedName, it->second.type(),
+        GTLCore::AST::Expression::fromValue( it->second ), false );
+    variablesManager()->declareConstant( scopedName, gcd->variable() );
+    tree()->append( gcd );
+  }
+          
+  SHIVA_DEBUG("Parse body");
   // Parse "kernel" or "library"
   if( (d->compiler->isKernel() and isOfType( currentToken(), GTLCore::Token::KERNEL ) )
       or isOfType( currentToken(), GTLCore::Token::LIBRARY ) )

Modified: trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva	2008-12-10 22:37:05 UTC (rev 537)
@@ -16,7 +16,7 @@
     {
       histogram[i] = 0;
     }
-/*    float4 max_px;
+    float4 max_px;
     int max = 0;
     for( int y = yc - 4; y < yc + 4; ++y)
     {
@@ -31,7 +31,7 @@
           }
        }
     }
-    result = max_px;*/
+    result = max_px;
   }
   region changed(region changed_input_region, int input_index, region input_DOD[])
   {

Modified: trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	2008-12-09 23:08:53 UTC (rev 536)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	2008-12-10 22:37:05 UTC (rev 537)
@@ -1,3 +1,11 @@
+<
+  parameters: <
+    color: <
+      type: rgb;
+      defaultValue: { 0.2, 0.1, 0.3 };
+    >;
+  >;
+>;
 kernel PlainGenerator
 {
   void evaluatePixel(out pixel result)
@@ -2,5 +10,5 @@
   {
-    result[0] = 0.2;
-    result[1] = 0.1;
-    result[2] = 0.3;
+    result[0] = color[0];
+    result[1] = color[1];
+    result[2] = color[2];
   }


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