diff gen/statements.c @ 15:37a4fdab33fc trunk

[svn r19] * Added support for reassigning 'this' inside class constructors. * Added preliminary support for UnrolledLoopStatement. That is foreach on a tuple.
author lindquist
date Wed, 03 Oct 2007 04:56:32 +0200
parents 0e86428ee567
children a86fe7496b58
line wrap: on
line diff
--- a/gen/statements.c	Wed Oct 03 02:15:12 2007 +0200
+++ b/gen/statements.c	Wed Oct 03 04:56:32 2007 +0200
@@ -27,7 +27,7 @@
 #include "gen/runtime.h"
 #include "gen/arrays.h"
 
-/* --------------------------------------------------------------------------------------- */
+//////////////////////////////////////////////////////////////////////////////
 
 void CompoundStatement::toIR(IRState* p)
 {
@@ -71,6 +71,8 @@
     //p->bbs.pop();
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ReturnStatement::toIR(IRState* p)
 {
     static int rsi = 0;
@@ -134,6 +136,8 @@
     p->scope().returned = true;
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ExpStatement::toIR(IRState* p)
 {
     static int esi = 0;
@@ -150,6 +154,8 @@
     p->buf.writenl();*/
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void IfStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -204,6 +210,8 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ScopeStatement::toIR(IRState* p)
 {
     Logger::println("ScopeStatement::toIR(): %s", toChars());
@@ -240,6 +248,8 @@
     */
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void WhileStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -281,6 +291,8 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void DoStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -313,6 +325,8 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ForStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -374,6 +388,8 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void BreakStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -389,6 +405,8 @@
     }
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ContinueStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -404,6 +422,8 @@
     }
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void OnScopeStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -414,6 +434,8 @@
     //statement->toIR(p); // this seems to be redundant
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void TryFinallyStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -446,6 +468,8 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void TryCatchStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -465,6 +489,8 @@
     }
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void ThrowStatement::toIR(IRState* p)
 {
     static int wsi = 0;
@@ -478,6 +504,8 @@
     delete e;
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
 void SwitchStatement::toIR(IRState* p)
 {
     Logger::println("SwitchStatement::toIR(): %s", toChars());
@@ -561,6 +589,35 @@
     gIR->scope() = IRScope(endbb,oldend);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
+void UnrolledLoopStatement::toIR(IRState* p)
+{
+    Logger::println("UnrolledLoopStatement::toIR(): %s", toChars());
+    LOG_SCOPE;
+
+    llvm::BasicBlock* oldend = gIR->scopeend();
+    llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend);
+
+    p->scope() = IRScope(p->scopebb(),endbb);
+    p->loopbbs.push_back(IRScope(p->scopebb(),endbb));
+
+    for (int i=0; i<statements->dim; ++i)
+    {
+        Statement* s = (Statement*)statements->data[i];
+        s->toIR(p);
+    }
+
+    p->loopbbs.pop_back();
+
+    new llvm::BranchInst(endbb, p->scopebb());
+    p->scope() = IRScope(endbb,oldend);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////
+
 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();}
 //STUBST(BreakStatement);
 //STUBST(ForStatement);
@@ -589,5 +646,5 @@
 STUBST(GotoCaseStatement);
 STUBST(GotoDefaultStatement);
 STUBST(GotoStatement);
-STUBST(UnrolledLoopStatement);
+//STUBST(UnrolledLoopStatement);
 //STUBST(OnScopeStatement);