[opengtl-commits] [161] internal API change : since llvm type doesn' t hold information about wether a type is a signed or unisgned integer, pass a pointer to a GTLCore::Type with a llvm::Value |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
- To: opengtl-commits@xxxxxxxxxxxxxxxxxxx
- Subject: [opengtl-commits] [161] internal API change : since llvm type doesn' t hold information about wether a type is a signed or unisgned integer, pass a pointer to a GTLCore::Type with a llvm::Value
- From: subversion@xxxxxxxxxxxxx
- Date: Fri, 02 May 2008 18:58:36 +0200
Revision: 161
Author: cyrille
Date: 2008-05-02 18:58:35 +0200 (Fri, 02 May 2008)
Log Message:
-----------
internal API change : since llvm type doesn't hold information about wether a type is a signed or unisgned integer, pass a pointer to a GTLCore::Type with a llvm::Value
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Type.h
trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -168,7 +168,7 @@
int programNb = ++Program::Private::s_id;
llvm::Function* func = cg.createFunction( definitionType, "CTLProgram" + GTLCore::String::number(programNb));
// Initialise a generation context
- GTLCore::GenerationContext gc( &cg, func, d->module );
+ GTLCore::GenerationContext gc( &cg, func, 0, d->module );
// {
llvm::BasicBlock* initialBlock = new llvm::BasicBlock;
func->getBasicBlockList().push_back( initialBlock );
@@ -185,7 +185,7 @@
} else {
vng = new GTLCore::VariableNG(GTLCore::Type::Integer32, false );
}
- vng->initialise( gc, initialBlock, 0, std::list<llvm::Value*>());
+ vng->initialise( gc, initialBlock, 0, 0, std::list<llvm::Value*>());
buffer[i] = vng;
} else {
buffer[i] = 0;
@@ -204,18 +204,18 @@
// Construct the "conditions" of the loop
// int i = 0;
GTLCore::VariableNG* posSrc = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- posSrc->initialise( gc, initialBlock, cg.integerToConstant(0), std::list<llvm::Value*>());
+ posSrc->initialise( gc, initialBlock, cg.integerToConstant(0), GTLCore::Type::Integer32, std::list<llvm::Value*>());
GTLCore::VariableNG* posDst = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- posDst->initialise( gc, initialBlock, cg.integerToConstant(0), std::list<llvm::Value*>());
+ posDst->initialise( gc, initialBlock, cg.integerToConstant(0), GTLCore::Type::Integer32, std::list<llvm::Value*>());
// i < size
llvm::BasicBlock* forTestBlock = new llvm::BasicBlock("forTestBlock");
func->getBasicBlockList().push_back( forTestBlock);
- llvm::Value* forTest = cg.createStrictInferiorExpression(forTestBlock, posSrc->get( gc, forTestBlock ), size);
+ llvm::Value* forTest = cg.createStrictInferiorExpression(forTestBlock, posSrc->get( gc, forTestBlock ), posSrc->type(), size, GTLCore::Type::Integer32 );
// i += pixelSize
llvm::BasicBlock* updateBlock = new llvm::BasicBlock("updateBlock");
func->getBasicBlockList().push_back( updateBlock);
- posSrc->set( gc, updateBlock, cg.createAdditionExpression( updateBlock, posSrc->get( gc, updateBlock), srcPixelSizeValue ));
- posDst->set( gc, updateBlock, cg.createAdditionExpression( updateBlock, posDst->get( gc, updateBlock), dstPixelSizeValue ));
+ posSrc->set( gc, updateBlock, cg.createAdditionExpression( updateBlock, posSrc->get( gc, updateBlock), posSrc->type(), srcPixelSizeValue, GTLCore::Type::Integer32 ), GTLCore::Type::Integer32 );
+ posDst->set( gc, updateBlock, cg.createAdditionExpression( updateBlock, posDst->get( gc, updateBlock), posSrc->type(), dstPixelSizeValue, GTLCore::Type::Integer32 ), GTLCore::Type::Integer32 );
// Construct the body of the for loop
llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
@@ -229,9 +229,9 @@
{
// Load the value from the input buffer
llvm::Value* convertedIn = new llvm::LoadInst(
- cg.convertValueTo( bodyBlock,
- new llvm::GetElementPtrInst( in, cg.createAdditionExpression( bodyBlock, srcIndex, srcIndexes[i]), "", bodyBlock),
- llvm::PointerType::get( srcChannelsTypes[i]->data()->type(), 0 )),
+ cg.convertPointerTo( bodyBlock,
+ new llvm::GetElementPtrInst( in, cg.createAdditionExpression( bodyBlock, srcIndex, posSrc->type(), srcIndexes[i], GTLCore::Type::Integer32), "", bodyBlock),
+ srcChannelsTypes[i]->data()->type()),
"", bodyBlock);
if( srcNeedBuffer[i])
{ // if a buffer is needed that means that the value must be converted
@@ -239,7 +239,7 @@
{
convertedIn = cg.convertFromHalf( bodyBlock, convertedIn);
} else {
- convertedIn = cg.convertValueTo( bodyBlock, convertedIn, llvm::Type::Int32Ty);
+ convertedIn = cg.convertValueTo( bodyBlock, convertedIn, srcChannelsTypes[i], GTLCore::Type::Integer32);
}
}
arguments.push_back( convertedIn );
@@ -249,11 +249,11 @@
llvm::Value* dstIndex = posDst->get( gc, bodyBlock);
for(int i = 0; i < dstCountChannels; ++i)
{
- llvm::Value* pointer = cg.convertValueTo( bodyBlock, new llvm::GetElementPtrInst( out, cg.createAdditionExpression( bodyBlock, dstIndex, dstIndexes[i]), "", bodyBlock), llvm::PointerType::get( dstPixelDescription.channelTypes()[i]->data()->type(), 0 ));
+ llvm::Value* pointer = cg.convertPointerTo( bodyBlock, new llvm::GetElementPtrInst( out, cg.createAdditionExpression( bodyBlock, dstIndex, GTLCore::Type::Integer32, dstIndexes[i], GTLCore::Type::Integer32), "", bodyBlock), dstPixelDescription.channelTypes()[i]->data()->type());
if( dstNeedBuffer[i])
{
OCTL_ASSERT(buffer[i]);
- buffer[i]->set( gc, bodyBlock, new llvm::LoadInst(pointer,"", bodyBlock));
+ buffer[i]->set( gc, bodyBlock, new llvm::LoadInst(pointer,"", bodyBlock), dstPixelDescription.channelTypes()[i]);
arguments.push_back( buffer[i]->pointer());
} else {
arguments.push_back(pointer);
@@ -294,13 +294,13 @@
if( dstNeedBuffer[i])
{
const llvm::Type* channelType = dstChannelsTypes[i]->data()->type();
- llvm::Value* pointer = cg.convertValueTo( bodyBlock, new llvm::GetElementPtrInst( out, cg.createAdditionExpression( bodyBlock, dstIndex, dstIndexes[i]), "", bodyBlock), llvm::PointerType::get( channelType, 0 ));
+ llvm::Value* pointer = cg.convertPointerTo( bodyBlock, new llvm::GetElementPtrInst( out, cg.createAdditionExpression( bodyBlock, dstIndex, GTLCore::Type::Integer32, dstIndexes[i], GTLCore::Type::Integer32), "", bodyBlock), channelType);
llvm::Value* result = 0;
if( dstChannelsTypes[i] == GTLCore::Type::Half )
{
- result = cg.convertToHalf( bodyBlock, buffer[i]->get( gc, bodyBlock ) );
+ result = cg.convertToHalf( bodyBlock, buffer[i]->get( gc, bodyBlock ), GTLCore::Type::Float );
} else {
- result = cg.convertValueTo( bodyBlock, buffer[i]->get( gc, bodyBlock ), channelType );
+ result = cg.convertValueTo( bodyBlock, buffer[i]->get( gc, bodyBlock ), GTLCore::Type::Integer32, dstChannelsTypes[i] );
}
OCTL_DEBUG( *result->getType() << *pointer->getType() );
new llvm::StoreInst( result, pointer, bodyBlock);
@@ -310,7 +310,7 @@
// for(int i = 0; i < size; ++i)
llvm::BasicBlock* finBlock = new llvm::BasicBlock("finBlock");
func->getBasicBlockList().push_back( finBlock);
- cg.createForStatement(initialBlock, forTestBlock, forTest, updateBlock, bodyBlock, bodyBlock, finBlock);
+ cg.createForStatement(initialBlock, forTestBlock, forTest, GTLCore::Type::Boolean, updateBlock, bodyBlock, bodyBlock, finBlock);
// return;
new llvm::ReturnInst(finBlock);
OCTL_DEBUG(*d->module);
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -125,7 +125,7 @@
GTLCore::Function::Data* data = new GTLCore::Function::Data(arguments, arguments.size() );
data->setFunctions( functions );
data->setModule( d->module );
- GTLCore::Function* function = new GTLCore::Function( _name, GTLCore::Type::Void, data );
+ GTLCore::Function* function = new GTLCore::Function( _name, retType, data );
OCTL_ASSERT( declareFunction(GTLCore::ScopedName("", _name), function) );
d->functionsToDelete.push_back(function);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -49,106 +49,146 @@
return GTLCore::Type::Boolean;
}
+const GTLCore::Type* OrBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult OrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createOrExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createOrExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* AndBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult AndBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createAndExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createAndExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult BitOrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createBitOrExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createBitOrExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult BitXorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createBitXorExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createBitXorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult BitAndBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createBitAndExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createBitAndExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* EqualEqualBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult EqualEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* DifferentBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult DifferentBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createDifferentExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createDifferentExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* InferiorEqualBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult InferiorEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createInferiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createInferiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* InferiorBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult InferiorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createStrictInferiorExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createStrictInferiorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* SupperiorEqualBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult SupperiorEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createSupperiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createSupperiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
+const GTLCore::Type* SupperiorBinaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult SupperiorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createStrictSupperiorExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createStrictSupperiorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult RightShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createRightShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createRightShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult LeftShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createLeftShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createLeftShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult AdditionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createAdditionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createAdditionExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult SubstractionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createSubstractionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createSubstractionExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult MultiplicationBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createMultiplicationExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createMultiplicationExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult DivisionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createDivisionExpression(bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createDivisionExpression(bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult ModuloBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createModuloExpression(bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createModuloExpression(bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
llvm::BasicBlock* AssignementBinaryExpression::generateStatement( GenerationContext& _gc, llvm::BasicBlock* _bb) const
{
return m_lhs->variable()->set( _gc, _bb,
- rightHandSide()->generateValue( _gc, _bb).value(), m_lhs->memberArray());
+ rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type(), m_lhs->memberArray());
}
GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
llvm::BasicBlock* bbr = m_lhs->variable()->set( _gc, bb,
- rightHandSide()->generateValue( _gc, bb).value(), m_lhs->memberArray());
+ rightHandSide()->generateValue( _gc, bb).value(), rightHandSide()->type(), m_lhs->memberArray());
GTL_ASSERT( bbr == bb);
return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, bb) );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -59,6 +59,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -70,6 +71,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -114,6 +116,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -125,6 +128,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -136,6 +140,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -147,6 +152,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -158,6 +164,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
@@ -169,6 +176,7 @@
{
}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -65,7 +65,7 @@
for( std::vector<Expression*>::const_iterator it = m_expressions.begin();
it != m_expressions.end(); ++it)
{
- members.push_back( _gc.codeGenerator()->convertConstantTo( (*it)->generateValue( _gc, _bb).constant(), arrayType ) );
+ 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() ) );
@@ -92,7 +92,7 @@
std::vector<llvm::Constant*> members;
for( uint i = 0; i < m_expressions.size(); ++i)
{
- members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _bb).constant(), (*m_type->structDataMembers())[i].type() ) );
+ members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _bb).constant(), m_expressions[i]->type(), (*m_type->structDataMembers())[i].type() ) );
}
const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->data()->type() );
return GTLCore::ExpressionResult(
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -107,6 +107,7 @@
const GTLCore::Type* FunctionCallExpression::type() const
{
+ GTL_DEBUG( m_function->name() << " <=> " << *m_function->returnType() );
return m_function->returnType();
}
@@ -132,9 +133,10 @@
GTL_DEBUG(*varex->variable()->pointer()->getType() << " " << *oparam_it->type()->data()->type() );
} else {
llvm::Value* value = (*it)->generateValue(_gc, bb).value();
+ GTL_ASSERT( value );
if( oparam_it->type()->data()->type()->isFirstClassType() )
{
- value = _gc.codeGenerator()-> convertValueTo( bb, value, oparam_it->type()->data()->type() );
+ value = _gc.codeGenerator()-> convertValueTo( bb, value, (*it)->type(), oparam_it->type() );
}
convertedParams.push_back( value );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -111,17 +111,20 @@
for( unsigned int i = m_function->parameters().size(); i > m_function->data()->minimumParameters(); i--)
{
// Create the function type
- const llvm::Type* type = params.back();
params.pop_back(); // remove the last parameter
llvm::FunctionType* definitionType = llvm::FunctionType::get( m_function->returnType()->data()->type(), params, false );
// Create the function
llvm::Function* function = _codeGenerator->createFunction( definitionType, m_function->name() + GTLCore::String::number((int)params.size()));
- GenerationContext generationContext( _codeGenerator, function, _module);
+ GenerationContext generationContext( _codeGenerator, function, m_function, _module);
// Create a block for the call to the function with one more parameter
llvm::BasicBlock* BB = new llvm::BasicBlock("CallForwarder");
function->getBasicBlockList().push_back( BB );
llvm::Value* defaultValue = m_parameters[i - 1]->initialiser()->generateValue( generationContext , BB).value();
- defaultValue = _codeGenerator->convertValueTo( BB, defaultValue, type);
+ if( m_parameters[i - 1]->parameter().type()->dataType() != Type::STRUCTURE
+ and m_parameters[i - 1]->parameter().type()->dataType() != Type::ARRAY )
+ {
+ defaultValue = _codeGenerator->convertValueTo( BB, defaultValue, m_parameters[i - 1]->initialiser()->type(), m_parameters[i - 1]->parameter().type());
+ }
// Prepare the arguments to call the function with one more parameter
std::vector<llvm::Value*> arguments;
for( llvm::Function::arg_iterator it = function->arg_begin();
@@ -144,7 +147,7 @@
llvm::BasicBlock* firstBlock = new llvm::BasicBlock;
fullFunction->getBasicBlockList().push_back( firstBlock );
// Initialise the context
- GenerationContext generationContext( _codeGenerator, fullFunction, _module);
+ GenerationContext generationContext( _codeGenerator, fullFunction, m_function, _module);
// Initialize the arguments
{
llvm::Function::arg_iterator arg_it = fullFunction->arg_begin(); // Get the arg.
@@ -160,7 +163,7 @@
{
(*pv_it)->initialise( generationContext, arg_it );
} else {
- firstBlock = (*pv_it)->initialise( generationContext, firstBlock, arg_it, std::list<llvm::Value*>() );
+ firstBlock = (*pv_it)->initialise( generationContext, firstBlock, arg_it, it->type(), std::list<llvm::Value*>() );
}
}
}
@@ -175,7 +178,7 @@
new llvm::ReturnInst(lastBlock);
} else
{
- new llvm::ReturnInst( _codeGenerator->convertConstantTo( _codeGenerator->integerToConstant( 0), m_function->returnType()->data()->type() ), lastBlock );
+ new llvm::ReturnInst( _codeGenerator->convertConstantTo( _codeGenerator->integerToConstant( 0), GTLCore::Type::Integer32, m_function->returnType() ), lastBlock );
}
}
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -30,6 +30,7 @@
// GTLCore
#include <GTLCore/CodeGenerator_p.h>
#include <GTLCore/ExpressionResult_p.h>
+#include <GTLCore/Function.h>
#include <GTLCore/Type.h>
#include <GTLCore/Utils_p.h>
#include <GTLCore/VariableNG_p.h>
@@ -44,8 +45,9 @@
llvm::BasicBlock* Statement::createBlock( GenerationContext& context) const
{
+ GTL_ASSERT( context.llvmFunction() );
llvm::BasicBlock* bb = new llvm::BasicBlock;
- context.function()->getBasicBlockList().push_back( bb );
+ context.llvmFunction()->getBasicBlockList().push_back( bb );
return bb;
}
@@ -85,9 +87,11 @@
llvm::BasicBlock* VariableDeclaration::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
{
llvm::Value* initialiserValue = 0;
+ const Type* initialiserType = 0;
if( m_initialiser )
{
initialiserValue = m_initialiser->generateValue( _context, _bb).value();
+ initialiserType = m_initialiser->type();
}
std::list<llvm::Value*> initialSizeValues;
if( not m_initialSizes.empty() )
@@ -103,7 +107,7 @@
}
}
}
- _bb = m_variable->initialise( _context, _bb, initialiserValue, initialSizeValues);
+ _bb = m_variable->initialise( _context, _bb, initialiserValue, initialiserType, initialSizeValues);
if(m_functionInitialiser)
{
return m_functionInitialiser->generateStatement( _context, _bb );
@@ -126,7 +130,7 @@
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_ifStatement->generateStatement( _context, startAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createIfStatement( _bb, test, startAction, endAction, after);
+ _context.codeGenerator()->createIfStatement( _bb, test, m_expression->type(), startAction, endAction, after);
return after;
}
@@ -145,7 +149,7 @@
llvm::BasicBlock* startElseAction = createBlock( _context );
llvm::BasicBlock* endElseAction = m_elseStatement->generateStatement( _context, startElseAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createIfElseStatement( _bb, test, startAction, endAction, startElseAction, endElseAction, after );
+ _context.codeGenerator()->createIfElseStatement( _bb, test, m_expression->type(), startAction, endAction, startElseAction, endElseAction, after );
return after;
}
@@ -167,7 +171,7 @@
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_forStatement->generateStatement( _context, startAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createForStatement( initBlock, testBlock, test, updateBlock, startAction, endAction, after);
+ _context.codeGenerator()->createForStatement( initBlock, testBlock, test, m_testExpression->type(), updateBlock, startAction, endAction, after);
return after;
}
@@ -184,7 +188,7 @@
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_whileStatement->generateStatement( _context, startAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createWhileStatement( _bb, testBlock, test, startAction, endAction, after );
+ _context.codeGenerator()->createWhileStatement( _bb, testBlock, test, m_expression->type(), startAction, endAction, after );
return after;
}
@@ -198,10 +202,7 @@
if( m_returnExpr )
{
llvm::Value* result = m_returnExpr->generateValue( _context, _bb).value();
- const llvm::FunctionType *FTy =
- llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>( _context.function()->getType())->getElementType());
-
- new llvm::ReturnInst( _context.codeGenerator()->convertValueTo(_bb, result, FTy->getReturnType() ), _bb);
+ new llvm::ReturnInst( _context.codeGenerator()->convertValueTo(_bb, result, m_returnExpr->type(), _context.function()->returnType() ), _bb);
} else {
new llvm::ReturnInst( _bb );
}
@@ -239,11 +240,11 @@
} else if( type == llvm::Type::FloatTy )
{
values.push_back( _context.codeGenerator()->integerToConstant( 1) );
- values.push_back( _context.codeGenerator()->convertValueTo( _bb, value.value(), llvm::Type::DoubleTy));
+ values.push_back( _context.codeGenerator()->convertValueTo( _bb, value.value(), (*it)->type(), GTLCore::Type::Double ));
} else if( type == llvm::Type::Int1Ty )
{
values.push_back( _context.codeGenerator()->integerToConstant( 2) );
- values.push_back( _context.codeGenerator()->convertValueTo( _bb, value.value(), llvm::Type::Int32Ty));
+ values.push_back( _context.codeGenerator()->convertValueTo( _bb, value.value(), (*it)->type(), GTLCore::Type::Integer32 ));
} else {
GTL_DEBUG("Unknown type for print " << *type);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -49,9 +49,9 @@
void GlobalConstantDeclaration::generate( llvm::Module* _module, GTLCore::CodeGenerator* _codeGenerator)
{
- GTLCore::GenerationContext gc( _codeGenerator, 0, _module);
+ GTLCore::GenerationContext gc( _codeGenerator, 0, 0, _module);
- llvm::Constant* value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_type->data()->type() );
+ llvm::Constant* value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
llvm::Value* pointer = new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _module );
m_variable->initialise( gc, pointer);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -20,6 +20,7 @@
#include "UnaryExpression.h"
#include <GTLCore/CodeGenerator_p.h>
+#include <GTLCore/Type.h>
#include <GTLCore/ExpressionResult_p.h>
using namespace GTLCore::AST;
@@ -32,7 +33,7 @@
GTLCore::ExpressionResult MinusUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createMinusExpression( bb, rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createMinusExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult MinusMinusUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
@@ -47,12 +48,17 @@
return m_rhs->generateValue( _gc, bb);
}
+const GTLCore::Type* NotUnaryExpression::type() const
+{
+ return Type::Boolean;
+}
+
GTLCore::ExpressionResult NotUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createNotExpression( bb, rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createNotExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
GTLCore::ExpressionResult TildeUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createTildeExpression( bb, rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createTildeExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -82,6 +82,7 @@
public:
explicit NotUnaryExpression(Expression* rhs) : UnaryExpression(rhs) {}
virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual const GTLCore::Type* type() const;
};
/**
* @internal
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -77,7 +77,7 @@
}
}
-llvm::BasicBlock* Accessor::initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value )
+llvm::BasicBlock* Accessor::initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType )
{
GTL_ASSERT(not m_initialisedValue);
m_initialisedValue = true;
@@ -85,7 +85,7 @@
{
bool constant = m_constant;
m_constant = false;
- _currentBlock = set( _generationContext, _currentBlock, _pointer, _value );
+ _currentBlock = set( _generationContext, _currentBlock, _pointer, _value, _valueType );
m_constant = constant;
}
return _currentBlock;
@@ -109,12 +109,12 @@
}
llvm::BasicBlock* PrimitiveAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
- llvm::Value* _pointer, llvm::Value* _value, MemberArray* _ma)
+ llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma)
{
GTL_ASSERT( not _ma or _ma->empty );
GTL_ASSERT( not isConstant());
new llvm::StoreInst(
- _generationContext.codeGenerator()->convertValueTo( _currentBlock, _value, type()->data()->type() ),
+ _generationContext.codeGenerator()->convertValueTo( _currentBlock, _value, _valueType, type() ),
_pointer, "", _currentBlock);
return _currentBlock;
}
@@ -173,49 +173,50 @@
}
}
-llvm::BasicBlock* ArrayAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, MemberArray* _ma )
+llvm::BasicBlock* ArrayAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
{
if( not _ma or _ma->empty )
{
// Check if size are identical or update the size of this array
{
- llvm::Value* test= _generationContext.codeGenerator()->createDifferentExpression( _currentBlock, getSize( _generationContext, _currentBlock, _pointer ), getSize( _generationContext, _currentBlock, _value ));
+ llvm::Value* test= _generationContext.codeGenerator()->createDifferentExpression( _currentBlock, getSize( _generationContext, _currentBlock, _pointer ), Type::Integer32, getSize( _generationContext, _currentBlock, _value ), Type::Integer32);
llvm::BasicBlock* ifContent = new llvm::BasicBlock;
- _generationContext.function()->getBasicBlockList().push_back( ifContent );
+ _generationContext.llvmFunction()->getBasicBlockList().push_back( ifContent );
setSize( _generationContext, ifContent, _pointer, getSize( _generationContext, ifContent, _value ) );
llvm::BasicBlock* afterIf = new llvm::BasicBlock;
- _generationContext.function()->getBasicBlockList().push_back( afterIf);
- _generationContext.codeGenerator()->createIfStatement( _currentBlock, test, ifContent, ifContent, afterIf );
+ _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIf);
+ _generationContext.codeGenerator()->createIfStatement( _currentBlock, test, Type::Boolean, ifContent, ifContent, afterIf );
_currentBlock = afterIf;
}
// int i = 0;
GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), std::list<llvm::Value*>());
+ index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
// Construct the body of the for loop
llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
- _generationContext.function()->getBasicBlockList().push_back( bodyBlock);
+ _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
// GTL_DEBUG( " value = " << *_pointer << " type = " << *_pointer->getType() );
// GTL_DEBUG( " value = " << *_value << " type = " << *_value->getType() );
llvm::BasicBlock* endBodyBlock = m_accessor->set( _generationContext, bodyBlock,
_generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ),
- new llvm::LoadInst( _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _value, index->get( _generationContext, bodyBlock ) ), "", bodyBlock ), 0 );
+ new llvm::LoadInst( _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _value, index->get( _generationContext, bodyBlock ) ), "", bodyBlock ), _valueType->arrayType() );
// Create the for statement
return _generationContext.codeGenerator()->createIterationForStatement(
- _generationContext.function(),
+ _generationContext.llvmFunction(),
_currentBlock,
index,
getSize( _generationContext, _currentBlock, _pointer),
+ Type::Integer32,
bodyBlock,
endBodyBlock );
} else {
GTL_ASSERT( _ma->array);
llvm::Value* nptr = pointerToValue(_generationContext, _currentBlock, _pointer, _ma);
- m_accessor->set( _generationContext, _currentBlock, nptr, _value, _ma->next );
+ m_accessor->set( _generationContext, _currentBlock, nptr, _value, _valueType, _ma->next );
return _currentBlock;
}
}
@@ -228,7 +229,7 @@
indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
{ // Init the size
llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
- new llvm::StoreInst(_generationContext.codeGenerator()->convertValueTo( _currentBlock, _size, GTLCore::Type::Integer32->data()->type() ), ptr, "", _currentBlock);
+ new llvm::StoreInst(_generationContext.codeGenerator()->convertValueTo( _currentBlock, _size, GTLCore::Type::Integer32, GTLCore::Type::Integer32 ), ptr, "", _currentBlock);
}
// Allocate the Array
indexes[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
@@ -259,21 +260,22 @@
sizeAfter.pop_front();
// int i = 0;
GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), std::list<llvm::Value*>());
+ index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
// Construct the body of the for loop
llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
- _generationContext.function()->getBasicBlockList().push_back( bodyBlock);
+ _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
llvm::BasicBlock* endBodyBlock = m_accessor->initialise( _generationContext, bodyBlock,
_generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ), sizeAfter );
// Create the for statement
return _generationContext.codeGenerator()->createIterationForStatement(
- _generationContext.function(),
+ _generationContext.llvmFunction(),
_currentBlock,
index,
_generationContext.codeGenerator()->integerToConstant(_sizes.size()),
+ Type::Integer32,
bodyBlock,
endBodyBlock );
}
@@ -339,7 +341,7 @@
}
llvm::BasicBlock* StructureAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
- llvm::Value* _pointer, llvm::Value* _value, MemberArray* _ma )
+ llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
{
if( not _ma or _ma->empty )
{
@@ -348,14 +350,14 @@
llvm::Value* nptrToOwnMember = pointerToValue(_generationContext, _currentBlock, _pointer, i);
llvm::Value* nptrToValueMember = pointerToValue( _generationContext, _currentBlock, _value, i);
llvm::Value* memberValue = m_accessors[i]->get( _generationContext, _currentBlock, nptrToValueMember, 0 );
- m_accessors[i]->set( _generationContext, _currentBlock, nptrToOwnMember, memberValue, _ma ? _ma->next : (MemberArray*)0 );
+ m_accessors[i]->set( _generationContext, _currentBlock, nptrToOwnMember, memberValue, (*_valueType->structDataMembers())[i].type() , _ma ? _ma->next : (MemberArray*)0 );
}
} else {
GTL_ASSERT( _ma->member );
int idx = memberToIndex( _ma );
GTL_ASSERT( idx != -1 );
llvm::Value* nptr = pointerToValue(_generationContext, _currentBlock, _pointer, idx);
- m_accessors[idx]->set( _generationContext, _currentBlock, nptr, _value, _ma->next );
+ m_accessors[idx]->set( _generationContext, _currentBlock, nptr, _value, _valueType, _ma->next );
}
return _currentBlock;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -73,7 +73,7 @@
* @param _ma
*/
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
- llvm::Value* _pointer, llvm::Value* _value, MemberArray* _ma = 0) = 0;
+ llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma = 0) = 0;
/**
* @return true if this accessor is pointer toward a constant value
*/
@@ -108,7 +108,7 @@
* @param _size the size of the array, if applicable
*/
virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes) = 0;
- llvm::BasicBlock* initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value );
+ llvm::BasicBlock* initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType );
public:
/**
* This function create the accessor for the type given in argument
@@ -135,7 +135,7 @@
virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
llvm::Value* pointer, MemberArray* _ma = 0);
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
- llvm::Value* pointer, llvm::Value*, MemberArray* _ma = 0);
+ llvm::Value* pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
virtual void setSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, llvm::Value* _size );
virtual llvm::Value* getSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer );
virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes);
@@ -151,7 +151,7 @@
virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
llvm::Value* _pointer, MemberArray* _ma = 0);
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
- llvm::Value* _pointer, llvm::Value*, MemberArray* _ma = 0);
+ llvm::Value* _pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
virtual void setSize( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
llvm::Value* _pointer, llvm::Value* _size);
virtual llvm::Value* getSize( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
@@ -173,7 +173,7 @@
virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
llvm::Value* pointer, MemberArray* _ma = 0);
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
- llvm::Value* pointer, llvm::Value*, MemberArray* _ma = 0);
+ llvm::Value* pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
virtual void setSize( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, llvm::Value* _size );
virtual llvm::Value* getSize( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer );
virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes);
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -36,47 +36,48 @@
#define UNIFORMIZE_TYPES( _v1_, _v2_) \
GTL_ASSERT( _v1_.value() ); \
GTL_ASSERT( _v2_.value() ); \
- const llvm::Type* highestPriorityType = selectType( _v1_.value()->getType(), _v2_.value()->getType()); \
- if( not highestPriorityType ) \
- { \
- return GTLCore::ExpressionResult(); \
- } \
+ const Type* highestPriorityType = selectType( lhsType, rhsType); \
+ GTL_ASSERT( highestPriorityType ); \
GTLCore::ExpressionResult v1; \
GTLCore::ExpressionResult v2; \
if(_v1_.isConstant() and _v2_.isConstant()) \
{ \
- v1.setConstant(convertConstantTo( _v1_.constant(), highestPriorityType)); \
- v2.setConstant(convertConstantTo( _v2_.constant(), highestPriorityType)); \
+ v1.setConstant(convertConstantTo( _v1_.constant(), lhsType, highestPriorityType)); \
+ v2.setConstant(convertConstantTo( _v2_.constant(), rhsType, highestPriorityType)); \
} else { \
- v1.setValue(convertValueTo( currentBlock, _v1_.value(), highestPriorityType)); \
- v2.setValue(convertValueTo( currentBlock, _v2_.value(), highestPriorityType)); \
- }
+ v1.setValue(convertValueTo( currentBlock, _v1_.value(), lhsType, highestPriorityType)); \
+ v2.setValue(convertValueTo( currentBlock, _v2_.value(), rhsType, highestPriorityType)); \
+ } \
+ GTL_ASSERT( v1.value() ); \
+ GTL_ASSERT( v2.value() );
#define UNIFORMIZE_VALUE_TYPES( _v1_, _v2_ ) \
- const llvm::Type* highestPriorityType = selectType( _v1_->getType(), _v2_->getType()); \
- if( not highestPriorityType ) \
- { \
- return 0; \
- } \
- llvm::Value* v1 = convertValueTo( currentBlock, _v1_, highestPriorityType); \
- llvm::Value* v2 = convertValueTo( currentBlock, _v2_, highestPriorityType);
+ const Type* highestPriorityType = selectType( lhsType, rhsType); \
+ GTL_ASSERT( highestPriorityType ); \
+ llvm::Value* v1 = convertValueTo( currentBlock, _v1_, lhsType, highestPriorityType); \
+ llvm::Value* v2 = convertValueTo( currentBlock, _v2_, rhsType, highestPriorityType); \
+ GTL_ASSERT( v1 ); \
+ GTL_ASSERT( v2 );
#define UNIFORMIZE_CONSTANT_TYPES( _v1_, _v2_ ) \
- const llvm::Type* highestPriorityType = selectType( _v1_->getType(), _v2_->getType()); \
- if( not highestPriorityType ) \
- { \
- return 0; \
- } \
- llvm::Constant* v1 = convertConstantTo( _v1_, highestPriorityType); \
- llvm::Constant* v2 = convertConstantTo( _v2_, highestPriorityType);
+ const Type* highestPriorityType = selectType( lhsType, rhsType); \
+ GTL_ASSERT( highestPriorityType ); \
+ llvm::Constant* v1 = convertConstantTo( _v1_, lhsType, highestPriorityType); \
+ llvm::Constant* v2 = convertConstantTo( _v2_, rhsType, highestPriorityType); \
+ GTL_ASSERT( v1 ); \
+ GTL_ASSERT( v2 );
#define MAKE_VALUE_BOOLEAN( _v1_, _v2_ ) \
llvm::Value* v1 = convertValueTo( currentBlock, _v1_, llvm::IntegerType::get(1)); \
- llvm::Value* v2 = convertValueTo( currentBlock, _v2_, llvm::IntegerType::get(1));
+ llvm::Value* v2 = convertValueTo( currentBlock, _v2_, llvm::IntegerType::get(1)); \
+ GTL_ASSERT( v1 ); \
+ GTL_ASSERT( v2 );
#define MAKE_CONSTANT_BOOLEAN( _v1_, _v2_ ) \
llvm::Constant* v1 = convertConstantTo( _v1_, llvm::IntegerType::get(1)); \
- llvm::Constant* v2 = convertConstantTo( _v2_, llvm::IntegerType::get(1));
+ llvm::Constant* v2 = convertConstantTo( _v2_, llvm::IntegerType::get(1)); \
+ GTL_ASSERT( v1 ); \
+ GTL_ASSERT( v2 );
using namespace GTLCore;
@@ -109,6 +110,7 @@
return llvm::ConstantFP::get(llvm::Type::FloatTy, llvm::APFloat(v));
}
+
llvm::Constant* CodeGenerator::valueToConstant( const GTLCore::Value& v)
{
if( v.type() == GTLCore::Type::Integer32 or v.type() == GTLCore::Type::UnsignedInteger32 )
@@ -122,6 +124,7 @@
return 0;
}
+#if 0
llvm::Value* CodeGenerator::convertValueTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const llvm::Type* type)
{
llvm::Constant* constant = dynamic_cast<llvm::Constant*>(value);
@@ -186,15 +189,82 @@
{
return convertConstantTo( _constant, _type->data()->type());
}
+#endif
+
+llvm::Value* CodeGenerator::convertPointerTo(llvm::BasicBlock* _currentBlock, llvm::Value* _value, const llvm::Type* _type)
+{
+ return new llvm::BitCastInst( _value, llvm::PointerType::get( _type, 0 ), "", _currentBlock );
+}
-llvm::Value* CodeGenerator::convertToHalf( llvm::BasicBlock* currentBlock, llvm::Value* value)
+llvm::Value* CodeGenerator::convertValueTo(llvm::BasicBlock* _currentBlock, llvm::Value* _value, const Type* _valueType, const Type* _targetType)
{
+ llvm::Constant* _constant = dynamic_cast<llvm::Constant*>(_value);
+ if(_constant)
+ {
+ return convertConstantTo( _constant, _valueType, _targetType);
+ }
+ GTL_ASSERT(_value);
+ GTL_ASSERT(_valueType);
+ GTL_ASSERT(_targetType);
+ if(_value->getType() == _targetType->data()->type() )
+ { // Don't cast the value as it has allready the correct type
+ return _value;
+ }
+ GTL_ASSERT(_targetType->data()->type()->isFirstClassType());
+ GTL_ASSERT(_value->getType()->isFirstClassType());
+ if( _value->getType()->isInteger() and _targetType->data()->type()->isInteger())
+ { // Cast integers between integers
+ return llvm::CastInst::createIntegerCast(_value, _targetType->data()->type(), false, "", _currentBlock);
+ } else if( _value->getType()->isFloatingPoint() and _targetType->data()->type()->isFloatingPoint() )
+ { // Cast floats between floats
+ return llvm::CastInst::createFPCast(_value, _targetType->data()->type(), "", _currentBlock);
+ } else { // Other casts
+ return llvm::CastInst::create(
+ llvm::CastInst::getCastOpcode(_value, true, _targetType->data()->type(), true), _value, _targetType->data()->type(), "", _currentBlock ); // TODO support for unsigned
+ }
+}
+
+llvm::Constant* CodeGenerator::convertConstantTo(llvm::Constant* _constant, const Type* _constantType, const Type* _targetType)
+{
+ GTL_DEBUG( *_constant->getType() << " " << *_targetType->data()->type() );
+ if(_constant->getType() == _targetType->data()->type() )
+ { // Don't cast the value as it has allready the correct type
+ return _constant;
+ }
+ GTL_ASSERT(_targetType->data()->type()->isFirstClassType());
+ GTL_ASSERT(_constant->getType()->isFirstClassType());
+ if( _constant->getType()->isInteger() and _targetType->data()->type()->isInteger())
+ { // Cast integers between integers
+ if( _constant->getType()->getPrimitiveSizeInBits() > _targetType->data()->type()->getPrimitiveSizeInBits() )
+ {
+ return llvm::ConstantExpr::getTrunc(_constant, _targetType->data()->type());
+ } else {
+ return llvm::ConstantExpr::getZExt(_constant, _targetType->data()->type());
+ }
+ } else if( _constant->getType()->isFloatingPoint() and _targetType->data()->type()->isFloatingPoint() )
+ { // Cast floats between floats
+ if( _constant->getType()->getPrimitiveSizeInBits() > _targetType->data()->type()->getPrimitiveSizeInBits() )
+ {
+ return llvm::ConstantExpr::getFPTrunc(_constant, _targetType->data()->type());
+ } else {
+ return llvm::ConstantExpr::getFPExtend(_constant, _targetType->data()->type());
+ }
+ } else { // Other casts
+ return llvm::ConstantExpr::getCast(
+ (unsigned)llvm::CastInst::getCastOpcode(_constant, true, _targetType->data()->type(), true), _constant, _targetType->data()->type() ); // TODO support for unsigned
+ }
+}
+
+
+
+llvm::Value* CodeGenerator::convertToHalf( llvm::BasicBlock* currentBlock, llvm::Value* value, const GTLCore::Type* _valueType )
+{
std::vector<const llvm::Type*> llvmArguments;
llvmArguments.push_back( llvm::Type::FloatTy );
llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->getOrInsertFunction( "_Z10float2halff",
llvm::FunctionType::get( llvm::Type::Int16Ty , llvmArguments, false ) ) );
std::vector<llvm::Value*> convertedParams;
- convertedParams.push_back( convertValueTo( currentBlock, value, llvm::Type::FloatTy ) );
+ convertedParams.push_back( convertValueTo( currentBlock, value, _valueType, GTLCore::Type::Float ) );
return new llvm::CallInst( func, convertedParams.begin(), convertedParams.end(), "", currentBlock );
}
@@ -205,48 +275,48 @@
llvm::Function* func = dynamic_cast<llvm::Function*>( d->module->getOrInsertFunction( "_Z10half2floatt",
llvm::FunctionType::get( llvm::Type::FloatTy , llvmArguments, false ) ) );
std::vector<llvm::Value*> convertedParams;
- convertedParams.push_back( convertValueTo( currentBlock, value, llvm::Type::Int16Ty ) );
+ convertedParams.push_back( convertValueTo( currentBlock, value, GTLCore::Type::Half, GTLCore::Type::Integer16 ) );
return new llvm::CallInst( func, convertedParams.begin(), convertedParams.end(), "", currentBlock );
}
-void CodeGenerator::createIfStatement( llvm::BasicBlock* before, llvm::Value* test, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
+void CodeGenerator::createIfStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
{
if( not lastAction->getTerminator() )
{
new llvm::BranchInst( after, lastAction );
}
- new llvm::BranchInst( firstAction, after, convertValueTo( before, test, GTLCore::Type::Boolean ), before);
+ new llvm::BranchInst( firstAction, after, convertValueTo( before, test, testType, GTLCore::Type::Boolean ), before);
}
-void CodeGenerator::createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after)
+void CodeGenerator::createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after)
{
if( not lastAction->getTerminator() )
{
new llvm::BranchInst( after, lastAction );
}
- new llvm::BranchInst( firstAction, firstElseAction, convertValueTo( before, test, GTLCore::Type::Boolean ), before);
+ new llvm::BranchInst( firstAction, firstElseAction, convertValueTo( before, test, testType, GTLCore::Type::Boolean ), before);
if( not lastElseAction->getTerminator() )
{
new llvm::BranchInst( after, lastElseAction );
}
}
-void CodeGenerator::createForStatement(llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, llvm::BasicBlock* update, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
+void CodeGenerator::createForStatement(llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, const Type* testType, llvm::BasicBlock* update, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
{
new llvm::BranchInst( test, before );
- new llvm::BranchInst( firstAction, after, convertValueTo( before, testResult, GTLCore::Type::Boolean ), test );
+ new llvm::BranchInst( firstAction, after, convertValueTo( before, testResult, testType, GTLCore::Type::Boolean ), test );
new llvm::BranchInst( update, lastAction);
new llvm::BranchInst( test, update);
}
-llvm::BasicBlock* CodeGenerator::createIterationForStatement( llvm::Function* function, llvm::BasicBlock* before, GTLCore::VariableNG* variable, llvm::Value* maxValue, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction)
+llvm::BasicBlock* CodeGenerator::createIterationForStatement( llvm::Function* function, llvm::BasicBlock* before, GTLCore::VariableNG* variable, llvm::Value* maxValue, const Type* maxValueType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction)
{
// i < size
llvm::BasicBlock* forTestBlock = new llvm::BasicBlock("forTestBlock");
function->getBasicBlockList().push_back( forTestBlock);
- GenerationContext generationContext( this, function, d->module );
- llvm::Value* forTest = createStrictInferiorExpression(forTestBlock, variable->get( generationContext, forTestBlock ), maxValue);
+ GenerationContext generationContext( this, function, 0, d->module );
+ llvm::Value* forTest = createStrictInferiorExpression(forTestBlock, variable->get( generationContext, forTestBlock ), variable->type(), maxValue, maxValueType);
// i += pixelSize
llvm::BasicBlock* updateBlock = new llvm::BasicBlock("updateBlock");
function->getBasicBlockList().push_back( updateBlock);
@@ -255,14 +325,14 @@
llvm::BasicBlock* finBlock = new llvm::BasicBlock("finBlock");
function->getBasicBlockList().push_back( finBlock);
// Create for statement
- createForStatement(before, forTestBlock, forTest, updateBlock, firstAction, lastAction, finBlock);
+ createForStatement(before, forTestBlock, forTest, Type::Boolean, updateBlock, firstAction, lastAction, finBlock);
return finBlock;
}
-void CodeGenerator::createWhileStatement( llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
+void CodeGenerator::createWhileStatement( llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after)
{
new llvm::BranchInst( test, before);
- new llvm::BranchInst( firstAction, after, convertValueTo( before, testResult, GTLCore::Type::Boolean ), test);
+ new llvm::BranchInst( firstAction, after, convertValueTo( before, testResult, testType, GTLCore::Type::Boolean ), test);
new llvm::BranchInst( after, lastAction );
}
@@ -276,36 +346,36 @@
void CodeGenerator::createIncrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var)
{
- GenerationContext gc(this, 0, 0);
- var->set( gc, currentBlock, createAdditionExpression( currentBlock, var->get(gc, currentBlock), integerToConstant(1)));
+ GenerationContext gc(this, 0, 0, 0);
+ var->set( gc, currentBlock, createAdditionExpression( currentBlock, var->get(gc, currentBlock), var->type(), integerToConstant(1), Type::Integer32), var->type());
}
void CodeGenerator::createDecrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var)
{
- GenerationContext gc(this, 0, 0);
- var->set(gc, currentBlock, createSubstractionExpression( currentBlock, var->get(gc, currentBlock), integerToConstant(1)));
+ GenerationContext gc(this, 0, 0, 0);
+ var->set(gc, currentBlock, createSubstractionExpression( currentBlock, var->get(gc, currentBlock), var->type(), integerToConstant(1), Type::Integer32), var->type());
}
#define CREATE_BINARY_OPERATOR( _creator_, _v1_, _v2_) \
if( _v1_.isConstant() and _v2_.isConstant() ) \
{ \
- return GTLCore::ExpressionResult( _creator_(_v1_.constant(), _v2_.constant())); \
+ return GTLCore::ExpressionResult( _creator_(_v1_.constant(), lhsType, _v2_.constant(), rhsType )); \
} else { \
- return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), _v2_.value() ) ); \
+ return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), lhsType, _v2_.value(), rhsType )); \
}
#define CREATE_BINARY_EXPRESSION(_GTL_Function_Name_, _LLVM_Constant_Expr_, _LLVM_Binary_Operator ) \
- llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs) \
+ llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType) \
{ \
UNIFORMIZE_VALUE_TYPES( lhs, rhs ) \
return llvm::BinaryOperator::_LLVM_Binary_Operator( v1, v2, "", currentBlock ); \
} \
- llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, llvm::Constant* rhs) \
+ llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType) \
{ \
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs ) \
return llvm::ConstantExpr::_LLVM_Constant_Expr_( v1, v2 ); \
} \
- ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs) \
+ ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
{ \
UNIFORMIZE_TYPES(lhs, rhs); \
CREATE_BINARY_OPERATOR( _GTL_Function_Name_, v1, v2); \
@@ -318,7 +388,7 @@
CREATE_BINARY_EXPRESSION(createLeftShiftExpression, getShl, createShl);
-llvm::Value* CodeGenerator::createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs)
+llvm::Value* CodeGenerator::createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType)
{
UNIFORMIZE_VALUE_TYPES( lhs, rhs );
if( v1->getType()->isFloatingPoint() )
@@ -329,7 +399,7 @@
}
}
-llvm::Constant* CodeGenerator::createDivisionExpression( llvm::Constant* lhs, llvm::Constant* rhs)
+llvm::Constant* CodeGenerator::createDivisionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType)
{
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs );
if( v1->getType()->isFloatingPoint() )
@@ -340,25 +410,25 @@
}
}
-ExpressionResult CodeGenerator::createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs)
+ExpressionResult CodeGenerator::createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType)
{
UNIFORMIZE_TYPES(lhs, rhs);
CREATE_BINARY_OPERATOR( createDivisionExpression, v1, v2);
}
-llvm::Value* CodeGenerator::createModuloExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs)
+llvm::Value* CodeGenerator::createModuloExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType)
{
UNIFORMIZE_VALUE_TYPES( lhs, rhs );
return llvm::BinaryOperator::createSRem( v1, v2 );
}
-llvm::Constant* CodeGenerator::createModuloExpression( llvm::Constant* lhs, llvm::Constant* rhs)
+llvm::Constant* CodeGenerator::createModuloExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType)
{
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs );
return llvm::ConstantExpr::getSRem( v1, v2);
}
-ExpressionResult CodeGenerator::createModuloExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs)
+ExpressionResult CodeGenerator::createModuloExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType)
{
UNIFORMIZE_TYPES(lhs, rhs);
CREATE_BINARY_OPERATOR( createModuloExpression, v1, v2);
@@ -366,17 +436,17 @@
#define CREATE_BINARY_BOOLEAN_EXPRESSION(_GTL_Function_Name_, _LLVM_Constant_Expr_, _LLVM_Binary_Operator ) \
- llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs) \
+ llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType) \
{ \
MAKE_BOOLEAN_VALUE( lhs, rhs ) \
return llvm::BinaryOperator::_LLVM_Binary_Operator( v1, v2, "", currentBlock ); \
} \
- llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, llvm::Constant* rhs) \
+ llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType) \
{ \
MAKE_BOOLEAN_CONSTANT( lhs, rhs ) \
return llvm::ConstantExpr::_LLVM_Constant_Expr_( v1, v2 ); \
} \
- ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs) \
+ ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
{ \
UNIFORMIZE_TYPES(lhs, rhs); \
CREATE_BINARY_OPERATOR( _GTL_Function_Name_, v1, v2); \
@@ -386,21 +456,21 @@
CREATE_BINARY_EXPRESSION(createAndExpression, getAnd, createAnd)
#define CREATE_BINARY_INTEGER_EXPRESSION(_GTL_Function_Name_, _LLVM_Constant_Expr_, _LLVM_Binary_Operator ) \
- llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs) \
+ llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType) \
{ \
UNIFORMIZE_VALUE_TYPES( lhs, rhs ) \
GTL_ASSERT( v1->getType()->isInteger() ); \
GTL_ASSERT( v2->getType()->isInteger() ); \
return llvm::BinaryOperator::_LLVM_Binary_Operator( v1, v2, "", currentBlock ); \
} \
- llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, llvm::Constant* rhs) \
+ llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType) \
{ \
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs ) \
GTL_ASSERT( v1->getType()->isInteger() ); \
GTL_ASSERT( v2->getType()->isInteger() ); \
return llvm::ConstantExpr::_LLVM_Constant_Expr_( v1, v2 ); \
} \
- ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs) \
+ ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
{ \
UNIFORMIZE_TYPES(lhs, rhs); \
CREATE_BINARY_OPERATOR( _GTL_Function_Name_, v1, v2); \
@@ -412,17 +482,17 @@
#define CREATE_COMPARISON_EXPRESSION(_GTL_Function_Name_, _LLVM_Int_Expr_, _LLVM_Float_Expr_ ) \
- llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs) \
+ llvm::Value* CodeGenerator::_GTL_Function_Name_(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType) \
{ \
- return createComparisonExpression( currentBlock, lhs, rhs, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+ return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
} \
- llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, llvm::Constant* rhs) \
+ llvm::Constant* CodeGenerator::_GTL_Function_Name_( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType) \
{ \
- return createComparisonExpression( lhs, rhs, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+ return createComparisonExpression( lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
} \
- ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs) \
+ ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
{ \
- return createComparisonExpression( currentBlock, lhs, rhs, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
+ return createComparisonExpression( currentBlock, lhs, lhsType, rhs, rhsType, llvm::ICmpInst::_LLVM_Int_Expr_, llvm::FCmpInst::_LLVM_Float_Expr_); \
}
CREATE_COMPARISON_EXPRESSION(createEqualExpression, ICMP_EQ, FCMP_OEQ);
@@ -432,7 +502,7 @@
CREATE_COMPARISON_EXPRESSION(createStrictSupperiorExpression, ICMP_UGT, FCMP_OGT);
CREATE_COMPARISON_EXPRESSION(createSupperiorOrEqualExpression, ICMP_UGE, FCMP_OGE);
-llvm::Value* CodeGenerator::createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs, unsigned int integerPred, unsigned int floatPred)
+llvm::Value* CodeGenerator::createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
{
UNIFORMIZE_VALUE_TYPES( lhs, rhs );
if( v1->getType()->isFloatingPoint() )
@@ -445,86 +515,93 @@
}
}
-llvm::Constant* CodeGenerator::createComparisonExpression( llvm::Constant* lhs, llvm::Constant* rhs, unsigned int integerPred, unsigned int floatPred)
+llvm::Constant* CodeGenerator::createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
{
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs );
unsigned op = v1->getType()->isFloatingPoint() ? floatPred : integerPred;
return (llvm::Constant*)llvm::ConstantExpr::getCompare( op, v1, v2);
}
-ExpressionResult CodeGenerator::createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs, unsigned int integerPred, unsigned int floatPred)
+ExpressionResult CodeGenerator::createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred)
{
UNIFORMIZE_TYPES(lhs, rhs);
if( v1.isConstant() and v2.isConstant() )
{
- return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), v2.constant(), integerPred, floatPred));
+ return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), lhsType, v2.constant(), rhsType, integerPred, floatPred));
} else {
- return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), v2.value(), integerPred, floatPred));
+ return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), lhsType, v2.value(), rhsType, integerPred, floatPred));
}
}
#define CREATE_UNARY_OPERATOR( _creator_, _v1_) \
if( _v1_.isConstant() ) \
{ \
- return GTLCore::ExpressionResult( _creator_(_v1_.constant())); \
+ return GTLCore::ExpressionResult( _creator_(_v1_.constant(), rhsType)); \
} else { \
- return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value() ) ); \
+ return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), rhsType ) ); \
}
-ExpressionResult CodeGenerator::createMinusExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs)
+ExpressionResult CodeGenerator::createMinusExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType)
{
CREATE_UNARY_OPERATOR( createMinusExpression, rhs);
}
-llvm::Value* CodeGenerator::createMinusExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs)
+llvm::Value* CodeGenerator::createMinusExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType)
{
return llvm::BinaryOperator::createNeg( rhs, "", currentBlock );
}
-llvm::Constant* CodeGenerator::createMinusExpression( llvm::Constant* rhs)
+llvm::Constant* CodeGenerator::createMinusExpression( llvm::Constant* rhs, const Type* rhsType)
{
return llvm::ConstantExpr::getNeg( rhs);
}
-ExpressionResult CodeGenerator::createNotExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs)
+ExpressionResult CodeGenerator::createNotExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType)
{
CREATE_UNARY_OPERATOR( createNotExpression, rhs);
}
-llvm::Value* CodeGenerator::createNotExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs)
+llvm::Value* CodeGenerator::createNotExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType)
{
return llvm::BinaryOperator::createNot( rhs, "", currentBlock );
}
-llvm::Constant* CodeGenerator::createNotExpression( llvm::Constant* rhs)
+llvm::Constant* CodeGenerator::createNotExpression( llvm::Constant* rhs, const Type* rhsType)
{
return llvm::ConstantExpr::getNot( rhs);
}
-ExpressionResult CodeGenerator::createTildeExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs)
+ExpressionResult CodeGenerator::createTildeExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType)
{
CREATE_UNARY_OPERATOR( createTildeExpression, rhs);
}
-llvm::Value* CodeGenerator::createTildeExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs)
+llvm::Value* CodeGenerator::createTildeExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType)
{
return llvm::BinaryOperator::createXor( rhs, integerToConstant(0xFFFFFFFF ), "", currentBlock );
}
-llvm::Constant* CodeGenerator::createTildeExpression( llvm::Constant* rhs)
+llvm::Constant* CodeGenerator::createTildeExpression( llvm::Constant* rhs, const Type* rhsType)
{
return llvm::ConstantExpr::getXor(rhs, integerToConstant(0xFFFFFFFF ));
}
-const llvm::Type* CodeGenerator::selectType(const llvm::Type* type1, const llvm::Type* type2)
+const Type* CodeGenerator::selectType(const Type* type1, const Type* type2)
{
- // Floating points have a higher priority
- if(type1->isFloatingPoint()) return type1;
- if(type2->isFloatingPoint()) return type2;
- if(type1->isInteger() and type2->isInteger() )
+ if( type1 == Type::Float or type2 == Type::Float )
{
- return type1->getPrimitiveSizeInBits() > type2->getPrimitiveSizeInBits() ? type1 : type2;
+ return Type::Float;
+ } else if( type1 == Type::Integer32 or type2 == Type::Integer32 )
+ {
+ return Type::Integer32;
+ } else if( type1 == Type::UnsignedInteger32 or type2 == Type::UnsignedInteger32 )
+ {
+ return Type::UnsignedInteger32;
+ } else if( type1 == Type::Boolean or type2 == Type::Boolean )
+ {
+ return Type::UnsignedInteger32;
}
+ GTL_DEBUG("Select type failed : "<< *type1 << " " << *type2 );
return 0;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -79,94 +79,95 @@
* @return a pointer to the llvm function
*/
llvm::Function* createFunction( llvm::FunctionType* type, const GTLCore::String& name);
- llvm::Value* convertValueTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const llvm::Type* type);
- llvm::Constant* convertConstantTo(llvm::Constant* constant, const llvm::Type* type);
- llvm::Value* convertValueTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* type);
- llvm::Constant* convertConstantTo(llvm::Constant* constant, const Type* type);
- llvm::Value* convertToHalf( llvm::BasicBlock* currentBlock, llvm::Value* value);
+// llvm::Value* convertValueTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const llvm::Type* type);
+// llvm::Constant* convertConstantTo(llvm::Constant* constant, const llvm::Type* type);
+ llvm::Value* convertPointerTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const llvm::Type* type);
+ llvm::Value* convertValueTo(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* valueType, const Type* type);
+ llvm::Constant* convertConstantTo(llvm::Constant* constant, const Type* constantType, const Type* type);
+ llvm::Value* convertToHalf( llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* _valueType);
llvm::Value* convertFromHalf( llvm::BasicBlock* currentBlock, llvm::Value* value);
public: // Boolean Expression
- llvm::Value* createOrExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createOrExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- llvm::Value* createAndExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createAndExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createOrExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createOrExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ llvm::Value* createAndExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createAndExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Bit expressions
- llvm::Value* createBitXorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createBitXorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createBitXorExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- llvm::Value* createBitOrExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createBitOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createBitOrExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- llvm::Value* createBitAndExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createBitAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createBitAndExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createBitXorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createBitXorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createBitXorExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ llvm::Value* createBitOrExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createBitOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createBitOrExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ llvm::Value* createBitAndExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createBitAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createBitAndExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Arithmetic expressions
// Addition
- llvm::Value* createAdditionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createAdditionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createAdditionExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createAdditionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createAdditionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createAdditionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Substraction
- llvm::Value* createSubstractionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createSubstractionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createSubstractionExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createSubstractionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createSubstractionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createSubstractionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Multiplication
- llvm::Value* createMultiplicationExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createMultiplicationExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createMultiplicationExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createMultiplicationExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createMultiplicationExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createMultiplicationExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Division
- llvm::Value* createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- llvm::Constant* createDivisionExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- ExpressionResult createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
+ llvm::Value* createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ llvm::Constant* createDivisionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ ExpressionResult createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
// Modulo
- llvm::Value* createModuloExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- llvm::Constant* createModuloExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- ExpressionResult createModuloExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
+ llvm::Value* createModuloExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ llvm::Constant* createModuloExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ ExpressionResult createModuloExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
public: // Shift expressions
- llvm::Value* createRightShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createRightShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createRightShiftExpression( llvm::Constant* lhs, llvm::Constant* rhs);
- llvm::Value* createLeftShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createLeftShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createLeftShiftExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createRightShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createRightShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createRightShiftExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ llvm::Value* createLeftShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createLeftShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createLeftShiftExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Comparison Expressions
- llvm::Value* createEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createEqualExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createEqualExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
//
- llvm::Value* createDifferentExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createDifferentExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createDifferentExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createDifferentExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createDifferentExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createDifferentExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
//
- llvm::Value* createStrictInferiorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createStrictInferiorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createStrictInferiorExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createStrictInferiorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createStrictInferiorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createStrictInferiorExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// createInferiorExpression
- llvm::Value* createInferiorOrEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createInferiorOrEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createInferiorOrEqualExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createInferiorOrEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createInferiorOrEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createInferiorOrEqualExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
//
- llvm::Value* createStrictSupperiorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createStrictSupperiorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createStrictSupperiorExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createStrictSupperiorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createStrictSupperiorExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createStrictSupperiorExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
//
- llvm::Value* createSupperiorOrEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs);
- ExpressionResult createSupperiorOrEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
- llvm::Constant* createSupperiorOrEqualExpression( llvm::Constant* lhs, llvm::Constant* rhs);
+ llvm::Value* createSupperiorOrEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ ExpressionResult createSupperiorOrEqualExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ llvm::Constant* createSupperiorOrEqualExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Unary expression
// Minus
- ExpressionResult createMinusExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs);
- llvm::Value* createMinusExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs);
- llvm::Constant* createMinusExpression( llvm::Constant* rhs);
+ ExpressionResult createMinusExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType);
+ llvm::Value* createMinusExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType);
+ llvm::Constant* createMinusExpression( llvm::Constant* rhs, const Type* rhsType);
// Not
- ExpressionResult createNotExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs);
- llvm::Value* createNotExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs);
- llvm::Constant* createNotExpression( llvm::Constant* rhs);
+ ExpressionResult createNotExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType);
+ llvm::Value* createNotExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType);
+ llvm::Constant* createNotExpression( llvm::Constant* rhs, const Type* rhsType);
// Tilde
- ExpressionResult createTildeExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs);
- llvm::Value* createTildeExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs);
- llvm::Constant* createTildeExpression( llvm::Constant* rhs);
+ ExpressionResult createTildeExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType);
+ llvm::Value* createTildeExpression(llvm::BasicBlock* currentBlock, llvm::Value* rhs, const Type* rhsType);
+ llvm::Constant* createTildeExpression( llvm::Constant* rhs, const Type* rhsType);
// Increment
void createIncrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var);
void createDecrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var);
@@ -180,8 +181,8 @@
* @param lastAction the block with the last action in case if is true
* @param after the basic block after the if statement
*/
- void createIfStatement( llvm::BasicBlock* before, llvm::Value* test, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
- void createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after);
+ void createIfStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
+ void createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after);
/**
* Create a for statement.
* @param before the basic block before the for statement
@@ -192,7 +193,7 @@
* @param lastAction the block with the last action of the loop
* @param after the basic block after the for statement
*/
- void createForStatement(llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, llvm::BasicBlock* update, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
+ void createForStatement(llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, const Type* testType, llvm::BasicBlock* update, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
/**
* Create an iteration for statement.
@@ -212,13 +213,13 @@
* @param lastAction the block with the last action of the loop
* @return the exit block of the loop
*/
- llvm::BasicBlock* createIterationForStatement( llvm::Function* function, llvm::BasicBlock* before, GTLCore::VariableNG* variable, llvm::Value* maxValue, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction);
+ llvm::BasicBlock* createIterationForStatement( llvm::Function* function, llvm::BasicBlock* before, GTLCore::VariableNG* variable, llvm::Value* maxValue, const Type* maxValueType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction);
- void createWhileStatement( llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
+ void createWhileStatement( llvm::BasicBlock* before, llvm::BasicBlock* test, llvm::Value* testResult, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
/**
* Select the type that has the higher priority
*/
- const llvm::Type* selectType(const llvm::Type* type1, const llvm::Type* type2);
+ const Type* selectType(const Type* type1, const Type* type2);
public:
/**
* @param _currentBlock the current basic block
@@ -228,9 +229,9 @@
*/
llvm::Value* accessArrayValue( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _index );
private:
- llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, llvm::Value* rhs, unsigned int integerPred, unsigned int floatPred);
- ExpressionResult createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs, unsigned int integerPred, unsigned int floatPred);
- llvm::Constant* createComparisonExpression( llvm::Constant* lhs, llvm::Constant* rhs, unsigned int integerPred, unsigned int floatPred);
+ llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
+ ExpressionResult createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
+ llvm::Constant* createComparisonExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
private:
struct Private;
Private* const d;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -50,6 +50,8 @@
return ostr << "INTEGER32";
case Type::UNSIGNED_INTEGER32:
return ostr << "UNSIGNED_INTEGER32";
+ case Type::DOUBLE:
+ return ostr << "DOUBLE";
case Type::FLOAT:
return ostr << "FLOAT";
case Type::HALF:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -44,6 +44,7 @@
ExpressionResult::ExpressionResult(llvm::Value* value, const GTLCore::ScopedName& _name) : d(new Private)
{
+ GTL_ASSERT( value );
d->name = _name;
d->valueOrConstant.value = value;
d->isConstant = false;
@@ -51,6 +52,7 @@
ExpressionResult::ExpressionResult(llvm::Constant* constant, const GTLCore::ScopedName& _name) : d(new Private)
{
+ GTL_ASSERT( constant );
d->name = _name;
d->valueOrConstant.constant = constant;
d->isConstant = true;
@@ -58,12 +60,14 @@
ExpressionResult::ExpressionResult(llvm::Value* value) : d(new Private)
{
+ GTL_ASSERT( value );
d->valueOrConstant.value = value;
d->isConstant = false;
}
ExpressionResult::ExpressionResult(llvm::Constant* constant) : d(new Private)
{
+ GTL_ASSERT( constant );
d->valueOrConstant.constant = constant;
d->isConstant = true;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -22,8 +22,8 @@
using namespace GTLCore;
GenerationContext::GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
- llvm::Function* _function, llvm::Module* _module )
- : m_codeGenerator(_codeGenerator), m_function(_function), m_module( _module)
+ llvm::Function* _llvmFunction, Function* _function, llvm::Module* _module )
+ : m_codeGenerator(_codeGenerator), m_llvmFunction(_llvmFunction), m_function(_function), m_module( _module)
{
}
@@ -32,8 +32,13 @@
return m_codeGenerator;
}
-llvm::Function* GenerationContext::function()
+llvm::Function* GenerationContext::llvmFunction()
{
+ return m_llvmFunction;
+}
+
+Function* GenerationContext::function()
+{
return m_function;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -27,16 +27,19 @@
namespace GTLCore {
class CodeGenerator;
+ class Function;
class GenerationContext {
public:
- GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
- llvm::Function* _function, llvm::Module* _module );
- GTLCore::CodeGenerator* codeGenerator();
- llvm::Function* function();
+ GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
+ llvm::Function* _llvmFunction, Function* _function, llvm::Module* _module );
+ CodeGenerator* codeGenerator();
+ llvm::Function* llvmFunction();
+ Function* function();
llvm::Module* module();
private:
GTLCore::CodeGenerator* m_codeGenerator;
- llvm::Function* m_function;
+ llvm::Function* m_llvmFunction;
+ Function* m_function;
llvm::Module* m_module;
};
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -492,7 +492,7 @@
if( initialiser)
{
GTLCore::CodeGenerator cg( 0 );
- GTLCore::GenerationContext gc( &cg, 0, 0);
+ GTLCore::GenerationContext gc( &cg, 0, 0, 0);
llvm::Constant* constant = initialiser->generateValue( gc, 0 ).constant();
if( constant )
{
@@ -1133,7 +1133,7 @@
{
std::list<int> integersList;
GTLCore::CodeGenerator cg( 0 );
- GTLCore::GenerationContext gc( &cg, 0, 0);
+ GTLCore::GenerationContext gc( &cg, 0, 0, 0);
for( std::list< AST::Expression* >::const_iterator it = list.begin();
it != list.end(); ++it)
{
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -103,6 +103,7 @@
const Type* Type::UnsignedInteger16 = new Type(Type::UNSIGNED_INTEGER16);
const Type* Type::Integer32 = new Type(Type::INTEGER32);
const Type* Type::UnsignedInteger32 = new Type(Type::UNSIGNED_INTEGER32);
+const Type* Type::Double = new Type(Type::DOUBLE);
const Type* Type::Float = new Type(Type::FLOAT);
const Type* Type::Half = new Type(Type::HALF);
const Type* Type::Void = new Type(Type::VOID);
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -42,6 +42,7 @@
UNSIGNED_INTEGER16,
INTEGER32,
UNSIGNED_INTEGER32,
+ DOUBLE,
FLOAT,
HALF,
VOID,
@@ -93,6 +94,7 @@
static const Type* UnsignedInteger16;
static const Type* Integer32;
static const Type* UnsignedInteger32;
+ static const Type* Double;
static const Type* Float;
static const Type* Half;
static const Type* Void;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -104,6 +104,9 @@
case Type::HALF: // HALF are stored in unsigned int16
m_type = llvm::Type::Int16Ty;
break;
+ case Type::DOUBLE:
+ m_type = llvm::Type::DoubleTy;
+ break;
case Type::FLOAT:
m_type = llvm::Type::FloatTy;
break;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-05-02 16:58:35 UTC (rev 161)
@@ -62,12 +62,12 @@
return d->type;
}
-llvm::BasicBlock* VariableNG::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const std::list<llvm::Value*>& _initialSize )
+llvm::BasicBlock* VariableNG::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const GTLCore::Type* _initialiserType, const std::list<llvm::Value*>& _initialSize )
{
GTL_DEBUG( _initialSize.size() );
initialise( _generationContext, new llvm::AllocaInst::AllocaInst( d->type->data()->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb) );
_bb = d->accessor->initialise( _generationContext, _bb, d->pointer, _initialSize);
- _bb = d->accessor->initialiseValue( _generationContext, _bb, d->pointer, _initialiser);
+ _bb = d->accessor->initialiseValue( _generationContext, _bb, d->pointer, _initialiser, _initialiserType);
return _bb;
}
@@ -85,10 +85,10 @@
return v;
}
-llvm::BasicBlock* VariableNG::set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _value, MemberArray* _ma )
+llvm::BasicBlock* VariableNG::set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
{
GTL_ASSERT(not constant() );
- return d->accessor->set( _generationContext, _currentBlock, d->pointer, _value, _ma );
+ return d->accessor->set( _generationContext, _currentBlock, d->pointer, _value, _valueType, _ma );
}
void VariableNG::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _size)
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-05-01 12:37:48 UTC (rev 160)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-05-02 16:58:35 UTC (rev 161)
@@ -48,7 +48,7 @@
* @param _initialiser initial value of the variable
* @param _initialSize the initial size of the variable
*/
- llvm::BasicBlock* initialise( GenerationContext&, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const std::list<llvm::Value*>& _initialSize );
+ llvm::BasicBlock* initialise( GenerationContext&, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const GTLCore::Type* _initialiserType, const std::list<llvm::Value*>& _initialSize );
/**
* Initialise a Variable with a given pointer. This function will not call \ref Accessor::initialise
* @param _pointer a pointer that will be used by this variable
@@ -73,7 +73,7 @@
* @param _ma a pointer to a structure describing the member or index accessed
* @return the new basic block
*/
- llvm::BasicBlock* set(GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _value, MemberArray* _ma = 0);
+ llvm::BasicBlock* set(GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
/**
* Set the size of an array, raise an assert otherwise.
*/