Mercurial > projects > ldc
annotate gen/irstate.cpp @ 314:8d98e42ece93 trunk
[svn r335] The basics of exception handling are in place.
Still need to make sure calls are turned into invokes everywhere. (NewExpression for instance)
Still some rough edges and corner cases to figure out.
Needs testing!
author | ChristianK |
---|---|
date | Wed, 02 Jul 2008 22:20:18 +0200 |
parents | 9967a3270837 |
children | a9697749e898 |
rev | line source |
---|---|
1 | 1 /* DMDFE backend stubs |
2 * This file contains the implementations of the backend routines. | |
3 * For dmdfe these do nothing but print a message saying the module | |
4 * has been parsed. Substitute your own behaviors for these routimes. | |
5 */ | |
6 | |
40 | 7 #include <cstdarg> |
8 | |
9 #include "gen/llvm.h" | |
10 | |
1 | 11 #include "mtype.h" |
40 | 12 #include "declaration.h" |
309 | 13 #include "statement.h" |
40 | 14 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
15 #include "gen/irstate.h" |
40 | 16 #include "tollvm.h" |
1 | 17 |
18 IRState* gIR = 0; | |
73 | 19 const llvm::TargetData* gTargetData = 0; |
1 | 20 |
21 ////////////////////////////////////////////////////////////////////////////////////////// | |
22 IRScope::IRScope() | |
23 { | |
40 | 24 begin = end = NULL; |
1 | 25 } |
26 | |
27 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
28 { | |
29 begin = b; | |
30 end = e; | |
40 | 31 builder.SetInsertPoint(b); |
1 | 32 } |
33 | |
34 ////////////////////////////////////////////////////////////////////////////////////////// | |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
35 IRLoopScope::IRLoopScope() |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
36 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
37 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
38 |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
39 IRLoopScope::IRLoopScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* b, llvm::BasicBlock* e, bool isSwitch) |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
40 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
41 begin = b; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
42 end = e; |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
252
diff
changeset
|
43 //builder.SetInsertPoint(b); |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
44 this->s = s; |
309 | 45 this->enclosinghandler = enclosinghandler; |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
46 this->isSwitch = isSwitch; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
47 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
48 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
49 ////////////////////////////////////////////////////////////////////////////////////////// |
1 | 50 IRState::IRState() |
51 { | |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
52 interfaceInfoType = NULL; |
309 | 53 mutexType = NULL; |
54 | |
1 | 55 dmodule = 0; |
56 module = 0; | |
57 emitMain = false; | |
58 mainFunc = 0; | |
40 | 59 ir.state = this; |
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
|
60 asmBlock = NULL; |
252 | 61 |
62 dwarfCUs = NULL; | |
63 dwarfSPs = NULL; | |
64 dwarfGVs = NULL; | |
40 | 65 } |
66 | |
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:
113
diff
changeset
|
67 IrFunction* IRState::func() |
40 | 68 { |
69 assert(!functions.empty() && "Function stack is empty!"); | |
70 return functions.back(); | |
1 | 71 } |
72 | |
73 llvm::Function* IRState::topfunc() | |
74 { | |
40 | 75 assert(!functions.empty() && "Function stack is empty!"); |
100 | 76 return functions.back()->func; |
1 | 77 } |
78 | |
79 TypeFunction* IRState::topfunctype() | |
80 { | |
40 | 81 assert(!functions.empty() && "Function stack is empty!"); |
100 | 82 return functions.back()->type; |
1 | 83 } |
84 | |
85 llvm::Instruction* IRState::topallocapoint() | |
86 { | |
40 | 87 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 88 return functions.back()->allocapoint; |
1 | 89 } |
90 | |
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:
113
diff
changeset
|
91 IrStruct* IRState::topstruct() |
1 | 92 { |
93 assert(!structs.empty() && "Struct vector is empty!"); | |
94 return structs.back(); | |
95 } | |
96 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
97 IRExp* IRState::topexp() |
1 | 98 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
99 return exps.empty() ? NULL : &exps.back(); |
1 | 100 } |
101 | |
102 IRScope& IRState::scope() | |
103 { | |
104 assert(!scopes.empty()); | |
105 return scopes.back(); | |
106 } | |
107 | |
108 llvm::BasicBlock* IRState::scopebb() | |
109 { | |
110 IRScope& s = scope(); | |
111 assert(s.begin); | |
112 return s.begin; | |
113 } | |
114 llvm::BasicBlock* IRState::scopeend() | |
115 { | |
116 IRScope& s = scope(); | |
117 assert(s.end); | |
118 return s.end; | |
119 } | |
120 bool IRState::scopereturned() | |
121 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
122 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
123 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 124 } |
125 | |
126 ////////////////////////////////////////////////////////////////////////////////////////// | |
127 | |
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:
189
diff
changeset
|
128 IRBuilder* IRBuilderHelper::operator->() |
40 | 129 { |
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:
189
diff
changeset
|
130 IRBuilder& b = state->scope().builder; |
40 | 131 assert(b.GetInsertBlock() != NULL); |
132 return &b; | |
133 } | |
134 | |
135 ////////////////////////////////////////////////////////////////////////////////////////// | |
136 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
137 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
138 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
139 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
140 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
141 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
142 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
143 IRExp::IRExp(Expression* l, Expression* r, DValue* val) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
144 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
145 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
146 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
147 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
148 } |