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