[opengtl-commits] [708] start working on a expression to convert array to vectors

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


Revision: 708
Author:   cyrille
Date:     2009-04-08 14:39:57 +0200 (Wed, 08 Apr 2009)

Log Message:
-----------
start working on a expression to convert array to vectors

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2009-03-26 19:02:52 UTC (rev 707)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2009-04-08 12:39:57 UTC (rev 708)
@@ -79,11 +79,7 @@
 llvm::Value* ArraySizeAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
   GTL_DEBUG("ArraySizeAccessorExpression::pointer");
-  std::vector<llvm::Value*> indexes;
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_SIZE)); // Access the size of the array
-  llvm::Value* val = llvm::GetElementPtrInst::Create( m_parent->pointer( _gc, _bb),
-                                      indexes.begin(), indexes.end(), "", _bb);
+  llvm::Value* val = GTLCore::CodeGenerator::accessArraySizePointer(_bb, m_parent->pointer( _gc, _bb))
   GTL_DEBUG( *val );
   return val;
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp	2009-03-26 19:02:52 UTC (rev 707)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp	2009-04-08 12:39:57 UTC (rev 708)
@@ -72,3 +72,27 @@
     return GTLCore::ExpressionResult( CodeGenerator::convertValueTo( bb,  result.value(), result.type(), m_dstType ), m_dstType);
   }
 }
+
+ArrayToVectorConvertExpression::ArrayToVectorConvertExpression( AST::Expression* _value, const GTLCore::Type* _dstType ) : ConvertExpression(_value), m_dstType(_dstType)
+{
+}
+
+ArrayToVectorConvertExpression::~ArrayToVectorConvertExpression()
+{
+}
+
+const GTLCore::Type* ArrayToVectorConvertExpression::type() const
+{
+  return m_dstType;
+}
+
+GTLCore::ExpressionResult ArrayToVectorConvertExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+{
+  GTLCore::ExpressionResult result = value()->generateValue( _gc, bb );
+  if( result.isConstant() )
+  {
+    return GTLCore::ExpressionResult( CodeGenerator::convertConstantArrayToVector( result.constant(), result.type(), m_dstType ), m_dstType);
+  } else {
+    return GTLCore::ExpressionResult( CodeGenerator::convertArrayToVector( bb,  result.value(), result.type(), m_dstType ), m_dstType);
+  }
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h	2009-03-26 19:02:52 UTC (rev 707)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h	2009-04-08 12:39:57 UTC (rev 708)
@@ -56,6 +56,15 @@
       private:
         const GTLCore::Type* m_dstType;
     };
+    class ArrayToVectorConvertExpression : public ConvertExpression {
+      public:
+        ArrayToVectorConvertExpression( AST::Expression* _value, const GTLCore::Type* _dstType );
+        virtual ~ArrayToVectorConvertExpression();
+        virtual const GTLCore::Type* type() const;
+        virtual GTLCore::ExpressionResult generateValue( GenerationContext&, llvm::BasicBlock* bb ) const;
+      private:
+        const GTLCore::Type* m_dstType;
+    };
   }
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2009-03-26 19:02:52 UTC (rev 707)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2009-04-08 12:39:57 UTC (rev 708)
@@ -262,6 +262,46 @@
   
 }
 
+llvm::Value* CodeGenerator::convertArrayToVector(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* valueType, const Type* type)
+{
+  // int arraySize = value->size;
+  // if( arraySize > type->vectorSize() ) arraySize = type->vectorSize();
+  // 'type' result;
+  // for(int i = 0; i < arraySize; ++i )
+  // {
+  //   result[i] = array[i];
+  // }
+  
+#if s0
+  // int arraySize = value->size;
+  llvm::Value* arraySize = accessArraySize(_currentBlock, value);
+  // arraySize > type->vectorSize()
+  llvm::Value aStVComp = createStrictSupperiorExpression(currentBlock, , );
+  type->vectorSize()
+#endif
+  GTL_ABORT("Unimplemented");
+  return 0;
+}
+
+llvm::Constant* CodeGenerator::convertConstantArrayToVector(llvm::Constant* constant, const Type* constantType, const Type* type)
+{
+  llvm::ConstantArray* arrayConstant = dynamic_cast<llvm::ConstantArray*>(constant);
+  GTL_ASSERT(arrayConstant);
+  GTL_ASSERT(constantType->dataType() == Type::ARRAY );
+  GTL_ASSERT(constantType->dataType() == Type::VECTOR );
+  std::vector<llvm::Constant*> constants;
+  for(unsigned int i = 0; i < arrayConstant->getNumOperands(); ++i )
+  {
+    constants.push_back(arrayConstant->getOperand(i));
+    if( constants.size() == type->vectorSize() )
+    {
+      break;
+    }
+  }
+  GTL_ASSERT( constants.size() == type->vectorSize() );
+  return llvm::ConstantVector::get( static_cast<const llvm::VectorType*>( type->d->type() ), constants);
+}
+
 llvm::Value* CodeGenerator::vectorValueAt( llvm::BasicBlock* _currentBlock, llvm::Value* _vector, llvm::Value* _index)
 {
   return new llvm::ExtractElementInst( _vector, _index, "", _currentBlock );
@@ -627,6 +667,19 @@
   return llvm::GetElementPtrInst::Create( iptr_val, _index, "", _currentBlock);
 }
 
+llvm::Value* CodeGenerator::accessArraySizePointer( 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
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, ArrayWrap::POS_SIZE)); // Access the size of the array
+  return llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
+}
+
+llvm::Value* CodeGenerator::accessArraySize( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
+{
+  return new llvm::LoadInst( accessArraySizePointer(_currentBlock, _pointer), "", _currentBlock);
+}
+
 GTLCore::ExpressionResult CodeGenerator::callFunction( GenerationContext& _gc, llvm::BasicBlock* bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& _arguments )
 {
   // Function Type

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2009-03-26 19:02:52 UTC (rev 707)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2009-04-08 12:39:57 UTC (rev 708)
@@ -106,6 +106,8 @@
       static llvm::Constant* convertConstantTo(llvm::Constant* constant, const Type* constantType, const Type* type);
       static llvm::Value* convertToHalf( GenerationContext& generationContext, llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* _valueType);
       static llvm::Value* convertFromHalf( GenerationContext& generationContext, llvm::BasicBlock* currentBlock, llvm::Value* value);
+      static llvm::Value* convertArrayToVector(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* valueType, const Type* type);
+      static llvm::Constant* convertConstantArrayToVector(llvm::Constant* constant, const Type* constantType, const Type* type);
       static llvm::Value* vectorValueAt( llvm::BasicBlock* _currentBlock, llvm::Value* _vector, llvm::Value* _index);
       static llvm::Value* createRound( llvm::BasicBlock* _currentBlock, llvm::Value* _val );
     public: // Boolean Expression
@@ -263,10 +265,12 @@
        * @return a pointer on the value of an array
        */
       llvm::Value* accessArrayValue( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _index );
+      static llvm::Value* accessArraySizePointer( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
+      static llvm::Value* accessArraySize( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
     public:
       GTLCore::ExpressionResult callFunction( GenerationContext& _gc, llvm::BasicBlock* _bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& m_arguments );
     public:
-      static llvm::Value* allocateMemory( GenerationContext& _gc, const llvm::Type* _type, llvm::Value* _size, llvm::BasicBlock* _bb);
+      static llvm::Value* allocateMemory( GenerationContext& _gc, const llvm::Type* _type, llvm::Value* _a, llvm::BasicBlock* _bb);
       static void freeMemory( GenerationContext& _gc, llvm::Value* _ptr, llvm::BasicBlock* _bb);
     private:
       static llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int unsignedIntegerPred, unsigned int signedIntegerPred, unsigned int floatPred);


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