annotate gen/statements.cpp @ 299:df8a7b8d5929 trunk

[svn r320] Begun work on branches out of asm blocks. Unfinished.
author ChristianK
date Tue, 24 Jun 2008 21:38:23 +0200
parents 3b8ada4c9f8b
children bef811104734
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"
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
10 #include "llvm/InlineAsm.h"
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
11 #include "llvm/Support/CFG.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
12
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
13 #include "mars.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
14 #include "total.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
15 #include "init.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
16 #include "mtype.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
17 #include "hdrgen.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
18 #include "port.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
19
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
20 #include "gen/irstate.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
21 #include "gen/logger.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
22 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
23 #include "gen/llvmhelpers.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
24 #include "gen/runtime.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
25 #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
26 #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
27 #include "gen/dvalue.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
28
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
29 #include "ir/irfunction.h"
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
30
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
31 //////////////////////////////////////////////////////////////////////////////
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
32
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
33 void CompoundStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
34 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
35 Logger::println("CompoundStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
36 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
37
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
38 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
39 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
40 Statement* s = (Statement*)statements->data[i];
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
41 if (s) {
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
42 s->toIR(p);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
43 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
44 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
45 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
46
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
47 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
48
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
49 // generates IR for finally blocks between the 'start' and 'end' statements
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
50 // will begin with the finally block belonging to 'start' and does not include
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
51 // the finally block of 'end'
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
52 void emit_finallyblocks(IRState* p, TryFinallyStatement* start, TryFinallyStatement* end)
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
53 {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
54 // verify that end encloses start
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
55 TryFinallyStatement* endfinally = start;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
56 while(endfinally != NULL && endfinally != end) {
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
57 endfinally = endfinally->enclosingtryfinally;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
58 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
59 assert(endfinally == end);
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
60
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
61 // emit code for finallys between start and end
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
62 TryFinallyStatement* tf = start;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
63 while(tf != end) {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
64 tf->finalbody->toIR(p);
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
65 tf = tf->enclosingtryfinally;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
66 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
67 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
68
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
69 //////////////////////////////////////////////////////////////////////////////
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
70
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
71 void ReturnStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
72 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
73 Logger::println("ReturnStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
74 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
75
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
76 if (exp)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
77 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
78 if (p->topfunc()->getReturnType() == LLType::VoidTy) {
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
79 IrFunction* f = p->func();
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 109
diff changeset
80 assert(f->type->llvmRetInPtr);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
81 assert(f->decl->ir.irFunc->retArg);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
82
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
83 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
84
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
85 DValue* rvar = new DVarValue(f->type->next, f->decl->ir.irFunc->retArg, true);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
87 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
88 DValue* e = exp->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 51
diff changeset
89 p->exps.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
90
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
91 if (!e->inPlace())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
92 DtoAssign(rvar, e);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
93
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
94 emit_finallyblocks(p, enclosingtryfinally, NULL);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
95
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
96 if (f->inVolatile) {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
97 // store-load barrier
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
98 DtoMemoryBarrier(false, false, true, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
99 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
100
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
101 if (global.params.symdebug) DtoDwarfFuncEnd(f->decl);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
102 llvm::ReturnInst::Create(p->scopebb());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
103
14
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 {
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
106 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
107 DValue* e = exp->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
108 LLValue* v = e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
109 delete e;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
110 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
111
185
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
112 // can happen for classes
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
113 if (v->getType() != p->topfunc()->getReturnType())
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
114 {
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
115 v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp");
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
116 Logger::cout() << "return value after cast: " << *v << '\n';
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
117 }
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
118
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
119 emit_finallyblocks(p, enclosingtryfinally, NULL);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
120
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
121 if (gIR->func()->inVolatile) {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
122 // store-load barrier
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
123 DtoMemoryBarrier(false, false, true, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
124 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
125
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
126 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
127 llvm::ReturnInst::Create(v, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
128 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
129 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
130 else
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
131 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
132 assert(p->topfunc()->getReturnType() == LLType::VoidTy);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
133 emit_finallyblocks(p, enclosingtryfinally, NULL);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
134
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
135 if (gIR->func()->inVolatile) {
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
136 // store-load barrier
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
137 DtoMemoryBarrier(false, false, true, false);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
138 }
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
139
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
140 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl);
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
141 llvm::ReturnInst::Create(p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
142 }
267
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
143
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
144 // the return terminated this basicblock, start a new one
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
145 llvm::BasicBlock* oldend = gIR->scopeend();
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
146 llvm::BasicBlock* bb = llvm::BasicBlock::Create("afterreturn", p->topfunc(), oldend);
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
147 p->scope() = IRScope(bb,oldend);
14
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
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
150 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
151
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
152 void ExpStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
153 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
154 Logger::println("ExpStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
155 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
156
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
157 if (global.params.symdebug)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
158 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
159
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
160 if (exp) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
161 if (global.params.llvmAnnotate)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
162 DtoAnnotation(exp->toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
163 elem* e = exp->toElem(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
164 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
165 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
166 /*elem* e = exp->toElem(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
167 p->buf.printf("%s", e->toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
168 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
169 p->buf.writenl();*/
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
170 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
171
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
172 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
173
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
174 void IfStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
175 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
176 Logger::println("IfStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
177 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
178
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
179 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
180 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
181
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
182 if (match)
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
183 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
184 LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint());
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
185 match->ir.irLocal = new IrLocal(match);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
186 match->ir.irLocal->value = allocainst;
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
187 }
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
188
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
189 DValue* cond_e = condition->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
190 LLValue* cond_val = cond_e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
191 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
192
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
193 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
194
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
195 llvm::BasicBlock* ifbb = llvm::BasicBlock::Create("if", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
196 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endif", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
197 llvm::BasicBlock* elsebb = elsebody ? llvm::BasicBlock::Create("else", gIR->topfunc(), endbb) : endbb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
198
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
199 if (cond_val->getType() != LLType::Int1Ty) {
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
200 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
201 cond_val = DtoBoolean(cond_val);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
202 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
203 LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
204
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
205 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
206 gIR->scope() = IRScope(ifbb,elsebb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
207
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
208 // do scoped statements
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
209 if (ifbody)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
210 ifbody->toIR(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
211 if (!gIR->scopereturned()) {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
212 llvm::BranchInst::Create(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
213 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
214
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
215 if (elsebody) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
216 //assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
217 gIR->scope() = IRScope(elsebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
218 elsebody->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
219 if (!gIR->scopereturned()) {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
220 llvm::BranchInst::Create(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
221 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
222 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
223
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
224 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
225 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
226 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
227
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
228 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
229
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
230 void ScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
231 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
232 Logger::println("ScopeStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
233 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
234
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
235 /*llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
236
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
237 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
238
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
239 // 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
240 llvm::BasicBlock* bb = p->scopebb();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
241 if (bb->empty()) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
242 beginbb = bb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
243 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
244 else {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
245 beginbb = llvm::BasicBlock::Create("scope", p->topfunc(), oldend);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
246 if (!p->scopereturned())
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
247 llvm::BranchInst::Create(beginbb, bb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
248 }
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
249
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
250 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endscope", p->topfunc(), oldend);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
251 if (beginbb != bb)
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
252 p->scope() = IRScope(beginbb, endbb);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
253 else
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
254 p->scope().end = endbb;*/
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
255
181
ef4108f34db6 [svn r197] Fixed: empty scope statement segfaulted.
lindquist
parents: 175
diff changeset
256 if (statement)
ef4108f34db6 [svn r197] Fixed: empty scope statement segfaulted.
lindquist
parents: 175
diff changeset
257 statement->toIR(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
258
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
259 /*p->scope().end = oldend;
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
260 Logger::println("Erasing scope endbb");
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
261 endbb->eraseFromParent();*/
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
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
264 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
265
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
266 void WhileStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
267 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
268 Logger::println("WhileStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
269 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
270
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
271 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
272 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
273
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
274 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
275 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
276 llvm::BasicBlock* whilebb = llvm::BasicBlock::Create("whilecond", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
277 llvm::BasicBlock* whilebodybb = llvm::BasicBlock::Create("whilebody", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
278 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endwhile", gIR->topfunc(), oldend);
14
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
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
281 p->ir->CreateBr(whilebb);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
282 //llvm::BranchInst::Create(whilebb, 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(whilebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
286
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
287 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
288 DValue* cond_e = condition->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
289 LLValue* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
290 delete cond_e;
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 // conditional branch
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
293 LLValue* ifbreak = llvm::BranchInst::Create(whilebodybb, endbb, cond_val, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
294
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
295 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
296 gIR->scope() = IRScope(whilebodybb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
297
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
298 // while body code
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
299 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,whilebb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
300 body->toIR(p);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
301 p->loopbbs.pop_back();
14
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 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
304 if (!gIR->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
305 llvm::BranchInst::Create(whilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
306
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
307 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
308 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
309 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
310
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
311 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
312
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
313 void DoStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
314 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
315 Logger::println("DoStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
316 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
317
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
318 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
319 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
320
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
321 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
322 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
323 llvm::BasicBlock* dowhilebb = llvm::BasicBlock::Create("dowhile", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
324 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("enddowhile", gIR->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
325
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
326 // move into the while block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
327 assert(!gIR->scopereturned());
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
328 llvm::BranchInst::Create(dowhilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
329
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
330 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
331 gIR->scope() = IRScope(dowhilebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
332
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
333 // do-while body code
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
334 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,dowhilebb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
335 body->toIR(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
336 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
337
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
338 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
339 DValue* cond_e = condition->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
340 LLValue* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
341 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
342
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
343 // conditional branch
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
344 LLValue* ifbreak = llvm::BranchInst::Create(dowhilebb, endbb, cond_val, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
345
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
346 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
347 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
348 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
349
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
350 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
351
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
352 void ForStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
353 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
354 Logger::println("ForStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
355 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
356
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
357 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
358 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
359
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
360 // create for blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
361 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
362 llvm::BasicBlock* forbb = llvm::BasicBlock::Create("forcond", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
363 llvm::BasicBlock* forbodybb = llvm::BasicBlock::Create("forbody", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
364 llvm::BasicBlock* forincbb = llvm::BasicBlock::Create("forinc", gIR->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
365 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endfor", gIR->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
366
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
367 // init
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
368 if (init != 0)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
369 init->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
370
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
371 // move into the for condition block, ie. start the loop
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
372 assert(!gIR->scopereturned());
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
373 llvm::BranchInst::Create(forbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
374
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
375 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,forincbb,endbb));
14
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 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
378 gIR->scope() = IRScope(forbb,forbodybb);
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 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
381 DValue* cond_e = condition->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
382 LLValue* cond_val = DtoBoolean(cond_e->getRVal());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
383 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
384
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
385 // conditional branch
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
386 assert(!gIR->scopereturned());
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
387 llvm::BranchInst::Create(forbodybb, endbb, cond_val, gIR->scopebb());
14
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 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
390 gIR->scope() = IRScope(forbodybb,forincbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
391
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
392 // do for body code
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
393 body->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
394
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
395 // move into the for increment block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
396 if (!gIR->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
397 llvm::BranchInst::Create(forincbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
398 gIR->scope() = IRScope(forincbb, endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
399
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
400 // increment
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
401 if (increment) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
402 DValue* inc = increment->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
403 delete inc;
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
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
406 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
407 if (!gIR->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
408 llvm::BranchInst::Create(forbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
409
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
410 p->loopbbs.pop_back();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
411
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
412 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
413 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
414 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
415
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
416 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
417
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
418 void BreakStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
419 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
420 Logger::println("BreakStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
421 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
422
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
423 // don't emit two terminators in a row
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
424 // happens just before DMD generated default statements if the last case terminates
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
425 if (p->scopereturned())
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
426 return;
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
427
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
428 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
429 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
430
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
431 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
432 Logger::println("ident = %s", ident->toChars());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
433
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
434 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
435
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
436 // get the loop statement the label refers to
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
437 Statement* targetLoopStatement = target->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
438 ScopeStatement* tmp;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
439 while(tmp = targetLoopStatement->isScopeStatement())
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
440 targetLoopStatement = tmp->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
441
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
442 // find the right break block and jump there
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
443 bool found = false;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
444 IRState::LoopScopeVec::reverse_iterator it;
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
445 for(it = p->loopbbs.rbegin(); it != p->loopbbs.rend(); ++it) {
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
446 if(it->s == targetLoopStatement) {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
447 llvm::BranchInst::Create(it->end, p->scopebb());
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
448 found = true;
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
449 break;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
450 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
451 }
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
452 assert(found);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
453 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
454 else {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
455 emit_finallyblocks(p, enclosingtryfinally, p->loopbbs.back().enclosingtryfinally);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
456 llvm::BranchInst::Create(p->loopbbs.back().end, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
457 }
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
458
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
459 // the break terminated this basicblock, start a new one
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
460 llvm::BasicBlock* oldend = gIR->scopeend();
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
461 llvm::BasicBlock* bb = llvm::BasicBlock::Create("afterbreak", p->topfunc(), oldend);
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
462 p->scope() = IRScope(bb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
463 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
464
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
465 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
466
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
467 void ContinueStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
468 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
469 Logger::println("ContinueStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
470 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
471
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
472 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
473 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
474
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
475 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
476 Logger::println("ident = %s", ident->toChars());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
477
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
478 emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
479
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
480 // get the loop statement the label refers to
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
481 Statement* targetLoopStatement = target->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
482 ScopeStatement* tmp;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
483 while(tmp = targetLoopStatement->isScopeStatement())
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
484 targetLoopStatement = tmp->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
485
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
486 // find the right continue block and jump there
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
487 IRState::LoopScopeVec::reverse_iterator it;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
488 for(it = gIR->loopbbs.rbegin(); it != gIR->loopbbs.rend(); ++it) {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
489 if(it->s == targetLoopStatement) {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
490 llvm::BranchInst::Create(it->begin, gIR->scopebb());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
491 return;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
492 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
493 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
494 assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
495 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
496 else {
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
497 emit_finallyblocks(p, enclosingtryfinally, gIR->loopbbs.back().enclosingtryfinally);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
498 llvm::BranchInst::Create(gIR->loopbbs.back().begin, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
499 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
500 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
501
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
502 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
503
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
504 void OnScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
505 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
506 Logger::println("OnScopeStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
507 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
508
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
509 assert(statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
510 //statement->toIR(p); // this seems to be redundant
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
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
513 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
514
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
515 void TryFinallyStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
516 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
517 Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
518 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
519
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
520 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
521 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
522
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
523 // create basic blocks
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
524 llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
525
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
526 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
527 llvm::BasicBlock* finallybb = llvm::BasicBlock::Create("finally", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
528 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endtryfinally", p->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
529
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
530 // 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
531 assert(!gIR->scopereturned());
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
532 llvm::BranchInst::Create(trybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
533
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
534 // do the try block
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
535 p->scope() = IRScope(trybb,finallybb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
536
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
537 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
538 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
539
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
540 // 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
541 if (!p->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
542 llvm::BranchInst::Create(finallybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
543
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
544 // do finally block
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
545 p->scope() = IRScope(finallybb,endbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
546 assert(finalbody);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
547 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
548
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
549 // 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
550 if (!gIR->scopereturned()) {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
551 llvm::BranchInst::Create(endbb, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
552 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
553
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
554 // rewrite the scope
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
555 p->scope() = IRScope(endbb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
556 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
557
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
558 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
559
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
560 void TryCatchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
561 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
562 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
563 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
564
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
565 Logger::attention(loc, "try-catch is not yet fully implemented");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
566
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
567 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
568 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
569
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
570 // create basic blocks
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
571 llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
572
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
573 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
574 llvm::BasicBlock* catchbb = llvm::BasicBlock::Create("catch", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
575 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endtrycatch", p->topfunc(), oldend);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
576
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
577 // pass the previous BB into this
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
578 assert(!gIR->scopereturned());
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
579 llvm::BranchInst::Create(trybb, p->scopebb());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
580
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
581 // do the try block
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
582 p->scope() = IRScope(trybb,catchbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
583 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
584 body->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
585
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
586 if (!gIR->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
587 llvm::BranchInst::Create(endbb, p->scopebb());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
588
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
589 // do catch
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
590 p->scope() = IRScope(catchbb,oldend);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
591 llvm::BranchInst::Create(endbb, p->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
592 /*assert(catches);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
593 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
594 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
595 Catch* c = (Catch*)catches->data[i];
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
596 c->handler->toIR(p);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
597 }*/
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
598
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
599 // rewrite the scope
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
600 p->scope() = IRScope(endbb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
601 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
602
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
603 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
604
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
605 void ThrowStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
606 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
607 Logger::println("ThrowStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
608 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
609
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
610 Logger::attention(loc, "throw is not yet fully implemented");
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
611
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
612 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
613 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
614
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
615 assert(exp);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
616 DValue* e = exp->toElem(p);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
617 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
618 //Logger::cout() << "calling: " << *fn << '\n';
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
619 LLValue* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
620 //Logger::cout() << "arg: " << *arg << '\n';
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
621 gIR->ir->CreateCall(fn, arg, "");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
622 gIR->ir->CreateUnreachable();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
623 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
624
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
625 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
626
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
627 // used to build the sorted list of cases
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
628 struct Case : Object
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
629 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
630 StringExp* str;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
631 size_t index;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
632
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
633 Case(StringExp* s, size_t i) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
634 str = s;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
635 index = i;
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
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
638 int compare(Object *obj) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
639 Case* c2 = (Case*)obj;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
640 return str->compare(c2->str);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
641 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
642 };
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
643
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
644 static LLValue* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e)
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
645 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
646 Type* dt = DtoDType(e->type);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
647 Type* dtnext = DtoDType(dt->next);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
648 TY ty = dtnext->ty;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
649 const char* fname;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
650 if (ty == Tchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
651 fname = "_d_switch_string";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
652 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
653 else if (ty == Twchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
654 fname = "_d_switch_ustring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
655 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
656 else if (ty == Tdchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
657 fname = "_d_switch_dstring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
658 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
659 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
660 assert(0 && "not char/wchar/dchar");
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
661 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
662
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
663 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
664
197
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
665 Logger::cout() << *table->getType() << '\n';
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
666 Logger::cout() << *fn->getFunctionType()->getParamType(0) << '\n';
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
667 assert(table->getType() == fn->getFunctionType()->getParamType(0));
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
668
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
669 DValue* val = e->toElem(gIR);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
670 LLValue* llval;
197
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
671 if (DSliceValue* sval = val->isSlice())
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
672 {
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
673 // give storage
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
674 llval = new llvm::AllocaInst(DtoType(e->type), "tmp", gIR->topallocapoint());
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
675 DVarValue* vv = new DVarValue(e->type, llval, true);
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
676 DtoAssign(vv, val);
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
677 }
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
678 else
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
679 {
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
680 llval = val->getRVal();
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
681 }
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
682 assert(llval->getType() == fn->getFunctionType()->getParamType(1));
bfcb657756f6 [svn r213] Fixed: foreach on an object seems to have been broken, the issue was that DMD generates an implicit delegate with conflicting types for 'this'.
lindquist
parents: 185
diff changeset
683
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
684 llvm::CallInst* call = gIR->ir->CreateCall2(fn, table, llval, "tmp");
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
685
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
686 llvm::PAListPtr palist;
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
687 palist = palist.addAttr(1, llvm::ParamAttr::ByVal);
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
688 palist = palist.addAttr(2, llvm::ParamAttr::ByVal);
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
689 call->setParamAttrs(palist);
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
690
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
691 return call;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
692 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
693
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
694 void SwitchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
695 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
696 Logger::println("SwitchStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
697 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
698
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
699 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
700 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
701
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
702 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
703
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
704 // clear data from previous passes... :/
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
705 for (int i=0; i<cases->dim; ++i)
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
706 {
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
707 CaseStatement* cs = (CaseStatement*)cases->data[i];
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
708 cs->bodyBB = NULL;
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
709 cs->llvmIdx = NULL;
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
710 }
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
711
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
712 // string switch?
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
713 llvm::GlobalVariable* switchTable = 0;
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
714 Array caseArray;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
715 if (!condition->type->isintegral())
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
716 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
717 Logger::println("is string switch");
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
718 // build array of the stringexpS
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
719 caseArray.reserve(cases->dim);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
720 for (int i=0; i<cases->dim; ++i)
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
721 {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
722 CaseStatement* cs = (CaseStatement*)cases->data[i];
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
723
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
724 assert(cs->exp->op == TOKstring);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
725 caseArray.push(new Case((StringExp*)cs->exp, i));
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
726 }
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
727 // first sort it
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
728 caseArray.sort();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
729 // iterate and add indices to cases
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
730 std::vector<LLConstant*> inits(caseArray.dim);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
731 for (size_t i=0; i<caseArray.dim; ++i)
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
732 {
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
733 Case* c = (Case*)caseArray.data[i];
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
734 CaseStatement* cs = (CaseStatement*)cases->data[c->index];
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
735 cs->llvmIdx = DtoConstUint(i);
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
736 inits[i] = c->str->toConstElem(p);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
737 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
738 // build static array for ptr or final array
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
739 const LLType* elemTy = DtoType(condition->type);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
740 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
741 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits);
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
742 llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, ".string_switch_table_data", gIR->module);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
743
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
744 const LLType* elemPtrTy = getPtrToType(elemTy);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
745 LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
746
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
747 // build the static table
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
748 std::vector<const LLType*> types;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
749 types.push_back(DtoSize_t());
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
750 types.push_back(elemPtrTy);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
751 const llvm::StructType* sTy = llvm::StructType::get(types);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
752 std::vector<LLConstant*> sinits;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
753 sinits.push_back(DtoConstSize_t(inits.size()));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
754 sinits.push_back(arrPtr);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
755 LLConstant* sInit = llvm::ConstantStruct::get(sTy, sinits);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
756
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
757 switchTable = new llvm::GlobalVariable(sTy, true, llvm::GlobalValue::InternalLinkage, sInit, ".string_switch_table", gIR->module);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
758 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
759
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
760 // body block
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
761 llvm::BasicBlock* bodybb = llvm::BasicBlock::Create("switchbody", p->topfunc(), oldend);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
762
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
763 // default
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
764 llvm::BasicBlock* defbb = 0;
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
765 if (sdefault) {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
766 Logger::println("has default");
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
767 defbb = llvm::BasicBlock::Create("default", p->topfunc(), oldend);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
768 sdefault->bodyBB = defbb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
769 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
770
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
771 // end (break point)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
772 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("switchend", p->topfunc(), oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
773
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
774 // condition var
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
775 LLValue* condVal;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
776 // integral switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
777 if (condition->type->isintegral()) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
778 DValue* cond = condition->toElem(p);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
779 condVal = cond->getRVal();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
780 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
781 // string switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
782 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
783 condVal = call_string_switch_runtime(switchTable, condition);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
784 }
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
785 llvm::SwitchInst* si = llvm::SwitchInst::Create(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
786
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
787 // do switch body
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
788 assert(body);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
789
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
790 p->scope() = IRScope(bodybb, endbb);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
791 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb));
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
792 body->toIR(p);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
793 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
794
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
795 if (!p->scopereturned())
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
796 llvm::BranchInst::Create(endbb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
797
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
798 // add the cases
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
799 for (int i=0; i<cases->dim; ++i)
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
800 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
801 CaseStatement* cs = (CaseStatement*)cases->data[i];
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
802 si->addCase(cs->llvmIdx, cs->bodyBB);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
803 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
804
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
805 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
806 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
807
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
808 //////////////////////////////////////////////////////////////////////////////
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
809 void CaseStatement::toIR(IRState* p)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
810 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
811 Logger::println("CaseStatement::toIR(): %s", loc.toChars());
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
812 LOG_SCOPE;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
813
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
814 llvm::BasicBlock* nbb = llvm::BasicBlock::Create("case", p->topfunc(), p->scopeend());
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
815
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
816 if (bodyBB && !bodyBB->getTerminator())
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
817 {
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
818 llvm::BranchInst::Create(nbb, bodyBB);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
819 }
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
820 bodyBB = nbb;
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
821
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
822 if (llvmIdx == NULL) {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
823 LLConstant* c = exp->toConstElem(p);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
824 llvmIdx = isaConstantInt(c);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
825 }
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
826
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
827 if (!p->scopereturned())
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
828 llvm::BranchInst::Create(bodyBB, p->scopebb());
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
829
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
830 p->scope() = IRScope(bodyBB, p->scopeend());
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
831
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
832 assert(statement);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
833 statement->toIR(p);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
834 }
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
835
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
836 //////////////////////////////////////////////////////////////////////////////
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
837 void DefaultStatement::toIR(IRState* p)
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
838 {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
839 Logger::println("DefaultStatement::toIR(): %s", loc.toChars());
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
840 LOG_SCOPE;
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
841
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
842 assert(bodyBB);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
843
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
844 llvm::BasicBlock* nbb = llvm::BasicBlock::Create("default", p->topfunc(), p->scopeend());
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
845
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
846 if (!bodyBB->getTerminator())
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
847 {
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
848 llvm::BranchInst::Create(nbb, bodyBB);
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
849 }
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
850 bodyBB = nbb;
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
851
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
852 if (!p->scopereturned())
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
853 llvm::BranchInst::Create(bodyBB, p->scopebb());
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
854
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
855 p->scope() = IRScope(bodyBB, p->scopeend());
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
856
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
857 assert(statement);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
858 statement->toIR(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
859 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
860
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
861 //////////////////////////////////////////////////////////////////////////////
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
862
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
863 void UnrolledLoopStatement::toIR(IRState* p)
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
864 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
865 Logger::println("UnrolledLoopStatement::toIR(): %s", loc.toChars());
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
866 LOG_SCOPE;
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
867
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
868 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
869 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
870
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
871 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
872 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("unrolledend", p->topfunc(), oldend);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
873
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
874 p->scope() = IRScope(p->scopebb(),endbb);
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
875 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb));
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
876
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
877 for (int i=0; i<statements->dim; ++i)
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
878 {
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
879 Statement* s = (Statement*)statements->data[i];
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
880 s->toIR(p);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
881 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
882
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
883 p->loopbbs.pop_back();
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
884
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
885 llvm::BranchInst::Create(endbb, p->scopebb());
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
886 p->scope() = IRScope(endbb,oldend);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
887 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
888
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
889 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
890
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
891 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
892 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
893 Logger::println("ForeachStatement::toIR(): %s", loc.toChars());
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
894 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
895
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
896 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
897 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
898
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
899 //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
900 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
901 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
902 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
903 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
904
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
905 //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
906 //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
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 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
909
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
910 // key
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
911 const LLType* keytype = key ? DtoType(key->type) : DtoSize_t();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
912 LLValue* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
913 if (key)
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
914 {
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
915 //key->llvmValue = keyvar;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
916 assert(!key->ir.irLocal);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
917 key->ir.irLocal = new IrLocal(key);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
918 key->ir.irLocal->value = keyvar;
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
919 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
920 LLValue* 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
921
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
922 // value
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 200
diff changeset
923 Logger::println("value = %s", value->toPrettyChars());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
924 const LLType* valtype = DtoType(value->type);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
925 LLValue* valvar = NULL;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
926 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
927 valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint());
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 200
diff changeset
928 if (!value->ir.irLocal)
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 200
diff changeset
929 value->ir.irLocal = new IrLocal(value);
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
930
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
931 // what to iterate
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
932 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
933 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
934
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
935 // get length and pointer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
936 LLValue* val = 0;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
937 LLValue* niters = 0;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
938
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
939 // static array
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
940 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
941 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
942 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
943 val = aggrval->getRVal();
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
944 assert(isaPointer(val->getType()));
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
945 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
946 assert(arrty);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
947 size_t nelems = arrty->getNumElements();
200
e937752e4541 [svn r216] don't crash on foreach over zero-length static array
ChristianK
parents: 197
diff changeset
948 if(nelems == 0)
e937752e4541 [svn r216] don't crash on foreach over zero-length static array
ChristianK
parents: 197
diff changeset
949 return;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
950 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
951 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
952 // dynamic array
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
953 else if (aggrtype->ty == Tarray)
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
954 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
955 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
956 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
957 niters = slice->len;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
958 assert(niters);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
959 val = slice->ptr;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
960 assert(val);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
961 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
962 else {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
963 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
964 val = aggrval->getRVal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
965 niters = DtoGEPi(val,0,0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
966 niters = DtoLoad(niters, "numiterations");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
967 val = DtoGEPi(val,0,1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
968 val = DtoLoad(val, "collection");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
969 }
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
970 }
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
971 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
972 {
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
973 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
974 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
975
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
976 if (niters->getType() != keytype)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
977 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
978 size_t sz1 = getTypeBitSize(niters->getType());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
979 size_t sz2 = getTypeBitSize(keytype);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
980 if (sz1 < sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
981 niters = gIR->ir->CreateZExt(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
982 else if (sz1 > sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
983 niters = gIR->ir->CreateTrunc(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
984 else
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
985 niters = gIR->ir->CreateBitCast(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
986 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
987
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
988 LLConstant* delta = 0;
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
989 if (op == TOKforeach) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
990 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
991 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
992 else {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
993 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
994 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
995
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
996 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
997 llvm::BasicBlock* condbb = llvm::BasicBlock::Create("foreachcond", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
998 llvm::BasicBlock* bodybb = llvm::BasicBlock::Create("foreachbody", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
999 llvm::BasicBlock* nextbb = llvm::BasicBlock::Create("foreachnext", p->topfunc(), oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1000 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("foreachend", 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
1001
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1002 llvm::BranchInst::Create(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
1003
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1004 // condition
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1005 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
1006
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1007 LLValue* done = 0;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
1008 LLValue* load = DtoLoad(keyvar);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1009 if (op == TOKforeach) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1010 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
1011 }
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1012 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
1013 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
1014 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
1015 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
1016 }
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1017 llvm::BranchInst::Create(bodybb, endbb, done, p->scopebb());
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1018
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1019 // init body
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1020 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
1021
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1022 // get value for this iteration
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1023 LLConstant* zero = llvm::ConstantInt::get(keytype,0,false);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1024 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
1025 if (aggrtype->ty == Tsarray)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1026 value->ir.irLocal->value = DtoGEP(val,zero,loadedKey,"tmp");
45
ff359b65fa62 [svn r49] foreach on dynamic arrays
lindquist
parents: 40
diff changeset
1027 else if (aggrtype->ty == Tarray)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1028 value->ir.irLocal->value = llvm::GetElementPtrInst::Create(val,loadedKey,"tmp",p->scopebb());
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
1029
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1030 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
1031 DValue* dst = new DVarValue(value->type, valvar, true);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1032 DValue* src = new DVarValue(value->type, value->ir.irLocal->value, true);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1033 DtoAssign(dst, src);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1034 value->ir.irLocal->value = valvar;
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
1035 }
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
1036
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1037 // emit body
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1038 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,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
1039 body->toIR(p);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1040 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
1041
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1042 if (!p->scopereturned())
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1043 llvm::BranchInst::Create(nextbb, p->scopebb());
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1044
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1045 // next
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1046 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
1047 if (op == TOKforeach) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1048 LLValue* load = DtoLoad(keyvar);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1049 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
1050 DtoStore(load, keyvar);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1051 }
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1052 llvm::BranchInst::Create(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
1053
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1054 // 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
1055 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
1056 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1057
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1058 //////////////////////////////////////////////////////////////////////////////
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1059
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1060 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
1061 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1062 Logger::println("LabelStatement::toIR(): %s", loc.toChars());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1063 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1064
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1065 // if it's an inline asm label, we don't create a basicblock, just emit it in the asm
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
1066 if (p->asmBlock)
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1067 {
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1068 IRAsmStmt* a = new IRAsmStmt;
299
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 298
diff changeset
1069 // a->code = ".LDASM_";
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1070 a->code += ident->toChars();
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1071 a->code += ":";
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
1072 p->asmBlock->s.push_back(a);
299
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 298
diff changeset
1073 p->asmBlock->internalLabels.push_back(ident);
298
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1074 }
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1075 else
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1076 {
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1077
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1078 assert(tf == NULL);
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1079
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1080 llvm::BasicBlock* oldend = gIR->scopeend();
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1081 if (llvmBB)
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1082 llvmBB->moveBefore(oldend);
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1083 else
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1084 llvmBB = llvm::BasicBlock::Create("label", p->topfunc(), oldend);
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1085
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1086 if (!p->scopereturned())
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1087 llvm::BranchInst::Create(llvmBB, p->scopebb());
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1088
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1089 p->scope() = IRScope(llvmBB,oldend);
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1090 }
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1091
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1092 if (statement)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1093 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
1094 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1095
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1096 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1097
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1098 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
1099 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1100 Logger::println("GotoStatement::toIR(): %s", loc.toChars());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1101 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1102
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1103 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1104 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1105
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1106 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
1107
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1108 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1109 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergoto", p->topfunc(), oldend);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1110
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1111 if (label->statement->llvmBB == NULL)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1112 label->statement->llvmBB = llvm::BasicBlock::Create("label", p->topfunc());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1113 assert(!p->scopereturned());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1114
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1115 // find finallys between goto and label
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1116 TryFinallyStatement* endfinally = enclosingtryfinally;
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1117 while(endfinally != NULL && endfinally != label->statement->enclosingtryfinally) {
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1118 endfinally = endfinally->enclosingtryfinally;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1119 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1120
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1121 // error if didn't find tf statement of label
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1122 if(endfinally != label->statement->enclosingtryfinally)
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1123 error("cannot goto into try block", loc.toChars());
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1124
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1125 // emit code for finallys between goto and label
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1126 emit_finallyblocks(p, enclosingtryfinally, endfinally);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1127
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1128 llvm::BranchInst::Create(label->statement->llvmBB, p->scopebb());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1129 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
1130 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1131
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1132 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1133
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1134 void GotoDefaultStatement::toIR(IRState* p)
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1135 {
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1136 Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars());
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1137 LOG_SCOPE;
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1138
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1139 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1140 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1141
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1142 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1143 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotodefault", p->topfunc(), oldend);
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1145 assert(!p->scopereturned());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1146 assert(sw->sdefault->bodyBB);
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1147
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1148 emit_finallyblocks(p, enclosingtryfinally, sw->enclosingtryfinally);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1149
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1150 llvm::BranchInst::Create(sw->sdefault->bodyBB, p->scopebb());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1151 p->scope() = IRScope(bb,oldend);
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1152 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1153
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1154 //////////////////////////////////////////////////////////////////////////////
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1155
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1156 void GotoCaseStatement::toIR(IRState* p)
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1157 {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1158 Logger::println("GotoCaseStatement::toIR(): %s", loc.toChars());
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1159 LOG_SCOPE;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1160
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1161 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1162 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1163
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1164 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1165 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftergotocase", p->topfunc(), oldend);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1166
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1167 assert(!p->scopereturned());
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
1168 if (!cs->bodyBB)
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
1169 {
263
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
1170 cs->bodyBB = llvm::BasicBlock::Create("goto_case", p->topfunc(), p->scopeend());
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
1171 }
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1172
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 146
diff changeset
1173 emit_finallyblocks(p, enclosingtryfinally, sw->enclosingtryfinally);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1174
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1175 llvm::BranchInst::Create(cs->bodyBB, p->scopebb());
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1176 p->scope() = IRScope(bb,oldend);
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1177 }
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1178
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1179 //////////////////////////////////////////////////////////////////////////////
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1180
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1181 void WithStatement::toIR(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1182 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1183 Logger::println("WithStatement::toIR(): %s", loc.toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1184 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1185
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1186 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1187 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1188
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1189 assert(exp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1190 assert(body);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1191
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1192 DValue* e = exp->toElem(p);
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
1193 assert(!wthis->ir.isSet());
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
1194 wthis->ir.irLocal = new IrLocal(wthis);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1195 wthis->ir.irLocal->value = e->getRVal();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1196
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1197 body->toIR(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1198 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1199
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1200 //////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1201
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1202 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
1203 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1204 Logger::println("SynchronizedStatement::toIR(): %s", loc.toChars());
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1205 LOG_SCOPE;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1206
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1207 Logger::attention(loc, "synchronized is currently ignored. only the body will be emitted");
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1208
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1209 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1210 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1211
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1212 body->toIR(p);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1213 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1214
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1215 //////////////////////////////////////////////////////////////////////////////
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1216
219
761c8352f494 [svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents: 217
diff changeset
1217 /* this has moved to asmstmt.cpp
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1218 void AsmStatement::toIR(IRState* p)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1219 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1220 Logger::println("AsmStatement::toIR(): %s", loc.toChars());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1221 LOG_SCOPE;
219
761c8352f494 [svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents: 217
diff changeset
1222 // error("%s: inline asm is not yet implemented", loc.toChars());
761c8352f494 [svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents: 217
diff changeset
1223 // fatal();
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1224
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1225 assert(!asmcode && !asmalign && !refparam && !naked && !regs);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1226
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1227 Token* t = tokens;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1228 assert(t);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1229
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1230 std::string asmstr;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1231
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1232 do {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1233 Logger::println("token: %s", t->toChars());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1234 asmstr.append(t->toChars());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1235 asmstr.append(" ");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1236 } while (t = t->next);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1237
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1238 Logger::println("asm expr = '%s'", asmstr.c_str());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1239
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1240 // create function type
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1241 std::vector<const LLType*> args;
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1242 const llvm::FunctionType* fty = llvm::FunctionType::get(DtoSize_t(), args, false);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1243
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1244 // create inline asm callee
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1245 llvm::InlineAsm* inasm = llvm::InlineAsm::get(fty, asmstr, "r,r", false);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1246
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1247 assert(0);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1248 }
219
761c8352f494 [svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents: 217
diff changeset
1249 */
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1250 //////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1251
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1252 void VolatileStatement::toIR(IRState* p)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1253 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1254 Logger::println("VolatileStatement::toIR(): %s", loc.toChars());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1255 LOG_SCOPE;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1256
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1257 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1258 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1259
206
cd2c9f4010e4 [svn r222] Forgot to remove volatile ATTENTION.
lindquist
parents: 205
diff changeset
1260 // mark in-volatile
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1261 bool old = gIR->func()->inVolatile;
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1262 gIR->func()->inVolatile = true;
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1263
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1264 // has statement
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1265 if (statement != NULL)
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1266 {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1267 // load-store
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1268 DtoMemoryBarrier(false, true, false, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1269
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1270 // do statement
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1271 statement->toIR(p);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1272
206
cd2c9f4010e4 [svn r222] Forgot to remove volatile ATTENTION.
lindquist
parents: 205
diff changeset
1273 // no point in a unreachable barrier, terminating statements should insert this themselves.
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1274 if (statement->fallOffEnd())
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1275 {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1276 // store-load
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1277 DtoMemoryBarrier(false, false, true, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1278 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1279 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1280 // barrier only
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1281 else
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1282 {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1283 // load-store & store-load
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1284 DtoMemoryBarrier(false, true, true, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1285 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1286
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1287 // restore volatile state
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 201
diff changeset
1288 gIR->func()->inVolatile = old;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1289 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1290
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1291 //////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1292
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1293 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1294
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1295 #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
1296 //STUBST(BreakStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1297 //STUBST(ForStatement);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1298 //STUBST(WithStatement);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1299 //STUBST(SynchronizedStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1300 //STUBST(ReturnStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1301 //STUBST(ContinueStatement);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
1302 //STUBST(DefaultStatement);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1303 //STUBST(CaseStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1304 //STUBST(SwitchStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1305 STUBST(SwitchErrorStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1306 STUBST(Statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1307 //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
1308 //STUBST(ForeachStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1309 //STUBST(DoStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1310 //STUBST(WhileStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1311 //STUBST(ExpStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1312 //STUBST(CompoundStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1313 //STUBST(ScopeStatement);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1314 //STUBST(AsmStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1315 //STUBST(TryCatchStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1316 //STUBST(TryFinallyStatement);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1317 //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
1318 //STUBST(LabelStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1319 //STUBST(ThrowStatement);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1320 //STUBST(GotoCaseStatement);
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1321 //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
1322 //STUBST(GotoStatement);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1323 //STUBST(UnrolledLoopStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1324 //STUBST(OnScopeStatement);