[opengtl-commits] [383] * add the possibility to delayed the code generation of statements in the GenerationContext |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 383
Author: cyrille
Date: 2008-09-11 00:28:17 +0200 (Thu, 11 Sep 2008)
Log Message:
-----------
* add the possibility to delayed the code generation of statements in the GenerationContext
* add a garbage collection statement that does nothing at the moment
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
Added Paths:
-----------
trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-09-10 22:28:17 UTC (rev 383)
@@ -35,6 +35,8 @@
#include "../wrappers/ArrayWrap.h"
#include "../wrappers/StructWrap.h"
+#include "GarbageCollectionStatement.h"
+
using namespace GTLCore::AST;
//------------------- AccessorExpression -------------------//
@@ -238,7 +240,11 @@
GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
GTL_DEBUG("Call member funcion: " << m_member->function()->name());
- return _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
+ GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
+
+ _gc.appendDelayedStatement( new GarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
+
+ return returnValue;
}
llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-09-10 22:28:17 UTC (rev 383)
@@ -38,6 +38,7 @@
#include "GTLCore/Function_p.h"
#include "AccessorExpression.h"
+#include "GarbageCollectionStatement.h"
using namespace GTLCore::AST;
@@ -96,7 +97,9 @@
GTLCore::ExpressionResult FunctionCallExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
+ GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
+ _gc.appendDelayedStatement( new GarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
+ return returnValue;
}
void FunctionCallExpression::markAsReturnExpression()
Added: trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp 2008-09-10 22:28:17 UTC (rev 383)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "GarbageCollectionStatement.h"
+
+#include <stdlib.h>
+
+using namespace GTLCore::AST;
+
+GarbageCollectionStatement::GarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type ) : m_pointer(_pointer), m_type(_type)
+{
+}
+
+GarbageCollectionStatement::~GarbageCollectionStatement()
+{
+}
+
+llvm::BasicBlock* GarbageCollectionStatement::generateStatement( GenerationContext&, llvm::BasicBlock* _curentBlock) const
+{
+ // FIXME: garbage collect if needed
+ return _curentBlock;
+}
Added: trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h 2008-09-10 22:28:17 UTC (rev 383)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GARBAGE_COLLECTION_STATEMENT_H_
+#define _GARBAGE_COLLECTION_STATEMENT_H_
+
+#include "GTLCore/AST/Statement.h"
+
+namespace GTLCore {
+ namespace AST {
+ class GarbageCollectionStatement : public Statement {
+ public:
+ GarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type );
+ virtual ~GarbageCollectionStatement();
+ virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
+ private:
+ llvm::Value* m_pointer;
+ const GTLCore::Type* m_type;
+ };
+ }
+}
+
+#endif
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-09-10 22:28:17 UTC (rev 383)
@@ -59,6 +59,10 @@
it != m_list.end(); ++it)
{
currentBlock = (*it)->generateStatement( _context, currentBlock);
+ if( not dynamic_cast<ReturnStatement*>(*it))
+ {
+ currentBlock = _context.flushDelayedStatement( currentBlock );
+ }
}
return currentBlock;
}
@@ -221,6 +225,7 @@
if( m_returnExpr )
{
llvm::Value* result = m_returnExpr->generateValue( _context, _bb).value();
+ _bb = _context.flushDelayedStatement( _bb );
for( std::list<VariableNG*>::const_iterator it = m_variablesToClean.begin();
it != m_variablesToClean.end(); ++it)
{
@@ -237,6 +242,7 @@
_bb = visitor->mark( _context, _bb, result, returnType, CodeGenerator::integerToConstant( -1 ) );
llvm::ReturnInst::Create( result, _bb);
} else {
+ _bb = _context.flushDelayedStatement( _bb );
for( std::list<VariableNG*>::const_iterator it = m_variablesToClean.begin();
it != m_variablesToClean.end(); ++it)
{
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-09-10 22:28:17 UTC (rev 383)
@@ -31,6 +31,7 @@
AST/BinaryExpression.cpp
AST/ConvertExpression.cpp
AST/CoumpoundExpression.cpp
+ AST/GarbageCollectionStatement.cpp
AST/Expression.cpp
AST/FunctionDeclaration.cpp
AST/Statement.cpp
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2008-09-10 22:28:17 UTC (rev 383)
@@ -22,6 +22,8 @@
#include "ModuleData_p.h"
#include "Debug.h"
+#include "AST/Statement.h"
+
using namespace GTLCore;
GenerationContext::GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
@@ -56,3 +58,20 @@
{
return m_module;
}
+
+void GenerationContext::appendDelayedStatement( AST::Statement* _statement )
+{
+ m_delayedStatements.push_back( _statement );
+}
+
+llvm::BasicBlock* GenerationContext::flushDelayedStatement(llvm::BasicBlock* _bb)
+{
+ for( std::list< AST::Statement* >::iterator it = m_delayedStatements.begin();
+ it != m_delayedStatements.end(); ++it)
+ {
+ _bb = (*it)->generateStatement( *this, _bb );
+ delete *it;
+ }
+ m_delayedStatements.clear();
+ return _bb;
+}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2008-09-10 20:50:41 UTC (rev 382)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2008-09-10 22:28:17 UTC (rev 383)
@@ -20,15 +20,26 @@
#ifndef _GTLCORE_GENERATION_CONTEXT_H_
#define _GTLCORE_GENERATION_CONTEXT_H_
+#include <list>
+
namespace llvm {
class Function;
class Module;
+ class BasicBlock;
}
namespace GTLCore {
class CodeGenerator;
class Function;
class ModuleData;
+ namespace AST {
+ class Statement;
+ }
+ /**
+ * @internal
+ * This class contains information needed to generate the code from an AST.
+ * @ingroup GTLCore
+ */
class GenerationContext {
public:
GenerationContext( GTLCore::CodeGenerator* _codeGenerator,
@@ -38,11 +49,20 @@
Function* function();
llvm::Module* llvmModule();
ModuleData* module();
+ /**
+ * Append a statement that will generated after the current statement has been finished.
+ */
+ void appendDelayedStatement( AST::Statement* _statement );
+ /**
+ * Generate the statement that were delayed
+ */
+ llvm::BasicBlock* flushDelayedStatement(llvm::BasicBlock*);
private:
GTLCore::CodeGenerator* m_codeGenerator;
llvm::Function* m_llvmFunction;
Function* m_function;
ModuleData* m_module;
+ std::list< AST::Statement* > m_delayedStatements;
};
}