Mercurial > projects > ldc
annotate gen/tollvm.cpp @ 135:176bd52b3cf5 trunk
[svn r139] Fixed bug #33, thanks for the report :)
author | lindquist |
---|---|
date | Mon, 14 Jan 2008 23:09:55 +0100 |
parents | 44a95ac7368a |
children | 0e28624814e8 |
rev | line source |
---|---|
1 | 1 #include <iostream> |
2 | |
40 | 3 #include "gen/llvm.h" |
1 | 4 |
5 #include "mtype.h" | |
6 #include "dsymbol.h" | |
7 #include "aggregate.h" | |
8 #include "declaration.h" | |
9 #include "init.h" | |
10 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
11 #include "gen/tollvm.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
12 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
13 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
14 #include "gen/runtime.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
15 #include "gen/arrays.h" |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
16 #include "gen/dvalue.h" |
100 | 17 #include "gen/functions.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
18 #include "gen/structs.h" |
100 | 19 #include "gen/classes.h" |
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
|
20 #include "gen/typeinf.h" |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
21 #include "gen/complex.h" |
1 | 22 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
23 bool DtoIsPassedByRef(Type* type) |
40 | 24 { |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
25 Type* typ = DtoDType(type); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
26 TY t = typ->ty; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
27 return (t == Tstruct || t == Tarray || t == Tdelegate || t == Tsarray || typ->iscomplex()); |
40 | 28 } |
29 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
30 Type* DtoDType(Type* t) |
40 | 31 { |
32 if (t->ty == Ttypedef) { | |
33 Type* bt = t->toBasetype(); | |
34 assert(bt); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
35 return DtoDType(bt); |
40 | 36 } |
37 return t; | |
38 } | |
39 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
40 const llvm::Type* DtoType(Type* t) |
1 | 41 { |
42 assert(t); | |
43 switch (t->ty) | |
44 { | |
45 // integers | |
46 case Tint8: | |
47 case Tuns8: | |
48 case Tchar: | |
49 return (const llvm::Type*)llvm::Type::Int8Ty; | |
50 case Tint16: | |
51 case Tuns16: | |
52 case Twchar: | |
53 return (const llvm::Type*)llvm::Type::Int16Ty; | |
54 case Tint32: | |
55 case Tuns32: | |
56 case Tdchar: | |
57 return (const llvm::Type*)llvm::Type::Int32Ty; | |
58 case Tint64: | |
59 case Tuns64: | |
60 return (const llvm::Type*)llvm::Type::Int64Ty; | |
61 | |
62 case Tbool: | |
63 return (const llvm::Type*)llvm::ConstantInt::getTrue()->getType(); | |
64 | |
65 // floats | |
66 case Tfloat32: | |
62
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
67 case Timaginary32: |
1 | 68 return llvm::Type::FloatTy; |
69 case Tfloat64: | |
62
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
70 case Timaginary64: |
1 | 71 case Tfloat80: |
62
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
72 case Timaginary80: |
1 | 73 return llvm::Type::DoubleTy; |
74 | |
62
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
75 // complex |
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
76 case Tcomplex32: |
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
77 case Tcomplex64: |
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
78 case Tcomplex80: |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
79 return DtoComplexType(t); |
62
b86e00b938a5
[svn r66] Added support for imaginary floating point types
lindquist
parents:
58
diff
changeset
|
80 |
1 | 81 // pointers |
82 case Tpointer: { | |
83 assert(t->next); | |
84 if (t->next->ty == Tvoid) | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
85 return (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty); |
1 | 86 else |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
87 return (const llvm::Type*)getPtrToType(DtoType(t->next)); |
1 | 88 } |
89 | |
90 // arrays | |
91 case Tarray: | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
92 return DtoArrayType(t); |
1 | 93 case Tsarray: |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
94 return DtoStaticArrayType(t); |
1 | 95 |
96 // void | |
97 case Tvoid: | |
98 return llvm::Type::VoidTy; | |
99 | |
100 // aggregates | |
101 case Tstruct: { | |
100 | 102 if (!t->llvmType || *t->llvmType == NULL) { |
1 | 103 // recursive or cyclic declaration |
104 if (!gIR->structs.empty()) | |
105 { | |
106 IRStruct* found = 0; | |
107 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i) | |
108 { | |
100 | 109 if (t == (*i)->type) |
1 | 110 { |
100 | 111 return (*i)->recty.get(); |
1 | 112 } |
113 } | |
114 } | |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
115 } |
1 | 116 |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
117 TypeStruct* ts = (TypeStruct*)t; |
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
118 assert(ts->sym); |
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
119 DtoResolveDsymbol(ts->sym); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
120 return ts->sym->llvmIRStruct->recty.get();//t->llvmType->get(); |
1 | 121 } |
122 | |
123 case Tclass: { | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
124 /*if (!t->llvmType || *t->llvmType == NULL) { |
6 | 125 // recursive or cyclic declaration |
126 if (!gIR->structs.empty()) | |
127 { | |
128 IRStruct* found = 0; | |
129 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i) | |
130 { | |
100 | 131 if (t == (*i)->type) |
6 | 132 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
133 return getPtrToType((*i)->recty.get()); |
6 | 134 } |
135 } | |
136 } | |
132 | 137 Logger::println("no type found"); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
138 }*/ |
6 | 139 |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
140 TypeClass* tc = (TypeClass*)t; |
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
141 assert(tc->sym); |
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
142 DtoResolveDsymbol(tc->sym); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
143 return getPtrToType(tc->sym->llvmIRStruct->recty.get());//t->llvmType->get()); |
1 | 144 } |
145 | |
146 // functions | |
147 case Tfunction: | |
148 { | |
100 | 149 if (!t->llvmType || *t->llvmType == NULL) { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
150 return DtoFunctionType(t,NULL); |
1 | 151 } |
152 else { | |
100 | 153 return t->llvmType->get(); |
1 | 154 } |
155 } | |
6 | 156 |
1 | 157 // delegates |
158 case Tdelegate: | |
159 { | |
100 | 160 if (!t->llvmType || *t->llvmType == NULL) { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
161 return DtoDelegateType(t); |
1 | 162 } |
163 else { | |
100 | 164 return t->llvmType->get(); |
1 | 165 } |
166 } | |
167 | |
168 // typedefs | |
52 | 169 // enum |
1 | 170 case Ttypedef: |
52 | 171 case Tenum: |
1 | 172 { |
173 Type* bt = t->toBasetype(); | |
174 assert(bt); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
175 return DtoType(bt); |
1 | 176 } |
177 | |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
178 // associative arrays |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
179 case Taarray: |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
180 { |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
181 TypeAArray* taa = (TypeAArray*)t; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
182 std::vector<const llvm::Type*> types; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
183 types.push_back(DtoType(taa->key)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
184 types.push_back(DtoType(taa->next)); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
185 return getPtrToType(llvm::StructType::get(types)); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
186 } |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
187 |
1 | 188 default: |
189 printf("trying to convert unknown type with value %d\n", t->ty); | |
190 assert(0); | |
191 } | |
192 return 0; | |
193 } | |
194 | |
195 ////////////////////////////////////////////////////////////////////////////////////////// | |
196 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
197 const llvm::StructType* DtoDelegateType(Type* t) |
1 | 198 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
199 const llvm::Type* i8ptr = getPtrToType(llvm::Type::Int8Ty); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
200 const llvm::Type* func = DtoFunctionType(t->next, i8ptr); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
201 const llvm::Type* funcptr = getPtrToType(func); |
1 | 202 |
203 std::vector<const llvm::Type*> types; | |
204 types.push_back(i8ptr); | |
205 types.push_back(funcptr); | |
206 return llvm::StructType::get(types); | |
207 } | |
208 | |
209 ////////////////////////////////////////////////////////////////////////////////////////// | |
210 | |
211 static llvm::Function* LLVM_DeclareMemIntrinsic(const char* name, int bits, bool set=false) | |
212 { | |
213 assert(bits == 32 || bits == 64); | |
214 const llvm::Type* int8ty = (const llvm::Type*)llvm::Type::Int8Ty; | |
215 const llvm::Type* int32ty = (const llvm::Type*)llvm::Type::Int32Ty; | |
216 const llvm::Type* int64ty = (const llvm::Type*)llvm::Type::Int64Ty; | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
217 const llvm::Type* int8ptrty = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty); |
1 | 218 const llvm::Type* voidty = (const llvm::Type*)llvm::Type::VoidTy; |
219 | |
220 assert(gIR); | |
221 assert(gIR->module); | |
222 | |
223 // parameter types | |
224 std::vector<const llvm::Type*> pvec; | |
225 pvec.push_back(int8ptrty); | |
226 pvec.push_back(set?int8ty:int8ptrty); | |
227 pvec.push_back(bits==32?int32ty:int64ty); | |
228 pvec.push_back(int32ty); | |
229 llvm::FunctionType* functype = llvm::FunctionType::get(voidty, pvec, false); | |
230 return new llvm::Function(functype, llvm::GlobalValue::ExternalLinkage, name, gIR->module); | |
231 } | |
232 | |
233 ////////////////////////////////////////////////////////////////////////////////////////// | |
234 | |
235 // llvm.memset.i32 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
236 llvm::Function* LLVM_DeclareMemSet32() |
1 | 237 { |
238 static llvm::Function* _func = 0; | |
239 if (_func == 0) { | |
240 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i32", 32, true); | |
241 } | |
242 return _func; | |
243 } | |
244 | |
245 ////////////////////////////////////////////////////////////////////////////////////////// | |
246 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
247 llvm::Function* LLVM_DeclareMemSet64() |
1 | 248 { |
249 static llvm::Function* _func = 0; | |
250 if (_func == 0) { | |
251 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i64", 64, true); | |
252 } | |
253 return _func; | |
254 } | |
255 | |
256 ////////////////////////////////////////////////////////////////////////////////////////// | |
257 | |
258 // llvm.memcpy.i32 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
259 llvm::Function* LLVM_DeclareMemCpy32() |
1 | 260 { |
261 static llvm::Function* _func = 0; | |
262 if (_func == 0) { | |
263 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i32", 32); | |
264 } | |
265 return _func; | |
266 } | |
267 | |
268 ////////////////////////////////////////////////////////////////////////////////////////// | |
269 | |
270 // llvm.memcpy.i64 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
271 llvm::Function* LLVM_DeclareMemCpy64() |
1 | 272 { |
273 static llvm::Function* _func = 0; | |
274 if (_func == 0) { | |
275 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i64", 64); | |
276 } | |
277 return _func; | |
278 } | |
279 | |
280 ////////////////////////////////////////////////////////////////////////////////////////// | |
281 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
282 llvm::Value* DtoNullDelegate(llvm::Value* v) |
1 | 283 { |
284 assert(gIR); | |
285 d_uns64 n = (global.params.is64bit) ? 16 : 8; | |
286 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
287 const llvm::Type* i8p_ty = getPtrToType(llvm::Type::Int8Ty); |
1 | 288 |
289 llvm::Value* arr = new llvm::BitCastInst(v,i8p_ty,"tmp",gIR->scopebb()); | |
290 | |
291 llvm::Function* fn = LLVM_DeclareMemSet32(); | |
292 std::vector<llvm::Value*> llargs; | |
293 llargs.resize(4); | |
294 llargs[0] = arr; | |
295 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); | |
296 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); | |
297 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
298 | |
299 llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
300 | |
301 return ret; | |
302 } | |
303 | |
304 ////////////////////////////////////////////////////////////////////////////////////////// | |
305 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
306 llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src) |
1 | 307 { |
308 assert(dst->getType() == src->getType()); | |
309 assert(gIR); | |
310 | |
311 d_uns64 n = (global.params.is64bit) ? 16 : 8; | |
312 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
313 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
1 | 314 |
315 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); | |
316 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); | |
317 | |
318 llvm::Function* fn = LLVM_DeclareMemCpy32(); | |
319 std::vector<llvm::Value*> llargs; | |
320 llargs.resize(4); | |
321 llargs[0] = dstarr; | |
322 llargs[1] = srcarr; | |
323 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); | |
324 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
325 | |
326 return new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
327 } | |
328 | |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
329 ////////////////////////////////////////////////////////////////////////////////////////// |
1 | 330 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
331 llvm::Value* DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs) |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
332 { |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
333 llvm::ICmpInst::Predicate pred = (op == TOKequal) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
334 llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp"); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
335 llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp"); |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
336 llvm::Value* b1 = gIR->ir->CreateICmp(pred,l,r,"tmp"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
337 l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp"); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
338 r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp"); |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
339 llvm::Value* b2 = gIR->ir->CreateICmp(pred,l,r,"tmp"); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
340 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp"); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
341 if (op == TOKnotequal) |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
342 return gIR->ir->CreateNot(b,"tmp"); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
343 return b; |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
344 } |
1 | 345 |
346 ////////////////////////////////////////////////////////////////////////////////////////// | |
347 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
348 llvm::GlobalValue::LinkageTypes DtoLinkage(PROT prot, uint stc) |
1 | 349 { |
350 switch(prot) | |
351 { | |
352 case PROTprivate: | |
132 | 353 if (stc & STCextern) |
354 return llvm::GlobalValue::ExternalLinkage; | |
355 else | |
356 return llvm::GlobalValue::InternalLinkage; | |
1 | 357 |
358 case PROTpublic: | |
359 case PROTpackage: | |
360 case PROTprotected: | |
361 case PROTexport: | |
362 return llvm::GlobalValue::ExternalLinkage; | |
363 | |
364 case PROTundefined: | |
365 case PROTnone: | |
366 assert(0 && "Unsupported linkage type"); | |
367 } | |
368 return llvm::GlobalValue::ExternalLinkage; | |
369 | |
370 /* ExternalLinkage = 0, LinkOnceLinkage, WeakLinkage, AppendingLinkage, | |
371 InternalLinkage, DLLImportLinkage, DLLExportLinkage, ExternalWeakLinkage, | |
372 GhostLinkage */ | |
373 } | |
374 | |
375 ////////////////////////////////////////////////////////////////////////////////////////// | |
376 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
377 unsigned DtoCallingConv(LINK l) |
1 | 378 { |
379 if (l == LINKc) | |
380 return llvm::CallingConv::C; | |
381 else if (l == LINKd || l == LINKdefault) | |
382 return llvm::CallingConv::Fast; | |
383 else if (l == LINKwindows) | |
384 return llvm::CallingConv::X86_StdCall; | |
385 else | |
386 assert(0 && "Unsupported calling convention"); | |
387 } | |
388 | |
389 ////////////////////////////////////////////////////////////////////////////////////////// | |
390 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
391 llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val) |
1 | 392 { |
393 const llvm::Type* ptrTy = ptr->getType()->getContainedType(0); | |
394 const llvm::Type* valTy = val->getType(); | |
395 // ptr points to val's type | |
396 if (ptrTy == valTy) | |
397 { | |
398 return val; | |
399 } | |
400 // ptr is integer pointer | |
401 else if (ptrTy->isInteger()) | |
402 { | |
403 // val is integer | |
404 assert(valTy->isInteger()); | |
405 const llvm::IntegerType* pt = llvm::cast<const llvm::IntegerType>(ptrTy); | |
406 const llvm::IntegerType* vt = llvm::cast<const llvm::IntegerType>(valTy); | |
407 if (pt->getBitWidth() < vt->getBitWidth()) { | |
408 return new llvm::TruncInst(val, pt, "tmp", gIR->scopebb()); | |
409 } | |
410 else | |
411 assert(0); | |
412 } | |
413 // something else unsupported | |
414 else | |
415 { | |
416 Logger::cout() << *ptrTy << '|' << *valTy << '\n'; | |
417 assert(0); | |
418 } | |
419 return 0; | |
420 } | |
421 | |
422 ////////////////////////////////////////////////////////////////////////////////////////// | |
423 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
424 llvm::Value* DtoBoolean(llvm::Value* val) |
1 | 425 { |
426 const llvm::Type* t = val->getType(); | |
427 if (t->isInteger()) | |
428 { | |
429 if (t == llvm::Type::Int1Ty) | |
430 return val; | |
431 else { | |
432 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false); | |
433 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); | |
434 } | |
435 } | |
96 | 436 else if (isaPointer(t)) { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
437 llvm::Value* zero = llvm::Constant::getNullValue(t); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
438 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); |
1 | 439 } |
440 else | |
441 { | |
442 Logger::cout() << *t << '\n'; | |
443 } | |
444 assert(0); | |
445 return 0; | |
446 } | |
447 | |
448 ////////////////////////////////////////////////////////////////////////////////////////// | |
449 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
450 const llvm::Type* DtoSize_t() |
1 | 451 { |
452 if (global.params.is64bit) | |
453 return llvm::Type::Int64Ty; | |
454 else | |
455 return llvm::Type::Int32Ty; | |
456 } | |
457 | |
458 ////////////////////////////////////////////////////////////////////////////////////////// | |
459 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
460 llvm::Constant* DtoConstInitializer(Type* type, Initializer* init) |
1 | 461 { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
462 llvm::Constant* _init = 0; // may return zero |
1 | 463 if (!init) |
464 { | |
40 | 465 Logger::println("const default initializer for %s", type->toChars()); |
466 _init = type->defaultInit()->toConstElem(gIR); | |
1 | 467 } |
468 else if (ExpInitializer* ex = init->isExpInitializer()) | |
469 { | |
40 | 470 Logger::println("const expression initializer"); |
471 _init = ex->exp->toConstElem(gIR); | |
1 | 472 } |
473 else if (StructInitializer* si = init->isStructInitializer()) | |
474 { | |
40 | 475 Logger::println("const struct initializer"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
476 _init = DtoConstStructInitializer(si); |
1 | 477 } |
478 else if (ArrayInitializer* ai = init->isArrayInitializer()) | |
479 { | |
40 | 480 Logger::println("const array initializer"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
481 _init = DtoConstArrayInitializer(ai); |
1 | 482 } |
483 else if (init->isVoidInitializer()) | |
484 { | |
40 | 485 Logger::println("const void initializer"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
486 const llvm::Type* ty = DtoType(type); |
1 | 487 _init = llvm::Constant::getNullValue(ty); |
488 } | |
489 else { | |
40 | 490 Logger::println("unsupported const initializer: %s", init->toChars()); |
491 } | |
492 return _init; | |
493 } | |
494 | |
495 ////////////////////////////////////////////////////////////////////////////////////////// | |
496 | |
100 | 497 llvm::Constant* DtoConstFieldInitializer(Type* t, Initializer* init) |
498 { | |
499 Logger::println("DtoConstFieldInitializer"); | |
500 LOG_SCOPE; | |
501 | |
502 const llvm::Type* _type = DtoType(t); | |
503 | |
504 llvm::Constant* _init = DtoConstInitializer(t, init); | |
505 assert(_init); | |
506 if (_type != _init->getType()) | |
507 { | |
508 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; | |
509 if (t->ty == Tsarray) | |
510 { | |
511 const llvm::ArrayType* arrty = isaArray(_type); | |
512 uint64_t n = arrty->getNumElements(); | |
513 std::vector<llvm::Constant*> vals(n,_init); | |
514 _init = llvm::ConstantArray::get(arrty, vals); | |
515 } | |
516 else if (t->ty == Tarray) | |
517 { | |
518 assert(isaStruct(_type)); | |
519 _init = llvm::ConstantAggregateZero::get(_type); | |
520 } | |
521 else if (t->ty == Tstruct) | |
522 { | |
523 const llvm::StructType* structty = isaStruct(_type); | |
524 TypeStruct* ts = (TypeStruct*)t; | |
525 assert(ts); | |
526 assert(ts->sym); | |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
116
diff
changeset
|
527 assert(ts->sym->llvmConstInit); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
116
diff
changeset
|
528 _init = ts->sym->llvmConstInit; |
100 | 529 } |
530 else if (t->ty == Tclass) | |
531 { | |
532 _init = llvm::Constant::getNullValue(_type); | |
533 } | |
534 else { | |
535 Logger::println("failed for type %s", t->toChars()); | |
536 assert(0); | |
537 } | |
538 } | |
539 | |
540 return _init; | |
541 } | |
542 | |
543 ////////////////////////////////////////////////////////////////////////////////////////// | |
544 | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
545 DValue* DtoInitializer(Initializer* init) |
40 | 546 { |
547 if (ExpInitializer* ex = init->isExpInitializer()) | |
548 { | |
549 Logger::println("expression initializer"); | |
92 | 550 assert(ex->exp); |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
551 return ex->exp->toElem(gIR); |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
552 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
553 else if (init->isVoidInitializer()) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
554 { |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
555 // do nothing |
40 | 556 } |
557 else { | |
1 | 558 Logger::println("unsupported initializer: %s", init->toChars()); |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
559 assert(0); |
1 | 560 } |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
561 return 0; |
1 | 562 } |
6 | 563 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
564 ////////////////////////////////////////////////////////////////////////////////////////// |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
565 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
566 llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb) |
6 | 567 { |
568 std::vector<llvm::Value*> v(2); | |
569 v[0] = i0; | |
570 v[1] = i1; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
571 //Logger::cout() << "DtoGEP: " << *ptr << '\n'; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
572 return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb()); |
6 | 573 } |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
574 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
575 ////////////////////////////////////////////////////////////////////////////////////////// |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
576 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
577 llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb) |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
578 { |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
579 size_t n = src.size(); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
580 std::vector<llvm::Value*> dst(n, NULL); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
581 //std::ostream& ostr = Logger::cout(); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
582 //ostr << "indices for '" << *ptr << "':"; |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
583 for (size_t i=0; i<n; ++i) |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
584 { |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
585 //ostr << ' ' << i; |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
586 dst[i] = llvm::ConstantInt::get(llvm::Type::Int32Ty, src[i], false); |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
587 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
588 //ostr << '\n';*/ |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
589 return new llvm::GetElementPtrInst(ptr, dst.begin(), dst.end(), var, bb?bb:gIR->scopebb()); |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
590 } |
9 | 591 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
592 ////////////////////////////////////////////////////////////////////////////////////////// |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
593 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
594 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i, const std::string& var, llvm::BasicBlock* bb) |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
595 { |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
596 return new llvm::GetElementPtrInst(ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false), var, bb?bb:gIR->scopebb()); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
597 } |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
598 |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
599 ////////////////////////////////////////////////////////////////////////////////////////// |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
600 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
601 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb) |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
602 { |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
603 std::vector<llvm::Value*> v(2); |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
604 v[0] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i0, false); |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
605 v[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i1, false); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
606 return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb()); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
607 } |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
608 |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
609 ////////////////////////////////////////////////////////////////////////////////////////// |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
610 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
611 llvm::Value* DtoRealloc(llvm::Value* ptr, const llvm::Type* ty) |
34 | 612 { |
613 /*size_t sz = gTargetData->getTypeSize(ty); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
614 llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false); |
34 | 615 if (ptr == 0) { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
616 llvm::PointerType* i8pty = getPtrToType(llvm::Type::Int8Ty); |
34 | 617 ptr = llvm::ConstantPointerNull::get(i8pty); |
618 } | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
619 return DtoRealloc(ptr, n);*/ |
34 | 620 return NULL; |
621 } | |
622 | |
623 ////////////////////////////////////////////////////////////////////////////////////////// | |
624 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
625 llvm::Value* DtoRealloc(llvm::Value* ptr, llvm::Value* n) |
34 | 626 { |
627 assert(ptr); | |
628 assert(n); | |
629 | |
630 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_realloc"); | |
631 assert(fn); | |
632 | |
633 llvm::Value* newptr = ptr; | |
634 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
635 const llvm::PointerType* i8pty = getPtrToType(llvm::Type::Int8Ty); |
34 | 636 if (ptr->getType() != i8pty) { |
637 newptr = new llvm::BitCastInst(ptr,i8pty,"tmp",gIR->scopebb()); | |
638 } | |
639 | |
640 std::vector<llvm::Value*> args; | |
641 args.push_back(newptr); | |
642 args.push_back(n); | |
643 llvm::Value* ret = new llvm::CallInst(fn, args.begin(), args.end(), "tmprealloc", gIR->scopebb()); | |
644 | |
645 return ret->getType() == ptr->getType() ? ret : new llvm::BitCastInst(ret,ptr->getType(),"tmp",gIR->scopebb()); | |
646 } | |
647 | |
648 ////////////////////////////////////////////////////////////////////////////////////////// | |
649 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
650 void DtoAssert(Loc* loc, DValue* msg) |
34 | 651 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
652 std::vector<llvm::Value*> args; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
653 llvm::Constant* c; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
654 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
655 // func |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
656 const char* fname = msg ? "_d_assert_msg" : "_d_assert"; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
657 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
658 // msg param |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
659 if (msg) args.push_back(msg->getRVal()); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
660 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
661 // file param |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
662 c = DtoConstString(loc->filename); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
663 llvm::AllocaInst* alloc = new llvm::AllocaInst(c->getType(), "srcfile", gIR->topallocapoint()); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
664 llvm::Value* ptr = DtoGEPi(alloc, 0,0, "tmp"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
665 DtoStore(c->getOperand(0), ptr); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
666 ptr = DtoGEPi(alloc, 0,1, "tmp"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
667 DtoStore(c->getOperand(1), ptr); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
668 args.push_back(alloc); |
34 | 669 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
670 // line param |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
671 c = DtoConstUint(loc->linnum); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
672 args.push_back(c); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
673 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
674 // call |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
675 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
676 llvm::CallInst* call = new llvm::CallInst(fn, args.begin(), args.end(), "", gIR->scopebb()); |
34 | 677 } |
678 | |
40 | 679 ////////////////////////////////////////////////////////////////////////////////////////// |
34 | 680 |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
681 static const llvm::Type* get_next_frame_ptr_type(Dsymbol* sc) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
682 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
683 assert(sc->isFuncDeclaration() || sc->isClassDeclaration()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
684 Dsymbol* p = sc->toParent2(); |
131 | 685 if (!p->isFuncDeclaration() && !p->isClassDeclaration()) |
686 Logger::println("unexpected parent symbol found while resolving frame pointer - '%s' kind: '%s'", p->toChars(), p->kind()); | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
687 assert(p->isFuncDeclaration() || p->isClassDeclaration()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
688 if (FuncDeclaration* fd = p->isFuncDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
689 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
690 llvm::Value* v = fd->llvmNested; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
691 assert(v); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
692 return v->getType(); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
693 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
694 else if (ClassDeclaration* cd = p->isClassDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
695 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
696 return DtoType(cd->type); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
697 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
698 else |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
699 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
700 Logger::println("symbol: '%s' kind: '%s'", sc->toChars(), sc->kind()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
701 assert(0); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
702 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
703 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
704 |
131 | 705 ////////////////////////////////////////////////////////////////////////////////////////// |
706 | |
707 static llvm::Value* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, llvm::Value* v) | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
708 { |
131 | 709 LOG_SCOPE; |
710 if (sc == func) | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
711 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
712 return v; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
713 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
714 else if (FuncDeclaration* fd = sc->isFuncDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
715 { |
131 | 716 Logger::println("scope is function: %s", fd->toChars()); |
717 | |
718 if (fd->toParent2() == func) | |
719 { | |
720 if (!func->llvmNested) | |
721 return NULL; | |
722 return DtoBitCast(v, func->llvmNested->getType()); | |
723 } | |
724 | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
725 v = DtoBitCast(v, get_next_frame_ptr_type(fd)); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
726 Logger::cout() << "v = " << *v << '\n'; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
727 |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
728 if (fd->toParent2()->isFuncDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
729 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
730 v = DtoGEPi(v, 0,0, "tmp"); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
731 v = DtoLoad(v); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
732 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
733 else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
734 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
735 size_t idx = 2; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
736 idx += cd->llvmIRStruct->interfaces.size(); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
737 v = DtoGEPi(v,0,idx,"tmp"); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
738 v = DtoLoad(v); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
739 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
740 else |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
741 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
742 assert(0); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
743 } |
131 | 744 return get_frame_ptr_impl(func, fd->toParent2(), v); |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
745 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
746 else if (ClassDeclaration* cd = sc->isClassDeclaration()) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
747 { |
131 | 748 Logger::println("scope is class: %s", cd->toChars()); |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
749 /*size_t idx = 2; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
750 idx += cd->llvmIRStruct->interfaces.size(); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
751 v = DtoGEPi(v,0,idx,"tmp"); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
752 Logger::cout() << "gep = " << *v << '\n'; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
753 v = DtoLoad(v);*/ |
131 | 754 return get_frame_ptr_impl(func, cd->toParent2(), v); |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
755 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
756 else |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
757 { |
131 | 758 Logger::println("symbol: '%s'", sc->toPrettyChars()); |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
759 assert(0); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
760 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
761 } |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
762 |
131 | 763 ////////////////////////////////////////////////////////////////////////////////////////// |
764 | |
765 static llvm::Value* get_frame_ptr(FuncDeclaration* func) | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
766 { |
131 | 767 Logger::println("Resolving context pointer for nested function: '%s'", func->toPrettyChars()); |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
768 LOG_SCOPE; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
769 IRFunction* irfunc = gIR->func(); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
770 |
131 | 771 // in the right scope already |
772 if (func == irfunc->decl) | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
773 return irfunc->decl->llvmNested; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
774 |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
775 // use the 'this' pointer |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
776 llvm::Value* ptr = irfunc->decl->llvmThisVar; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
777 assert(ptr); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
778 |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
779 // return the fully resolved frame pointer |
131 | 780 ptr = get_frame_ptr_impl(func, irfunc->decl, ptr); |
781 if (ptr) Logger::cout() << "Found context!" << *ptr; | |
782 else Logger::cout() << "NULL context!\n"; | |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
783 |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
784 return ptr; |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
785 } |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
786 |
131 | 787 ////////////////////////////////////////////////////////////////////////////////////////// |
788 | |
789 llvm::Value* DtoNestedContext(FuncDeclaration* func) | |
790 { | |
791 // resolve frame ptr | |
792 llvm::Value* ptr = get_frame_ptr(func); | |
793 Logger::cout() << "Nested context ptr = "; | |
794 if (ptr) Logger::cout() << *ptr; | |
795 else Logger::cout() << "NULL"; | |
796 Logger::cout() << '\n'; | |
797 return ptr; | |
798 } | |
799 | |
800 ////////////////////////////////////////////////////////////////////////////////////////// | |
801 | |
802 static void print_frame_worker(VarDeclaration* vd, Dsymbol* par) | |
803 { | |
804 if (vd->toParent2() == par) | |
805 { | |
806 Logger::println("found: '%s' kind: '%s'", par->toChars(), par->kind()); | |
807 return; | |
808 } | |
809 | |
810 Logger::println("diving into: '%s' kind: '%s'", par->toChars(), par->kind()); | |
811 LOG_SCOPE; | |
812 print_frame_worker(vd, par->toParent2()); | |
813 } | |
814 | |
815 ////////////////////////////////////////////////////////////////////////////////////////// | |
816 | |
817 static void print_nested_frame_list(VarDeclaration* vd, Dsymbol* par) | |
818 { | |
819 Logger::println("Frame pointer list for nested var: '%s'", vd->toPrettyChars()); | |
820 LOG_SCOPE; | |
821 if (vd->toParent2() != par) | |
822 print_frame_worker(vd, par); | |
823 else | |
824 Logger::println("Found at level 0"); | |
825 Logger::println("Done"); | |
826 } | |
827 | |
828 ////////////////////////////////////////////////////////////////////////////////////////// | |
829 | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
830 llvm::Value* DtoNestedVariable(VarDeclaration* vd) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
831 { |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
832 // log the frame list |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
833 IRFunction* irfunc = gIR->func(); |
135
176bd52b3cf5
[svn r139] Fixed bug #33, thanks for the report :)
lindquist
parents:
133
diff
changeset
|
834 if (Logger::enabled()) |
131 | 835 print_nested_frame_list(vd, irfunc->decl); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
836 |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
837 // resolve frame ptr |
131 | 838 FuncDeclaration* func = vd->toParent2()->isFuncDeclaration(); |
839 assert(func); | |
840 llvm::Value* ptr = DtoNestedContext(func); | |
841 assert(ptr && "nested var, but no context"); | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
842 |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
843 // we must cast here to be sure. nested classes just have a void* |
131 | 844 ptr = DtoBitCast(ptr, func->llvmNested->getType()); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
845 |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
846 // index nested var and load (if necessary) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
847 llvm::Value* v = DtoGEPi(ptr, 0, vd->llvmNestedIndex, "tmp"); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
848 // references must be loaded, for normal variables this IS already the variable storage!!! |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
849 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
850 v = DtoLoad(v); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
851 |
131 | 852 // log and return |
853 Logger::cout() << "Nested var ptr = " << *v << '\n'; | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
121
diff
changeset
|
854 return v; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
855 } |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
856 |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
857 ////////////////////////////////////////////////////////////////////////////////////////// |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
858 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
859 void DtoAssign(DValue* lhs, DValue* rhs) |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
860 { |
92 | 861 Logger::cout() << "DtoAssign(...);\n"; |
131 | 862 LOG_SCOPE; |
863 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
864 Type* t = DtoDType(lhs->getType()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
865 Type* t2 = DtoDType(rhs->getType()); |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
866 |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
867 if (t->ty == Tstruct) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
868 if (t2 != t) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
869 // TODO: fix this, use 'rhs' for something |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
870 DtoStructZeroInit(lhs->getLVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
871 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
872 else if (!rhs->inPlace()) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
873 DtoStructCopy(lhs->getLVal(),rhs->getRVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
874 } |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
875 } |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
876 else if (t->ty == Tarray) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
877 // lhs is slice |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
878 if (DSliceValue* s = lhs->isSlice()) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
879 if (DSliceValue* s2 = rhs->isSlice()) { |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
880 DtoArrayCopySlices(s, s2); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
881 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
882 else if (t->next == t2) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
883 if (s->len) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
884 DtoArrayInit(s->ptr, s->len, rhs->getRVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
885 else |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
886 DtoArrayInit(s->ptr, rhs->getRVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
887 } |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
888 else { |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
889 DtoArrayCopyToSlice(s, rhs); |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
890 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
891 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
892 // rhs is slice |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
893 else if (DSliceValue* s = rhs->isSlice()) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
894 DtoSetArray(lhs->getLVal(),s->len,s->ptr); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
895 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
896 // null |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
897 else if (rhs->isNull()) { |
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
|
898 DtoSetArrayToNull(lhs->getLVal()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
899 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
900 // reference assignment |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
901 else { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
902 DtoArrayAssign(lhs->getLVal(), rhs->getRVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
903 } |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
904 } |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
905 else if (t->ty == Tsarray) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
906 DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal()); |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
907 } |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
908 else if (t->ty == Tdelegate) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
909 if (rhs->isNull()) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
910 DtoNullDelegate(lhs->getLVal()); |
132 | 911 else if (!rhs->inPlace()) { |
912 llvm::Value* l = lhs->getLVal(); | |
913 llvm::Value* r = rhs->getRVal(); | |
914 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | |
915 DtoDelegateCopy(l, r); | |
916 } | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
917 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
918 else if (t->ty == Tclass) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
919 assert(t2->ty == Tclass); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
920 // assignment to this in constructor special case |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
921 if (lhs->isThis()) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
922 llvm::Value* tmp = rhs->getRVal(); |
100 | 923 FuncDeclaration* fdecl = gIR->func()->decl; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
924 // respecify the this param |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
925 if (!llvm::isa<llvm::AllocaInst>(fdecl->llvmThisVar)) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
926 fdecl->llvmThisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
927 DtoStore(tmp, fdecl->llvmThisVar); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
928 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
929 // regular class ref -> class ref assignment |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
930 else { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
931 DtoStore(rhs->getRVal(), lhs->getLVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
932 } |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
933 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
934 else if (t->iscomplex()) { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
935 assert(!lhs->isComplex()); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
936 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
937 llvm::Value* dst; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
938 if (DLRValue* lr = lhs->isLRValue()) { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
939 dst = lr->getLVal(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
940 rhs = DtoCastComplex(rhs, lr->getLType()); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
941 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
942 else { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
943 dst = lhs->getRVal(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
944 } |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
945 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
946 if (DComplexValue* cx = rhs->isComplex()) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
947 DtoComplexSet(dst, cx->re, cx->im); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
948 else |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
949 DtoComplexAssign(dst, rhs->getRVal()); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
950 } |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
951 else { |
131 | 952 llvm::Value* l = lhs->getLVal(); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
953 llvm::Value* r = rhs->getRVal(); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
954 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
955 const llvm::Type* lit = l->getType()->getContainedType(0); |
131 | 956 if (r->getType() != lit) { |
957 if (DLRValue* lr = lhs->isLRValue()) // handle lvalue cast assignments | |
958 r = DtoCast(rhs, lr->getLType())->getRVal(); | |
959 else | |
960 r = DtoCast(rhs, lhs->getType())->getRVal(); | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
961 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
962 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
963 gIR->ir->CreateStore(r, l); |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
964 } |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
965 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
966 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
967 ////////////////////////////////////////////////////////////////////////////////////////// |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
968 DValue* DtoCastInt(DValue* val, Type* _to) |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
969 { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
970 const llvm::Type* tolltype = DtoType(_to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
971 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
972 Type* to = DtoDType(_to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
973 Type* from = DtoDType(val->getType()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
974 assert(from->isintegral()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
975 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
976 size_t fromsz = from->size(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
977 size_t tosz = to->size(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
978 |
131 | 979 llvm::Value* rval = val->getRVal(); |
980 if (rval->getType() == tolltype) { | |
981 return new DImValue(_to, rval); | |
982 } | |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
983 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
984 if (to->isintegral()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
985 if (fromsz < tosz) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
986 Logger::cout() << "cast to: " << *tolltype << '\n'; |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
987 if (from->isunsigned() || from->ty == Tbool) { |
131 | 988 rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
989 } else { |
131 | 990 rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
991 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
992 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
993 else if (fromsz > tosz) { |
131 | 994 rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
995 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
996 else { |
131 | 997 rval = new llvm::BitCastInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
998 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
999 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1000 else if (to->isfloating()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1001 if (from->isunsigned()) { |
131 | 1002 rval = new llvm::UIToFPInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1003 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1004 else { |
131 | 1005 rval = new llvm::SIToFPInst(rval, tolltype, "tmp", gIR->scopebb()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1006 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1007 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1008 else if (to->ty == Tpointer) { |
131 | 1009 Logger::cout() << "cast pointer: " << *tolltype << '\n'; |
1010 rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp"); | |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1011 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1012 else { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1013 assert(0 && "bad int cast"); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1014 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1015 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1016 return new DImValue(_to, rval); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1017 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1018 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1019 DValue* DtoCastPtr(DValue* val, Type* to) |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1020 { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1021 const llvm::Type* tolltype = DtoType(to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1022 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1023 Type* totype = DtoDType(to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1024 Type* fromtype = DtoDType(val->getType()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1025 assert(fromtype->ty == Tpointer); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1026 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1027 llvm::Value* rval; |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1028 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1029 if (totype->ty == Tpointer || totype->ty == Tclass) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1030 llvm::Value* src = val->getRVal(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1031 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n'; |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1032 rval = new llvm::BitCastInst(src, tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1033 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1034 else if (totype->isintegral()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1035 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1036 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1037 else { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1038 Logger::println("invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1039 assert(0); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1040 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1041 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1042 return new DImValue(to, rval); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1043 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1044 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1045 DValue* DtoCastFloat(DValue* val, Type* to) |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1046 { |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1047 if (val->getType() == to) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1048 return val; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1049 |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1050 const llvm::Type* tolltype = DtoType(to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1051 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1052 Type* totype = DtoDType(to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1053 Type* fromtype = DtoDType(val->getType()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1054 assert(fromtype->isfloating()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1055 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1056 size_t fromsz = fromtype->size(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1057 size_t tosz = totype->size(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1058 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1059 llvm::Value* rval; |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1060 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1061 if (totype->iscomplex()) { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1062 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1063 //return new DImValue(to, DtoComplex(to, val)); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1064 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1065 else if (totype->isfloating()) { |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1066 if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1067 rval = val->getRVal(); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1068 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1069 else if (fromsz < tosz) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1070 rval = new llvm::FPExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1071 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1072 else if (fromsz > tosz) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1073 rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1074 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1075 else { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1076 assert(0 && "bad float cast"); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1077 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1078 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1079 else if (totype->isintegral()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1080 if (totype->isunsigned()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1081 rval = new llvm::FPToUIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1082 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1083 else { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1084 rval = new llvm::FPToSIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1085 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1086 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1087 else { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1088 assert(0 && "bad float cast"); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1089 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1090 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1091 return new DImValue(to, rval); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1092 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1093 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1094 DValue* DtoCastComplex(DValue* val, Type* _to) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1095 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1096 Type* to = DtoDType(_to); |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1097 Type* vty = val->getType(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1098 if (to->iscomplex()) { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1099 if (vty->size() == to->size()) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1100 return val; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1101 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1102 llvm::Value *re, *im; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1103 DtoGetComplexParts(val, re, im); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1104 const llvm::Type* toty = DtoComplexBaseType(to); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1105 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1106 if (to->size() < vty->size()) { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1107 re = gIR->ir->CreateFPTrunc(re, toty, "tmp"); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1108 im = gIR->ir->CreateFPTrunc(im, toty, "tmp"); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1109 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1110 else if (to->size() > vty->size()) { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1111 re = gIR->ir->CreateFPExt(re, toty, "tmp"); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1112 im = gIR->ir->CreateFPExt(im, toty, "tmp"); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1113 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1114 else { |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1115 return val; |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1116 } |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1117 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1118 if (val->isComplex()) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1119 return new DComplexValue(_to, re, im); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1120 |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1121 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1122 // so we need to give it storage, or fix the system that handles this stuff (DLRValue) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1123 llvm::Value* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1124 DtoComplexSet(mem, re, im); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1125 return new DLRValue(val->getType(), val->getRVal(), _to, mem); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1126 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1127 else if (to->isimaginary()) { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1128 if (val->isComplex()) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1129 return new DImValue(to, val->isComplex()->im); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1130 llvm::Value* v = val->getRVal(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1131 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1132 return DtoCastFloat(im, to); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1133 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1134 else if (to->isfloating()) { |
107
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1135 if (val->isComplex()) |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1136 return new DImValue(to, val->isComplex()->re); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1137 llvm::Value* v = val->getRVal(); |
3efbcc81ba45
[svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents:
106
diff
changeset
|
1138 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1139 return DtoCastFloat(re, to); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1140 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1141 else |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1142 assert(0); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1143 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1144 |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1145 DValue* DtoCast(DValue* val, Type* to) |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1146 { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1147 Type* fromtype = DtoDType(val->getType()); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
1148 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1149 if (fromtype->isintegral()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1150 return DtoCastInt(val, to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1151 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1152 else if (fromtype->iscomplex()) { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1153 return DtoCastComplex(val, to); |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1154 } |
97
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1155 else if (fromtype->isfloating()) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1156 return DtoCastFloat(val, to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1157 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1158 else if (fromtype->ty == Tclass) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1159 return DtoCastClass(val, to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1160 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1161 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1162 return DtoCastArray(val, to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1163 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1164 else if (fromtype->ty == Tpointer) { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1165 return DtoCastPtr(val, to); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1166 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1167 else { |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1168 assert(0); |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1169 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1170 } |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1171 |
c4e161556a21
[svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents:
96
diff
changeset
|
1172 ////////////////////////////////////////////////////////////////////////////////////////// |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1173 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1174 llvm::ConstantInt* DtoConstSize_t(size_t i) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1175 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1176 return llvm::ConstantInt::get(DtoSize_t(), i, false); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1177 } |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1178 llvm::ConstantInt* DtoConstUint(unsigned i) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1179 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1180 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1181 } |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1182 llvm::ConstantInt* DtoConstInt(int i) |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1183 { |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1184 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, true); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1185 } |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1186 llvm::Constant* DtoConstBool(bool b) |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1187 { |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1188 return llvm::ConstantInt::get(llvm::Type::Int1Ty, b, false); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1189 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1190 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1191 llvm::ConstantFP* DtoConstFP(Type* t, long double value) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1192 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1193 TY ty = DtoDType(t)->ty; |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1194 if (ty == Tfloat32 || ty == Timaginary32) |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1195 return llvm::ConstantFP::get(llvm::Type::FloatTy, llvm::APFloat(float(value))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1196 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tfloat80 || ty == Timaginary80) |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1197 return llvm::ConstantFP::get(llvm::Type::DoubleTy, llvm::APFloat(double(value))); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1198 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1199 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1200 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1201 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1202 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1203 llvm::Constant* DtoConstString(const char* str) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1204 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1205 std::string s(str); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1206 llvm::Constant* init = llvm::ConstantArray::get(s, true); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1207 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1208 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1209 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1210 return DtoConstSlice( |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1211 DtoConstSize_t(s.length()), |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1212 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2) |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1213 ); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1214 } |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1215 llvm::Constant* DtoConstStringPtr(const char* str, const char* section) |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1216 { |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1217 std::string s(str); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1218 llvm::Constant* init = llvm::ConstantArray::get(s, true); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1219 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1220 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1221 if (section) gvar->setSection(section); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1222 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1223 return llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1224 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1225 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1226 ////////////////////////////////////////////////////////////////////////////////////////// |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1227 |
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
|
1228 llvm::Constant* DtoConstNullPtr(const llvm::Type* t) |
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
|
1229 { |
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
|
1230 return llvm::ConstantPointerNull::get( |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1231 getPtrToType(t) |
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
|
1232 ); |
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
|
1233 } |
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
|
1234 |
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
|
1235 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1236 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1237 void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1238 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1239 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1240 llvm::Value *dstarr; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1241 if (dst->getType() == arrty) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1242 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1243 dstarr = dst; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1244 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1245 else |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1246 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1247 dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1248 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1249 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1250 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemSet64() : LLVM_DeclareMemSet32(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1251 std::vector<llvm::Value*> llargs; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1252 llargs.resize(4); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1253 llargs[0] = dstarr; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1254 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1255 llargs[2] = nbytes; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1256 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1257 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1258 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1259 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1260 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1261 ////////////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1262 |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
78
diff
changeset
|
1263 void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes) |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1264 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1265 assert(dst->getType() == src->getType()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1266 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1267 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1268 llvm::Value *dstarr, *srcarr; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1269 if (dst->getType() == arrty) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1270 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1271 dstarr = dst; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1272 srcarr = src; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1273 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1274 else |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1275 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1276 dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1277 srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1278 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1279 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1280 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1281 std::vector<llvm::Value*> llargs; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1282 llargs.resize(4); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1283 llargs[0] = dstarr; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1284 llargs[1] = srcarr; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1285 llargs[2] = nbytes; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1286 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1287 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1288 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1289 } |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
1290 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
1291 ////////////////////////////////////////////////////////////////////////////////////////// |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
1292 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1293 llvm::Value* DtoLoad(llvm::Value* src) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1294 { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1295 return gIR->ir->CreateLoad(src,"tmp"); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1296 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1297 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1298 void DtoStore(llvm::Value* src, llvm::Value* dst) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1299 { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1300 gIR->ir->CreateStore(src,dst); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1301 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1302 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1303 bool DtoCanLoad(llvm::Value* ptr) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1304 { |
96 | 1305 if (isaPointer(ptr->getType())) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1306 return ptr->getType()->getContainedType(0)->isFirstClassType(); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1307 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1308 return false; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1309 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1310 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1311 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1312 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1313 llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t, const char* name) |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1314 { |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
1315 if (v->getType() == t) |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
1316 return v; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1317 return gIR->ir->CreateBitCast(v, t, name ? name : "tmp"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1318 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1319 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1320 ////////////////////////////////////////////////////////////////////////////////////////// |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
103
diff
changeset
|
1321 |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1322 const llvm::PointerType* isaPointer(llvm::Value* v) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1323 { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1324 return llvm::dyn_cast<llvm::PointerType>(v->getType()); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1325 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1326 |
96 | 1327 const llvm::PointerType* isaPointer(const llvm::Type* t) |
1328 { | |
1329 return llvm::dyn_cast<llvm::PointerType>(t); | |
1330 } | |
1331 | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1332 const llvm::ArrayType* isaArray(llvm::Value* v) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1333 { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1334 return llvm::dyn_cast<llvm::ArrayType>(v->getType()); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1335 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1336 |
96 | 1337 const llvm::ArrayType* isaArray(const llvm::Type* t) |
1338 { | |
1339 return llvm::dyn_cast<llvm::ArrayType>(t); | |
1340 } | |
1341 | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1342 const llvm::StructType* isaStruct(llvm::Value* v) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1343 { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1344 return llvm::dyn_cast<llvm::StructType>(v->getType()); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1345 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1346 |
96 | 1347 const llvm::StructType* isaStruct(const llvm::Type* t) |
1348 { | |
1349 return llvm::dyn_cast<llvm::StructType>(t); | |
1350 } | |
1351 | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1352 llvm::Constant* isaConstant(llvm::Value* v) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1353 { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1354 return llvm::dyn_cast<llvm::Constant>(v); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1355 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1356 |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1357 llvm::ConstantInt* isaConstantInt(llvm::Value* v) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1358 { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1359 return llvm::dyn_cast<llvm::ConstantInt>(v); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1360 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1361 |
96 | 1362 llvm::Argument* isaArgument(llvm::Value* v) |
1363 { | |
1364 return llvm::dyn_cast<llvm::Argument>(v); | |
1365 } | |
1366 | |
106 | 1367 llvm::GlobalVariable* isaGlobalVar(llvm::Value* v) |
1368 { | |
1369 return llvm::dyn_cast<llvm::GlobalVariable>(v); | |
1370 } | |
1371 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1372 ////////////////////////////////////////////////////////////////////////////////////////// |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1373 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1374 const llvm::PointerType* getPtrToType(const llvm::Type* t) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1375 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1376 return llvm::PointerType::get(t, 0); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1377 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1378 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1379 llvm::ConstantPointerNull* getNullPtr(const llvm::Type* t) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1380 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1381 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(t); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1382 return llvm::ConstantPointerNull::get(pt); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1383 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1384 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1385 ////////////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1386 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1387 size_t getTypeBitSize(const llvm::Type* t) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1388 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1389 return gTargetData->getTypeSizeInBits(t); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1390 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1391 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1392 size_t getTypeStoreSize(const llvm::Type* t) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1393 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1394 return gTargetData->getTypeStoreSize(t); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1395 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1396 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1397 size_t getABITypeSize(const llvm::Type* t) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1398 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1399 return gTargetData->getABITypeSize(t); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1400 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1401 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1402 ////////////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1403 |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1404 bool DtoIsTemplateInstance(Dsymbol* s) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1405 { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1406 if (!s) return false; |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1407 if (s->isTemplateInstance() && !s->isTemplateMixin()) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1408 return true; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1409 else if (s->parent) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1410 return DtoIsTemplateInstance(s->parent); |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1411 return false; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
83
diff
changeset
|
1412 } |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1413 |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1414 ////////////////////////////////////////////////////////////////////////////////////////// |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1415 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1416 void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1417 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1418 // create a flag to make sure initialization only happens once |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1419 llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1420 std::string gflagname(gvar->getName()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1421 gflagname.append("__initflag"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1422 llvm::GlobalVariable* gflag = new llvm::GlobalVariable(llvm::Type::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1423 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1424 // check flag and do init if not already done |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1425 llvm::BasicBlock* oldend = gIR->scopeend(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1426 llvm::BasicBlock* initbb = new llvm::BasicBlock("ifnotinit",gIR->topfunc(),oldend); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1427 llvm::BasicBlock* endinitbb = new llvm::BasicBlock("ifnotinitend",gIR->topfunc(),oldend); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1428 llvm::Value* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1429 gIR->ir->CreateCondBr(cond, initbb, endinitbb); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1430 gIR->scope() = IRScope(initbb,endinitbb); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
93
diff
changeset
|
1431 DValue* ie = DtoInitializer(init); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1432 if (!ie->inPlace()) { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1433 DValue* dst = new DVarValue(t, gvar, true); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1434 DtoAssign(dst, ie); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1435 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1436 gIR->ir->CreateStore(DtoConstBool(true), gflag); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1437 gIR->ir->CreateBr(endinitbb); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1438 gIR->scope() = IRScope(endinitbb,oldend); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
1439 } |
100 | 1440 |
1441 ////////////////////////////////////////////////////////////////////////////////////////// | |
1442 | |
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
|
1443 void DtoResolveDsymbol(Dsymbol* dsym) |
100 | 1444 { |
1445 if (StructDeclaration* sd = dsym->isStructDeclaration()) { | |
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
|
1446 DtoResolveStruct(sd); |
100 | 1447 } |
1448 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
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
|
1449 DtoResolveClass(cd); |
100 | 1450 } |
1451 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
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
|
1452 DtoResolveFunction(fd); |
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
|
1453 } |
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
|
1454 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { |
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
|
1455 DtoResolveTypeInfo(fd); |
100 | 1456 } |
1457 else { | |
1458 error(dsym->loc, "unsupported dsymbol: %s", dsym->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
|
1459 assert(0 && "unsupported dsymbol for DtoResolveDsymbol"); |
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
|
1460 } |
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
|
1461 } |
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
|
1462 |
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
|
1463 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1464 |
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
|
1465 void DtoDeclareDsymbol(Dsymbol* dsym) |
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
|
1466 { |
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
|
1467 if (StructDeclaration* sd = dsym->isStructDeclaration()) { |
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
|
1468 DtoDeclareStruct(sd); |
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
|
1469 } |
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
|
1470 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { |
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
|
1471 DtoDeclareClass(cd); |
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
|
1472 } |
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
|
1473 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { |
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
|
1474 DtoDeclareFunction(fd); |
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
|
1475 } |
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
|
1476 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { |
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
|
1477 DtoDeclareTypeInfo(fd); |
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
|
1478 } |
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
|
1479 else { |
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
|
1480 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); |
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
|
1481 assert(0 && "unsupported dsymbol for DtoDeclareDsymbol"); |
100 | 1482 } |
1483 } | |
1484 | |
1485 ////////////////////////////////////////////////////////////////////////////////////////// | |
1486 | |
1487 void DtoConstInitDsymbol(Dsymbol* dsym) | |
1488 { | |
1489 if (StructDeclaration* sd = dsym->isStructDeclaration()) { | |
1490 DtoConstInitStruct(sd); | |
1491 } | |
1492 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
1493 DtoConstInitClass(cd); | |
1494 } | |
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
|
1495 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { |
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
|
1496 DtoConstInitTypeInfo(fd); |
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
|
1497 } |
100 | 1498 else if (VarDeclaration* vd = dsym->isVarDeclaration()) { |
1499 DtoConstInitGlobal(vd); | |
1500 } | |
1501 else { | |
1502 error(dsym->loc, "unsupported dsymbol: %s", dsym->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
|
1503 assert(0 && "unsupported dsymbol for DtoConstInitDsymbol"); |
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
|
1504 } |
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
|
1505 } |
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
|
1506 |
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
|
1507 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1508 |
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
|
1509 void DtoDefineDsymbol(Dsymbol* dsym) |
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
|
1510 { |
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
|
1511 if (StructDeclaration* sd = dsym->isStructDeclaration()) { |
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
|
1512 DtoDefineStruct(sd); |
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
|
1513 } |
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
|
1514 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { |
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
|
1515 DtoDefineClass(cd); |
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
|
1516 } |
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
|
1517 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { |
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
|
1518 DtoDefineFunc(fd); |
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
|
1519 } |
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
|
1520 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { |
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
|
1521 DtoDefineTypeInfo(fd); |
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
|
1522 } |
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
|
1523 else { |
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
|
1524 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); |
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
|
1525 assert(0 && "unsupported dsymbol for DtoDefineDsymbol"); |
100 | 1526 } |
1527 } | |
1528 | |
1529 ////////////////////////////////////////////////////////////////////////////////////////// | |
1530 | |
1531 void DtoConstInitGlobal(VarDeclaration* vd) | |
1532 { | |
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
|
1533 if (vd->llvmInitialized) 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
|
1534 vd->llvmInitialized = gIR->dmodule; |
100 | 1535 |
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
|
1536 Logger::println("* DtoConstInitGlobal(%s)", vd->toChars()); |
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
|
1537 LOG_SCOPE; |
100 | 1538 |
1539 bool emitRTstaticInit = false; | |
1540 | |
1541 llvm::Constant* _init = 0; | |
1542 if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) { | |
1543 _init = DtoConstInitializer(vd->type, NULL); | |
1544 emitRTstaticInit = true; | |
1545 } | |
1546 else { | |
1547 _init = DtoConstInitializer(vd->type, vd->init); | |
1548 } | |
1549 | |
1550 const llvm::Type* _type = DtoType(vd->type); | |
1551 Type* t = DtoDType(vd->type); | |
1552 | |
1553 //Logger::cout() << "initializer: " << *_init << '\n'; | |
1554 if (_type != _init->getType()) { | |
1555 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | |
1556 // zero initalizer | |
1557 if (_init->isNullValue()) | |
1558 _init = llvm::Constant::getNullValue(_type); | |
1559 // pointer to global constant (struct.init) | |
1560 else if (llvm::isa<llvm::GlobalVariable>(_init)) | |
1561 { | |
1562 assert(_init->getType()->getContainedType(0) == _type); | |
1563 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); | |
1564 assert(t->ty == Tstruct); | |
1565 TypeStruct* ts = (TypeStruct*)t; | |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
116
diff
changeset
|
1566 assert(ts->sym->llvmConstInit); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
116
diff
changeset
|
1567 _init = ts->sym->llvmConstInit; |
100 | 1568 } |
1569 // array single value init | |
1570 else if (isaArray(_type)) | |
1571 { | |
1572 _init = DtoConstStaticArray(_type, _init); | |
1573 } | |
1574 else { | |
1575 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; | |
1576 //assert(0); | |
1577 } | |
1578 } | |
1579 | |
1580 bool istempl = false; | |
1581 if ((vd->storage_class & STCcomdat) || (vd->parent && DtoIsTemplateInstance(vd->parent))) { | |
1582 istempl = true; | |
1583 } | |
1584 | |
1585 if (_init && _init->getType() != _type) | |
1586 _type = _init->getType(); | |
1587 llvm::cast<llvm::OpaqueType>(vd->llvmIRGlobal->type.get())->refineAbstractTypeTo(_type); | |
1588 _type = vd->llvmIRGlobal->type.get(); | |
1589 assert(!_type->isAbstract()); | |
1590 | |
1591 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->llvmValue); | |
1592 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) | |
1593 { | |
1594 gvar->setInitializer(_init); | |
1595 } | |
1596 | |
1597 if (emitRTstaticInit) | |
1598 DtoLazyStaticInit(istempl, gvar, vd->init, t); | |
1599 } | |
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
|
1600 |
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
|
1601 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1602 |
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
|
1603 void DtoEmptyResolveList() |
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
|
1604 { |
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
|
1605 //Logger::println("DtoEmptyResolveList()"); |
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
|
1606 Dsymbol* dsym; |
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
|
1607 while (!gIR->resolveList.empty()) { |
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
|
1608 dsym = gIR->resolveList.front(); |
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
|
1609 gIR->resolveList.pop_front(); |
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
|
1610 DtoResolveDsymbol(dsym); |
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
|
1611 } |
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
|
1612 } |
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
|
1613 |
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
|
1614 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1615 |
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
|
1616 void DtoEmptyDeclareList() |
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
|
1617 { |
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
|
1618 //Logger::println("DtoEmptyDeclareList()"); |
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
|
1619 Dsymbol* dsym; |
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
|
1620 while (!gIR->declareList.empty()) { |
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
|
1621 dsym = gIR->declareList.front(); |
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
|
1622 gIR->declareList.pop_front(); |
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
|
1623 DtoDeclareDsymbol(dsym); |
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
|
1624 } |
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
|
1625 } |
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
|
1626 |
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
|
1627 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1628 |
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
|
1629 void DtoEmptyConstInitList() |
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
|
1630 { |
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
|
1631 //Logger::println("DtoEmptyConstInitList()"); |
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
|
1632 Dsymbol* dsym; |
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
|
1633 while (!gIR->constInitList.empty()) { |
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
|
1634 dsym = gIR->constInitList.front(); |
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
|
1635 gIR->constInitList.pop_front(); |
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
|
1636 DtoConstInitDsymbol(dsym); |
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
|
1637 } |
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
|
1638 } |
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
|
1639 |
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
|
1640 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1641 |
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
|
1642 void DtoEmptyDefineList() |
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
|
1643 { |
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
|
1644 //Logger::println("DtoEmptyDefineList()"); |
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
|
1645 Dsymbol* dsym; |
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
|
1646 while (!gIR->defineList.empty()) { |
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
|
1647 dsym = gIR->defineList.front(); |
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
|
1648 gIR->defineList.pop_front(); |
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
|
1649 DtoDefineDsymbol(dsym); |
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
|
1650 } |
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
|
1651 } |
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
|
1652 |
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
|
1653 ////////////////////////////////////////////////////////////////////////////////////////// |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1654 void DtoEmptyAllLists() |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1655 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1656 for(;;) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1657 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1658 Dsymbol* dsym; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1659 if (!gIR->resolveList.empty()) { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1660 dsym = gIR->resolveList.front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1661 gIR->resolveList.pop_front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1662 DtoResolveDsymbol(dsym); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1663 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1664 else if (!gIR->declareList.empty()) { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1665 dsym = gIR->declareList.front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1666 gIR->declareList.pop_front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1667 DtoDeclareDsymbol(dsym); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1668 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1669 else if (!gIR->constInitList.empty()) { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1670 dsym = gIR->constInitList.front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1671 gIR->constInitList.pop_front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1672 DtoConstInitDsymbol(dsym); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1673 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1674 else if (!gIR->defineList.empty()) { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1675 dsym = gIR->defineList.front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1676 gIR->defineList.pop_front(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1677 DtoDefineDsymbol(dsym); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1678 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1679 else { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1680 break; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1681 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1682 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1683 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1684 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
114
diff
changeset
|
1685 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1686 |
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
|
1687 void DtoForceDeclareDsymbol(Dsymbol* dsym) |
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
|
1688 { |
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
|
1689 if (dsym->llvmDeclared) return; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1690 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars()); |
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
|
1691 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
|
1692 DtoResolveDsymbol(dsym); |
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
|
1693 |
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
|
1694 DtoEmptyResolveList(); |
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
|
1695 |
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
|
1696 DtoDeclareDsymbol(dsym); |
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
|
1697 } |
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
|
1698 |
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
|
1699 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1700 |
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
|
1701 void DtoForceConstInitDsymbol(Dsymbol* dsym) |
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
|
1702 { |
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
|
1703 if (dsym->llvmInitialized) return; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1704 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars()); |
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
|
1705 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
|
1706 DtoResolveDsymbol(dsym); |
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
|
1707 |
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
|
1708 DtoEmptyResolveList(); |
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
|
1709 DtoEmptyDeclareList(); |
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
|
1710 |
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
|
1711 DtoConstInitDsymbol(dsym); |
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
|
1712 } |
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
|
1713 |
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
|
1714 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
1715 |
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
|
1716 void DtoForceDefineDsymbol(Dsymbol* dsym) |
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
|
1717 { |
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
|
1718 if (dsym->llvmDefined) return; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1719 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars()); |
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
|
1720 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
|
1721 DtoResolveDsymbol(dsym); |
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
|
1722 |
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
|
1723 DtoEmptyResolveList(); |
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
|
1724 DtoEmptyDeclareList(); |
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
|
1725 DtoEmptyConstInitList(); |
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
|
1726 |
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
|
1727 DtoDefineDsymbol(dsym); |
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
|
1728 } |
131 | 1729 |
1730 ////////////////////////////////////////////////////////////////////////////////////////// | |
1731 | |
1732 void DtoAnnotation(const char* str) | |
1733 { | |
1734 std::string s("CODE: "); | |
1735 s.append(str); | |
1736 char* p = &s[0]; | |
1737 while (*p) | |
1738 { | |
1739 if (*p == '"') | |
1740 *p = '\''; | |
1741 ++p; | |
1742 } | |
1743 // create a noop with the code as the result name! | |
1744 gIR->ir->CreateAnd(DtoConstSize_t(0),DtoConstSize_t(0),s.c_str()); | |
1745 } |