annotate gen/statements.cpp @ 127:facc562f5674 trunk

[svn r131] Fixed #11 All associative array properties now work as they should. Fixed problems with some cases of array.length and array.ptr. Fixed some problems with array properties. Fixed 'in' contracts.
author lindquist
date Fri, 30 Nov 2007 12:56:52 +0100
parents 7f9a0a58394b
children 5825d48b27d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1 // Statements: D -> LLVM glue
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
2
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
3 #include <stdio.h>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
4 #include <math.h>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
5 #include <sstream>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
6 #include <fstream>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
7 #include <iostream>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
8
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
9 #include "gen/llvm.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
10
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
11 #include "total.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
12 #include "init.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
13 #include "mtype.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
14 #include "hdrgen.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
15 #include "port.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
16
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
17 #include "gen/irstate.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
18 #include "gen/logger.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
19 #include "gen/tollvm.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
20 #include "gen/runtime.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
21 #include "gen/arrays.h"
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
22 #include "gen/todebug.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
23 #include "gen/dvalue.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
24
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
25 //////////////////////////////////////////////////////////////////////////////
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
26
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
27 void CompoundStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
28 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
29 Logger::println("CompoundStatement::toIR()");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
30 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
31
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
32 for (int i=0; i<statements->dim; i++)
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
33 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
34 Statement* s = (Statement*)statements->data[i];
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
35 if (s)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
36 s->toIR(p);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
37 else {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
38 Logger::println("??? null statement found in CompoundStatement");
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
39 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
40 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
41 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
42
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
43 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
44
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
45 void ReturnStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
46 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
47 static int rsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
48 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
49 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
50
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
51 if (exp)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
52 {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 51
diff changeset
53 Logger::println("return type is: %s", exp->type->toChars());
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 51
diff changeset
54
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
55 Type* exptype = DtoDType(exp->type);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
56 TY expty = exptype->ty;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
57 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
58 assert(DtoIsPassedByRef(exptype));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
59
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
60 IRFunction* f = p->func();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
61 assert(f->type->llvmRetInPtr);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
62 assert(f->decl->llvmRetArg);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
63
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
64 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
65
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
66 DValue* rvar = new DVarValue(f->type->next, f->decl->llvmRetArg, true);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
67
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
68 p->exps.push_back(IRExp(NULL,exp,rvar));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
69 DValue* e = exp->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 51
diff changeset
70 p->exps.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
71
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
72 if (!e->inPlace())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
73 DtoAssign(rvar, e);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
74
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
75 IRFunction::FinallyVec& fin = f->finallys;
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
76 if (fin.empty()) {
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
77 if (global.params.symdebug) DtoDwarfFuncEnd(f->decl);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
78 new llvm::ReturnInst(p->scopebb());
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
79 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
80 else {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
81 new llvm::BranchInst(fin.back().retbb, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
82 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
83 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
84 else {
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
85 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
86 DValue* e = exp->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
87 llvm::Value* v = e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
88 delete e;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
89 Logger::cout() << "return value is '" <<*v << "'\n";
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 51
diff changeset
90
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
91 IRFunction::FinallyVec& fin = p->func()->finallys;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
92 if (fin.empty()) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
93 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
94 new llvm::ReturnInst(v, p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
95 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
96 else {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
97 if (!p->func()->finallyretval)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
98 p->func()->finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
99 llvm::Value* rettmp = p->func()->finallyretval;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
100 new llvm::StoreInst(v,rettmp,p->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
101 new llvm::BranchInst(fin.back().retbb, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
102 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
103 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
104 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
105 else
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
106 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
107 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
108 IRFunction::FinallyVec& fin = p->func()->finallys;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
109 if (fin.empty()) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
110 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
111 new llvm::ReturnInst(p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
112 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
113 else {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
114 new llvm::BranchInst(fin.back().retbb, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
115 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
116 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
117 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
118 assert(0); // why should this ever happen?
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
119 new llvm::UnreachableInst(p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
120 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
121 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
122 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
123
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
124 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
125
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
126 void ExpStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
127 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
128 static int esi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
129 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
130 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
131
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
132 if (global.params.symdebug)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
133 DtoDwarfStopPoint(loc.linnum);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
134
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
135 if (exp != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
136 elem* e = exp->toElem(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
137 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
138 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
139 /*elem* e = exp->toElem(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
140 p->buf.printf("%s", e->toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
141 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
142 p->buf.writenl();*/
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
143 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
144
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
145 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
146
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
147 void IfStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
148 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
149 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
150 Logger::println("IfStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
151 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
152
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
153 DValue* cond_e = condition->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
154 llvm::Value* cond_val = cond_e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
155 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
156
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
157 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
158
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
159 llvm::BasicBlock* ifbb = new llvm::BasicBlock("if", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
160 llvm::BasicBlock* endbb = new llvm::BasicBlock("endif", gIR->topfunc(), oldend);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
161 llvm::BasicBlock* elsebb = elsebody ? new llvm::BasicBlock("else", gIR->topfunc(), endbb) : endbb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
162
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
163 if (cond_val->getType() != llvm::Type::Int1Ty) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
164 Logger::cout() << "if conditional: " << *cond_val << '\n';
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
165 cond_val = DtoBoolean(cond_val);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
166 }
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
167 llvm::Value* ifgoback = new llvm::BranchInst(ifbb, elsebb, cond_val, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
168
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
169 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
170 gIR->scope() = IRScope(ifbb,elsebb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
171
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
172 // do scoped statements
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
173 ifbody->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
174 if (!gIR->scopereturned()) {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
175 new llvm::BranchInst(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
176 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
177
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
178 if (elsebody) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
179 //assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
180 gIR->scope() = IRScope(elsebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
181 elsebody->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
182 if (!gIR->scopereturned()) {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
183 new llvm::BranchInst(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
184 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
185 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
186
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
187 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
188 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
189 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
190
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
191 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
192
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
193 void ScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
194 {
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 122
diff changeset
195 Logger::println("ScopeStatement::toIR()");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
196 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
197
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
198 llvm::BasicBlock* oldend = p->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
199
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
200 llvm::BasicBlock* beginbb = 0;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
201
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
202 // remove useless branches by clearing and reusing the current basicblock
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
203 llvm::BasicBlock* bb = p->scopebb();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
204 if (bb->empty()) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
205 beginbb = bb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
206 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
207 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
208 assert(!p->scopereturned());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
209 beginbb = new llvm::BasicBlock("scope", p->topfunc(), oldend);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
210 new llvm::BranchInst(beginbb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
211 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
212 llvm::BasicBlock* endbb = new llvm::BasicBlock("endscope", p->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
213
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
214 gIR->scope() = IRScope(beginbb, endbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
215
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
216 statement->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
217
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
218 p->scope() = IRScope(p->scopebb(),oldend);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
219 endbb->eraseFromParent();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
220 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
221
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
222 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
223
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
224 void WhileStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
225 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
226 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
227 Logger::println("WhileStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
228 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
229
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
230 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
231 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
232 llvm::BasicBlock* whilebb = new llvm::BasicBlock("whilecond", gIR->topfunc(), oldend);
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
233 llvm::BasicBlock* whilebodybb = new llvm::BasicBlock("whilebody", gIR->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
234 llvm::BasicBlock* endbb = new llvm::BasicBlock("endwhile", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
235
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
236 // move into the while block
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
237 p->ir->CreateBr(whilebb);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
238 //new llvm::BranchInst(whilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
239
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
240 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
241 gIR->scope() = IRScope(whilebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
242
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
243 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
244 DValue* cond_e = condition->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
245 llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
246 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
247
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
248 // conditional branch
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
249 llvm::Value* ifbreak = new llvm::BranchInst(whilebodybb, endbb, cond_val, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
250
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
251 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
252 gIR->scope() = IRScope(whilebodybb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
253
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
254 // while body code
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
255 p->loopbbs.push_back(IRScope(whilebb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
256 body->toIR(p);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
257 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
258
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
259 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
260 if (!gIR->scopereturned())
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
261 new llvm::BranchInst(whilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
262
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
263 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
264 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
265 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
266
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
267 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
268
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
269 void DoStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
270 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
271 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
272 Logger::println("DoStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
273 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
274
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
275 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
276 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
277 llvm::BasicBlock* dowhilebb = new llvm::BasicBlock("dowhile", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
278 llvm::BasicBlock* endbb = new llvm::BasicBlock("enddowhile", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
279
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
280 // move into the while block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
281 assert(!gIR->scopereturned());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
282 new llvm::BranchInst(dowhilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
283
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
284 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
285 gIR->scope() = IRScope(dowhilebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
286
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
287 // do-while body code
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
288 p->loopbbs.push_back(IRScope(dowhilebb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
289 body->toIR(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
290 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
291
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
292 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
293 DValue* cond_e = condition->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
294 llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
295 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
296
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
297 // conditional branch
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
298 llvm::Value* ifbreak = new llvm::BranchInst(dowhilebb, endbb, cond_val, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
299
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
300 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
301 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
302 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
303
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
304 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
305
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
306 void ForStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
307 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
308 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
309 Logger::println("ForStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
310 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
311
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
312 // create for blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
313 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
314 llvm::BasicBlock* forbb = new llvm::BasicBlock("forcond", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
315 llvm::BasicBlock* forbodybb = new llvm::BasicBlock("forbody", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
316 llvm::BasicBlock* forincbb = new llvm::BasicBlock("forinc", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
317 llvm::BasicBlock* endbb = new llvm::BasicBlock("endfor", gIR->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
318
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
319 // init
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
320 if (init != 0)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
321 init->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
322
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
323 // move into the for condition block, ie. start the loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
324 new llvm::BranchInst(forbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
325
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
326 p->loopbbs.push_back(IRScope(forincbb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
327
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
328 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
329 gIR->scope() = IRScope(forbb,forbodybb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
330
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
331 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
332 DValue* cond_e = condition->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
333 llvm::Value* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
334 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
335
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
336 // conditional branch
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
337 llvm::Value* ifbreak = new llvm::BranchInst(forbodybb, endbb, cond_val, forbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
338
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
339 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
340 gIR->scope() = IRScope(forbodybb,forincbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
341
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
342 // do for body code
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
343 body->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
344
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
345 // move into the for increment block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
346 if (!gIR->scopereturned())
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
347 new llvm::BranchInst(forincbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
348 gIR->scope() = IRScope(forincbb, endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
349
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
350 // increment
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
351 if (increment) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
352 DValue* inc = increment->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
353 delete inc;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
354 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
355
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
356 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
357 if (!gIR->scopereturned())
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
358 new llvm::BranchInst(forbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
359
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
360 p->loopbbs.pop_back();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
361
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
362 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
363 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
364 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
365
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
366 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
367
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
368 void BreakStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
369 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
370 Logger::println("BreakStatement::toIR(): %s", toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
371 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
372
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
373 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
374 Logger::println("ident = %s", ident->toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
375 assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
376 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
377 else {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
378 new llvm::BranchInst(gIR->loopbbs.back().end, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
379 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
380 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
381
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
382 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
383
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
384 void ContinueStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
385 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
386 Logger::println("ContinueStatement::toIR(): %s", toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
387 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
388
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
389 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
390 Logger::println("ident = %s", ident->toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
391 assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
392 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
393 else {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
394 new llvm::BranchInst(gIR->loopbbs.back().begin, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
395 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
396 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
397
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
398 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
399
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
400 void OnScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
401 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
402 Logger::println("OnScopeStatement::toIR(): %s", toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
403 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
404
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
405 assert(statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
406 //statement->toIR(p); // this seems to be redundant
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
407 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
408
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
409 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
410
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
411 void TryFinallyStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
412 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
413 Logger::println("TryFinallyStatement::toIR(): %s", toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
414 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
415
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
416 // create basic blocks
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
417 llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
418
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
419 llvm::BasicBlock* trybb = new llvm::BasicBlock("try", p->topfunc(), oldend);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
420 llvm::BasicBlock* finallybb = new llvm::BasicBlock("finally", p->topfunc(), oldend);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
421 llvm::BasicBlock* finallyretbb = new llvm::BasicBlock("finallyreturn", p->topfunc(), oldend);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
422 llvm::BasicBlock* endbb = new llvm::BasicBlock("endtryfinally", p->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
423
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
424 // pass the previous BB into this
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
425 assert(!gIR->scopereturned());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
426 new llvm::BranchInst(trybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
427
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
428 // do the try block
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
429 p->scope() = IRScope(trybb,finallybb);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
430 gIR->func()->finallys.push_back(IRFinally(finallybb,finallyretbb));
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
431 IRFinally& fin = p->func()->finallys.back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
432
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
433 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
434 body->toIR(p);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
435
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
436 // terminate try BB
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
437 if (!p->scopereturned())
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
438 new llvm::BranchInst(finallybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
439
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
440 // do finally block
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
441 p->scope() = IRScope(finallybb,finallyretbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
442 assert(finalbody);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
443 finalbody->toIR(p);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
444
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
445 // terminate finally
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
446 if (!gIR->scopereturned()) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
447 new llvm::BranchInst(endbb, p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
448 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
449
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
450 // do finally block (return path)
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
451 p->scope() = IRScope(finallyretbb,endbb);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
452 assert(finalbody);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
453 finalbody->toIR(p); // hope this will work, otherwise it's time it gets fixed
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
454
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
455 // terminate finally (return path)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
456 size_t nfin = p->func()->finallys.size();
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
457 if (nfin > 1) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
458 IRFinally& ofin = p->func()->finallys[nfin-2];
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
459 p->ir->CreateBr(ofin.retbb);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
460 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
461 // no outer
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
462 else
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
463 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
464 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
465 llvm::Value* retval = p->func()->finallyretval;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
466 if (retval) {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
467 retval = p->ir->CreateLoad(retval,"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
468 p->ir->CreateRet(retval);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
469 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
470 else {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
471 FuncDeclaration* fd = p->func()->decl;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
472 if (fd->isMain()) {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
473 assert(fd->type->next->ty == Tvoid);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
474 p->ir->CreateRet(DtoConstInt(0));
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
475 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
476 else {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
477 p->ir->CreateRetVoid();
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
478 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
479 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
480 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
481
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
482 // rewrite the scope
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
483 p->func()->finallys.pop_back();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
484 p->scope() = IRScope(endbb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
485 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
486
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
487 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
488
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
489 void TryCatchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
490 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
491 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
492 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
493 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
494
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
495 Logger::attention("try-catch is not yet fully implemented, only the try block will be emitted.");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
496
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
497 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
498 body->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
499
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
500 /*assert(catches);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
501 for(size_t i=0; i<catches->dim; ++i)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
502 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
503 Catch* c = (Catch*)catches->data[i];
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
504 c->handler->toIR(p);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
505 }*/
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
506 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
507
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
508 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
509
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
510 void ThrowStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
511 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
512 static int wsi = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
513 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
514 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
515
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
516 Logger::attention("throw is not yet implemented, replacing expression with assert(0);");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
517
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
518 DtoAssert(NULL, &loc, NULL);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
519
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
520 /*
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
521 assert(exp);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
522 DValue* e = exp->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
523 delete e;
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
524 */
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
525 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
526
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
527 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
528
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
529 // used to build the sorted list of cases
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
530 struct Case : Object
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
531 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
532 StringExp* str;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
533 size_t index;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
534
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
535 Case(StringExp* s, size_t i) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
536 str = s;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
537 index = i;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
538 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
539
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
540 int compare(Object *obj) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
541 Case* c2 = (Case*)obj;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
542 return str->compare(c2->str);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
543 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
544 };
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
545
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
546 static llvm::Value* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e)
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
547 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
548 Type* dt = DtoDType(e->type);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
549 Type* dtnext = DtoDType(dt->next);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
550 TY ty = dtnext->ty;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
551 const char* fname;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
552 if (ty == Tchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
553 fname = "_d_switch_string";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
554 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
555 else if (ty == Twchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
556 fname = "_d_switch_ustring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
557 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
558 else if (ty == Tdchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
559 fname = "_d_switch_dstring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
560 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
561 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
562 assert(0 && "not char/wchar/dchar");
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
563 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
564
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
565 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
566 std::vector<llvm::Value*> args;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
567 args.push_back(table);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
568 args.push_back(e->toElem(gIR)->getRVal());
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
569 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
570 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
571
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
572 void SwitchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
573 {
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
574 Logger::println("SwitchStatement::toIR()");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
575 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
576
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
577 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
578
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
579 // collect the needed cases
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
580 typedef std::pair<llvm::BasicBlock*, std::vector<llvm::ConstantInt*> > CasePair;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
581 std::vector<CasePair> vcases;
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
582 std::vector<Statement*> vbodies;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
583 Array caseArray;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
584 for (int i=0; i<cases->dim; ++i)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
585 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
586 CaseStatement* cs = (CaseStatement*)cases->data[i];
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
587
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
588 std::string lblname("case");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
589 llvm::BasicBlock* bb = new llvm::BasicBlock(lblname, p->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
590
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
591 std::vector<llvm::ConstantInt*> tmp;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
592 CaseStatement* last;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
593 bool first = true;
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
594 do {
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
595 // integral case
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
596 if (cs->exp->type->isintegral()) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
597 llvm::Constant* c = cs->exp->toConstElem(p);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
598 tmp.push_back(isaConstantInt(c));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
599 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
600 // string case
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
601 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
602 assert(cs->exp->op == TOKstring);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
603 // for string switches this is unfortunately necessary or there will be duplicates in the list
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
604 if (first) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
605 caseArray.push(new Case((StringExp*)cs->exp, i));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
606 first = false;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
607 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
608 }
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
609 last = cs;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
610 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
611 while (cs = cs->statement->isCaseStatement());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
612
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
613 vcases.push_back(CasePair(bb, tmp));
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
614 vbodies.push_back(last->statement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
615 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
616
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
617 // string switch?
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
618 llvm::GlobalVariable* switchTable = 0;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
619 if (!condition->type->isintegral())
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
620 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
621 // first sort it
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
622 caseArray.sort();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
623 // iterate and add indices to cases
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
624 std::vector<llvm::Constant*> inits;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
625 for (size_t i=0; i<caseArray.dim; ++i)
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
626 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
627 Case* c = (Case*)caseArray.data[i];
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
628 vcases[c->index].second.push_back(DtoConstUint(i));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
629 inits.push_back(c->str->toConstElem(p));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
630 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
631 // build static array for ptr or final array
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
632 const llvm::Type* elemTy = DtoType(condition->type);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
633 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size());
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
634 llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, inits);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
635 llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, "string_switch_table_data", gIR->module);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
636
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
637 const llvm::Type* elemPtrTy = llvm::PointerType::get(elemTy);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
638 llvm::Constant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
639
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
640 // build the static table
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
641 std::vector<const llvm::Type*> types;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
642 types.push_back(DtoSize_t());
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
643 types.push_back(elemPtrTy);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
644 const llvm::StructType* sTy = llvm::StructType::get(types);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
645 std::vector<llvm::Constant*> sinits;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
646 sinits.push_back(DtoConstSize_t(inits.size()));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
647 sinits.push_back(arrPtr);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
648 llvm::Constant* sInit = llvm::ConstantStruct::get(sTy, sinits);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
649
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
650 switchTable = new llvm::GlobalVariable(sTy, true, llvm::GlobalValue::InternalLinkage, sInit, "string_switch_table", gIR->module);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
651 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
652
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
653 // default
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
654 llvm::BasicBlock* defbb = 0;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
655 if (!hasNoDefault) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
656 defbb = new llvm::BasicBlock("default", p->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
657 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
658
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
659 // end (break point)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
660 llvm::BasicBlock* endbb = new llvm::BasicBlock("switchend", p->topfunc(), oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
661
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
662 // condition var
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
663 llvm::Value* condVal;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
664 // integral switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
665 if (condition->type->isintegral()) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
666 DValue* cond = condition->toElem(p);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
667 condVal = cond->getRVal();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
668 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
669 // string switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
670 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
671 condVal = call_string_switch_runtime(switchTable, condition);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
672 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
673 llvm::SwitchInst* si = new llvm::SwitchInst(condVal, defbb ? defbb : endbb, cases->dim, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
674
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
675 // add the cases
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
676 size_t n = vcases.size();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
677 for (size_t i=0; i<n; ++i)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
678 {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
679 size_t nc = vcases[i].second.size();
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
680 for (size_t j=0; j<nc; ++j)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
681 {
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
682 si->addCase(vcases[i].second[j], vcases[i].first);
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
683 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
684 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
685
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
686 // insert case statements
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
687 for (size_t i=0; i<n; ++i)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
688 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
689 llvm::BasicBlock* nextbb = (i == n-1) ? (defbb ? defbb : endbb) : vcases[i+1].first;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
690 p->scope() = IRScope(vcases[i].first,nextbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
691
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
692 p->loopbbs.push_back(IRScope(p->scopebb(),endbb));
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
693 vbodies[i]->toIR(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
694 p->loopbbs.pop_back();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
695
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
696 llvm::BasicBlock* curbb = p->scopebb();
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
697 if (curbb->empty() || !curbb->back().isTerminator())
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
698 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
699 new llvm::BranchInst(nextbb, curbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
700 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
701 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
702
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
703 // default statement
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
704 if (defbb)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
705 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
706 p->scope() = IRScope(defbb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
707 p->loopbbs.push_back(IRScope(defbb,endbb));
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
708 Logger::println("doing default statement");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
709 sdefault->statement->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
710 p->loopbbs.pop_back();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
711
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
712 llvm::BasicBlock* curbb = p->scopebb();
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
713 if (curbb->empty() || !curbb->back().isTerminator())
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
714 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
715 new llvm::BranchInst(endbb, curbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
716 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
717 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
718
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
719 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
720 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
721
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
722 //////////////////////////////////////////////////////////////////////////////
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
723 void CaseStatement::toIR(IRState* p)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
724 {
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
725 Logger::println("CaseStatement::toIR(): %s", toChars());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
726 LOG_SCOPE;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
727
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
728 assert(0);
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
729 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
730
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
731 //////////////////////////////////////////////////////////////////////////////
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
732
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
733 void UnrolledLoopStatement::toIR(IRState* p)
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
734 {
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
735 Logger::println("UnrolledLoopStatement::toIR(): %s", toChars());
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
736 LOG_SCOPE;
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
737
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
738 llvm::BasicBlock* oldend = gIR->scopeend();
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
739 llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
740
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
741 p->scope() = IRScope(p->scopebb(),endbb);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
742 p->loopbbs.push_back(IRScope(p->scopebb(),endbb));
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
743
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
744 for (int i=0; i<statements->dim; ++i)
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
745 {
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
746 Statement* s = (Statement*)statements->data[i];
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
747 s->toIR(p);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
748 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
749
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
750 p->loopbbs.pop_back();
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
751
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
752 new llvm::BranchInst(endbb, p->scopebb());
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
753 p->scope() = IRScope(endbb,oldend);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
754 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
755
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
756 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
757
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
758 void ForeachStatement::toIR(IRState* p)
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
759 {
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
760 Logger::println("ForeachStatement::toIR(): %s", toChars());
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
761 LOG_SCOPE;
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
762
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
763 //assert(arguments->dim == 1);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
764 assert(value != 0);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
765 assert(body != 0);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
766 assert(aggr != 0);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
767 assert(func != 0);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
768
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
769 //Argument* arg = (Argument*)arguments->data[0];
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
770 //Logger::println("Argument is %s", arg->toChars());
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
771
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
772 Logger::println("aggr = %s", aggr->toChars());
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
773
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
774 // key
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
775 const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t();
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
776 llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
777 if (key) key->llvmValue = keyvar;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
778 llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false);
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
779
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
780 // value
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
781 const llvm::Type* valtype = DtoType(value->type);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
782 llvm::Value* valvar = NULL;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
783 if (!value->isRef() && !value->isOut())
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
784 valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint());
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
785
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
786 // what to iterate
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
787 DValue* aggrval = aggr->toElem(p);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
788 Type* aggrtype = DtoDType(aggr->type);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
789
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
790 // get length and pointer
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
791 llvm::Value* val = 0;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
792 llvm::Value* niters = 0;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
793
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
794 // static array
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
795 if (aggrtype->ty == Tsarray)
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
796 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
797 Logger::println("foreach over static array");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
798 val = aggrval->getRVal();
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
799 assert(isaPointer(val->getType()));
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
800 const llvm::ArrayType* arrty = isaArray(val->getType()->getContainedType(0));
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
801 assert(arrty);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
802 size_t nelems = arrty->getNumElements();
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
803 assert(nelems > 0);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
804 niters = llvm::ConstantInt::get(keytype,nelems,false);
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
805 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
806 // dynamic array
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
807 else if (aggrtype->ty == Tarray)
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
808 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
809 if (DSliceValue* slice = aggrval->isSlice()) {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
810 Logger::println("foreach over slice");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
811 niters = slice->len;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
812 assert(niters);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
813 val = slice->ptr;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
814 assert(val);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
815 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
816 else {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
817 Logger::println("foreach over dynamic array");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
818 val = aggrval->getRVal();
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
819 niters = DtoGEPi(val,0,0,"tmp",p->scopebb());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
820 niters = p->ir->CreateLoad(niters, "numiterations");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
821 val = DtoGEPi(val,0,1,"tmp",p->scopebb());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
822 val = p->ir->CreateLoad(val, "collection");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
823 }
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
824 }
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
825 else
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
826 {
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
827 assert(0 && "aggregate type is not Tarray or Tsarray");
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
828 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
829
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
830 if (niters->getType() != keytype)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
831 {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
832 size_t sz1 = gTargetData->getTypeSize(niters->getType());
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
833 size_t sz2 = gTargetData->getTypeSize(keytype);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
834 if (sz1 < sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
835 niters = gIR->ir->CreateZExt(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
836 else if (sz1 > sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
837 niters = gIR->ir->CreateTrunc(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
838 else
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
839 niters = gIR->ir->CreateBitCast(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
840 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
841
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
842 llvm::Constant* delta = 0;
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
843 if (op == TOKforeach) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
844 new llvm::StoreInst(zerokey, keyvar, p->scopebb());
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
845 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
846 else {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
847 new llvm::StoreInst(niters, keyvar, p->scopebb());
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
848 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
849
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
850 llvm::BasicBlock* oldend = gIR->scopeend();
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
851 llvm::BasicBlock* condbb = new llvm::BasicBlock("foreachcond", p->topfunc(), oldend);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
852 llvm::BasicBlock* bodybb = new llvm::BasicBlock("foreachbody", p->topfunc(), oldend);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
853 llvm::BasicBlock* nextbb = new llvm::BasicBlock("foreachnext", p->topfunc(), oldend);
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
854 llvm::BasicBlock* endbb = new llvm::BasicBlock("foreachend", p->topfunc(), oldend);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
855
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
856 new llvm::BranchInst(condbb, p->scopebb());
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
857
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
858 // condition
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
859 p->scope() = IRScope(condbb,bodybb);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
860
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
861 llvm::Value* done = 0;
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
862 llvm::Value* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb());
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
863 if (op == TOKforeach) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
864 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_ULT, load, niters, "tmp", p->scopebb());
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
865 }
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
866 else if (op == TOKforeach_reverse) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
867 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_UGT, load, zerokey, "tmp", p->scopebb());
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
868 load = llvm::BinaryOperator::createSub(load,llvm::ConstantInt::get(keytype, 1, false),"tmp",p->scopebb());
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
869 new llvm::StoreInst(load, keyvar, p->scopebb());
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
870 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
871 new llvm::BranchInst(bodybb, endbb, done, p->scopebb());
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
872
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
873 // init body
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
874 p->scope() = IRScope(bodybb,nextbb);
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
875
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
876 // get value for this iteration
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
877 llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
878 llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
879 if (aggrtype->ty == Tsarray)
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 80
diff changeset
880 value->llvmValue = DtoGEP(val,zero,loadedKey,"tmp");
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
881 else if (aggrtype->ty == Tarray)
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
882 value->llvmValue = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb());
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
883
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
884 if (!value->isRef() && !value->isOut()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
885 DValue* dst = new DVarValue(value->type, valvar, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
886 DValue* src = new DVarValue(value->type, value->llvmValue, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
887 DtoAssign(dst, src);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
888 value->llvmValue = valvar;
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
889 }
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
890
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
891 // emit body
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
892 p->loopbbs.push_back(IRScope(nextbb,endbb));
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
893 body->toIR(p);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
894 p->loopbbs.pop_back();
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
895
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
896 if (!p->scopereturned())
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
897 new llvm::BranchInst(nextbb, p->scopebb());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
898
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
899 // next
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
900 p->scope() = IRScope(nextbb,endbb);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
901 if (op == TOKforeach) {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
902 llvm::Value* load = DtoLoad(keyvar);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
903 load = p->ir->CreateAdd(load, llvm::ConstantInt::get(keytype, 1, false), "tmp");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
904 DtoStore(load, keyvar);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
905 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
906 new llvm::BranchInst(condbb, p->scopebb());
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
907
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
908 // end
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
909 p->scope() = IRScope(endbb,oldend);
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
910 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
911
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
912 //////////////////////////////////////////////////////////////////////////////
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
913
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
914 void LabelStatement::toIR(IRState* p)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
915 {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
916 Logger::println("LabelStatement::toIR(): %s", toChars());
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
917 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
918
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
919 assert(tf == NULL);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
920 assert(!isReturnLabel);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
921
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
922 llvm::BasicBlock* oldend = gIR->scopeend();
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
923 if (llvmBB)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
924 llvmBB->moveBefore(oldend);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
925 else
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
926 llvmBB = new llvm::BasicBlock("label", p->topfunc(), oldend);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
927
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
928 if (!p->scopereturned())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
929 new llvm::BranchInst(llvmBB, p->scopebb());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
930
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
931 p->scope() = IRScope(llvmBB,oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
932 if (statement)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
933 statement->toIR(p);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
934 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
935
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
936 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
937
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
938 void GotoStatement::toIR(IRState* p)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
939 {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
940 Logger::println("GotoStatement::toIR(): %s", toChars());
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
941 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
942
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
943 assert(tf == NULL);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
944
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
945 llvm::BasicBlock* oldend = gIR->scopeend();
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
946 llvm::BasicBlock* bb = new llvm::BasicBlock("aftergoto", p->topfunc(), oldend);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
947
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
948 if (label->statement->llvmBB == NULL)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
949 label->statement->llvmBB = new llvm::BasicBlock("label", p->topfunc());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
950 assert(!p->scopereturned());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
951 new llvm::BranchInst(label->statement->llvmBB, p->scopebb());
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
952 p->scope() = IRScope(bb,oldend);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
953 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
954
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
955 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
956
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
957 void WithStatement::toIR(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
958 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
959 Logger::println("WithStatement::toIR(): %s", toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
960 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
961
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
962 assert(exp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
963 assert(body);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
964
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
965 DValue* e = exp->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
966 wthis->llvmValue = e->getRVal();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
967 delete e;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
968
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
969 body->toIR(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
970 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
971
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
972 //////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
973
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
974 void SynchronizedStatement::toIR(IRState* p)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
975 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
976 Logger::println("SynchronizedStatement::toIR(): %s", toChars());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
977 LOG_SCOPE;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
978
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
979 Logger::attention("synchronized is currently ignored. only the body will be emitted");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
980
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
981 body->toIR(p);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
982 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
983
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
984 //////////////////////////////////////////////////////////////////////////////
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
985
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
986 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
987
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
988 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();}
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
989 //STUBST(BreakStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
990 //STUBST(ForStatement);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
991 //STUBST(WithStatement);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
992 //STUBST(SynchronizedStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
993 //STUBST(ReturnStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
994 //STUBST(ContinueStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
995 STUBST(DefaultStatement);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
996 //STUBST(CaseStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
997 //STUBST(SwitchStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
998 STUBST(SwitchErrorStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
999 STUBST(Statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1000 //STUBST(IfStatement);
32
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1001 //STUBST(ForeachStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1002 //STUBST(DoStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1003 //STUBST(WhileStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1004 //STUBST(ExpStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1005 //STUBST(CompoundStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1006 //STUBST(ScopeStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1007 STUBST(AsmStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1008 //STUBST(TryCatchStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1009 //STUBST(TryFinallyStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1010 STUBST(VolatileStatement);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1011 //STUBST(LabelStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1012 //STUBST(ThrowStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1013 STUBST(GotoCaseStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1014 STUBST(GotoDefaultStatement);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1015 //STUBST(GotoStatement);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1016 //STUBST(UnrolledLoopStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1017 //STUBST(OnScopeStatement);