[opengtl-commits] [712] refactor expression generation to allow changing the basic block |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 712
Author: cyrille
Date: 2009-04-08 23:50:38 +0200 (Wed, 08 Apr 2009)
Log Message:
-----------
refactor expression generation to allow changing the basic block
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
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/CodeGenerator_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.h
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -36,27 +36,28 @@
#include "../wrappers/StructWrap.h"
#include "GarbageCollectionStatement.h"
+#include "../ExpressionGenerationContext_p.h"
using namespace GTLCore::AST;
//------------------- AccessorExpression -------------------//
-GTLCore::ExpressionResult AccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
+GTLCore::ExpressionResult AccessorExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- llvm::Value* ptr_ = pointer( _gc, _bb );
+ llvm::Value* ptr_ = pointer( _gc, _egc );
GTL_ASSERT(ptr_);
const Visitor* visitor = Visitor::getVisitorFor( type() );
GTL_DEBUG("Type = " << *type() << " ptr = " << *ptr_);
- GTLCore::ExpressionResult result = visitor->get( _gc, _bb, ptr_, type() );
+ GTLCore::ExpressionResult result = visitor->get( _gc, _egc.currentBasicBlock(), ptr_, type() );
GTL_DEBUG("Result = " << result );
return result;
}
-llvm::BasicBlock* AccessorExpression::affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value )
+llvm::BasicBlock* AccessorExpression::affect( GenerationContext& _gc, ExpressionGenerationContext& _egc, const ExpressionResult& _value )
{
- llvm::Value* ptr_ = pointer( _gc, _bb );
+ llvm::Value* ptr_ = pointer( _gc, _egc );
const Visitor* visitor = Visitor::getVisitorFor( type() );
- return visitor->set( _gc, _bb, ptr_, type(), _value.value(), _value.type(), allocatedInMemory());
+ return visitor->set( _gc, _egc.currentBasicBlock(), ptr_, type(), _value.value(), _value.type(), allocatedInMemory());
}
//------------------- ArraySizeAccessorExpression -------------------//
@@ -76,10 +77,10 @@
}
-llvm::Value* ArraySizeAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
+llvm::Value* ArraySizeAccessorExpression::pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
GTL_DEBUG("ArraySizeAccessorExpression::pointer");
- llvm::Value* val = GTLCore::CodeGenerator::accessArraySizePointer(_bb, m_parent->pointer( _gc, _bb));
+ llvm::Value* val = GTLCore::CodeGenerator::accessArraySizePointer(_egc.currentBasicBlock(), m_parent->pointer( _gc, _egc));
GTL_DEBUG( *val );
return val;
}
@@ -102,13 +103,13 @@
delete m_parent;
}
-llvm::Value* StructAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
+llvm::Value* StructAccessorExpression::pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
GTL_DEBUG("StructAccessorExpression::pointer");
std::vector<llvm::Value*> indexes;
indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
indexes.push_back( _gc.codeGenerator()->integerToConstant(m_index + STRUCT_FIRST_ELEMENT));
- llvm::Value* val = llvm::GetElementPtrInst::Create( m_parent->pointer( _gc, _bb) , indexes.begin(), indexes.end(), "", _bb);
+ llvm::Value* val = llvm::GetElementPtrInst::Create( m_parent->pointer( _gc, _egc) , indexes.begin(), indexes.end(), "", _egc.currentBasicBlock());
GTL_DEBUG( val );
return val;
}
@@ -140,14 +141,14 @@
delete m_index;
}
-llvm::Value* ArrayAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
+llvm::Value* ArrayAccessorExpression::pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
GTL_DEBUG("ArrayAccessorExpression::pointer");
- llvm::Value* ptr_ = m_parent->pointer( _gc, _bb);
+ llvm::Value* ptr_ = m_parent->pointer( _gc, _egc);
GTL_ASSERT(ptr_);
const Visitor* visitor = Visitor::getVisitorFor( m_parent->type() );
- llvm::Value* index = m_index->generateValue(_gc, _bb).value();
- llvm::Value* val = visitor->pointerToIndex(_gc, _bb, ptr_, m_parent->type(), index );
+ llvm::Value* index = m_index->generateValue(_gc, _egc).value();
+ llvm::Value* val = visitor->pointerToIndex(_gc, _egc.currentBasicBlock(), ptr_, m_parent->type(), index );
GTL_DEBUG( *val );
return val;
}
@@ -176,10 +177,10 @@
{
}
-llvm::Value* VariableAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
+llvm::Value* VariableAccessorExpression::pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
GTL_DEBUG("VariableAccessorExpression::pointer");
- llvm::Value* val = m_variable->pointer(bb);
+ llvm::Value* val = m_variable->pointer(_egc.currentBasicBlock());
GTL_DEBUG(*val);
return val;
}
@@ -204,13 +205,13 @@
return m_variable->allocatedInMemory();
}
-llvm::BasicBlock* VariableAccessorExpression::affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value )
+llvm::BasicBlock* VariableAccessorExpression::affect( GenerationContext& _gc, ExpressionGenerationContext& _egc, const ExpressionResult& _value )
{
if( _value.functionResult() and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) and not m_variable->constantPointer() )
{
- return m_variable->replacePointer( _gc, _bb, _value.value() );
+ return m_variable->replacePointer( _gc, _egc.currentBasicBlock(), _value.value() );
} else {
- return AccessorExpression::affect( _gc, _bb, _value );
+ return AccessorExpression::affect( _gc, _egc, _value );
}
}
@@ -240,17 +241,17 @@
return m_member->returnType();
}
-GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
GTL_DEBUG("Call member funcion: " << m_member->function()->name());
- GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
+ GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, _egc, m_member->function(), m_arguments );
_gc.appendDelayedStatement( new PointerGarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
return returnValue;
}
-llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
+llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
GTL_ABORT("No pointer for function member accessor.");
return 0;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -33,11 +33,11 @@
*/
class AccessorExpression : public Expression {
public:
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
public:
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const = 0;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const = 0;
virtual bool allocatedInMemory() const = 0;
- virtual llvm::BasicBlock* affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value );
+ virtual llvm::BasicBlock* affect( GenerationContext& _gc, ExpressionGenerationContext& _egc, const ExpressionResult& _value );
};
/**
* @internal
@@ -49,7 +49,7 @@
ArraySizeAccessorExpression(AccessorExpression* _parent );
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
private:
@@ -67,7 +67,7 @@
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
public:
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
private:
@@ -86,7 +86,7 @@
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
public:
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
private:
@@ -104,10 +104,10 @@
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
public:
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const;
- virtual llvm::BasicBlock* affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value );
+ virtual llvm::BasicBlock* affect( GenerationContext& _gc, ExpressionGenerationContext& _egc, const ExpressionResult& _value );
private:
GTLCore::VariableNG* m_variable;
};
@@ -125,8 +125,8 @@
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
public:
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
- virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
+ virtual llvm::Value* pointer(GenerationContext& _gc, ExpressionGenerationContext& _egc) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const;
private:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -31,6 +31,7 @@
#include "AccessorExpression.h"
#include "Expression.h"
+#include "../ExpressionGenerationContext_p.h"
using namespace GTLCore::AST;
@@ -61,9 +62,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult OrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult OrBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createOrExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createOrExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
const GTLCore::Type* AndBinaryExpression::type() const
@@ -71,24 +72,24 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult AndBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult AndBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createAndExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb));
+ return _gc.codeGenerator()->createAndExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc));
}
-GTLCore::ExpressionResult BitOrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult BitOrBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createBitOrExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createBitOrExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
-GTLCore::ExpressionResult BitXorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult BitXorBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createBitXorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createBitXorExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
-GTLCore::ExpressionResult BitAndBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult BitAndBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createBitAndExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createBitAndExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* EqualEqualBinaryExpression::type() const
@@ -96,9 +97,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult EqualEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult EqualEqualBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createEqualExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* DifferentBinaryExpression::type() const
@@ -106,9 +107,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult DifferentBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult DifferentBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createDifferentExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createDifferentExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* InferiorEqualBinaryExpression::type() const
@@ -116,9 +117,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult InferiorEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult InferiorEqualBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createInferiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createInferiorOrEqualExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* InferiorBinaryExpression::type() const
@@ -126,9 +127,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult InferiorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult InferiorBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createStrictInferiorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createStrictInferiorExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* SupperiorEqualBinaryExpression::type() const
@@ -136,9 +137,9 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult SupperiorEqualBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult SupperiorEqualBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createSupperiorOrEqualExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createSupperiorOrEqualExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
const GTLCore::Type* SupperiorBinaryExpression::type() const
@@ -146,44 +147,44 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult SupperiorBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult SupperiorBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createStrictSupperiorExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createStrictSupperiorExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
-GTLCore::ExpressionResult RightShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult RightShiftBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createRightShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createRightShiftExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
-GTLCore::ExpressionResult LeftShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult LeftShiftBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createLeftShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createLeftShiftExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
-GTLCore::ExpressionResult AdditionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult AdditionBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createAdditionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createAdditionExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
-GTLCore::ExpressionResult SubstractionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult SubstractionBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createSubstractionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb));
+ return _gc.codeGenerator()->createSubstractionExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc));
}
-GTLCore::ExpressionResult MultiplicationBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult MultiplicationBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createMultiplicationExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createMultiplicationExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
-GTLCore::ExpressionResult DivisionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult DivisionBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createDivisionExpression(bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
+ return _gc.codeGenerator()->createDivisionExpression(_egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), rightHandSide()->generateValue( _gc, _egc) );
}
-GTLCore::ExpressionResult ModuloBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult ModuloBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createModuloExpression(bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createModuloExpression( _egc.currentBasicBlock(), leftHandSide()->generateValue( _gc, _egc), leftHandSide()->type(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
AssignementBinaryExpression::AssignementBinaryExpression( AccessorExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(lhs)
@@ -196,16 +197,16 @@
GTL_ASSERT( m_lhs);
GTL_DEBUG( *m_lhs->type() );
GTL_DEBUG( *rightHandSide()->type() );
- ExpressionResult rhsValue = rightHandSide()->generateValue( _gc, _bb);
- return m_lhs->affect( _gc, _bb, rhsValue );
+ ExpressionGenerationContext egc(_bb);
+ ExpressionResult rhsValue = rightHandSide()->generateValue( _gc, egc);
+ return m_lhs->affect( _gc, egc, rhsValue );
}
-GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
+GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
GTL_ASSERT( m_lhs);
- llvm::BasicBlock* bbr = generateStatement( _gc, _bb );
- GTL_ASSERT( bbr == _bb);
- UNUSED( bbr );
- return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, _bb) );
+ llvm::BasicBlock* bbr = generateStatement( _gc, _egc.currentBasicBlock() );
+ _egc.setCurrentBasicBlock( bbr );
+ return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, _egc) );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -60,7 +60,7 @@
OrBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -72,7 +72,7 @@
AndBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -84,7 +84,7 @@
BitOrBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -95,7 +95,7 @@
BitXorBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -106,7 +106,7 @@
BitAndBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -117,7 +117,7 @@
EqualEqualBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -129,7 +129,7 @@
DifferentBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -141,7 +141,7 @@
InferiorEqualBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -153,7 +153,7 @@
InferiorBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -165,7 +165,7 @@
SupperiorEqualBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -177,7 +177,7 @@
SupperiorBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -189,7 +189,7 @@
RightShiftBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -200,7 +200,7 @@
LeftShiftBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -211,7 +211,7 @@
AdditionBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -222,7 +222,7 @@
SubstractionBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -233,7 +233,7 @@
MultiplicationBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -244,7 +244,7 @@
DivisionBinaryExpression ( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -255,7 +255,7 @@
ModuloBinaryExpression( Expression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs )
{
}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -267,7 +267,7 @@
public:
AssignementBinaryExpression( AccessorExpression* lhs, Expression* rhs );
virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
private:
AccessorExpression* m_lhs;
};
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -29,6 +29,7 @@
#include "../Type.h"
#include "../Type_p.h"
#include "../ExpressionResult_p.h"
+#include "../ExpressionGenerationContext_p.h"
using namespace GTLCore::AST;
@@ -56,7 +57,7 @@
return m_constant;
}
-GTLCore::ExpressionResult ConstantCoumpoundExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
+GTLCore::ExpressionResult ConstantCoumpoundExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
GTL_DEBUG( m_type->dataType() << " " << Type::ARRAY << " " << Type::STRUCTURE );
if( m_type->dataType() == Type::ARRAY or m_type->dataType() == Type::VECTOR)
@@ -66,7 +67,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(), (*it)->type(), arrayType ) );
+ members.push_back( _gc.codeGenerator()->convertConstantTo( (*it)->generateValue( _gc, _egc).constant(), (*it)->type(), arrayType ) );
}
if( m_type->dataType() == Type::ARRAY )
{
@@ -102,7 +103,7 @@
members.push_back( CodeGenerator::integerToConstant( 0 ) ); // GC constant
for( uint i = 0; i < m_expressions.size(); ++i)
{
- members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _bb).constant(), m_expressions[i]->type(), m_type->structDataMember(i).type() ) );
+ members.push_back( _gc.codeGenerator()->convertConstantTo( m_expressions[i]->generateValue( _gc, _egc).constant(), m_expressions[i]->type(), m_type->structDataMember(i).type() ) );
}
const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->d->type() );
return GTLCore::ExpressionResult(
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -35,7 +35,7 @@
~ConstantCoumpoundExpression( );
virtual const GTLCore::Type* type() const;
virtual bool isConstant() const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
int size() { return m_expressions.size(); }
void markAsReturnExpression();
Expression* expressionAt(unsigned int _idx );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -21,6 +21,7 @@
#include "../CodeGenerator_p.h"
#include "../ExpressionResult_p.h"
+#include "../ExpressionGenerationContext_p.h"
using namespace GTLCore;
using namespace GTLCore::AST;
@@ -62,14 +63,14 @@
return m_dstType;
}
-GTLCore::ExpressionResult DefaultConvertExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult DefaultConvertExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- GTLCore::ExpressionResult result = value()->generateValue( _gc, bb );
+ GTLCore::ExpressionResult result = value()->generateValue( _gc, _egc );
if( result.isConstant() )
{
return GTLCore::ExpressionResult( CodeGenerator::convertConstantTo( result.constant(), result.type(), m_dstType ), m_dstType);
} else {
- return GTLCore::ExpressionResult( CodeGenerator::convertValueTo( bb, result.value(), result.type(), m_dstType ), m_dstType);
+ return GTLCore::ExpressionResult( CodeGenerator::convertValueTo( _egc.currentBasicBlock(), result.value(), result.type(), m_dstType ), m_dstType);
}
}
@@ -86,13 +87,13 @@
return m_dstType;
}
-GTLCore::ExpressionResult ArrayToVectorConvertExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult ArrayToVectorConvertExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- GTLCore::ExpressionResult result = value()->generateValue( _gc, bb );
+ GTLCore::ExpressionResult result = value()->generateValue( _gc, _egc );
if( result.isConstant() )
{
return GTLCore::ExpressionResult( CodeGenerator::convertConstantArrayToVector( result.constant(), result.type(), m_dstType ), m_dstType);
} else {
- return GTLCore::ExpressionResult( CodeGenerator::convertArrayToVector( bb, result.value(), result.type(), m_dstType ), m_dstType);
+ return GTLCore::ExpressionResult( CodeGenerator::convertArrayToVector( _egc.currentBasicBlock(), result.value(), result.type(), m_dstType ), m_dstType);
}
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -52,7 +52,7 @@
DefaultConvertExpression( AST::Expression* _value, const GTLCore::Type* _dstType );
virtual ~DefaultConvertExpression();
virtual const GTLCore::Type* type() const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext&, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext&, ExpressionGenerationContext& _egc ) const;
private:
const GTLCore::Type* m_dstType;
};
@@ -61,7 +61,7 @@
ArrayToVectorConvertExpression( AST::Expression* _value, const GTLCore::Type* _dstType );
virtual ~ArrayToVectorConvertExpression();
virtual const GTLCore::Type* type() const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext&, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext&, ExpressionGenerationContext& _egc ) const;
private:
const GTLCore::Type* m_dstType;
};
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -29,6 +29,7 @@
#include "../Type.h"
#include "../Type_p.h"
#include "../ExpressionResult_p.h"
+#include "../ExpressionGenerationContext_p.h"
using namespace GTLCore::AST;
@@ -56,9 +57,9 @@
return m_constant;
}
-GTLCore::ExpressionResult CoumpoundExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
+GTLCore::ExpressionResult CoumpoundExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- GTL_ASSERT( _bb );
+ GTL_ASSERT( _egc.currentBasicBlock() );
GTL_DEBUG( *m_type << " " << m_type->dataType() << " " << Type::ARRAY << " " << Type::STRUCTURE << " " << Type::VECTOR );
switch( m_type->dataType() )
@@ -71,9 +72,9 @@
// Affect the same value to each element of the vector
for(std::size_t i = 0; i < m_expressions.size(); ++i)
{
- llvm::Value* val = m_expressions[i]->generateValue( _gc, _bb ).value();
+ llvm::Value* val = m_expressions[i]->generateValue( _gc, _egc ).value();
GTL_DEBUG( i << " " << *val );
- resultLoad = llvm::InsertElementInst::Create( resultLoad, val, i, "", _bb );
+ resultLoad = llvm::InsertElementInst::Create( resultLoad, val, i, "", _egc.currentBasicBlock() );
}
return GTLCore::ExpressionResult( resultLoad, m_type );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -35,7 +35,7 @@
~CoumpoundExpression( );
virtual const GTLCore::Type* type() const;
virtual bool isConstant() const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
int size() { return m_expressions.size(); }
void markAsReturnExpression();
private:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -43,6 +43,8 @@
#include "GarbageCollectionStatement.h"
#include "ConstantCoumpoundExpression.h"
+#include "../ExpressionGenerationContext_p.h"
+
using namespace GTLCore::AST;
//------------------------------------------//
@@ -51,8 +53,9 @@
llvm::BasicBlock* Expression::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb) const
{
- generateValue( _context, _bb);
- return _bb;
+ ExpressionGenerationContext egc(_bb);
+ generateValue( _context, egc);
+ return egc.currentBasicBlock();
}
Expression* Expression::fromValue( const GTLCore::Value& _val)
@@ -83,9 +86,9 @@
//------------- ProxyExpression ------------//
//------------------------------------------//
-GTLCore::ExpressionResult ProxyExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult ProxyExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
- return m_clone->generateValue( _gc, bb);
+ return m_clone->generateValue( _gc, _egc);
}
GlobalDataExpression::GlobalDataExpression( Expression* expression ) : m_expression( expression )
@@ -96,9 +99,9 @@
delete m_expression;
}
-GTLCore::ExpressionResult GlobalDataExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult GlobalDataExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
- GTLCore::ExpressionResult value = m_expression->generateValue( _gc, 0 );
+ GTLCore::ExpressionResult value = m_expression->generateValue( _gc, _egc );
if( type()->dataType() == Type::VECTOR )
{
return value;
@@ -122,9 +125,9 @@
return m_function->returnType();
}
-GTLCore::ExpressionResult FunctionCallExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult FunctionCallExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
- GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
+ GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, _egc, m_function, m_arguments );
_gc.appendDelayedStatement( new PointerGarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
return returnValue;
}
@@ -152,7 +155,7 @@
return GTLCore::Type::Float;
}
template<>
-GTLCore::ExpressionResult NumberExpression<float>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
+GTLCore::ExpressionResult NumberExpression<float>::generateValue( GenerationContext& _gc, ExpressionGenerationContext& ) const
{
return GTLCore::ExpressionResult(_gc.codeGenerator()->floatToConstant( m_val ), type());
}
@@ -163,7 +166,7 @@
return GTLCore::Type::Integer32;
}
template<>
-GTLCore::ExpressionResult NumberExpression<int>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
+GTLCore::ExpressionResult NumberExpression<int>::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
return GTLCore::ExpressionResult(_gc.codeGenerator()->integerToConstant( m_val ), type());
}
@@ -174,14 +177,14 @@
return GTLCore::Type::Boolean;
}
template<>
-GTLCore::ExpressionResult NumberExpression<bool>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
+GTLCore::ExpressionResult NumberExpression<bool>::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
return GTLCore::ExpressionResult(_gc.codeGenerator()-> boolToConstant(m_val ), type());
}
}
}
-GTLCore::ExpressionResult StringExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult StringExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc) const
{
return GTLCore::ExpressionResult(llvm::ConstantArray::get(m_string, true ), Type::Integer8 ); // return a null terminated string
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -25,6 +25,7 @@
namespace GTLCore {
class ExpressionResult;
+ class ExpressionGenerationContext;
class Type;
class Function;
class Value;
@@ -42,7 +43,7 @@
virtual const GTLCore::Type* type() const = 0;
virtual bool isConstant() const = 0;
virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
- virtual GTLCore::ExpressionResult generateValue( GenerationContext&, llvm::BasicBlock* bb ) const = 0;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext&, ExpressionGenerationContext& ) const = 0;
virtual bool isReturnStatement() const { return false; }
/**
* This function is called inside a \ref ReturnStatement to warn the \ref Expression
@@ -80,7 +81,7 @@
{}
virtual const GTLCore::Type* type() const { return m_clone->type(); }
virtual bool isConstant() const { return m_clone->isConstant(); }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& ) const;
virtual void markAsReturnExpression() { m_clone->markAsReturnExpression(); }
private:
Expression* m_clone;
@@ -91,7 +92,7 @@
~GlobalDataExpression();
virtual const GTLCore::Type* type() const { return m_expression->type(); }
virtual bool isConstant() const { return true; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& ) const;
virtual void markAsReturnExpression() { m_expression->markAsReturnExpression(); }
private:
Expression* m_expression;
@@ -108,7 +109,7 @@
virtual const GTLCore::Type* type() const;
virtual bool isConstant() const { return true; }
_T_ value() const { return m_val; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& ) const;
virtual void markAsReturnExpression() { }
private:
_T_ m_val;
@@ -131,7 +132,7 @@
~FunctionCallExpression();
virtual const GTLCore::Type* type() const;
virtual bool isConstant() const { return false; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& ) const;
virtual void markAsReturnExpression();
private:
GTLCore::Function* m_function;
@@ -158,7 +159,7 @@
*/
virtual const GTLCore::Type* type() const { return 0; }
virtual bool isConstant() const { return true; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual void markAsReturnExpression() {}
private:
GTLCore::String m_string;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -33,6 +33,7 @@
#include <GTLCore/Function_p.h>
#include <GTLCore/Utils_p.h>
#include <GTLCore/ModuleData_p.h>
+#include <GTLCore/ExpressionGenerationContext_p.h>
#include "Expression.h"
#include "Statement.h"
@@ -125,7 +126,9 @@
// Create a block for the call to the function with one more parameter
llvm::BasicBlock* BB = llvm::BasicBlock::Create("CallForwarder");
function->getBasicBlockList().push_back( BB );
- llvm::Value* defaultValue = m_parameters[i - 1]->initialiser()->generateValue( generationContext , BB).value();
+ ExpressionGenerationContext egc( BB);
+ llvm::Value* defaultValue = m_parameters[i - 1]->initialiser()->generateValue( generationContext , egc).value();
+ BB = egc.currentBasicBlock();
if( m_parameters[i - 1]->parameter().type()->dataType() != Type::STRUCTURE
and m_parameters[i - 1]->parameter().type()->dataType() != Type::ARRAY )
{
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -35,6 +35,7 @@
#include <GTLCore/Utils_p.h>
#include <GTLCore/VariableNG_p.h>
#include <GTLCore/Visitor_p.h>
+#include <GTLCore/ExpressionGenerationContext_p.h>
// GTLCore
#include <GTLCore/Debug.h>
@@ -103,9 +104,10 @@
llvm::BasicBlock* VariableDeclaration::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
{
ExpressionResult initialiserValue;
+ ExpressionGenerationContext egc(_bb);
if( m_initialiser )
{
- initialiserValue = m_initialiser->generateValue( _context, _bb);
+ initialiserValue = m_initialiser->generateValue( _context, egc);
}
std::list<llvm::Value*> initialSizeValues;
if( not m_initialSizes.empty() )
@@ -115,13 +117,13 @@
{
if( *it )
{
- initialSizeValues.push_back( (*it)->generateValue( _context, _bb).value() );
+ initialSizeValues.push_back( (*it)->generateValue( _context, egc).value() );
} else {
initialSizeValues.push_back( _context.codeGenerator()->integerToConstant( 0 ) );
}
}
}
- _bb = m_variable->initialise( _context, _bb, initialiserValue, initialSizeValues);
+ _bb = m_variable->initialise( _context, egc.currentBasicBlock(), initialiserValue, initialSizeValues);
if(m_functionInitialiser)
{
return m_functionInitialiser->generateStatement( _context, _bb );
@@ -140,11 +142,13 @@
llvm::BasicBlock* IfStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
{
- llvm::Value* test = m_expression->generateValue( _context, _bb ).value();
+ ExpressionGenerationContext egc(_bb);
+ llvm::Value* test = m_expression->generateValue( _context, egc ).value();
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_ifStatement->generateStatement( _context, startAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createIfStatement( _bb, test, m_expression->type(), startAction, endAction, after);
+ _context.codeGenerator()->createIfStatement( egc.currentBasicBlock(), test,
+ m_expression->type(), startAction, endAction, after);
return after;
}
@@ -157,13 +161,14 @@
llvm::BasicBlock* IfElseStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb) const
{
- llvm::Value* test = m_expression->generateValue( _context, _bb ).value();
+ ExpressionGenerationContext egc(_bb);
+ llvm::Value* test = m_expression->generateValue( _context, egc ).value();
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_ifStatement->generateStatement( _context, startAction );
llvm::BasicBlock* startElseAction = createBlock( _context );
llvm::BasicBlock* endElseAction = m_elseStatement->generateStatement( _context, startElseAction );
llvm::BasicBlock* after = createBlock( _context );
- _context.codeGenerator()->createIfElseStatement( _bb, test, m_expression->type(), startAction, endAction, startElseAction, endElseAction, after );
+ _context.codeGenerator()->createIfElseStatement( egc.currentBasicBlock(), test, m_expression->type(), startAction, endAction, startElseAction, endElseAction, after );
return after;
}
@@ -185,7 +190,9 @@
}
// Generate the test block
llvm::BasicBlock* testBlock = createBlock( _context );
- llvm::Value* test = m_testExpression->generateValue( _context, testBlock ).value();
+ ExpressionGenerationContext egc(testBlock);
+ llvm::Value* test = m_testExpression->generateValue( _context, egc ).value();
+ GTL_ASSERT( egc.currentBasicBlock() == testBlock);
// Generate the update block
llvm::BasicBlock* updateBlock = createBlock( _context );
if( m_updateExpression )
@@ -208,7 +215,9 @@
llvm::BasicBlock* WhileStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb) const
{
llvm::BasicBlock* testBlock = createBlock( _context );
- llvm::Value* test = m_expression->generateValue( _context, testBlock ).value();
+ ExpressionGenerationContext egc(testBlock);
+ llvm::Value* test = m_expression->generateValue( _context, egc ).value();
+ GTL_ASSERT( egc.currentBasicBlock() == testBlock);
llvm::BasicBlock* startAction = createBlock( _context );
llvm::BasicBlock* endAction = m_whileStatement->generateStatement( _context, startAction );
llvm::BasicBlock* after = createBlock( _context );
@@ -238,10 +247,11 @@
// FIXME share the cleanup code
if( m_returnExpr )
{
- ExpressionResult result = m_returnExpr->generateValue( _context, _bb);
+ ExpressionGenerationContext egc(_bb);
+ ExpressionResult result = m_returnExpr->generateValue( _context, egc);
const GTLCore::Type* returnType = m_returnExpr->type();
const Visitor* visitor = Visitor::getVisitorFor( returnType );
- _bb = visitor->mark( _context, _bb, result.value(), returnType, CodeGenerator::integerToConstant( 1 ) );
+ _bb = visitor->mark( _context, egc.currentBasicBlock(), result.value(), returnType, CodeGenerator::integerToConstant( 1 ) );
_bb = _context.flushDelayedStatement( _bb );
_bb = m_garbageCollectionStatement->generateStatement( _context, _bb );
llvm::Value* resultValue = result.value();
@@ -268,7 +278,7 @@
deleteAll( m_expressions );
}
-llvm::BasicBlock* PrintStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
+llvm::BasicBlock* PrintStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb1 ) const
{
std::vector<const llvm::Type*> params;
params.push_back( llvm::Type::Int32Ty);
@@ -278,10 +288,11 @@
std::vector<llvm::Value*> values;
values.push_back( _context.codeGenerator()->integerToConstant( m_expressions.size() ));
+ ExpressionGenerationContext egc(_bb1);
for( std::list<AST::Expression*>::const_iterator it = m_expressions.begin();
it != m_expressions.end(); ++it)
{
- GTLCore::ExpressionResult value = (*it)->generateValue( _context, _bb);
+ GTLCore::ExpressionResult value = (*it)->generateValue( _context, egc);
const llvm::Type* type = value.value()->getType();
if( (*it)->type() == 0 )
{ // It's a string
@@ -294,15 +305,15 @@
} else if( type == llvm::Type::FloatTy )
{
values.push_back( _context.codeGenerator()->integerToConstant( 1) );
- values.push_back( _context.codeGenerator()->convertValueTo( _bb, value.value(), (*it)->type(), GTLCore::Type::Double ));
+ values.push_back( _context.codeGenerator()->convertValueTo( egc.currentBasicBlock(), 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(), (*it)->type(), GTLCore::Type::Integer32 ));
+ values.push_back( _context.codeGenerator()->convertValueTo( egc.currentBasicBlock(), value.value(), (*it)->type(), GTLCore::Type::Integer32 ));
} else {
GTL_DEBUG("Unknown type for print " << *type);
}
}
- llvm::CallInst::Create(func, values.begin(), values.end(), "", _bb);
- return _bb;
+ llvm::CallInst::Create(func, values.begin(), values.end(), "", egc.currentBasicBlock());
+ return egc.currentBasicBlock();
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -26,6 +26,7 @@
#include "GTLCore/Debug.h"
#include "GTLCore/CodeGenerator_p.h"
+#include "GTLCore/ExpressionGenerationContext_p.h"
#include "GTLCore/ExpressionResult_p.h"
#include "GTLCore/Type.h"
#include "GTLCore/Type_p.h"
@@ -63,7 +64,8 @@
llvm::Constant* value = 0;
if( m_initialiser )
{
- value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
+ ExpressionGenerationContext egc(0);
+ value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, egc ).constant(), m_initialiser->type() , m_type );
GTL_ASSERT( value );
} else {
value = Visitor::getVisitorFor( m_type )->createStaticVariable( _module->llvmModule(), m_type, m_sizes );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -23,6 +23,7 @@
#include <GTLCore/Type.h>
#include <GTLCore/ExpressionResult_p.h>
#include <GTLCore/Debug.h>
+#include <GTLCore/ExpressionGenerationContext_p.h>
using namespace GTLCore::AST;
@@ -36,23 +37,23 @@
m_rhs->markAsReturnExpression();
}
-GTLCore::ExpressionResult MinusUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult MinusUnaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createMinusExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createMinusExpression( _egc.currentBasicBlock(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
-GTLCore::ExpressionResult MinusMinusUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult MinusMinusUnaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
GTL_ASSERT( m_rhs );
- _gc.codeGenerator()->createDecrementExpression( bb, m_rhs->pointer( _gc, bb) );
- return rightHandSide()->generateValue( _gc, bb);
+ _gc.codeGenerator()->createDecrementExpression( _egc.currentBasicBlock(), m_rhs->pointer( _gc, _egc) );
+ return rightHandSide()->generateValue( _gc, _egc);
}
-GTLCore::ExpressionResult PlusPlusUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult PlusPlusUnaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
GTL_ASSERT( m_rhs );
- _gc.codeGenerator()->createIncrementExpression( bb, m_rhs->pointer( _gc, bb) );
- return rightHandSide()->generateValue( _gc, bb);
+ _gc.codeGenerator()->createIncrementExpression( _egc.currentBasicBlock(), m_rhs->pointer( _gc, _egc) );
+ return rightHandSide()->generateValue( _gc, _egc);
}
const GTLCore::Type* NotUnaryExpression::type() const
@@ -60,12 +61,12 @@
return Type::Boolean;
}
-GTLCore::ExpressionResult NotUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult NotUnaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createNotExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createNotExpression( _egc.currentBasicBlock(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
-GTLCore::ExpressionResult TildeUnaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult TildeUnaryExpression::generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const
{
- return _gc.codeGenerator()->createTildeExpression( bb, rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createTildeExpression( _egc.currentBasicBlock(), rightHandSide()->generateValue( _gc, _egc), rightHandSide()->type() );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -50,7 +50,7 @@
class MinusUnaryExpression : public UnaryExpression {
public:
explicit MinusUnaryExpression(Expression* rhs) : UnaryExpression(rhs) {}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
/**
* @internal
@@ -60,7 +60,7 @@
public:
explicit MinusMinusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
virtual bool isConstant() const { return false; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
private:
AccessorExpression* m_rhs;
};
@@ -72,7 +72,7 @@
public:
explicit PlusPlusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
virtual bool isConstant() const { return false; }
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
private:
AccessorExpression* m_rhs;
};
@@ -83,7 +83,7 @@
class NotUnaryExpression : public UnaryExpression {
public:
explicit NotUnaryExpression(Expression* rhs) : UnaryExpression(rhs) {}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
virtual const GTLCore::Type* type() const;
};
/**
@@ -93,7 +93,7 @@
class TildeUnaryExpression : public UnaryExpression {
public:
explicit TildeUnaryExpression(Expression* rhs) : UnaryExpression(rhs) {}
- virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+ virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, ExpressionGenerationContext& _egc ) const;
};
}
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -37,10 +37,12 @@
#include "VariableNG_p.h"
#include "ModuleData_p.h"
#include "TypesManager_p.h"
+#include "ExpressionGenerationContext_p.h"
#include "AST/AccessorExpression.h"
#include "wrappers/ArrayWrap.h"
#include "MemoryModelConfig_p.h"
+#include "GenerationContext_p.h"
#define UNIFORMIZE_TYPES( _v1_, _v2_) \
GTL_ASSERT( _v1_.value() ); \
@@ -680,7 +682,7 @@
return new llvm::LoadInst( accessArraySizePointer(_currentBlock, _pointer), "", _currentBlock);
}
-GTLCore::ExpressionResult CodeGenerator::callFunction( GenerationContext& _gc, llvm::BasicBlock* bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& _arguments )
+GTLCore::ExpressionResult CodeGenerator::callFunction( GenerationContext& _gc, ExpressionGenerationContext& egc, const GTLCore::Function* _function, const std::list<AST::Expression*>& _arguments )
{
// Function Type
GTL_ASSERT( _function );
@@ -699,7 +701,7 @@
{
AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
GTL_ASSERT( aexp );
- llvm::Value* pointer = aexp->pointer( _gc, bb );
+ llvm::Value* pointer = aexp->pointer( _gc, egc );
GTL_ASSERT( pointer->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
convertedParams.push_back( pointer );
GTL_DEBUG(*pointer->getType() << " " << *oparam_it->type()->d->type() );
@@ -710,15 +712,15 @@
AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
if( aexp and not dynamic_cast<AST::FunctionMemberAccessorExpression*>( aexp ) )
{
- value = aexp->pointer( _gc, bb );
+ value = aexp->pointer( _gc, egc );
} else if( dynamic_cast<AST::FunctionCallExpression*>( *it )
or dynamic_cast<AST::GlobalDataExpression*>( *it ) or dynamic_cast<AST::FunctionMemberAccessorExpression*>( aexp ) ) {
- value = (*it)->generateValue(_gc, bb).value();
+ value = (*it)->generateValue(_gc, egc).value();
} else {
GTL_ABORT("Can't pass an array or a structure");
}
} else {
- value = (*it)->generateValue(_gc, bb).value();
+ value = (*it)->generateValue(_gc, egc).value();
}
GTL_ASSERT( value );
GTL_DEBUG( "param's type = " << *oparam_it->type()->d->type() << " value = " << *value );
@@ -750,7 +752,7 @@
}
#endif
- llvm::CallInst *CallFunc = llvm::CallInst::Create(llvmFunction, convertedParams.begin(), convertedParams.end(), "", bb);
+ llvm::CallInst *CallFunc = llvm::CallInst::Create(llvmFunction, convertedParams.begin(), convertedParams.end(), "", egc.currentBasicBlock());
CallFunc->setTailCall(false);
return GTLCore::ExpressionResult( CallFunc, _function->returnType(), true );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -39,6 +39,7 @@
// TODO: all functions should be static and take a GenerationContext as argument
namespace GTLCore {
+ class ExpressionGenerationContext;
class ExpressionResult;
class ModuleData;
class Type;
@@ -268,7 +269,7 @@
static llvm::Value* accessArraySizePointer( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
static llvm::Value* accessArraySize( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
public:
- GTLCore::ExpressionResult callFunction( GenerationContext& _gc, llvm::BasicBlock* _bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& m_arguments );
+ GTLCore::ExpressionResult callFunction( GenerationContext& _gc, ExpressionGenerationContext& egc, const GTLCore::Function* _function, const std::list<AST::Expression*>& m_arguments );
public:
static llvm::Value* allocateMemory( GenerationContext& _gc, const llvm::Type* _type, llvm::Value* _a, llvm::BasicBlock* _bb);
static void freeMemory( GenerationContext& _gc, llvm::Value* _ptr, llvm::BasicBlock* _bb);
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -22,6 +22,8 @@
#include "Debug.h"
#include <llvm/BasicBlock.h>
+#include "Macros_p.h"
+
using namespace GTLCore;
ExpressionGenerationContext::ExpressionGenerationContext(llvm::BasicBlock* _basicBlock) : m_currentBasicBlock(_basicBlock)
@@ -31,6 +33,17 @@
{
}
+ExpressionGenerationContext& ExpressionGenerationContext::operator=(const ExpressionGenerationContext& rhs)
+{
+ UNUSED(rhs);
+ GTL_ABORT("Don't copy ExpressionGenerationContext");
+}
+ExpressionGenerationContext::ExpressionGenerationContext(const ExpressionGenerationContext& rhs)
+{
+ UNUSED(rhs);
+ GTL_ABORT("Don't copy ExpressionGenerationContext");
+}
+
llvm::BasicBlock* ExpressionGenerationContext::currentBasicBlock()
{
return m_currentBasicBlock;
@@ -38,6 +51,7 @@
void ExpressionGenerationContext::setCurrentBasicBlock(llvm::BasicBlock* _bb)
{
+ if( m_currentBasicBlock == _bb) return;
GTL_ASSERT( m_currentBasicBlock == 0 or m_currentBasicBlock->getTerminator() );
m_currentBasicBlock = _bb;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.h 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ExpressionGenerationContext_p.h 2009-04-08 21:50:38 UTC (rev 712)
@@ -26,6 +26,9 @@
namespace GTLCore {
class ExpressionGenerationContext {
+ private:
+ ExpressionGenerationContext& operator=(const ExpressionGenerationContext& rhs);
+ ExpressionGenerationContext(const ExpressionGenerationContext& rhs);
public:
ExpressionGenerationContext(llvm::BasicBlock* _basicBlock);
~ExpressionGenerationContext();
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -48,6 +48,7 @@
#include "Function_p.h"
#include "Utils_p.h"
#include "VariablesManager_p.h"
+#include "ExpressionGenerationContext_p.h"
#include "TypesManager.h"
#include "TypesManager_p.h"
@@ -242,7 +243,8 @@
if( expr and expr->isConstant() )
{
GenerationContext gc( 0, 0, 0 ,0 );
- llvm::ConstantInt* idxCST = dynamic_cast<llvm::ConstantInt*>( expr->generateValue( gc, 0).constant() );
+ ExpressionGenerationContext egc(0);
+ llvm::ConstantInt* idxCST = dynamic_cast<llvm::ConstantInt*>( expr->generateValue( gc, egc).constant() );
GTL_ASSERT( idxCST );
idx = idxCST->getLimitedValue();
} else {
@@ -857,7 +859,8 @@
{
CodeGenerator cg( 0 );
GenerationContext gc( &cg, 0, 0, 0);
- llvm::Constant* constant = initialiser->generateValue( gc, 0 ).constant();
+ ExpressionGenerationContext egc(0);
+ llvm::Constant* constant = initialiser->generateValue( gc, egc ).constant();
if( constant )
{
if( constant->getType() == llvm::Type::Int32Ty )
@@ -1610,7 +1613,8 @@
{
if( (*it)->isConstant() )
{
- llvm::ConstantInt* v = dynamic_cast<llvm::ConstantInt* >( (*it)->generateValue( gc, 0 ).constant() );
+ ExpressionGenerationContext egc(0);
+ llvm::ConstantInt* v = dynamic_cast<llvm::ConstantInt* >( (*it)->generateValue( gc, egc ).constant() );
GTL_ASSERT( v );
integersList.push_back( v->getValue().getLimitedValue() );
} else {
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp 2009-04-08 15:05:16 UTC (rev 711)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelConvertExpressionFactory_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
@@ -28,6 +28,7 @@
#include "CodeGenerator_p.h"
#include "Debug.h"
#include "wrappers/PixelWrap_p.h"
+#include <GTLCore/ExpressionGenerationContext_p.h>
using namespace OpenShiva;
@@ -39,16 +40,16 @@
}
virtual ~PixelConvertExpression() {}
virtual const GTLCore::Type* type() const { return m_dstType; }
- virtual GTLCore::ExpressionResult generateValue( GTLCore::GenerationContext& _gc, llvm::BasicBlock* bb ) const
+ virtual GTLCore::ExpressionResult generateValue( GTLCore::GenerationContext& _gc, GTLCore::ExpressionGenerationContext& _egc ) const
{
if( value()->type()->dataType() == GTLCore::Type::STRUCTURE )
{
- llvm::Value* pixelPtr = value()->generateValue( _gc, bb).value();
+ llvm::Value* pixelPtr = value()->generateValue( _gc, _egc).value();
- llvm::Value* pixelDataPtr = OpenShiva::CodeGenerator::accessPixelDataPtr( _gc, bb, pixelPtr);
- return GTLCore::ExpressionResult( new llvm::LoadInst( pixelDataPtr, "", bb ) , m_dstType );
+ llvm::Value* pixelDataPtr = OpenShiva::CodeGenerator::accessPixelDataPtr( _gc, _egc.currentBasicBlock(), pixelPtr);
+ return GTLCore::ExpressionResult( new llvm::LoadInst( pixelDataPtr, "", _egc.currentBasicBlock() ) , m_dstType );
} else {
- return value()->generateValue( _gc, bb);
+ return value()->generateValue( _gc, _egc);
}
}
private: