[opengtl-commits] [283] make coumpound expression works for vectors too |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 283
Author: cyrille
Date: 2008-07-02 00:17:02 +0200 (Wed, 02 Jul 2008)
Log Message:
-----------
make coumpound expression works for vectors too
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-07-01 22:16:07 UTC (rev 282)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-07-01 22:17:02 UTC (rev 283)
@@ -22,6 +22,7 @@
#include <llvm/Constants.h>
#include <llvm/DerivedTypes.h>
#include <llvm/GlobalVariable.h>
+#include <llvm/Instructions.h>
#include "../CodeGenerator_p.h"
#include "../Debug.h"
@@ -58,7 +59,7 @@
GTLCore::ExpressionResult CoumpoundExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
{
GTL_DEBUG( m_type->dataType() << " " << Type::ARRAY << " " << Type::STRUCTURE );
- if( m_type->dataType() == Type::ARRAY )
+ if( m_type->dataType() == Type::ARRAY or m_type->dataType() == Type::VECTOR)
{
const GTLCore::Type* arrayType = m_type->embeddedType();
std::vector< llvm::Constant* > members;
@@ -67,26 +68,33 @@
{
members.push_back( _gc.codeGenerator()->convertConstantTo( (*it)->generateValue( _gc, _bb).constant(), (*it)->type(), arrayType ) );
}
- std::vector<llvm::Constant*> arrayStruct;
- arrayStruct.push_back( _gc.codeGenerator()->integerToConstant( members.size() ) );
- llvm::Constant* constant = llvm::ConstantArray::get(
- llvm::ArrayType::get( arrayType->d->type(), members.size()), members );
- llvm::GlobalVariable* gvar = new llvm::GlobalVariable( constant->getType(), true, llvm::GlobalValue::ExternalLinkage, constant, "", _gc.llvmModule() );
-
- llvm::Constant* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); // Access the structure of the array
- llvm::Constant *Ops[] = {zero, zero };
- llvm::Constant* iptr = llvm::ConstantExpr::getGetElementPtr( gvar, Ops, 2);
-
- arrayStruct.push_back( iptr );
-
- const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->d->type() );
-
-/* GTL_DEBUG( *structType );
- GTL_DEBUG( arrayStruct[0] );
- GTL_DEBUG( arrayStruct[1] );*/
-
- return GTLCore::ExpressionResult(
- llvm::ConstantStruct::get( structType, arrayStruct ), type() );
+ if( m_type->dataType() == Type::ARRAY )
+ {
+ std::vector<llvm::Constant*> arrayStruct;
+ arrayStruct.push_back( _gc.codeGenerator()->integerToConstant( members.size() ) );
+ llvm::Constant* constant = llvm::ConstantArray::get(
+ llvm::ArrayType::get( arrayType->d->type(), members.size()), members );
+ llvm::GlobalVariable* gvar = new llvm::GlobalVariable( constant->getType(), true, llvm::GlobalValue::ExternalLinkage, constant, "", _gc.llvmModule() );
+
+ llvm::Constant* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); // Access the structure of the array
+ llvm::Constant *Ops[] = {zero, zero };
+ llvm::Constant* iptr = llvm::ConstantExpr::getGetElementPtr( gvar, Ops, 2);
+
+ arrayStruct.push_back( iptr );
+
+ const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->d->type() );
+ GTL_ASSERT( structType );
+
+ return GTLCore::ExpressionResult(
+ llvm::ConstantStruct::get( structType, arrayStruct ), type() );
+ } else if( m_type->dataType() == Type::VECTOR )
+ {
+ const llvm::VectorType* vectorType = dynamic_cast<const llvm::VectorType*>( m_type->d->type() );
+ GTL_ASSERT( vectorType );
+ llvm::Constant* constant = llvm::ConstantVector::get( vectorType, members );
+ GTL_DEBUG( "Coumpound constant = " << *constant << " type = " << *m_type );
+ return GTLCore::ExpressionResult( constant, m_type );
+ }
} else if( m_type->dataType() == Type::STRUCTURE )
{
std::vector<llvm::Constant*> members;
@@ -98,7 +106,7 @@
return GTLCore::ExpressionResult(
llvm::ConstantStruct::get( structType, members ), type() );
}
- GTL_ABORT("Can't generate coumpound value, neither array, neither expression.");
+ GTL_ABORT("Can't generate coumpound value, neither array, neither vector.");
return GTLCore::ExpressionResult();
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-07-01 22:16:07 UTC (rev 282)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-07-01 22:17:02 UTC (rev 283)
@@ -70,8 +70,13 @@
GTLCore::ExpressionResult GlobalDataExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- llvm::Constant* value = m_expression->generateValue( _gc, 0 ).constant();
- return GTLCore::ExpressionResult( new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _gc.llvmModule() ), type() );
+ GTLCore::ExpressionResult value = m_expression->generateValue( _gc, 0 );
+ if( type()->dataType() == Type::VECTOR )
+ {
+ return value;
+ } else {
+ return GTLCore::ExpressionResult( new llvm::GlobalVariable( value.constant()->getType(), true, llvm::GlobalValue::InternalLinkage, value.constant(), "", _gc.llvmModule() ), type() );
+ }
}
//------------------------------------------//