Mercurial > projects > ldc
annotate gen/functions.cpp @ 311:9967a3270837 trunk
[svn r332] Fix codegen for continue within switch.
author | ChristianK |
---|---|
date | Sat, 28 Jun 2008 18:37:27 +0200 |
parents | 665b81613475 |
children | 7086a84ab3d6 |
rev | line source |
---|---|
100 | 1 #include "gen/llvm.h" |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
2 #include "llvm/Support/CFG.h" |
100 | 3 |
4 #include "mtype.h" | |
5 #include "aggregate.h" | |
6 #include "init.h" | |
7 #include "declaration.h" | |
8 #include "template.h" | |
9 #include "module.h" | |
10 #include "statement.h" | |
11 | |
12 #include "gen/irstate.h" | |
13 #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:
241
diff
changeset
|
14 #include "gen/llvmhelpers.h" |
100 | 15 #include "gen/runtime.h" |
16 #include "gen/arrays.h" | |
17 #include "gen/logger.h" | |
18 #include "gen/functions.h" | |
19 #include "gen/todebug.h" | |
20 #include "gen/classes.h" | |
131 | 21 #include "gen/dvalue.h" |
100 | 22 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
23 const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bool ismain) |
100 | 24 { |
25 TypeFunction* f = (TypeFunction*)type; | |
26 assert(f != 0); | |
27 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
28 if (type->ir.type != NULL) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
29 return llvm::cast<llvm::FunctionType>(type->ir.type->get()); |
100 | 30 } |
31 | |
32 bool typesafeVararg = false; | |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
33 bool arrayVararg = false; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
34 if (f->linkage == LINKd) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
35 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
36 if (f->varargs == 1) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
37 typesafeVararg = true; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
38 else if (f->varargs == 2) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
39 arrayVararg = true; |
100 | 40 } |
41 | |
42 // return value type | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
43 const LLType* rettype; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
44 const LLType* actualRettype; |
100 | 45 Type* rt = f->next; |
46 bool retinptr = false; | |
47 bool usesthis = false; | |
48 | |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
49 // parameter types |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
50 std::vector<const LLType*> paramvec; |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
51 |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
52 if (ismain) |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
53 { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
54 rettype = LLType::Int32Ty; |
100 | 55 actualRettype = rettype; |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
56 if (Argument::dim(f->parameters) == 0) |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
57 { |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
58 const LLType* arrTy = DtoArrayType(LLType::Int8Ty); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
59 const LLType* arrArrTy = DtoArrayType(arrTy); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
60 paramvec.push_back(getPtrToType(arrArrTy)); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
61 } |
100 | 62 } |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
225
diff
changeset
|
63 else{ |
100 | 64 assert(rt); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
65 Type* rtfin = DtoDType(rt); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
66 if (DtoIsReturnedInArg(rt)) { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
67 rettype = getPtrToType(DtoType(rt)); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
68 actualRettype = LLType::VoidTy; |
100 | 69 f->llvmRetInPtr = retinptr = true; |
70 } | |
71 else { | |
72 rettype = DtoType(rt); | |
73 actualRettype = rettype; | |
74 } | |
75 } | |
76 | |
77 if (retinptr) { | |
123
7f9a0a58394b
[svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents:
121
diff
changeset
|
78 //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n'; |
100 | 79 paramvec.push_back(rettype); |
80 } | |
81 | |
82 if (thistype) { | |
83 paramvec.push_back(thistype); | |
84 usesthis = true; | |
85 } | |
86 | |
87 if (typesafeVararg) { | |
88 ClassDeclaration* ti = Type::typeinfo; | |
89 ti->toObjFile(); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
90 DtoForceConstInitDsymbol(ti); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
91 assert(ti->ir.irStruct->constInit); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
92 std::vector<const LLType*> types; |
100 | 93 types.push_back(DtoSize_t()); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
94 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType()))); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
95 const LLType* t1 = llvm::StructType::get(types); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
96 paramvec.push_back(getPtrToType(t1)); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
97 paramvec.push_back(getPtrToType(LLType::Int8Ty)); |
100 | 98 } |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
99 else if (arrayVararg) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
100 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
101 // do nothing? |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
102 } |
100 | 103 |
104 size_t n = Argument::dim(f->parameters); | |
105 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
106 int nbyval = 0; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
107 |
100 | 108 for (int i=0; i < n; ++i) { |
109 Argument* arg = Argument::getNth(f->parameters, i); | |
110 // ensure scalar | |
111 Type* argT = DtoDType(arg->type); | |
112 assert(argT); | |
113 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
114 bool refOrOut = ((arg->storageClass & STCref) || (arg->storageClass & STCout)); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
115 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
116 const LLType* at = DtoType(argT); |
100 | 117 if (isaStruct(at)) { |
118 Logger::println("struct param"); | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
119 paramvec.push_back(getPtrToType(at)); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
120 arg->llvmByVal = !refOrOut; |
100 | 121 } |
122 else if (isaArray(at)) { | |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
262
diff
changeset
|
123 // static array are passed by reference |
100 | 124 Logger::println("sarray param"); |
125 assert(argT->ty == Tsarray); | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
126 paramvec.push_back(getPtrToType(at)); |
100 | 127 } |
128 else if (llvm::isa<llvm::OpaqueType>(at)) { | |
129 Logger::println("opaque param"); | |
130 assert(argT->ty == Tstruct || argT->ty == Tclass); | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
131 paramvec.push_back(getPtrToType(at)); |
100 | 132 } |
133 else { | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
134 if (refOrOut) { |
131 | 135 Logger::println("by ref param"); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
136 at = getPtrToType(at); |
100 | 137 } |
138 else { | |
139 Logger::println("in param"); | |
140 } | |
141 paramvec.push_back(at); | |
142 } | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
143 |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
144 if (arg->llvmByVal) |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
145 nbyval++; |
100 | 146 } |
147 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
148 //warning("set %d byval args for type: %s", nbyval, f->toChars()); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
149 |
100 | 150 // construct function type |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
151 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs; |
100 | 152 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); |
153 | |
154 f->llvmRetInPtr = retinptr; | |
155 f->llvmUsesThis = usesthis; | |
156 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
157 f->ir.type = new llvm::PATypeHolder(functype); |
100 | 158 |
159 return functype; | |
160 } | |
161 | |
162 ////////////////////////////////////////////////////////////////////////////////////////// | |
163 | |
164 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl) | |
165 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
166 // type has already been resolved |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
167 if (fdecl->type->ir.type != 0) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
168 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
169 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
170 |
100 | 171 TypeFunction* f = (TypeFunction*)fdecl->type; |
172 assert(f != 0); | |
173 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
174 const llvm::PointerType* i8pty = getPtrToType(LLType::Int8Ty); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
175 std::vector<const LLType*> args; |
100 | 176 |
177 if (fdecl->llvmInternal == LLVMva_start) { | |
178 args.push_back(i8pty); | |
179 } | |
180 else if (fdecl->llvmInternal == LLVMva_intrinsic) { | |
181 size_t n = Argument::dim(f->parameters); | |
182 for (size_t i=0; i<n; ++i) { | |
183 args.push_back(i8pty); | |
184 } | |
185 } | |
186 else | |
187 assert(0); | |
188 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
189 const llvm::FunctionType* fty = llvm::FunctionType::get(LLType::VoidTy, args, false); |
100 | 190 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
191 f->ir.type = new llvm::PATypeHolder(fty); |
100 | 192 |
193 return fty; | |
194 } | |
195 | |
196 ////////////////////////////////////////////////////////////////////////////////////////// | |
197 | |
198 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl) | |
199 { | |
200 if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) { | |
201 return DtoVaFunctionType(fdecl); | |
202 } | |
203 | |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
204 // unittest has null type, just build it manually |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
205 /*if (fdecl->isUnitTestDeclaration()) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
206 std::vector<const LLType*> args; |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
207 return llvm::FunctionType::get(LLType::VoidTy, args, false); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
208 }*/ |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
209 |
100 | 210 // type has already been resolved |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
211 if (fdecl->type->ir.type != 0) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
212 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get()); |
100 | 213 } |
214 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
215 const LLType* thisty = NULL; |
100 | 216 if (fdecl->needThis()) { |
132 | 217 if (AggregateDeclaration* ad = fdecl->isMember2()) { |
218 Logger::println("isMember = this is: %s", ad->type->toChars()); | |
100 | 219 thisty = DtoType(ad->type); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
220 //Logger::cout() << "this llvm type: " << *thisty << '\n'; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
221 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->recty.get())) |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
222 thisty = getPtrToType(thisty); |
100 | 223 } |
132 | 224 else { |
225 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); | |
226 assert(0); | |
227 } | |
100 | 228 } |
229 else if (fdecl->isNested()) { | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
230 thisty = getPtrToType(LLType::Int8Ty); |
100 | 231 } |
232 | |
233 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, fdecl->isMain()); | |
234 | |
235 return functype; | |
236 } | |
237 | |
238 ////////////////////////////////////////////////////////////////////////////////////////// | |
239 | |
240 static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl) | |
241 { | |
242 TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type); | |
243 const llvm::FunctionType* fty = DtoVaFunctionType(fdecl); | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
244 LLConstant* fn = 0; |
100 | 245 |
246 if (fdecl->llvmInternal == LLVMva_start) { | |
247 fn = gIR->module->getOrInsertFunction("llvm.va_start", fty); | |
248 assert(fn); | |
249 } | |
250 else if (fdecl->llvmInternal == LLVMva_intrinsic) { | |
251 fn = gIR->module->getOrInsertFunction(fdecl->llvmInternal1, fty); | |
252 assert(fn); | |
253 } | |
254 else | |
255 assert(0); | |
256 | |
257 llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn); | |
258 assert(func); | |
259 assert(func->isIntrinsic()); | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
260 fdecl->ir.irFunc->func = func; |
100 | 261 return func; |
262 } | |
263 | |
264 ////////////////////////////////////////////////////////////////////////////////////////// | |
265 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
266 void DtoResolveFunction(FuncDeclaration* fdecl) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
267 { |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
268 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) { |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
269 return; // ignore declaration completely |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
270 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
271 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
272 // is imported and we don't have access? |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
273 if (fdecl->getModule() != gIR->dmodule) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
274 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
275 if (fdecl->prot() == PROTprivate) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
276 return; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
277 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
278 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
279 if (fdecl->ir.resolved) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
280 fdecl->ir.resolved = true; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
281 |
132 | 282 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
283 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
284 |
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
|
285 if (fdecl->runTimeHack) { |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
286 gIR->declareList.push_back(fdecl); |
127 | 287 TypeFunction* tf = (TypeFunction*)fdecl->type; |
288 tf->llvmRetInPtr = DtoIsPassedByRef(tf->next); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
289 return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
290 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
291 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
292 if (fdecl->parent) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
293 if (TemplateInstance* tinst = fdecl->parent->isTemplateInstance()) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
294 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
295 TemplateDeclaration* tempdecl = tinst->tempdecl; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
296 if (tempdecl->llvmInternal == LLVMva_arg) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
297 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
298 Logger::println("magic va_arg found"); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
299 fdecl->llvmInternal = LLVMva_arg; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
300 fdecl->ir.declared = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
301 fdecl->ir.initialized = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
302 fdecl->ir.defined = true; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
303 return; // this gets mapped to an instruction so a declaration makes no sence |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
304 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
305 else if (tempdecl->llvmInternal == LLVMva_start) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
306 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
307 Logger::println("magic va_start found"); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
308 fdecl->llvmInternal = LLVMva_start; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
309 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
310 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
311 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
312 DtoFunctionType(fdecl); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
313 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
314 // queue declaration |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
315 if (!fdecl->isAbstract()) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
316 gIR->declareList.push_back(fdecl); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
317 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
318 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
319 ////////////////////////////////////////////////////////////////////////////////////////// |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
320 |
240
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
321 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl) |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
322 { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
323 assert(f->parameters); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
324 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
325 int llidx = 1; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
326 if (f->llvmRetInPtr) ++llidx; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
327 if (f->llvmUsesThis) ++llidx; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
328 if (f->linkage == LINKd && f->varargs == 1) |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
329 llidx += 2; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
330 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
331 int funcNumArgs = func->getArgumentList().size(); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
332 std::vector<llvm::ParamAttrsWithIndex> attrs; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
333 int k = 0; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
334 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
335 int nbyval = 0; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
336 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
337 if (fdecl->isMain() && Argument::dim(f->parameters) == 0) |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
338 { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
339 llvm::ParamAttrsWithIndex PAWI; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
340 PAWI.Index = llidx; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
341 PAWI.Attrs = llvm::ParamAttr::ByVal; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
342 attrs.push_back(PAWI); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
343 llidx++; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
344 nbyval++; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
345 } |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
346 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
347 for (; llidx <= funcNumArgs && f->parameters->dim > k; ++llidx,++k) |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
348 { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
349 Argument* fnarg = (Argument*)f->parameters->data[k]; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
350 assert(fnarg); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
351 if (fnarg->llvmByVal) |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
352 { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
353 llvm::ParamAttrsWithIndex PAWI; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
354 PAWI.Index = llidx; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
355 PAWI.Attrs = llvm::ParamAttr::ByVal; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
356 attrs.push_back(PAWI); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
357 nbyval++; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
358 } |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
359 } |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
360 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
361 if (nbyval) { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
362 llvm::PAListPtr palist = llvm::PAListPtr::get(attrs.begin(), attrs.end()); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
363 func->setParamAttrs(palist); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
364 } |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
365 } |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
366 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
367 ////////////////////////////////////////////////////////////////////////////////////////// |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
368 |
100 | 369 void DtoDeclareFunction(FuncDeclaration* fdecl) |
370 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
371 if (fdecl->ir.declared) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
372 fdecl->ir.declared = true; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
373 |
132 | 374 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); |
100 | 375 LOG_SCOPE; |
376 | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
377 assert(!fdecl->isAbstract()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
378 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
379 // intrinsic sanity check |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
380 if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) { |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
381 error(fdecl->loc, "intrinsics cannot have function bodies"); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
382 fatal(); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
383 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
384 |
240
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
385 // get TypeFunction* |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
386 Type* t = DtoDType(fdecl->type); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
387 TypeFunction* f = (TypeFunction*)t; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
388 |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
389 // runtime function special handling |
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
|
390 if (fdecl->runTimeHack) { |
100 | 391 Logger::println("runtime hack func chars: %s", fdecl->toChars()); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
392 if (!fdecl->ir.irFunc) { |
240
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
393 IrFunction* irfunc = new IrFunction(fdecl); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
394 llvm::Function* llfunc = LLVM_D_GetRuntimeFunction(gIR->module, fdecl->toChars()); |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
395 fdecl->ir.irFunc = irfunc; |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
396 fdecl->ir.irFunc->func = llfunc; |
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
|
397 } |
100 | 398 return; |
399 } | |
400 | |
401 bool declareOnly = false; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
402 bool templInst = fdecl->parent && DtoIsTemplateInstance(fdecl->parent); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
403 if (!templInst && fdecl->getModule() != gIR->dmodule) |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
139
diff
changeset
|
404 { |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
139
diff
changeset
|
405 Logger::println("not template instance, and not in this module. declare only!"); |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
139
diff
changeset
|
406 Logger::println("current module: %s", gIR->dmodule->ident->toChars()); |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
139
diff
changeset
|
407 Logger::println("func module: %s", fdecl->getModule()->ident->toChars()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
408 declareOnly = true; |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
139
diff
changeset
|
409 } |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
410 else if (fdecl->llvmInternal == LLVMva_start) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
411 declareOnly = true; |
100 | 412 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
413 if (!fdecl->ir.irFunc) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
414 fdecl->ir.irFunc = new IrFunction(fdecl); |
100 | 415 } |
416 | |
417 // mangled name | |
418 char* mangled_name; | |
419 if (fdecl->llvmInternal == LLVMintrinsic) | |
420 mangled_name = fdecl->llvmInternal1; | |
421 else | |
422 mangled_name = fdecl->mangle(); | |
423 | |
424 llvm::Function* vafunc = 0; | |
425 if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) { | |
426 vafunc = DtoDeclareVaFunction(fdecl); | |
427 } | |
428 | |
429 // construct function | |
430 const llvm::FunctionType* functype = DtoFunctionType(fdecl); | |
431 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name); | |
432 if (!func) | |
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:
173
diff
changeset
|
433 func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module); |
100 | 434 else |
435 assert(func->getFunctionType() == functype); | |
436 | |
437 // add func to IRFunc | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
438 fdecl->ir.irFunc->func = func; |
100 | 439 |
440 // calling convention | |
441 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic) | |
442 func->setCallingConv(DtoCallingConv(f->linkage)); | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
144
diff
changeset
|
443 else // fall back to C, it should be the right thing to do |
132 | 444 func->setCallingConv(llvm::CallingConv::C); |
445 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
446 fdecl->ir.irFunc->func = func; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
447 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get())); |
100 | 448 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
449 // parameter attributes |
240
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
450 if (f->parameters) { |
0db62b770a49
[svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents:
234
diff
changeset
|
451 set_param_attrs(f, func, fdecl); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
452 } |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
453 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
454 // main |
100 | 455 if (fdecl->isMain()) { |
456 gIR->mainFunc = func; | |
457 } | |
458 | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
459 // static ctor |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
162
diff
changeset
|
460 if (fdecl->isStaticCtorDeclaration() && fdecl->getModule() == gIR->dmodule) { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
461 gIR->ctors.push_back(fdecl); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
462 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
463 // static dtor |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
162
diff
changeset
|
464 else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
465 gIR->dtors.push_back(fdecl); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
466 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
467 |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
468 // we never reference parameters of function prototypes |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
469 if (!declareOnly) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
470 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
471 // name parameters |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
472 llvm::Function::arg_iterator iarg = func->arg_begin(); |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
473 int k = 0; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
474 if (f->llvmRetInPtr) { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
475 iarg->setName("retval"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
476 fdecl->ir.irFunc->retArg = iarg; |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
477 ++iarg; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
478 } |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
479 if (f->llvmUsesThis) { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
480 iarg->setName("this"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
481 fdecl->ir.irFunc->thisVar = iarg; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
482 assert(fdecl->ir.irFunc->thisVar); |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
483 ++iarg; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
484 } |
119
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
117
diff
changeset
|
485 |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
486 if (f->linkage == LINKd && f->varargs == 1) { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
487 iarg->setName("_arguments"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
488 fdecl->ir.irFunc->_arguments = iarg; |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
489 ++iarg; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
490 iarg->setName("_argptr"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
491 fdecl->ir.irFunc->_argptr = iarg; |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
492 ++iarg; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
493 } |
119
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
117
diff
changeset
|
494 |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
495 for (; iarg != func->arg_end(); ++iarg) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
496 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
497 if (fdecl->parameters && fdecl->parameters->dim > k) |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
498 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
499 Dsymbol* argsym = (Dsymbol*)fdecl->parameters->data[k++]; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
500 VarDeclaration* argvd = argsym->isVarDeclaration(); |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
501 assert(argvd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
502 assert(!argvd->ir.irLocal); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
503 argvd->ir.irLocal = new IrLocal(argvd); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
504 argvd->ir.irLocal->value = iarg; |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
505 iarg->setName(argvd->ident->toChars()); |
100 | 506 } |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
507 else |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
508 { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
509 iarg->setName("unnamed"); |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
510 } |
100 | 511 } |
512 } | |
513 | |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
514 if (fdecl->isUnitTestDeclaration()) |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
515 gIR->unitTests.push_back(fdecl); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
119
diff
changeset
|
516 |
100 | 517 if (!declareOnly) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
518 gIR->defineList.push_back(fdecl); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
519 else |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
520 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage); |
100 | 521 |
522 Logger::cout() << "func decl: " << *func << '\n'; | |
523 } | |
524 | |
525 ////////////////////////////////////////////////////////////////////////////////////////// | |
526 | |
527 void DtoDefineFunc(FuncDeclaration* fd) | |
528 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
529 if (fd->ir.defined) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
530 fd->ir.defined = true; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
531 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
532 assert(fd->ir.declared); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
533 |
132 | 534 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
535 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
536 |
100 | 537 // debug info |
538 if (global.params.symdebug) { | |
539 Module* mo = fd->getModule(); | |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
245
diff
changeset
|
540 fd->ir.irFunc->dwarfSubProg = DtoDwarfSubProgram(fd); |
100 | 541 } |
542 | |
543 Type* t = DtoDType(fd->type); | |
544 TypeFunction* f = (TypeFunction*)t; | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
545 assert(f->ir.type); |
100 | 546 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
547 llvm::Function* func = fd->ir.irFunc->func; |
100 | 548 const llvm::FunctionType* functype = func->getFunctionType(); |
549 | |
550 // only members of the current module or template instances maybe be defined | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
551 if (!(fd->getModule() == gIR->dmodule || DtoIsTemplateInstance(fd->parent))) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
552 return; |
100 | 553 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
554 // set module owner |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
555 fd->ir.DModule = gIR->dmodule; |
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:
173
diff
changeset
|
556 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
557 // is there a body? |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
558 if (fd->fbody == NULL) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
559 return; |
100 | 560 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
561 Logger::println("Doing function body for: %s", fd->toChars()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
562 assert(fd->ir.irFunc); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
563 gIR->functions.push_back(fd->ir.irFunc); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
564 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
565 if (fd->isMain()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
566 gIR->emitMain = true; |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
567 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
568 std::string entryname("entry_"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
569 entryname.append(fd->toPrettyChars()); |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
157
diff
changeset
|
570 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
571 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(entryname,func); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
572 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func); |
100 | 573 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
574 //assert(gIR->scopes.empty()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
575 gIR->scopes.push_back(IRScope(beginbb, endbb)); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
576 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
577 // create alloca point |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
578 llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
579 gIR->func()->allocapoint = allocaPoint; |
100 | 580 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
581 // need result variable? (not nested) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
582 if (fd->vresult && !fd->vresult->nestedref) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
583 Logger::println("non-nested vresult value"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
584 fd->vresult->ir.irLocal = new IrLocal(fd->vresult); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
585 fd->vresult->ir.irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
586 } |
100 | 587 |
254
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
588 // give 'this' argument debug info (and storage) |
258
8dbddae09152
[svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents:
254
diff
changeset
|
589 if (fd->needThis() && global.params.symdebug) |
254
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
590 { |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
591 LLValue** thisvar = &fd->ir.irFunc->thisVar; |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
592 assert(*thisvar); |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
593 LLValue* thismem = new llvm::AllocaInst((*thisvar)->getType(), "newthis", allocaPoint); |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
594 DtoDwarfLocalVariable(thismem, fd->vthis); |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
595 gIR->ir->CreateStore(*thisvar, thismem); |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
596 *thisvar = thismem; |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
597 } |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
598 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
599 // give arguments storage |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
600 if (fd->parameters) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
601 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
602 size_t n = fd->parameters->dim; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
603 for (int i=0; i < n; ++i) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
604 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
605 Dsymbol* argsym = (Dsymbol*)fd->parameters->data[i]; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
606 VarDeclaration* vd = argsym->isVarDeclaration(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
607 assert(vd); |
100 | 608 |
258
8dbddae09152
[svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents:
254
diff
changeset
|
609 // FIXME: llvm seems to want an alloca/byval for debug info |
254
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
610 if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut()) |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
611 continue; |
254
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
612 // debug info for normal aggr params seem to work fine |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
613 else if (DtoIsPassedByRef(vd->type)) |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
614 { |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
615 if (global.params.symdebug) |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
616 DtoDwarfLocalVariable(vd->ir.getIrValue(), vd); |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
617 continue; |
8187884566fa
[svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents:
250
diff
changeset
|
618 } |
100 | 619 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
620 LLValue* a = vd->ir.irLocal->value; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
621 assert(a); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
622 std::string s(a->getName()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
623 Logger::println("giving argument '%s' storage", s.c_str()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
624 s.append("_storage"); |
225
74701ba40398
[svn r241] Fixed missing terminator for void main() with inline asm block.
lindquist
parents:
217
diff
changeset
|
625 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
626 LLValue* v = new llvm::AllocaInst(a->getType(),s,allocaPoint); |
245
d61ce72c39ab
[svn r262] Fixed debug info for normal function parameters.
lindquist
parents:
244
diff
changeset
|
627 |
d61ce72c39ab
[svn r262] Fixed debug info for normal function parameters.
lindquist
parents:
244
diff
changeset
|
628 if (global.params.symdebug) |
d61ce72c39ab
[svn r262] Fixed debug info for normal function parameters.
lindquist
parents:
244
diff
changeset
|
629 DtoDwarfLocalVariable(v, vd); |
d61ce72c39ab
[svn r262] Fixed debug info for normal function parameters.
lindquist
parents:
244
diff
changeset
|
630 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
631 gIR->ir->CreateStore(a,v); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
632 vd->ir.irLocal->value = v; |
100 | 633 } |
634 } | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
635 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
636 // debug info |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
637 if (global.params.symdebug) DtoDwarfFuncStart(fd); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
638 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
639 LLValue* parentNested = NULL; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
640 if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
641 if (!fd->isStatic()) // huh? |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
642 parentNested = fd2->ir.irFunc->nestedVar; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
643 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
644 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
645 // need result variable? (nested) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
646 if (fd->vresult && fd->vresult->nestedref) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
647 Logger::println("nested vresult value: %s", fd->vresult->toChars()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
648 fd->nestedVars.insert(fd->vresult); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
649 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
650 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
651 // construct nested variables struct |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
652 if (!fd->nestedVars.empty() || parentNested) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
653 std::vector<const LLType*> nestTypes; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
654 int j = 0; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
655 if (parentNested) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
656 nestTypes.push_back(parentNested->getType()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
657 j++; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
658 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
659 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
660 VarDeclaration* vd = *i; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
661 Logger::println("referenced nested variable %s", vd->toChars()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
662 if (!vd->ir.irLocal) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
663 vd->ir.irLocal = new IrLocal(vd); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
664 vd->ir.irLocal->nestedIndex = j++; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
665 if (vd->isParameter()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
666 if (!vd->ir.irLocal->value) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
667 assert(vd == fd->vthis); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
668 vd->ir.irLocal->value = fd->ir.irFunc->thisVar; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
669 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
670 assert(vd->ir.irLocal->value); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
671 nestTypes.push_back(vd->ir.irLocal->value->getType()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
672 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
673 else { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
674 nestTypes.push_back(DtoType(vd->type)); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
675 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
676 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
677 const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
678 Logger::cout() << "nested var struct has type:" << *nestSType << '\n'; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
679 fd->ir.irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
680 if (parentNested) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
681 assert(fd->ir.irFunc->thisVar); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
682 LLValue* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
683 gIR->ir->CreateStore(ptr, DtoGEPi(fd->ir.irFunc->nestedVar, 0,0, "tmp")); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
684 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
685 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
686 VarDeclaration* vd = *i; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
687 if (vd->isParameter()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
688 assert(vd->ir.irLocal); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
689 gIR->ir->CreateStore(vd->ir.irLocal->value, DtoGEPi(fd->ir.irFunc->nestedVar, 0, vd->ir.irLocal->nestedIndex, "tmp")); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
690 vd->ir.irLocal->value = fd->ir.irFunc->nestedVar; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
691 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
692 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
693 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
694 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
695 // copy _argptr to a memory location |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
696 if (f->linkage == LINKd && f->varargs == 1) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
697 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
698 LLValue* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
699 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
700 fd->ir.irFunc->_argptr = argptrmem; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
701 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
702 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
703 // output function body |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
704 fd->fbody->toIR(gIR); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
705 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
706 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
707 // in automatically, so we do it here. |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
708 if (!fd->isMain()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
709 if (!gIR->scopereturned()) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
710 // pass the previous block into this block |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
711 if (global.params.symdebug) DtoDwarfFuncEnd(fd); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
712 if (func->getReturnType() == LLType::VoidTy) { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
713 llvm::ReturnInst::Create(gIR->scopebb()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
714 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
715 else { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
716 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
717 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
718 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
719 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
720 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
721 // erase alloca point |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
722 allocaPoint->eraseFromParent(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
723 allocaPoint = 0; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
724 gIR->func()->allocapoint = 0; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
725 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
726 gIR->scopes.pop_back(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
727 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
728 // get rid of the endentry block, it's never used |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
729 assert(!func->getBasicBlockList().empty()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
730 func->getBasicBlockList().pop_back(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
731 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
732 // if the last block is empty now, it must be unreachable or it's a bug somewhere else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
733 // would be nice to figure out how to assert that this is correct |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
734 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
735 if (lastbb->empty()) { |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
736 new llvm::UnreachableInst(lastbb); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
737 // if (llvm::pred_begin(lastbb) != llvm::pred_end(lastbb)) |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
738 // { |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
739 // Logger::println("Erasing lastbb"); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
740 // lastbb->eraseFromParent(); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
741 // } |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
742 // else { |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
743 // new llvm::UnreachableInst(lastbb); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
744 // // if (func->getReturnType() == LLType::VoidTy) { |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
745 // // llvm::ReturnInst::Create(lastbb); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
746 // // } |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
747 // // else { |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
748 // // llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), lastbb); |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
749 // // } |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
258
diff
changeset
|
750 // } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
751 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
752 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
753 // if the last block is not terminated we return a null value or void |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
754 // for some unknown reason this is needed when a void main() has a inline asm block ... |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
755 // this should be harmless for well formed code! |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
756 lastbb = &func->getBasicBlockList().back(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
757 if (!lastbb->getTerminator()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
758 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
759 Logger::println("adding missing return statement"); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
760 if (func->getReturnType() == LLType::VoidTy) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
761 llvm::ReturnInst::Create(lastbb); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
762 else |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
763 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
764 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
765 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
241
diff
changeset
|
766 gIR->functions.pop_back(); |
100 | 767 } |
768 | |
769 ////////////////////////////////////////////////////////////////////////////////////////// | |
770 | |
117 | 771 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl) |
772 { | |
773 Dsymbol* parent = fdecl->toParent(); | |
774 ClassDeclaration* cd = parent->isClassDeclaration(); | |
775 assert(cd); | |
776 | |
777 FuncDeclaration* f = fdecl; | |
778 | |
779 while (cd) | |
780 { | |
781 ClassDeclaration* base = cd->baseClass; | |
782 if (!base) | |
783 break; | |
784 FuncDeclaration* f2 = base->findFunc(fdecl->ident, (TypeFunction*)fdecl->type); | |
785 if (f2) { | |
786 f = f2; | |
787 cd = base; | |
788 } | |
789 else | |
790 break; | |
791 } | |
792 | |
793 DtoResolveDsymbol(f); | |
794 return llvm::cast<llvm::FunctionType>(DtoType(f->type)); | |
795 } | |
796 | |
797 ////////////////////////////////////////////////////////////////////////////////////////// | |
131 | 798 |
799 DValue* DtoArgument(Argument* fnarg, Expression* argexp) | |
800 { | |
801 Logger::println("DtoArgument"); | |
802 LOG_SCOPE; | |
803 | |
804 DValue* arg = argexp->toElem(gIR); | |
805 | |
806 // ref/out arg | |
807 if (fnarg && ((fnarg->storageClass & STCref) || (fnarg->storageClass & STCout))) | |
808 { | |
809 if (arg->isVar() || arg->isLRValue()) | |
810 arg = new DImValue(argexp->type, arg->getLVal(), false); | |
811 else | |
812 arg = new DImValue(argexp->type, arg->getRVal(), false); | |
813 } | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
814 // byval arg, but expr has no storage yet |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
815 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isComplex() || arg->isNull())) |
131 | 816 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
817 LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); |
131 | 818 DVarValue* vv = new DVarValue(argexp->type, alloc, true); |
819 DtoAssign(vv, arg); | |
820 arg = vv; | |
821 } | |
822 | |
823 return arg; | |
824 } | |
825 | |
826 ////////////////////////////////////////////////////////////////////////////////////////// | |
827 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
828 void DtoVariadicArgument(Expression* argexp, LLValue* dst) |
131 | 829 { |
830 Logger::println("DtoVariadicArgument"); | |
831 LOG_SCOPE; | |
832 DVarValue* vv = new DVarValue(argexp->type, dst, true); | |
215
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
213
diff
changeset
|
833 gIR->exps.push_back(IRExp(NULL, argexp, vv)); |
131 | 834 DtoAssign(vv, argexp->toElem(gIR)); |
215
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
213
diff
changeset
|
835 gIR->exps.pop_back(); |
131 | 836 } |
837 | |
838 ////////////////////////////////////////////////////////////////////////////////////////// |