[opengtl-commits] [379] add convenient functions to manipulate the count field of structures/ arrays

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


Revision: 379
Author:   cyrille
Date:     2008-09-09 09:16:33 +0200 (Tue, 09 Sep 2008)

Log Message:
-----------
add convenient functions to manipulate the count field of structures/arrays

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
    trunk/OpenGTL/OpenGTL/GTLCore.doxy


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-07 21:18:13 UTC (rev 378)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-09 07:16:33 UTC (rev 379)
@@ -654,3 +654,40 @@
   CallFunc->setTailCall();
   return GTLCore::ExpressionResult( CallFunc, _function->returnType(), true );
 }
+
+llvm::Value* CodeGenerator::countFieldPointer( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
+{
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array/structure
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the count field of the array/structure
+  // Select the pointer
+  return llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
+}
+
+void CodeGenerator::setCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value )
+{
+  new llvm::StoreInst( _value, countFieldPointer( _currentBlock, _pointer ), "", _currentBlock);
+}
+
+llvm::Value* CodeGenerator::getCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* _pointer )
+{
+  return new llvm::LoadInst( countFieldPointer( currentBlock, _pointer ) );
+}
+
+llvm::Value* CodeGenerator::incrementCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
+{
+  llvm::Value* val = createAdditionExpression( _currentBlock,
+                                new llvm::LoadInst( countFieldPointer(_currentBlock, _pointer), "", _currentBlock ),
+                                Type::Integer32, integerToConstant(1), Type::Integer32 );
+  new llvm::StoreInst( val, _pointer, "", _currentBlock );
+  return val;
+}
+
+llvm::Value* CodeGenerator::decrementCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
+{
+  llvm::Value* val = createSubstractionExpression( _currentBlock,
+                                new llvm::LoadInst( countFieldPointer(_currentBlock, _pointer), "", _currentBlock ),
+                                Type::Integer32, integerToConstant(1), Type::Integer32 );
+  new llvm::StoreInst( val, _pointer, "", _currentBlock );
+  return val;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-09-07 21:18:13 UTC (rev 378)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-09-09 07:16:33 UTC (rev 379)
@@ -229,6 +229,25 @@
       void createWhileStatement( llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction,  llvm::BasicBlock* after);
     public:
       /**
+       * Set the count field of a Structure/Array to a given value.
+       */
+      static void setCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr, llvm::Value* value );
+      /**
+       * @return the count field of a Structure/Array
+       */
+      static llvm::Value* getCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
+      /**
+       * Increment the count field.
+       */
+      static llvm::Value* incrementCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
+      /**
+       * Decrement the count field.
+       */
+      static llvm::Value* decrementCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
+    private:
+      static llvm::Value* countFieldPointer( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
+    public:
+      /**
        * @param _currentBlock the current basic block
        * @param _pointer a pointer to the array structure
        * @param _index the index of the value in the array

Modified: trunk/OpenGTL/OpenGTL/GTLCore.doxy
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore.doxy	2008-09-07 21:18:13 UTC (rev 378)
+++ trunk/OpenGTL/OpenGTL/GTLCore.doxy	2008-09-09 07:16:33 UTC (rev 379)
@@ -2,4 +2,6 @@
  * @addtogroup GTLCore GTLCore Library
  * @version 0.9.5
  * @author Cyrille Berger
+ * 
+ * This library contains the core functionnalities used by the compilers, and some convenient classes.
  */


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