annotate gen/statements.cpp @ 922:0749c0757a43

Apply naked changes of [920] to dmd2/
author Christian Kamm <kamm incasoftware de>
date Tue, 03 Feb 2009 18:11:39 +0100
parents 545f54041d91
children 03d7c4aac654
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 <fstream>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
6 #include <iostream>
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
7
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
8 #include "gen/llvm.h"
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
9 #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
10 #include "llvm/Support/CFG.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
11
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
12 #include "mars.h"
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
13 #include "total.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
14 #include "init.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
15 #include "mtype.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
16 #include "hdrgen.h"
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
17 #include "port.h"
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 652
diff changeset
18 #include "module.h"
14
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"
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 652
diff changeset
30 #include "ir/irmodule.h"
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
31 #include "ir/irlandingpad.h"
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
32
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
33 //////////////////////////////////////////////////////////////////////////////
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
34
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
35 void CompoundStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
36 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
37 Logger::println("CompoundStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
38 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
39
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
40 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
41 {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
42 Statement* s = (Statement*)statements->data[i];
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
43 if (s) {
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
44 s->toIR(p);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 33
diff changeset
45 }
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
46 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
47 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
48
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
49
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
50 //////////////////////////////////////////////////////////////////////////////
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
51
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
52 void ReturnStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
53 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
54 Logger::println("ReturnStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
55 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
56
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
57 if (exp)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
58 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
59 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
60 IrFunction* f = p->func();
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
61 assert(f->type->retInPtr);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
62 assert(f->decl->ir.irFunc->retArg);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
63
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
64 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
65
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 519
diff changeset
66 DValue* rvar = new DVarValue(f->type->next, f->decl->ir.irFunc->retArg);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
67
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
68 DValue* e = exp->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
69
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
70 DtoAssign(loc, rvar, e);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
71
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
72 DtoEnclosingHandlers(enclosinghandler, 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
73
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
74 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
75 llvm::ReturnInst::Create(p->scopebb());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
76
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
77 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
78 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
79 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
80 DValue* e = exp->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
81 LLValue* v = e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
82 delete e;
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
83
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
84 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
85 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
86
611
83ca663ecc20 Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents: 610
diff changeset
87 // can happen for classes
185
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
88 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
89 {
611
83ca663ecc20 Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents: 610
diff changeset
90 v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp");
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
91 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
92 Logger::cout() << "return value after cast: " << *v << '\n';
185
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
93 }
89e21eeaf4c4 [svn r201] Fixed: return statement could fail codegen with type mismatch for classes, added cast.
lindquist
parents: 181
diff changeset
94
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
95 DtoEnclosingHandlers(enclosinghandler, 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
96
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
97 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
98 llvm::ReturnInst::Create(v, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
99 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
100 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
101 else
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
102 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
103 assert(p->topfunc()->getReturnType() == LLType::VoidTy);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
104 DtoEnclosingHandlers(enclosinghandler, NULL);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
105
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
106 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
107 llvm::ReturnInst::Create(p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
108 }
267
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
109
c43911baea21 [svn r288] Let return statements start a new basic block after terminating the current one.
ChristianK
parents: 263
diff changeset
110 // 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
111 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
112 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
113 p->scope() = IRScope(bb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
114 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
115
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
116 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
117
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
118 void ExpStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
119 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
120 Logger::println("ExpStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
121 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
122
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
123 if (global.params.symdebug)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
124 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
125
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
126 if (exp) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
127 if (global.params.llvmAnnotate)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
128 DtoAnnotation(exp->toChars());
518
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
129 elem* e;
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
130 // a cast(void) around the expression is allowed, but doesn't require any code
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
131 if(exp->op == TOKcast && exp->type == Type::tvoid) {
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
132 CastExp* cexp = (CastExp*)exp;
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
133 e = cexp->e1->toElem(p);
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
134 }
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
135 else
243485af6523 Prevent cast error for cast(void) around expression statements.
Christian Kamm <kamm incasoftware de>
parents: 517
diff changeset
136 e = exp->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
137 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
138 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
139 /*elem* e = exp->toElem(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
140 p->buf.printf("%s", e->toChars());
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
141 delete e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
142 p->buf.writenl();*/
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
143 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
144
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
145 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
146
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
147 void IfStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
148 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
149 Logger::println("IfStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
150 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
151
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
152 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
153 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
154
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
155 if (match)
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 745
diff changeset
156 DtoRawVarDeclaration(match);
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 156
diff changeset
157
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
158 DValue* cond_e = condition->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
159 LLValue* cond_val = cond_e->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
160
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
161 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
162
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
163 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
164 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
165 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
166
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
167 if (cond_val->getType() != LLType::Int1Ty) {
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
168 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
169 Logger::cout() << "if conditional: " << *cond_val << '\n';
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 774
diff changeset
170 cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
171 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
172 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
173
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
174 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
175 gIR->scope() = IRScope(ifbb,elsebb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
176
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
177 // do scoped statements
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
178 if (ifbody)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
179 ifbody->toIR(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
180 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
181 llvm::BranchInst::Create(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
182 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
183
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
184 if (elsebody) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
185 //assert(0);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
186 gIR->scope() = IRScope(elsebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
187 elsebody->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
188 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
189 llvm::BranchInst::Create(endbb,gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
190 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
191 }
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 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
194 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
195 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
196
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
197 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
198
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
199 void ScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
200 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
201 Logger::println("ScopeStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
202 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
203
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
204 /*llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
205
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
206 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
207
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
208 // 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
209 llvm::BasicBlock* bb = p->scopebb();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
210 if (bb->empty()) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
211 beginbb = bb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
212 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
213 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
214 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
215 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
216 llvm::BranchInst::Create(beginbb, bb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
217 }
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
218
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
219 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
220 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
221 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
222 else
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
223 p->scope().end = endbb;*/
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
224
181
ef4108f34db6 [svn r197] Fixed: empty scope statement segfaulted.
lindquist
parents: 175
diff changeset
225 if (statement)
ef4108f34db6 [svn r197] Fixed: empty scope statement segfaulted.
lindquist
parents: 175
diff changeset
226 statement->toIR(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
227
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
228 /*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
229 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
230 endbb->eraseFromParent();*/
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
231 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
232
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
233 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
234
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
235 void WhileStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
236 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
237 Logger::println("WhileStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
238 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
239
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
240 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
241 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
242
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
243 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
244 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
245 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
246 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
247 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
248
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
249 // move into the while block
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
250 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
251 //llvm::BranchInst::Create(whilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
252
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
253 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
254 gIR->scope() = IRScope(whilebb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
255
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
256 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
257 DValue* cond_e = condition->toElem(p);
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 774
diff changeset
258 LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
259 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
260
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
261 // conditional branch
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
262 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
263
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
264 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
265 gIR->scope() = IRScope(whilebodybb,endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
266
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
267 // while body code
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
268 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,whilebb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
269 body->toIR(p);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
270 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
271
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
272 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
273 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
274 llvm::BranchInst::Create(whilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
275
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
276 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
277 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
278 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
279
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
280 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
281
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
282 void DoStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
283 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
284 Logger::println("DoStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
285 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
286
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
287 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
288 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
289
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
290 // create while blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
291 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
292 llvm::BasicBlock* dowhilebb = llvm::BasicBlock::Create("dowhile", gIR->topfunc(), oldend);
517
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
293 llvm::BasicBlock* condbb = llvm::BasicBlock::Create("dowhilecond", gIR->topfunc(), 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
294 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
295
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
296 // move into the while block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
297 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
298 llvm::BranchInst::Create(dowhilebb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
299
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
300 // replace current scope
517
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
301 gIR->scope() = IRScope(dowhilebb,condbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
302
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
303 // do-while body code
517
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
304 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,condbb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
305 body->toIR(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
306 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
307
517
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
308 // branch to condition block
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
309 llvm::BranchInst::Create(condbb, gIR->scopebb());
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
310 gIR->scope() = IRScope(condbb,endbb);
9534dbc70a56 Fix continue inside dowhile statements.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
311
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
312 // create the condition
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
313 DValue* cond_e = condition->toElem(p);
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 774
diff changeset
314 LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
315 delete cond_e;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
316
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
317 // conditional branch
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
318 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
319
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
320 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
321 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
322 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
323
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
324 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
325
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
326 void ForStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
327 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
328 Logger::println("ForStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
329 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
330
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
331 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
332 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
333
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
334 // create for blocks
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
335 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
336 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
337 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
338 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
339 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
340
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
341 // init
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
342 if (init != 0)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
343 init->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
344
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
345 // move into the for condition block, ie. start the loop
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
346 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
347 llvm::BranchInst::Create(forbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
348
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
349 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,forincbb,endbb));
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
350
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
351 // replace current scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
352 gIR->scope() = IRScope(forbb,forbodybb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
353
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
354 // create the condition
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
355 LLValue* cond_val;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
356 if (condition)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
357 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
358 DValue* cond_e = condition->toElem(p);
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 774
diff changeset
359 cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
360 delete cond_e;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
361 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
362 else
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
363 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
364 cond_val = DtoConstBool(true);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
365 }
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 // conditional branch
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
368 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
369 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
370
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
371 // rewrite scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
372 gIR->scope() = IRScope(forbodybb,forincbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
373
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
374 // do for body code
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
375 body->toIR(p);
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 // move into the for increment block
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
378 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
379 llvm::BranchInst::Create(forincbb, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
380 gIR->scope() = IRScope(forincbb, endbb);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
381
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
382 // increment
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
383 if (increment) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
384 DValue* inc = increment->toElem(p);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
385 delete inc;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
386 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
387
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
388 // loop
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
389 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
390 llvm::BranchInst::Create(forbb, gIR->scopebb());
14
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 p->loopbbs.pop_back();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
393
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
394 // rewrite the scope
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
395 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
396 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
397
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
398 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
399
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
400 void BreakStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
401 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
402 Logger::println("BreakStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
403 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
404
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
405 // 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
406 // 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
407 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
408 return;
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
409
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
410 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
411 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
412
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
413 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
414 Logger::println("ident = %s", ident->toChars());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
415
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
416 DtoEnclosingHandlers(enclosinghandler, target->enclosinghandler);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
417
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
418 // get the loop statement the label refers to
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
419 Statement* targetLoopStatement = target->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
420 ScopeStatement* tmp;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
421 while(tmp = targetLoopStatement->isScopeStatement())
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
422 targetLoopStatement = tmp->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
423
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
424 // 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
425 bool found = false;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
426 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
427 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
428 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
429 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
430 found = true;
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
431 break;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
432 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
433 }
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
434 assert(found);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
435 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
436 else {
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
437 DtoEnclosingHandlers(enclosinghandler, p->loopbbs.back().enclosinghandler);
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
438 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
439 }
270
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
440
d9d5d59873d8 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents: 268
diff changeset
441 // 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
442 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
443 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
444 p->scope() = IRScope(bb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
445 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
446
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
447 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
448
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
449 void ContinueStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
450 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
451 Logger::println("ContinueStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
452 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
453
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
454 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
455 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
456
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
457 if (ident != 0) {
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
458 Logger::println("ident = %s", ident->toChars());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
459
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
460 DtoEnclosingHandlers(enclosinghandler, target->enclosinghandler);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
461
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
462 // get the loop statement the label refers to
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
463 Statement* targetLoopStatement = target->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
464 ScopeStatement* tmp;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
465 while(tmp = targetLoopStatement->isScopeStatement())
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
466 targetLoopStatement = tmp->statement;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
467
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
468 // find the right continue block and jump there
395
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
469 bool found = false;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
470 IRState::LoopScopeVec::reverse_iterator it;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
471 for(it = gIR->loopbbs.rbegin(); it != gIR->loopbbs.rend(); ++it) {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
472 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
473 llvm::BranchInst::Create(it->begin, gIR->scopebb());
395
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
474 found = true;
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
475 break;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
476 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
477 }
395
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
478 assert(found);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
479 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
480 else {
311
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
481 // can't 'continue' within switch, so omit them
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
482 IRState::LoopScopeVec::reverse_iterator it;
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
483 for(it = gIR->loopbbs.rbegin(); it != gIR->loopbbs.rend(); ++it) {
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
484 if(!it->isSwitch) {
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
485 break;
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
486 }
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
487 }
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
488 DtoEnclosingHandlers(enclosinghandler, it->enclosinghandler);
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
489 llvm::BranchInst::Create(it->begin, gIR->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
490 }
395
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
491
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
492 // the continue terminated this basicblock, start a new one
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
493 llvm::BasicBlock* oldend = gIR->scopeend();
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
494 llvm::BasicBlock* bb = llvm::BasicBlock::Create("aftercontinue", p->topfunc(), oldend);
71a40b62b408 Start a new basic block after a continue statement.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
495 p->scope() = IRScope(bb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
496 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
497
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
498 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
499
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
500 void OnScopeStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
501 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
502 Logger::println("OnScopeStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
503 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
504
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
505 assert(statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
506 //statement->toIR(p); // this seems to be redundant
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
507 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
508
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
509 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
510
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
511 void TryFinallyStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
512 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
513 Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
514 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
515
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
516 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
517 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
518
652
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
519 // if there's no finalbody or no body, things are simple
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
520 if (!finalbody) {
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
521 if (body)
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
522 body->toIR(p);
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
523 return;
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
524 }
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
525 if (!body) {
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
526 finalbody->toIR(p);
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
527 return;
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
528 }
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
529
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
530 // create basic blocks
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
531 llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
532
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
533 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
534 llvm::BasicBlock* finallybb = llvm::BasicBlock::Create("finally", p->topfunc(), oldend);
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
535 // the landing pad for statements in the try block
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
536 llvm::BasicBlock* landingpadbb = llvm::BasicBlock::Create("landingpad", p->topfunc(), 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
537 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
538
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
539 // 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
540 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
541 llvm::BranchInst::Create(trybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
542
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
543 //
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
544 // set up the landing pad
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
545 //
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
546 p->scope() = IRScope(landingpadbb, endbb);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
547
652
c8fcde3337b0 Fix TryFinally without body or finalbody.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
548 assert(finalbody);
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
549 gIR->func()->landingPad.addFinally(finalbody);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
550 gIR->func()->landingPad.push(landingpadbb);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
551
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
552 //
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
553 // do the try block
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
554 //
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
555 p->scope() = IRScope(trybb,finallybb);
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 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
558 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
559
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
560 // 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
561 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
562 llvm::BranchInst::Create(finallybb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
563
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
564 gIR->func()->landingPad.pop();
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
565
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
566 //
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
567 // do finally block
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
568 //
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
569 p->scope() = IRScope(finallybb,landingpadbb);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
570 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
571
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
572 // terminate finally
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
573 //TODO: isn't it an error to have a 'returned' finally block?
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
574 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
575 llvm::BranchInst::Create(endbb, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
576 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
577
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
578 // rewrite the scope
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
579 p->scope() = IRScope(endbb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
580 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
581
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
582 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
583
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
584 void TryCatchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
585 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
586 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
587 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
588
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
589 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
590 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
591
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
592 // create basic blocks
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
593 llvm::BasicBlock* oldend = p->scopeend();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
594
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
595 llvm::BasicBlock* trybb = llvm::BasicBlock::Create("try", p->topfunc(), oldend);
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
596 // the landing pad will be responsible for branching to the correct catch block
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
597 llvm::BasicBlock* landingpadbb = llvm::BasicBlock::Create("landingpad", p->topfunc(), 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
598 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
599
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
600 // 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
601 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
602 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
603
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
604 //
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
605 // do catches and the landing pad
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
606 //
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
607 assert(catches);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
608 gIR->scope() = IRScope(landingpadbb, endbb);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
609
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
610 for (int i = 0; i < catches->dim; i++)
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
611 {
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
612 Catch *c = (Catch *)catches->data[i];
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
613 gIR->func()->landingPad.addCatch(c, endbb);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
614 }
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
615
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
616 gIR->func()->landingPad.push(landingpadbb);
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
617
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
618 //
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
619 // do the try block
314
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
620 //
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
621 p->scope() = IRScope(trybb,landingpadbb);
8d98e42ece93 [svn r335] The basics of exception handling are in place.
ChristianK
parents: 311
diff changeset
622
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
623 assert(body);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
624 body->toIR(p);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
625
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
626 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
627 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
628
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
629 gIR->func()->landingPad.pop();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
630
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
631 // rewrite the scope
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
632 p->scope() = IRScope(endbb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
633 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
634
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
635 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
636
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
637 void ThrowStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
638 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
639 Logger::println("ThrowStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
640 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
641
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
642 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
643 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
644
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
645 assert(exp);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
646 DValue* e = exp->toElem(p);
687
0a682c7805d2 Emit region.end debug calls before a throw.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
647
0a682c7805d2 Emit region.end debug calls before a throw.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
648 if (global.params.symdebug) DtoDwarfFuncEnd(gIR->func()->decl);
0a682c7805d2 Emit region.end debug calls before a throw.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
649
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
650 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
651 //Logger::cout() << "calling: " << *fn << '\n';
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
652 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
653 //Logger::cout() << "arg: " << *arg << '\n';
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
654 gIR->CreateCallOrInvoke(fn, arg);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
655 gIR->ir->CreateUnreachable();
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
656
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
657 // need a block after the throw for now
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
658 llvm::BasicBlock* oldend = gIR->scopeend();
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
659 llvm::BasicBlock* bb = llvm::BasicBlock::Create("afterthrow", p->topfunc(), oldend);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
660 p->scope() = IRScope(bb,oldend);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
661 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
662
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
663 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
664
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
665 // used to build the sorted list of cases
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
666 struct Case : Object
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
667 {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
668 StringExp* str;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
669 size_t index;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
670
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
671 Case(StringExp* s, size_t i) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
672 str = s;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
673 index = i;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
674 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
675
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
676 int compare(Object *obj) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
677 Case* c2 = (Case*)obj;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
678 return str->compare(c2->str);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
679 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
680 };
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
681
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
682 static LLValue* call_string_switch_runtime(llvm::Value* table, Expression* e)
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
683 {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
684 Type* dt = e->type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
685 Type* dtnext = dt->nextOf()->toBasetype();
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
686 TY ty = dtnext->ty;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
687 const char* fname;
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
688 if (ty == Tchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
689 fname = "_d_switch_string";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
690 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
691 else if (ty == Twchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
692 fname = "_d_switch_ustring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
693 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
694 else if (ty == Tdchar) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
695 fname = "_d_switch_dstring";
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
696 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
697 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
698 assert(0 && "not char/wchar/dchar");
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
699 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
700
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
701 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
702
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
703 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
704 {
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
705 Logger::cout() << *table->getType() << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
706 Logger::cout() << *fn->getFunctionType()->getParamType(0) << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
707 }
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
708 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
709
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
710 DValue* val = e->toElem(gIR);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
711 LLValue* llval = val->getRVal();
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
712 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
713
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
714 CallOrInvoke* call = gIR->CreateCallOrInvoke2(fn, table, llval, "tmp");
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
715
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
716 return call->get();
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
717 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
718
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
719 void SwitchStatement::toIR(IRState* p)
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
720 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
721 Logger::println("SwitchStatement::toIR(): %s", loc.toChars());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
722 LOG_SCOPE;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
723
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
724 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
725 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
726
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
727 llvm::BasicBlock* oldend = gIR->scopeend();
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
728
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
729 // 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
730 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
731 {
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
732 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
733 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
734 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
735 }
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
736
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
737 // string switch?
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
738 llvm::Value* 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
739 Array caseArray;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
740 if (!condition->type->isintegral())
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
741 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
742 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
743 // build array of the stringexpS
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
744 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
745 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
746 {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
747 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
748
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
749 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
750 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
751 }
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
752 // first sort it
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
753 caseArray.sort();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
754 // iterate and add indices to cases
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
755 std::vector<LLConstant*> inits(caseArray.dim);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
756 for (size_t i=0; i<caseArray.dim; ++i)
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
757 {
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
758 Case* c = (Case*)caseArray.data[i];
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
759 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
760 cs->llvmIdx = DtoConstUint(i);
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
761 inits[i] = c->str->toConstElem(p);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
762 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
763 // 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
764 const LLType* elemTy = DtoType(condition->type);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
765 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
766 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
767 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
768
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
769 const LLType* elemPtrTy = getPtrToType(elemTy);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
770 LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
771
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
772 // build the static table
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
773 std::vector<const LLType*> types;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
774 types.push_back(DtoSize_t());
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
775 types.push_back(elemPtrTy);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
776 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
777 std::vector<LLConstant*> sinits;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
778 sinits.push_back(DtoConstSize_t(inits.size()));
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
779 sinits.push_back(arrPtr);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
780 switchTable = llvm::ConstantStruct::get(sTy, sinits);
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
781 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
782
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
783 // body block
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
784 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
785
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
786 // default
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
787 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
788 if (sdefault) {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
789 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
790 defbb = llvm::BasicBlock::Create("default", p->topfunc(), oldend);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
791 sdefault->bodyBB = defbb;
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
792 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
793
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
794 // 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
795 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
796
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
797 // condition var
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
798 LLValue* condVal;
122
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
799 // integral switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
800 if (condition->type->isintegral()) {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
801 DValue* cond = condition->toElem(p);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
802 condVal = cond->getRVal();
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
803 }
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
804 // string switch
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
805 else {
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
806 condVal = call_string_switch_runtime(switchTable, condition);
36ab367572df [svn r126] String switch is now implemented.
lindquist
parents: 121
diff changeset
807 }
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
808 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
809
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
810 // 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
811 assert(body);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
812
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
813 p->scope() = IRScope(bodybb, endbb);
311
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
814 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,p->scopebb(),endbb,true));
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
815 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
816 p->loopbbs.pop_back();
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
817
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
818 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
819 llvm::BranchInst::Create(endbb, p->scopebb());
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
820
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
821 // 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
822 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
823 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
824 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
825 si->addCase(cs->llvmIdx, cs->bodyBB);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
826 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
827
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
828 gIR->scope() = IRScope(endbb,oldend);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
829 }
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
830
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
831 //////////////////////////////////////////////////////////////////////////////
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
832 void CaseStatement::toIR(IRState* p)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
833 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
834 Logger::println("CaseStatement::toIR(): %s", loc.toChars());
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
835 LOG_SCOPE;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
836
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
837 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
838
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
839 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
840 {
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
841 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
842 }
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
843 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
844
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 270
diff changeset
845 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
846 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
847 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
848 }
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
849
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
850 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
851 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
852
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
853 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
854
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
855 assert(statement);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
856 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
857 }
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
858
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
859 //////////////////////////////////////////////////////////////////////////////
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
860 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
861 {
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
862 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
863 LOG_SCOPE;
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
864
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
865 assert(bodyBB);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
866
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
867 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
868
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
869 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
870 {
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
871 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
872 }
2be09ee06bc7 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm!
lindquist
parents: 262
diff changeset
873 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
874
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
875 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
876 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
877
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
878 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
879
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
880 assert(statement);
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 244
diff changeset
881 statement->toIR(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
882 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
883
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
884 //////////////////////////////////////////////////////////////////////////////
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
885
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
886 void UnrolledLoopStatement::toIR(IRState* p)
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
887 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
888 Logger::println("UnrolledLoopStatement::toIR(): %s", loc.toChars());
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
889 LOG_SCOPE;
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
890
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
891 // if no statements, there's nothing to do
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
892 if (!statements || !statements->dim)
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
893 return;
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
894
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
895 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
896 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
897
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
898 // DMD doesn't fold stuff like continue/break, and since this isn't really a loop
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
899 // we have to keep track of each statement and jump to the next/end on continue/break
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
900
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
901 llvm::BasicBlock* oldend = gIR->scopeend();
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
902
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
903 // create a block for each statement
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
904 size_t nstmt = statements->dim;
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
905 LLSmallVector<llvm::BasicBlock*, 4> blocks(nstmt, NULL);
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
906
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
907 for (size_t i=0; i<nstmt; i++)
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
908 {
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
909 blocks[i] = llvm::BasicBlock::Create("unrolledstmt", p->topfunc(), oldend);
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
910 }
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
911
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
912 // create end block
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
913 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
914
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
915 // enter first stmt
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
916 if (!p->scopereturned())
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
917 p->ir->CreateBr(blocks[0]);
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
918
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
919 // do statements
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
920 Statement** stmts = (Statement**)statements->data;
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
921
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
922 for (int i=0; i<nstmt; i++)
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
923 {
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
924 Statement* s = stmts[i];
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
925
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
926 // get blocks
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
927 llvm::BasicBlock* thisbb = blocks[i];
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
928 llvm::BasicBlock* nextbb = (i+1 == nstmt) ? endbb : blocks[i+1];
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
929
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
930 // update scope
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
931 p->scope() = IRScope(thisbb,nextbb);
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
932
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
933 // push loop scope
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
934 // continue goes to next statement, break goes to end
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
935 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,nextbb,endbb));
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
936
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
937 // do statement
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
938 s->toIR(p);
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
939
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
940 // pop loop scope
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
941 p->loopbbs.pop_back();
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
942
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
943 // next stmt
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
944 if (!p->scopereturned())
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
945 p->ir->CreateBr(nextbb);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
946 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
947
774
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
948 // finish scope
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
949 if (!p->scopereturned())
9688da40cd4d Fixed problem with continue/break in unrolled loop statements.
tomas@myhost
parents: 758
diff changeset
950 p->ir->CreateBr(endbb);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
951 p->scope() = IRScope(endbb,oldend);
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
952 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
953
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
954 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
955
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
956 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
957 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
958 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
959 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
960
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
961 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
962 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
963
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
964 //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
965 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
966 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
967 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
968
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
969 //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
970 //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
971
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 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
973
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
974 // key
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
975 const LLType* keytype = key ? DtoType(key->type) : DtoSize_t();
745
5761d7e6f628 Tried using DtoDeclarationExp for VarDecls in Statements to fix nesting issues
Christian Kamm <kamm incasoftware de>
parents: 733
diff changeset
976 LLValue* 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
977 if (key)
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 745
diff changeset
978 keyvar = DtoRawVarDeclaration(key);
745
5761d7e6f628 Tried using DtoDeclarationExp for VarDecls in Statements to fix nesting issues
Christian Kamm <kamm incasoftware de>
parents: 733
diff changeset
979 else
5761d7e6f628 Tried using DtoDeclarationExp for VarDecls in Statements to fix nesting issues
Christian Kamm <kamm incasoftware de>
parents: 733
diff changeset
980 keyvar = DtoAlloca(keytype, "foreachkey");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
981 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
982
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
983 // value
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 200
diff changeset
984 Logger::println("value = %s", value->toPrettyChars());
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 745
diff changeset
985 DtoRawVarDeclaration(value);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
986 const LLType* valtype = DtoType(value->type);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
987 LLValue* valvar = NULL;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
988 if (!value->isRef() && !value->isOut())
745
5761d7e6f628 Tried using DtoDeclarationExp for VarDecls in Statements to fix nesting issues
Christian Kamm <kamm incasoftware de>
parents: 733
diff changeset
989 valvar = value->ir.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
990
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
991 // what to iterate
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
992 DValue* aggrval = aggr->toElem(p);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
993 Type* aggrtype = aggr->type->toBasetype();
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
994
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
995 // get length and pointer
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 305
diff changeset
996 LLValue* niters = DtoArrayLen(aggrval);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 305
diff changeset
997 LLValue* val = DtoArrayPtr(aggrval);
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
998
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
999 if (niters->getType() != keytype)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1000 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1001 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
1002 size_t sz2 = getTypeBitSize(keytype);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1003 if (sz1 < sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1004 niters = gIR->ir->CreateZExt(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1005 else if (sz1 > sz2)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1006 niters = gIR->ir->CreateTrunc(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1007 else
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1008 niters = gIR->ir->CreateBitCast(niters, keytype, "foreachtrunckey");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1009 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1010
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1011 LLConstant* delta = 0;
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1012 if (op == TOKforeach) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1013 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
1014 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1015 else {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1016 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
1017 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1018
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1019 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
1020 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
1021 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
1022 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
1023 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
1024
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
1025 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
1026
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1027 // condition
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1028 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
1029
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1030 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
1031 LLValue* load = DtoLoad(keyvar);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1032 if (op == TOKforeach) {
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1033 done = p->ir->CreateICmpULT(load, niters, "tmp");
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1034 }
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1035 else if (op == TOKforeach_reverse) {
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1036 done = p->ir->CreateICmpUGT(load, zerokey, "tmp");
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1037 load = p->ir->CreateSub(load, llvm::ConstantInt::get(keytype, 1, false), "tmp");
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1038 DtoStore(load, keyvar);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1039 }
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
1040 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
1041
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1042 // init body
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1043 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
1044
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1045 // get value for this iteration
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1046 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
1047 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 305
diff changeset
1048 value->ir.irLocal->value = DtoGEP1(val,loadedKey);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 45
diff changeset
1049
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1050 if (!value->isRef() && !value->isOut()) {
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 519
diff changeset
1051 DVarValue dst(value->type, valvar);
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 519
diff changeset
1052 DVarValue src(value->type, value->ir.irLocal->value);
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 519
diff changeset
1053 DtoAssign(loc, &dst, &src);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1054 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
1055 }
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
1056
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1057 // emit body
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1058 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,nextbb,endbb));
519
bc0835cd3440 Don't assert on empty foreach body.
Christian Kamm <kamm incasoftware de>
parents: 518
diff changeset
1059 if(body)
bc0835cd3440 Don't assert on empty foreach body.
Christian Kamm <kamm incasoftware de>
parents: 518
diff changeset
1060 body->toIR(p);
33
bc641b23a714 [svn r37] * Initial support for foreach on static arrays. Not 100% complete
lindquist
parents: 32
diff changeset
1061 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
1062
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1063 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
1064 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
1065
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1066 // next
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1067 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
1068 if (op == TOKforeach) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 206
diff changeset
1069 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
1070 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
1071 DtoStore(load, keyvar);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1072 }
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
1073 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
1074
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1075 // 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
1076 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
1077 }
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1078
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1079 //////////////////////////////////////////////////////////////////////////////
a86fe7496b58 [svn r36] * Fixed a bug where passing a regular argument to a ref argument did not allocate storage
lindquist
parents: 15
diff changeset
1080
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1081 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1082
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1083 void ForeachRangeStatement::toIR(IRState* p)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1084 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1085 Logger::println("ForeachRangeStatement::toIR(): %s", loc.toChars());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1086 LOG_SCOPE;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1087
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1088 if (global.params.symdebug)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1089 DtoDwarfStopPoint(loc.linnum);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1090
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1091 // evaluate lwr/upr
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1092 assert(lwr->type->isintegral());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1093 LLValue* lower = lwr->toElem(p)->getRVal();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1094 assert(upr->type->isintegral());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1095 LLValue* upper = upr->toElem(p)->getRVal();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1096
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1097 // handle key
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1098 assert(key->type->isintegral());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1099 LLValue* keyval = DtoRawVarDeclaration(key);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1100
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1101 // store initial value in key
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1102 if (op == TOKforeach)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1103 DtoStore(lower, keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1104 else
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1105 DtoStore(upper, keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1106
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1107 // set up the block we'll need
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1108 llvm::BasicBlock* oldend = gIR->scopeend();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1109 llvm::BasicBlock* condbb = llvm::BasicBlock::Create("foreachrange_cond", p->topfunc(), oldend);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1110 llvm::BasicBlock* bodybb = llvm::BasicBlock::Create("foreachrange_body", p->topfunc(), oldend);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1111 llvm::BasicBlock* nextbb = llvm::BasicBlock::Create("foreachrange_next", p->topfunc(), oldend);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1112 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("foreachrange_end", p->topfunc(), oldend);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1113
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1114 // jump to condition
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1115 llvm::BranchInst::Create(condbb, p->scopebb());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1116
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1117 // CONDITION
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1118 p->scope() = IRScope(condbb,bodybb);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1119
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1120 // first we test that lwr < upr
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1121 lower = DtoLoad(keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1122 assert(lower->getType() == upper->getType());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1123 llvm::ICmpInst::Predicate cmpop;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1124 if (key->type->isunsigned())
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1125 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1126 cmpop = (op == TOKforeach)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1127 ? llvm::ICmpInst::ICMP_ULT
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1128 : llvm::ICmpInst::ICMP_UGT;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1129 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1130 else
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1131 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1132 cmpop = (op == TOKforeach)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1133 ? llvm::ICmpInst::ICMP_SLT
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1134 : llvm::ICmpInst::ICMP_SGT;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1135 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1136 LLValue* cond = p->ir->CreateICmp(cmpop, lower, upper);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1137
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1138 // jump to the body if range is ok, to the end if not
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1139 llvm::BranchInst::Create(bodybb, endbb, cond, p->scopebb());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1140
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1141 // BODY
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1142 p->scope() = IRScope(bodybb,nextbb);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1143
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1144 // reverse foreach decrements here
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1145 if (op == TOKforeach_reverse)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1146 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1147 LLValue* v = DtoLoad(keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1148 LLValue* one = LLConstantInt::get(v->getType(), 1, false);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1149 v = p->ir->CreateSub(v, one);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1150 DtoStore(v, keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1151 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1152
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1153 // emit body
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1154 p->loopbbs.push_back(IRLoopScope(this,enclosinghandler,nextbb,endbb));
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1155 if (body)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1156 body->toIR(p);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1157 p->loopbbs.pop_back();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1158
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1159 // jump to next iteration
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1160 if (!p->scopereturned())
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1161 llvm::BranchInst::Create(nextbb, p->scopebb());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1162
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1163 // NEXT
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1164 p->scope() = IRScope(nextbb,endbb);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1165
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1166 // forward foreach increments here
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1167 if (op == TOKforeach)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1168 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1169 LLValue* v = DtoLoad(keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1170 LLValue* one = LLConstantInt::get(v->getType(), 1, false);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1171 v = p->ir->CreateAdd(v, one);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1172 DtoStore(v, keyval);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1173 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1174
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1175 // jump to condition
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1176 llvm::BranchInst::Create(condbb, p->scopebb());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1177
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1178 // END
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1179 p->scope() = IRScope(endbb,oldend);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1180 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1181
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1182 #endif // D2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1183
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1184 //////////////////////////////////////////////////////////////////////////////
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1185
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1186 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
1187 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1188 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
1189 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1190
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1191 // 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
1192 if (p->asmBlock)
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1193 {
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1194 IRAsmStmt* a = new IRAsmStmt;
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
1195 a->code += p->func()->decl->mangle();
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
1196 a->code += "_";
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1197 a->code += ident->toChars();
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1198 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
1199 p->asmBlock->s.push_back(a);
299
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 298
diff changeset
1200 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
1201 }
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1202 else
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1203 {
355
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
1204 std::string labelname = p->func()->getScopedLabelName(ident->toChars());
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1205 llvm::BasicBlock*& labelBB = p->func()->labelToBB[labelname];
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1206
298
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1207 llvm::BasicBlock* oldend = gIR->scopeend();
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1208 if (labelBB != NULL) {
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1209 labelBB->moveBefore(oldend);
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1210 } else {
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1211 labelBB = llvm::BasicBlock::Create("label", p->topfunc(), oldend);
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1212 }
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
1213
298
3b8ada4c9f8b [svn r319] Call substatement->toIR in LabelStatement::toIR even when the label is inside an asm block.
ChristianK
parents: 271
diff changeset
1214 if (!p->scopereturned())
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1215 llvm::BranchInst::Create(labelBB, p->scopebb());
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
1216
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 352
diff changeset
1217 p->scope() = IRScope(labelBB,oldend);
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1218 }
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 219
diff changeset
1219
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1220 if (statement)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
1221 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
1222 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1223
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1224 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1225
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1226 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
1227 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1228 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
1229 LOG_SCOPE;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1230
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1231 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1232 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1233
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1234 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
1235 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
1236
356
44daf304421c [svn r377] The previous check was too strict, it completely disallowed gotos within finally blocks. This reenables them as long as they don't cross a finally boundary.
ChristianK
parents: 355
diff changeset
1237 DtoGoto(&loc, label->ident, enclosinghandler, tf);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1238
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1239 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
1240 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1241
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1242 //////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 34
diff changeset
1243
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1244 void GotoDefaultStatement::toIR(IRState* p)
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1245 {
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1246 Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars());
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1247 LOG_SCOPE;
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1248
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1249 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1250 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1251
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1252 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
1253 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
1254
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1255 assert(!p->scopereturned());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1256 assert(sw->sdefault->bodyBB);
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1257
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1258 DtoEnclosingHandlers(enclosinghandler, sw->enclosinghandler);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1259
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
1260 llvm::BranchInst::Create(sw->sdefault->bodyBB, p->scopebb());
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1261 p->scope() = IRScope(bb,oldend);
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1262 }
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1263
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1264 //////////////////////////////////////////////////////////////////////////////
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1265
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1266 void GotoCaseStatement::toIR(IRState* p)
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1267 {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1268 Logger::println("GotoCaseStatement::toIR(): %s", loc.toChars());
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1269 LOG_SCOPE;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1270
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1271 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1272 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1273
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1274 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
1275 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
1276
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1277 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
1278 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
1279 {
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
1280 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
1281 }
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1282
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1283 DtoEnclosingHandlers(enclosinghandler, sw->enclosinghandler);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1284
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
1285 llvm::BranchInst::Create(cs->bodyBB, p->scopebb());
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1286 p->scope() = IRScope(bb,oldend);
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1287 }
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1288
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1289 //////////////////////////////////////////////////////////////////////////////
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1290
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1291 void WithStatement::toIR(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1292 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1293 Logger::println("WithStatement::toIR(): %s", loc.toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1294 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1295
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1296 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1297 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1298
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1299 assert(exp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1300 assert(body);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1301
831
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1302 // with(..) can either be used with expressions or with symbols
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1303 // wthis == null indicates the symbol form
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1304 if (wthis) {
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1305 DValue* e = exp->toElem(p);
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1306 LLValue* mem = DtoRawVarDeclaration(wthis);
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1307 DtoStore(e->getRVal(), mem);
7e59caf41433 Fix with(symbol) statement.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
1308 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1309
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1310 body->toIR(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1311 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1312
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1313 //////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1314
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1315 static LLConstant* generate_unique_critical_section()
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1316 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1317 const LLType* Mty = DtoMutexType();
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1318 return new llvm::GlobalVariable(Mty, false, llvm::GlobalValue::InternalLinkage, LLConstant::getNullValue(Mty), ".uniqueCS", gIR->module);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1319 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1320
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1321 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
1322 {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1323 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
1324 LOG_SCOPE;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1325
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1326 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1327 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1328
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1329 // enter lock
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1330 if (exp)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1331 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1332 llsync = exp->toElem(p)->getRVal();
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1333 DtoEnterMonitor(llsync);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1334 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1335 else
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1336 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1337 llsync = generate_unique_critical_section();
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1338 DtoEnterCritical(llsync);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1339 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1340
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1341 // emit body
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1342 body->toIR(p);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1343
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1344 // exit lock
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1345 // no point in a unreachable unlock, terminating statements must insert this themselves.
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1346 if (p->scopereturned())
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1347 return;
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1348 else if (exp)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1349 DtoLeaveMonitor(llsync);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1350 else
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1351 DtoLeaveCritical(llsync);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1352 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1353
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1354 //////////////////////////////////////////////////////////////////////////////
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1355
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1356 void VolatileStatement::toIR(IRState* p)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1357 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1358 Logger::println("VolatileStatement::toIR(): %s", loc.toChars());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1359 LOG_SCOPE;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1360
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1361 if (global.params.symdebug)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1362 DtoDwarfStopPoint(loc.linnum);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 267
diff changeset
1363
206
cd2c9f4010e4 [svn r222] Forgot to remove volatile ATTENTION.
lindquist
parents: 205
diff changeset
1364 // mark in-volatile
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1365 // FIXME
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
1366
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
1367 // 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
1368 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
1369 {
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
1370 // 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
1371 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
1372
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
1373 // 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
1374 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
1375
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1376 // no point in a unreachable barrier, terminating statements must insert this themselves.
875
330f999ade44 Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 831
diff changeset
1377 if (statement->blockExit() & BEfallthru)
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
1378 {
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
1379 // 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
1380 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
1381 }
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
1382 }
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
1383 // 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
1384 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
1385 {
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
1386 // 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
1387 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
1388 }
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
1389
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
1390 // restore volatile state
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 308
diff changeset
1391 // FIXME
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1392 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1393
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1394 //////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1395
331
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1396 void SwitchErrorStatement::toIR(IRState* p)
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1397 {
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1398 Logger::println("SwitchErrorStatement::toIR(): %s", loc.toChars());
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1399 LOG_SCOPE;
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1400
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1401 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_switch_error");
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1402
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1403 std::vector<LLValue*> args;
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1404
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1405 // file param
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1406 args.push_back(DtoLoad(gIR->dmodule->ir.irModule->fileName));
331
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1407
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1408 // line param
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 652
diff changeset
1409 LLConstant* c = DtoConstUint(loc.linnum);
331
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1410 args.push_back(c);
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1411
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1412 // call
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1413 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1414
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1415 gIR->ir->CreateUnreachable();
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1416 }
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1417
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1418 //////////////////////////////////////////////////////////////////////////////
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1419
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1420 //////////////////////////////////////////////////////////////////////////////
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1421
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1422 #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
1423 //STUBST(BreakStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1424 //STUBST(ForStatement);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1425 //STUBST(WithStatement);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
1426 //STUBST(SynchronizedStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1427 //STUBST(ReturnStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1428 //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
1429 //STUBST(DefaultStatement);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 100
diff changeset
1430 //STUBST(CaseStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1431 //STUBST(SwitchStatement);
331
04e1b4930975 [svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents: 319
diff changeset
1432 //STUBST(SwitchErrorStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1433 STUBST(Statement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1434 //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
1435 //STUBST(ForeachStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1436 //STUBST(DoStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1437 //STUBST(WhileStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1438 //STUBST(ExpStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1439 //STUBST(CompoundStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1440 //STUBST(ScopeStatement);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 123
diff changeset
1441 //STUBST(AsmStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1442 //STUBST(TryCatchStatement);
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1443 //STUBST(TryFinallyStatement);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1444 //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
1445 //STUBST(LabelStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1446 //STUBST(ThrowStatement);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 144
diff changeset
1447 //STUBST(GotoCaseStatement);
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 137
diff changeset
1448 //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
1449 //STUBST(GotoStatement);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1450 //STUBST(UnrolledLoopStatement);
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
diff changeset
1451 //STUBST(OnScopeStatement);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1452
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1453 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1454 STUBST(PragmaStatement);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 747
diff changeset
1455 #endif