Mercurial > projects > ldc
annotate gen/irstate.cpp @ 100:5071469303d4 trunk
[svn r104] TONS OF FIXES.
Split up declaration, constant initializer gen and definition for globals, structs, classes and functions.
Improved ClassInfo support (not complete), not in vtable yet.
Fixed a bunch of forward reference problems.
Much more. Major commit! :)
author | lindquist |
---|---|
date | Fri, 16 Nov 2007 08:21:47 +0100 |
parents | 61615fa85940 |
children | 855adfdb8d38 |
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" |
13 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
14 #include "gen/irstate.h" |
40 | 15 #include "tollvm.h" |
1 | 16 |
17 IRState* gIR = 0; | |
73 | 18 const llvm::TargetData* gTargetData = 0; |
1 | 19 |
20 ////////////////////////////////////////////////////////////////////////////////////////// | |
21 IRScope::IRScope() | |
22 { | |
40 | 23 begin = end = NULL; |
1 | 24 } |
25 | |
26 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
27 { | |
28 begin = b; | |
29 end = e; | |
40 | 30 builder.SetInsertPoint(b); |
1 | 31 } |
32 | |
33 ////////////////////////////////////////////////////////////////////////////////////////// | |
34 IRState::IRState() | |
35 { | |
36 dmodule = 0; | |
37 module = 0; | |
38 emitMain = false; | |
39 mainFunc = 0; | |
40 | 40 ir.state = this; |
41 } | |
42 | |
100 | 43 IRFunction* IRState::func() |
40 | 44 { |
45 assert(!functions.empty() && "Function stack is empty!"); | |
46 return functions.back(); | |
1 | 47 } |
48 | |
49 llvm::Function* IRState::topfunc() | |
50 { | |
40 | 51 assert(!functions.empty() && "Function stack is empty!"); |
100 | 52 return functions.back()->func; |
1 | 53 } |
54 | |
55 TypeFunction* IRState::topfunctype() | |
56 { | |
40 | 57 assert(!functions.empty() && "Function stack is empty!"); |
100 | 58 return functions.back()->type; |
1 | 59 } |
60 | |
61 llvm::Instruction* IRState::topallocapoint() | |
62 { | |
40 | 63 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 64 return functions.back()->allocapoint; |
1 | 65 } |
66 | |
100 | 67 IRStruct* IRState::topstruct() |
1 | 68 { |
69 assert(!structs.empty() && "Struct vector is empty!"); | |
70 return structs.back(); | |
71 } | |
72 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
73 IRExp* IRState::topexp() |
1 | 74 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
75 return exps.empty() ? NULL : &exps.back(); |
1 | 76 } |
77 | |
78 IRScope& IRState::scope() | |
79 { | |
80 assert(!scopes.empty()); | |
81 return scopes.back(); | |
82 } | |
83 | |
84 llvm::BasicBlock* IRState::scopebb() | |
85 { | |
86 return scopebegin(); | |
87 } | |
88 llvm::BasicBlock* IRState::scopebegin() | |
89 { | |
90 IRScope& s = scope(); | |
91 assert(s.begin); | |
92 return s.begin; | |
93 } | |
94 llvm::BasicBlock* IRState::scopeend() | |
95 { | |
96 IRScope& s = scope(); | |
97 assert(s.end); | |
98 return s.end; | |
99 } | |
100 bool IRState::scopereturned() | |
101 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
102 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
103 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 104 } |
105 | |
106 ////////////////////////////////////////////////////////////////////////////////////////// | |
107 | |
108 IRStruct::IRStruct() | |
109 : recty(llvm::OpaqueType::get()) | |
110 { | |
111 type = 0; | |
100 | 112 defined = false; |
113 constinited = false; | |
1 | 114 } |
115 | |
6 | 116 IRStruct::IRStruct(Type* t) |
1 | 117 : recty(llvm::OpaqueType::get()) |
118 { | |
119 type = t; | |
100 | 120 defined = false; |
121 constinited = false; | |
1 | 122 } |
123 | |
40 | 124 ////////////////////////////////////////////////////////////////////////////////////////// |
125 | |
126 IRFinally::IRFinally() | |
127 { | |
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:
73
diff
changeset
|
128 bb = 0; |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
129 retbb = 0; |
40 | 130 } |
131 | |
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:
73
diff
changeset
|
132 IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb) |
1 | 133 { |
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:
73
diff
changeset
|
134 bb = b; |
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:
73
diff
changeset
|
135 retbb = rb; |
1 | 136 } |
40 | 137 |
138 ////////////////////////////////////////////////////////////////////////////////////////// | |
139 | |
140 LLVMBuilder* IRBuilderHelper::operator->() | |
141 { | |
142 LLVMBuilder& b = state->scope().builder; | |
143 assert(b.GetInsertBlock() != NULL); | |
144 return &b; | |
145 } | |
146 | |
147 ////////////////////////////////////////////////////////////////////////////////////////// | |
148 | |
149 IRFunction::IRFunction(FuncDeclaration* fd) | |
150 { | |
151 decl = fd; | |
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:
73
diff
changeset
|
152 Type* t = DtoDType(fd->type); |
40 | 153 assert(t->ty == Tfunction); |
154 type = (TypeFunction*)t; | |
155 func = NULL; | |
156 allocapoint = NULL; | |
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:
73
diff
changeset
|
157 finallyretval = NULL; |
100 | 158 defined = false; |
40 | 159 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
160 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
161 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
162 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
163 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
164 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
165 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
166 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
167 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
168 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
169 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
|
170 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
171 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
172 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
173 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
174 } |
100 | 175 |
176 ////////////////////////////////////////////////////////////////////////////////////////// | |
177 | |
178 IRGlobal::IRGlobal(VarDeclaration* v) : | |
179 type(llvm::OpaqueType::get()) | |
180 { | |
181 var = v; | |
182 } |