[opengtl-commits] [564] use CodeGenerator's allocate function

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


Revision: 564
Author:   cyrille
Date:     2009-02-27 16:57:21 +0100 (Fri, 27 Feb 2009)

Log Message:
-----------
use CodeGenerator's allocate function

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2009-02-27 15:39:47 UTC (rev 563)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2009-02-27 15:57:21 UTC (rev 564)
@@ -104,7 +104,7 @@
   } else {
     if( d->allocatedInMemory )
     {
-      pointer_ = new llvm::MallocInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "Variable", _bb);
+      pointer_ = CodeGenerator::allocateMemory(d->type->d->type(), CodeGenerator::integerToConstant(1), _bb);
     } else {
       pointer_ = new llvm::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "Variable", _bb);
     }
@@ -196,6 +196,7 @@
   {
     llvm::Value* pointer_ = pointer( _currentBlock);
     _currentBlock = d->visitor->mark( _generationContext, _currentBlock, pointer_, d->type, CodeGenerator::integerToConstant( -1 ) );
+    // pointer_ is deallocated inside cleanup
     _currentBlock = d->visitor->cleanUp( _generationContext, _currentBlock, pointer_, d->type, _donttouch, d->allocatedInMemory, true, true );
   }
   return _currentBlock;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2009-02-27 15:39:47 UTC (rev 563)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2009-02-27 15:57:21 UTC (rev 564)
@@ -239,8 +239,8 @@
     llvm::Value* array = 0;
     if( _allocatedInMemory )
     {
-      array = new llvm::MallocInst(
-                    _pointerType->embeddedType()->d->type(), _size, "ArrayVisitor::setSize", _currentBlock);
+      array = CodeGenerator::allocateMemory(
+                    _pointerType->embeddedType()->d->type(), _size, _currentBlock);
     } else {
       array = new llvm::AllocaInst(
                     _pointerType->embeddedType()->d->type(), _size, "ArrayVisitor::setSize", _currentBlock);
@@ -363,10 +363,10 @@
       indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_DATA )); // Access the data of the array
       // Free the array
       llvm::Value* ptrToData = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "ArrayVisitor::cleanUp", afterBlock);
-      new llvm::FreeInst( new llvm::LoadInst( ptrToData, "ArrayVisitor::cleanUp", afterBlock ), afterBlock );
+      CodeGenerator::freeMemory(new llvm::LoadInst( ptrToData, "ArrayVisitor::cleanUp", afterBlock ), afterBlock );
       if( _deletePointer )
       {
-        new llvm::FreeInst( _pointer, afterBlock );
+        CodeGenerator::freeMemory( _pointer, afterBlock );
       }
     }
     
@@ -619,7 +619,7 @@
   _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIfBlock);
   if( _allocatedInMemory and _deletePointer )
   {
-    new llvm::FreeInst( _pointer, lastIfBlock );
+    CodeGenerator::freeMemory(_pointer, lastIfBlock );
   }
   CodeGenerator::createIfStatement( _currentBlock, test, Type::Boolean, firstIfBlock, lastIfBlock, afterIfBlock );
   

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2009-02-27 15:39:47 UTC (rev 563)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2009-02-27 15:57:21 UTC (rev 564)
@@ -609,7 +609,7 @@
                           GTLCore::CodeGenerator::integerToConstant( 1 ) );
     llvm::Value* y_i = GTLCore::CodeGenerator::createRound( currentBlock, y_f );
   //    pixelX* px = new pixelX;
-    llvm::Value* px_var = new llvm::MallocInst( _pixelType->d->type(), GTLCore::CodeGenerator::integerToConstant( 1 ), "", currentBlock );
+    llvm::Value* px_var = GTLCore::CodeGenerator::allocateMemory( _pixelType->d->type(), GTLCore::CodeGenerator::integerToConstant( 1 ), currentBlock );
     GTLCore::CodeGenerator::setCountFieldOf( currentBlock, px_var, GTLCore::CodeGenerator::integerToConstant( 0 ) );
   //    memToPixel( image, px, image_wrap_data(self, x, y ) );
     currentBlock = memToPixel( generationContext, currentBlock,

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2009-02-27 15:39:47 UTC (rev 563)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2009-02-27 15:57:21 UTC (rev 564)
@@ -117,7 +117,10 @@
     _generationContext.llvmFunction()->getBasicBlockList().push_back( firstIfBlock);
     llvm::BasicBlock* afterIfBlock = llvm::BasicBlock::Create("afterIfBlockStructureVisitorCleanUp");
     _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIfBlock);
-    new llvm::FreeInst( _pointer, firstIfBlock );
+    if( _allocatedInMemory )
+    {
+      GTLCore::CodeGenerator::freeMemory( _pointer, firstIfBlock );
+    }
     GTLCore::CodeGenerator::createIfStatement( _currentBlock, test, GTLCore::Type::Boolean, firstIfBlock, firstIfBlock, afterIfBlock );
     return afterIfBlock;
   }


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