Mercurial > projects > ldc
annotate gen/toir.c @ 23:77e3d1ddae3f trunk
[svn r27] * Fixed bug in aggregate field lookup.
* Fixed structs with no fields.
* Added support for NegExp as in -x.
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 09:24:15 +0200 |
parents | 8d45266bbabe |
children | 25bb577878e8 |
rev | line source |
---|---|
1 | 1 // Backend stubs |
2 | |
3 /* DMDFE backend stubs | |
4 * This file contains the implementations of the backend routines. | |
5 * For dmdfe these do nothing but print a message saying the module | |
6 * has been parsed. Substitute your own behaviors for these routimes. | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <math.h> | |
11 #include <sstream> | |
12 #include <fstream> | |
13 #include <iostream> | |
14 | |
15 #include "llvm/Type.h" | |
16 #include "llvm/DerivedTypes.h" | |
17 #include "llvm/Constants.h" | |
18 #include "llvm/Instructions.h" | |
19 #include "llvm/IntrinsicInst.h" | |
20 #include "llvm/CallingConv.h" | |
21 | |
22 #include "total.h" | |
23 #include "init.h" | |
24 #include "symbol.h" | |
25 #include "mtype.h" | |
26 #include "hdrgen.h" | |
27 #include "port.h" | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
28 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
29 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
30 #include "gen/elem.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
31 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
32 #include "gen/tollvm.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
33 #include "gen/runtime.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
34 #include "gen/arrays.h" |
1 | 35 |
36 ////////////////////////////////////////////////////////////////////////////////////////// | |
37 | |
38 elem* DeclarationExp::toElem(IRState* p) | |
39 { | |
40 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars()); | |
41 LOG_SCOPE; | |
42 elem* e = new elem; | |
43 | |
44 // variable declaration | |
45 if (VarDeclaration* vd = declaration->isVarDeclaration()) | |
46 { | |
47 Logger::println("VarDeclaration"); | |
48 | |
49 // handle const | |
50 // TODO probably not correct | |
51 bool isconst = (vd->storage_class & STCconst) != 0; | |
52 | |
53 // allocate storage on the stack | |
54 Logger::println("vdtype = %s", vd->type->toChars()); | |
55 const llvm::Type* lltype = LLVM_DtoType(vd->type); | |
56 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); | |
57 //allocainst->setAlignment(vd->type->alignsize()); // TODO | |
58 vd->llvmValue = allocainst; | |
59 // e->val = really needed?? | |
60 | |
61 LLVM_DtoInitializer(vd->type, vd->init); | |
62 } | |
63 // struct declaration | |
64 else if (StructDeclaration* s = declaration->isStructDeclaration()) | |
65 { | |
66 Logger::println("StructDeclaration"); | |
67 s->toObjFile(); | |
68 } | |
69 // unsupported declaration | |
70 else | |
71 { | |
72 error("Only Var/Struct-Declaration is supported for DeclarationExp"); | |
73 fatal(); | |
74 } | |
75 return e; | |
76 } | |
77 | |
78 ////////////////////////////////////////////////////////////////////////////////////////// | |
79 | |
80 elem* VarExp::toElem(IRState* p) | |
81 { | |
82 Logger::print("VarExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
83 LOG_SCOPE; | |
84 | |
85 elem* e = new elem; | |
86 | |
87 assert(var); | |
88 if (VarDeclaration* vd = var->isVarDeclaration()) | |
89 { | |
90 Logger::println("VarDeclaration"); | |
91 | |
92 if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) | |
93 { | |
94 Logger::println("TypeInfoDeclaration"); | |
95 } | |
96 | |
97 // this must be a dollar expression or some other magic value | |
98 if (!vd->llvmValue) | |
99 { | |
100 // dollar | |
101 if (!p->arrays.empty()) | |
102 { | |
103 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
6 | 104 //llvm::Value* tmp = new llvm::GetElementPtrInst(p->arrays.back(),zero,zero,"tmp",p->scopebb()); |
105 llvm::Value* tmp = LLVM_DtoGEP(p->arrays.back(),zero,zero,"tmp",p->scopebb()); | |
1 | 106 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
107 e->type = elem::VAL; | |
108 } | |
109 // magic | |
110 else | |
111 { | |
112 if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) | |
113 { | |
114 tid->toObjFile(); | |
115 e->mem = tid->llvmValue; | |
116 e->type = elem::VAR; | |
117 } | |
118 else | |
119 assert(0 && "only magic supported is typeinfo"); | |
120 } | |
121 return e; | |
122 } | |
123 | |
124 // function parameter | |
125 if (vd->storage_class & STCparameter) { | |
126 Logger::println("function param"); | |
127 if (vd->storage_class & (STCref | STCout)) { | |
128 e->mem = vd->llvmValue; | |
129 e->type = elem::VAR; | |
130 } | |
131 else { | |
132 if (vd->type->ty == Tstruct || vd->type->ty == Tdelegate || vd->type->ty == Tarray) { | |
133 e->mem = vd->llvmValue; | |
134 e->type = elem::VAR; | |
135 } | |
136 else { | |
137 e->val = vd->llvmValue; | |
138 e->type = elem::VAL; | |
139 } | |
140 } | |
141 } | |
142 else { | |
143 e->mem = vd->llvmValue; | |
144 //e->mem->setName(toChars()); | |
145 e->vardecl = vd; | |
146 e->type = elem::VAR; | |
147 } | |
148 } | |
149 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | |
150 { | |
151 Logger::println("FuncDeclaration"); | |
152 if (fdecl->llvmValue == 0) { | |
153 fdecl->toObjFile(); | |
154 } | |
155 e->val = fdecl->llvmValue; | |
156 e->type = elem::FUNC; | |
157 e->funcdecl = fdecl; | |
158 } | |
159 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) | |
160 { | |
161 // this seems to be the static initialiser for structs | |
162 Logger::print("Sym: type=%s\n", sdecl->type->toChars()); | |
163 assert(sdecl->type->ty == Tstruct); | |
164 //assert(sdecl->llvmInitZ); | |
165 //e->val = sdecl->llvmInitZ; | |
166 TypeStruct* ts = (TypeStruct*)sdecl->type; | |
167 e->mem = ts->llvmInit; | |
168 assert(e->mem); | |
169 e->type = elem::VAR; | |
170 } | |
171 else | |
172 { | |
173 assert(0 && "Unimplemented VarExp type"); | |
174 } | |
175 | |
176 assert(e->mem || e->val); | |
177 return e; | |
178 } | |
179 | |
180 ////////////////////////////////////////////////////////////////////////////////////////// | |
181 | |
182 elem* IntegerExp::toElem(IRState* p) | |
183 { | |
184 Logger::print("IntegerExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
185 LOG_SCOPE; | |
186 elem* e = new elem; | |
187 const llvm::Type* t = LLVM_DtoType(type); | |
188 if (llvm::isa<llvm::PointerType>(t)) { | |
189 llvm::Constant* i = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)value,false); | |
190 e->val = llvm::ConstantExpr::getIntToPtr(i, t); | |
191 } | |
192 else if (llvm::isa<llvm::IntegerType>(t)) { | |
193 e->val = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); | |
194 } | |
195 else { | |
196 assert(0); | |
197 } | |
198 e->type = elem::CONST; | |
199 return e; | |
200 } | |
201 | |
202 ////////////////////////////////////////////////////////////////////////////////////////// | |
203 | |
204 elem* RealExp::toElem(IRState* p) | |
205 { | |
206 Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
207 LOG_SCOPE; | |
208 elem* e = new elem; | |
6 | 209 const llvm::Type* fty = LLVM_DtoType(type); |
210 if (type->ty == Tfloat32) | |
211 e->val = llvm::ConstantFP::get(fty,float(value)); | |
212 else if (type->ty == Tfloat64 || type->ty == Tfloat80) | |
213 e->val = llvm::ConstantFP::get(fty,double(value)); | |
214 else | |
215 assert(0); | |
1 | 216 e->type = elem::CONST; |
217 return e; | |
218 } | |
219 | |
220 ////////////////////////////////////////////////////////////////////////////////////////// | |
221 | |
222 elem* NullExp::toElem(IRState* p) | |
223 { | |
224 Logger::print("NullExp::toElem(type=%s): %s\n", type->toChars(),toChars()); | |
225 LOG_SCOPE; | |
226 elem* e = new elem; | |
227 const llvm::Type* t = LLVM_DtoType(type); | |
228 if (llvm::isa<llvm::StructType>(t)) | |
229 t = llvm::PointerType::get(t); | |
230 Logger::cout() << *t << '\n'; | |
231 e->val = llvm::Constant::getNullValue(t); | |
232 assert(e->val); | |
233 Logger::cout() << *e->val << '\n'; | |
234 e->type = elem::NUL; | |
235 return e; | |
236 } | |
237 | |
238 ////////////////////////////////////////////////////////////////////////////////////////// | |
239 | |
240 elem* StringExp::toElem(IRState* p) | |
241 { | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
242 Logger::print("StringExp::toElem: %s | \n", toChars(), type->toChars()); |
1 | 243 LOG_SCOPE; |
244 | |
245 assert(type->next->ty == Tchar && "Only char is supported"); | |
246 assert(sz == 1); | |
247 | |
248 const llvm::Type* ct = LLVM_DtoType(type->next); | |
249 //printf("ct = %s\n", type->next->toChars()); | |
250 const llvm::ArrayType* at = llvm::ArrayType::get(ct,len+1); | |
251 | |
252 uint8_t* str = (uint8_t*)string; | |
253 std::string cont((char*)str, len); | |
254 | |
255 llvm::Constant* _init = llvm::ConstantArray::get(cont,true); | |
256 | |
257 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; | |
258 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,"stringliteral",gIR->module); | |
259 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
260 llvm::ConstantInt* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
261 //llvm::Value* arrptr = LLVM_DtoGEP(gvar,zero,zero,"tmp",p->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
262 llvm::Constant* idxs[2] = { zero, zero }; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
263 llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
1 | 264 |
265 elem* e = new elem; | |
266 | |
267 if (type->ty == Tarray) { | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
268 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
269 if (p->lvals.empty()) { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
270 e->type = elem::SLICE; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
271 e->arg = clen; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
272 e->mem = arrptr; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
273 return e; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
274 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
275 else { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
276 llvm::Value* arr = p->toplval(); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
277 if (llvm::isa<llvm::GlobalVariable>(arr)) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
278 e->val = LLVM_DtoConstantSlice(clen, arrptr); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
279 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
280 else { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
281 LLVM_DtoSetArray(arr, clen, arrptr); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
282 e->inplace = true; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
283 } |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
284 } |
1 | 285 } |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
286 else if (type->ty == Tsarray) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
287 const llvm::Type* dstType = llvm::PointerType::get(llvm::ArrayType::get(ct, len)); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
288 e->mem = new llvm::BitCastInst(gvar, dstType, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
289 } |
1 | 290 else if (type->ty == Tpointer) { |
291 e->mem = arrptr; | |
292 } | |
293 else { | |
294 assert(0); | |
295 } | |
296 | |
297 e->type = elem::VAL; | |
298 | |
299 return e; | |
300 } | |
301 | |
302 ////////////////////////////////////////////////////////////////////////////////////////// | |
303 | |
304 elem* AssignExp::toElem(IRState* p) | |
305 { | |
306 Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type->toChars()); | |
307 LOG_SCOPE; | |
308 | |
309 assert(e1 && e2); | |
310 p->inLvalue = true; | |
311 elem* l = e1->toElem(p); | |
312 p->inLvalue = false; | |
313 | |
314 p->lvals.push_back(l->mem); | |
315 elem* r = e2->toElem(p); | |
316 p->lvals.pop_back(); | |
317 | |
318 assert(l->mem); | |
319 //e->val = l->store(r->getValue()); | |
320 | |
321 TY e1ty = e1->type->ty; | |
322 TY e2ty = e2->type->ty; | |
323 | |
324 elem* e = new elem; | |
325 | |
326 // struct | |
327 if (e1ty == Tstruct) { | |
328 // struct + struct | |
329 if (e2ty == Tstruct) { | |
330 // struct literals do the assignment themselvs (in place) | |
331 if (!r->inplace) { | |
332 TypeStruct* ts = (TypeStruct*)e2->type; | |
333 assert(r->mem); | |
334 LLVM_DtoStructCopy(ts,l->mem,r->mem); | |
335 } | |
336 else { | |
337 e->inplace = true; | |
338 } | |
339 } | |
340 // struct + const int | |
341 else if (e2->type->isintegral()){ | |
342 IntegerExp* iexp = (IntegerExp*)e2; | |
343 assert(iexp->value == 0 && "Only integral struct initializer allowed is zero"); | |
344 TypeStruct* st = (TypeStruct*)e1->type; | |
345 LLVM_DtoStructZeroInit(st, l->mem); | |
346 } | |
347 // :x | |
348 else | |
349 assert(0 && "struct = unknown"); | |
350 } | |
351 else if (e1ty == Tsarray) { | |
352 assert(0 && "static array = not supported"); | |
353 } | |
354 else if (e1ty == Tarray) { | |
355 if (e2->type->isscalar() || e2->type->ty == Tclass){ | |
356 LLVM_DtoArrayInit(l->mem, r->getValue()); | |
357 } | |
358 else if (e2ty == Tarray) { | |
359 //new llvm::StoreInst(r->val,l->val,p->scopebb()); | |
360 if (r->type == elem::NUL) { | |
361 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); | |
362 assert(c->isNullValue()); | |
363 LLVM_DtoNullArray(l->mem); | |
364 } | |
365 else if (r->type == elem::SLICE) { | |
366 if (l->type == elem::SLICE) | |
367 LLVM_DtoArrayCopy(l,r); | |
368 else | |
369 LLVM_DtoSetArray(l->mem,r->arg,r->mem); | |
370 } | |
371 else { | |
372 // new expressions write directly to the array reference | |
373 // so do string literals | |
374 if (!r->inplace) { | |
375 assert(r->mem); | |
376 LLVM_DtoArrayAssign(l->mem, r->mem); | |
377 } | |
378 else { | |
379 e->inplace = true; | |
380 } | |
381 } | |
382 } | |
383 else | |
384 assert(0); | |
385 } | |
386 else if (e1ty == Tpointer) { | |
387 if (e2ty == Tpointer) { | |
388 llvm::Value* v = r->field ? r->mem : r->getValue(); | |
389 Logger::cout() << "*=*: " << *v << ", " << *l->mem << '\n'; | |
390 new llvm::StoreInst(v, l->mem, p->scopebb()); | |
391 } | |
392 else | |
393 assert(0); | |
394 } | |
395 else if (e1ty == Tclass) { | |
396 if (e2ty == Tclass) { | |
397 llvm::Value* tmp = r->getValue(); | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
398 Logger::cout() << "tmp: " << *tmp << " ||| " << *l->mem << '\n'; |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
399 // assignment to this in constructor special case |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
400 if (l->isthis) { |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
401 FuncDeclaration* fdecl = p->funcdecls.back(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
402 // respecify the this param |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
403 if (!llvm::isa<llvm::AllocaInst>(fdecl->llvmThisVar)) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
404 fdecl->llvmThisVar = new llvm::AllocaInst(tmp->getType(), "newthis", p->topallocapoint()); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
405 new llvm::StoreInst(tmp, fdecl->llvmThisVar, p->scopebb()); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
406 } |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
407 // regular class ref -> class ref assignment |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
408 else { |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
409 new llvm::StoreInst(tmp, l->mem, p->scopebb()); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
410 } |
1 | 411 } |
412 else | |
413 assert(0); | |
414 } | |
415 else if (e1ty == Tdelegate) { | |
416 Logger::println("Assigning to delegate"); | |
417 if (e2ty == Tdelegate) { | |
418 if (r->type == elem::NUL) { | |
419 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val); | |
420 if (c->isNullValue()) { | |
421 LLVM_DtoNullDelegate(l->mem); | |
422 } | |
423 else | |
424 assert(0); | |
425 } | |
426 else if (r->inplace) { | |
427 // do nothing | |
428 e->inplace = true; | |
429 } | |
430 else | |
431 assert(0); | |
432 } | |
433 else | |
434 assert(0); | |
435 } | |
436 // !struct && !array && !pointer && !class | |
437 else { | |
438 Logger::cout() << *l->mem << '\n'; | |
439 new llvm::StoreInst(r->getValue(),l->mem,p->scopebb()); | |
440 } | |
441 | |
442 delete r; | |
443 delete l; | |
444 return e; | |
445 } | |
446 | |
447 ////////////////////////////////////////////////////////////////////////////////////////// | |
448 | |
449 elem* AddExp::toElem(IRState* p) | |
450 { | |
23 | 451 Logger::print("AddExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1 | 452 LOG_SCOPE; |
453 elem* e = new elem; | |
454 elem* l = e1->toElem(p); | |
455 elem* r = e2->toElem(p); | |
456 | |
457 if (e1->type != e2->type) { | |
458 if (e1->type->ty == Tpointer && e1->type->next->ty == Tstruct) { | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
459 //assert(l->field); |
1 | 460 assert(r->type == elem::CONST); |
461 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); | |
462 | |
463 TypeStruct* ts = (TypeStruct*)e1->type->next; | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
464 std::vector<unsigned> offsets(1,0); |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
465 ts->sym->offsetToIndex(cofs->getZExtValue(), offsets); |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
466 e->mem = LLVM_DtoGEP(l->getValue(), offsets, "tmp", p->scopebb()); |
1 | 467 e->type = elem::VAR; |
468 e->field = true; | |
469 } | |
470 else if (e1->type->ty == Tpointer) { | |
471 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
472 e->type = elem::VAR; | |
473 } | |
474 else { | |
475 assert(0); | |
476 } | |
477 } | |
478 else { | |
479 e->val = llvm::BinaryOperator::createAdd(l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
480 e->type = elem::VAL; | |
481 } | |
482 delete l; | |
483 delete r; | |
484 return e; | |
485 } | |
486 | |
487 ////////////////////////////////////////////////////////////////////////////////////////// | |
488 | |
489 elem* AddAssignExp::toElem(IRState* p) | |
490 { | |
491 Logger::print("AddAssignExp::toElem: %s\n", toChars()); | |
492 LOG_SCOPE; | |
493 | |
494 elem* l = e1->toElem(p); | |
495 elem* r = e2->toElem(p); | |
496 | |
497 elem* e = new elem; | |
498 llvm::Value* val = 0; | |
499 if (e1->type->ty == Tpointer) { | |
500 val = e->mem = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
501 } | |
502 else { | |
503 val = e->val = llvm::BinaryOperator::createAdd(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
504 } | |
505 | |
506 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | |
507 if (llvm::isa<llvm::PointerType>(storeVal->getType()) && storeVal->getType()->getContainedType(0) != tmp->getType()) | |
508 { | |
509 tmp = LLVM_DtoPointedType(storeVal, tmp); | |
510 }*/ | |
511 | |
512 new llvm::StoreInst(val,l->mem,p->scopebb()); | |
513 e->type = elem::VAR; | |
514 | |
515 delete l; | |
516 delete r; | |
517 return e; | |
518 } | |
519 | |
520 ////////////////////////////////////////////////////////////////////////////////////////// | |
521 | |
522 elem* MinExp::toElem(IRState* p) | |
523 { | |
524 Logger::print("MinExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
525 LOG_SCOPE; | |
526 elem* e = new elem; | |
527 elem* l = e1->toElem(p); | |
528 elem* r = e2->toElem(p); | |
529 | |
530 llvm::Value* left = l->getValue(); | |
531 if (llvm::isa<llvm::PointerType>(left->getType())) | |
532 left = new llvm::PtrToIntInst(left,LLVM_DtoSize_t(),"tmp",p->scopebb()); | |
533 | |
534 llvm::Value* right = r->getValue(); | |
535 if (llvm::isa<llvm::PointerType>(right->getType())) | |
536 right = new llvm::PtrToIntInst(right,LLVM_DtoSize_t(),"tmp",p->scopebb()); | |
537 | |
538 e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb()); | |
539 e->type = elem::VAL; | |
540 | |
541 const llvm::Type* totype = LLVM_DtoType(type); | |
542 if (e->val->getType() != totype) { | |
543 assert(0); | |
544 assert(llvm::isa<llvm::PointerType>(e->val->getType())); | |
545 assert(llvm::isa<llvm::IntegerType>(totype)); | |
546 e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb()); | |
547 } | |
548 | |
549 delete l; | |
550 delete r; | |
551 return e; | |
552 } | |
553 | |
554 ////////////////////////////////////////////////////////////////////////////////////////// | |
555 | |
556 elem* MinAssignExp::toElem(IRState* p) | |
557 { | |
558 Logger::print("MinAssignExp::toElem: %s\n", toChars()); | |
559 LOG_SCOPE; | |
560 | |
561 elem* l = e1->toElem(p); | |
562 elem* r = e2->toElem(p); | |
563 | |
564 llvm::Value* tmp = 0; | |
565 if (e1->type->ty == Tpointer) { | |
566 tmp = r->getValue(); | |
567 llvm::Value* zero = llvm::ConstantInt::get(tmp->getType(),0,false); | |
568 tmp = llvm::BinaryOperator::createSub(zero,tmp,"tmp",p->scopebb()); | |
569 tmp = new llvm::GetElementPtrInst(l->getValue(),tmp,"tmp",p->scopebb()); | |
570 } | |
571 else { | |
572 tmp = llvm::BinaryOperator::createSub(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
573 } | |
574 | |
575 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | |
576 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | |
577 { | |
578 tmp = LLVM_DtoPointedType(storeVal, tmp); | |
579 }*/ | |
580 | |
581 new llvm::StoreInst(tmp, l->mem, p->scopebb()); | |
582 | |
583 delete l; | |
584 delete r; | |
585 | |
586 elem* e = new elem; | |
587 e->val = tmp; | |
588 e->type = elem::VAR; | |
589 return e; | |
590 } | |
591 | |
592 ////////////////////////////////////////////////////////////////////////////////////////// | |
593 | |
594 elem* MulExp::toElem(IRState* p) | |
595 { | |
596 Logger::print("MulExp::toElem: %s\n", toChars()); | |
597 LOG_SCOPE; | |
598 elem* e = new elem; | |
599 elem* l = e1->toElem(p); | |
600 elem* r = e2->toElem(p); | |
601 llvm::Value* vl = l->getValue(); | |
602 llvm::Value* vr = r->getValue(); | |
603 Logger::cout() << "mul: " << *vl << ", " << *vr << '\n'; | |
604 e->val = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb()); | |
605 e->type = elem::VAL; | |
606 delete l; | |
607 delete r; | |
608 return e; | |
609 } | |
610 | |
611 ////////////////////////////////////////////////////////////////////////////////////////// | |
612 | |
613 elem* MulAssignExp::toElem(IRState* p) | |
614 { | |
615 Logger::print("MulAssignExp::toElem: %s\n", toChars()); | |
616 LOG_SCOPE; | |
617 | |
618 elem* l = e1->toElem(p); | |
619 elem* r = e2->toElem(p); | |
620 llvm::Value* vl = l->getValue(); | |
621 llvm::Value* vr = r->getValue(); | |
622 Logger::cout() << "mulassign: " << *vl << ", " << *vr << '\n'; | |
623 llvm::Value* tmp = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb()); | |
624 | |
625 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | |
626 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | |
627 { | |
628 tmp = LLVM_DtoPointedType(storeVal, tmp); | |
629 }*/ | |
630 | |
631 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | |
632 | |
633 delete l; | |
634 delete r; | |
635 | |
636 elem* e = new elem; | |
637 e->val = tmp; | |
638 e->type = elem::VAR; | |
639 return e; | |
640 } | |
641 | |
642 ////////////////////////////////////////////////////////////////////////////////////////// | |
643 | |
644 elem* DivExp::toElem(IRState* p) | |
645 { | |
646 Logger::print("DivExp::toElem: %s\n", toChars()); | |
647 LOG_SCOPE; | |
648 elem* e = new elem; | |
649 elem* l = e1->toElem(p); | |
650 elem* r = e2->toElem(p); | |
651 | |
652 if (type->isunsigned()) | |
653 e->val = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
654 else if (type->isintegral()) | |
655 e->val = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
656 else if (type->isfloating()) | |
657 e->val = llvm::BinaryOperator::createFDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
658 else | |
659 assert(0); | |
660 e->type = elem::VAL; | |
661 delete l; | |
662 delete r; | |
663 return e; | |
664 } | |
665 | |
666 ////////////////////////////////////////////////////////////////////////////////////////// | |
667 | |
668 elem* DivAssignExp::toElem(IRState* p) | |
669 { | |
670 Logger::print("DivAssignExp::toElem: %s\n", toChars()); | |
671 LOG_SCOPE; | |
672 | |
673 elem* l = e1->toElem(p); | |
674 elem* r = e2->toElem(p); | |
675 | |
676 llvm::Value* tmp; | |
677 if (type->isunsigned()) | |
678 tmp = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
679 else if (type->isintegral()) | |
680 tmp = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
681 else if (type->isfloating()) | |
682 tmp = llvm::BinaryOperator::createFDiv(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
683 else | |
684 assert(0); | |
685 | |
686 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | |
687 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | |
688 { | |
689 tmp = LLVM_DtoPointedType(storeVal, tmp); | |
690 }*/ | |
691 | |
692 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | |
693 | |
694 delete l; | |
695 delete r; | |
696 | |
697 elem* e = new elem; | |
698 e->val = tmp; | |
699 e->type = elem::VAR; | |
700 return e; | |
701 } | |
702 | |
703 ////////////////////////////////////////////////////////////////////////////////////////// | |
704 | |
705 elem* ModExp::toElem(IRState* p) | |
706 { | |
707 Logger::print("ModExp::toElem: %s\n", toChars()); | |
708 LOG_SCOPE; | |
709 elem* e = new elem; | |
710 elem* l = e1->toElem(p); | |
711 elem* r = e2->toElem(p); | |
712 | |
713 if (type->isunsigned()) | |
714 e->val = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
715 else if (type->isintegral()) | |
716 e->val = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
717 else if (type->isfloating()) | |
718 e->val = llvm::BinaryOperator::createFRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
719 else | |
720 assert(0); | |
721 e->type = elem::VAL; | |
722 delete l; | |
723 delete r; | |
724 return e; | |
725 } | |
726 | |
727 ////////////////////////////////////////////////////////////////////////////////////////// | |
728 | |
729 elem* ModAssignExp::toElem(IRState* p) | |
730 { | |
731 Logger::print("ModAssignExp::toElem: %s\n", toChars()); | |
732 LOG_SCOPE; | |
733 | |
734 elem* l = e1->toElem(p); | |
735 elem* r = e2->toElem(p); | |
736 | |
737 llvm::Value* tmp; | |
738 if (type->isunsigned()) | |
739 tmp = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
740 else if (type->isintegral()) | |
741 tmp = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
742 else if (type->isfloating()) | |
743 tmp = llvm::BinaryOperator::createFRem(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
744 else | |
745 assert(0); | |
746 | |
747 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val; | |
748 if (storeVal->getType()->getContainedType(0) != tmp->getType()) | |
749 { | |
750 tmp = LLVM_DtoPointedType(storeVal, tmp); | |
751 }*/ | |
752 | |
753 new llvm::StoreInst(tmp,l->mem,p->scopebb()); | |
754 | |
755 delete l; | |
756 delete r; | |
757 | |
758 elem* e = new elem; | |
759 e->val = tmp; | |
760 e->type = elem::VAR; | |
761 return e; | |
762 } | |
763 | |
764 ////////////////////////////////////////////////////////////////////////////////////////// | |
765 | |
766 elem* CallExp::toElem(IRState* p) | |
767 { | |
768 Logger::print("CallExp::toElem: %s\n", toChars()); | |
769 LOG_SCOPE; | |
770 elem* e = new elem; | |
771 elem* fn = e1->toElem(p); | |
772 LINK dlink = LINKdefault; | |
18 | 773 |
1 | 774 bool delegateCall = false; |
775 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); | |
776 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); | |
777 | |
778 // hidden struct return parameter handling | |
779 bool retinptr = false; | |
18 | 780 |
1 | 781 TypeFunction* tf = 0; |
18 | 782 |
1 | 783 // regular functions |
784 if (e1->type->ty == Tfunction) { | |
785 tf = (TypeFunction*)e1->type; | |
786 if (tf->llvmRetInPtr) { | |
787 retinptr = true; | |
788 } | |
789 dlink = tf->linkage; | |
790 } | |
18 | 791 |
1 | 792 // delegates |
793 else if (e1->type->ty == Tdelegate) { | |
794 Logger::println("delegateTy = %s\n", e1->type->toChars()); | |
795 assert(e1->type->next->ty == Tfunction); | |
796 tf = (TypeFunction*)e1->type->next; | |
797 if (tf->llvmRetInPtr) { | |
798 retinptr = true; | |
799 } | |
800 dlink = tf->linkage; | |
801 delegateCall = true; | |
802 } | |
18 | 803 |
1 | 804 // invalid |
805 else { | |
806 assert(tf); | |
807 } | |
808 | |
809 size_t n = arguments->dim; | |
810 if (fn->arg || delegateCall) n++; | |
811 if (retinptr) n++; | |
812 | |
813 llvm::Value* funcval = fn->getValue(); | |
18 | 814 assert(funcval != 0); |
1 | 815 std::vector<llvm::Value*> llargs(n, 0); |
816 | |
817 const llvm::FunctionType* llfnty = 0; | |
18 | 818 |
1 | 819 // normal function call |
820 if (llvm::isa<llvm::FunctionType>(funcval->getType())) { | |
821 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()); | |
822 } | |
823 // pointer to something | |
824 else if (llvm::isa<llvm::PointerType>(funcval->getType())) { | |
825 // pointer to function pointer - I think this not really supposed to happen, but does :/ | |
826 // seems like sometimes we get a func* other times a func** | |
827 if (llvm::isa<llvm::PointerType>(funcval->getType()->getContainedType(0))) { | |
828 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | |
829 } | |
830 // function pointer | |
831 if (llvm::isa<llvm::FunctionType>(funcval->getType()->getContainedType(0))) { | |
832 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; | |
833 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); | |
834 } | |
835 // struct pointer - delegate | |
836 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { | |
6 | 837 funcval = LLVM_DtoGEP(funcval,zero,one,"tmp",p->scopebb()); |
1 | 838 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
839 const llvm::Type* ty = funcval->getType()->getContainedType(0); | |
840 llfnty = llvm::cast<llvm::FunctionType>(ty); | |
841 } | |
842 // unknown | |
843 else { | |
844 Logger::cout() << "what kind of pointer are we calling? : " << *funcval->getType() << '\n'; | |
845 } | |
846 } | |
847 else { | |
848 Logger::cout() << "what are we calling? : " << *funcval << '\n'; | |
849 } | |
850 assert(llfnty); | |
851 Logger::cout() << "Function LLVM type: " << *llfnty << '\n'; | |
852 | |
853 // argument handling | |
854 llvm::FunctionType::param_iterator argiter = llfnty->param_begin(); | |
855 int j = 0; | |
856 | |
857 // hidden struct return parameter | |
858 if (retinptr) { | |
859 if (!p->lvals.empty()) { | |
860 assert(llvm::isa<llvm::StructType>(p->toplval()->getType()->getContainedType(0))); | |
861 llargs[j] = p->toplval(); | |
862 TY Dty = tf->next->ty; | |
863 if (Dty == Tstruct || Dty == Tdelegate || Dty == Tarray) { | |
864 e->inplace = true; | |
865 } | |
866 else | |
867 assert(0); | |
868 } | |
869 else { | |
870 llargs[j] = new llvm::AllocaInst(argiter->get()->getContainedType(0),"rettmp",p->topallocapoint()); | |
871 } | |
872 ++j; | |
873 ++argiter; | |
874 e->type = elem::VAR; | |
875 } | |
876 else { | |
877 e->type = elem::VAL; | |
878 } | |
879 | |
880 // this parameter | |
881 if (fn->arg) { | |
882 Logger::println("This Call"); | |
883 if (fn->arg->getType() != argiter->get()) { | |
884 //Logger::cout() << *fn->thisparam << '|' << *argiter->get() << '\n'; | |
885 llargs[j] = new llvm::BitCastInst(fn->arg, argiter->get(), "tmp", p->scopebb()); | |
886 } | |
887 else { | |
888 llargs[j] = fn->arg; | |
889 } | |
890 ++j; | |
891 ++argiter; | |
892 } | |
893 // delegate context parameter | |
894 else if (delegateCall) { | |
895 Logger::println("Delegate Call"); | |
6 | 896 llvm::Value* contextptr = LLVM_DtoGEP(fn->mem,zero,zero,"tmp",p->scopebb()); |
1 | 897 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); |
898 ++j; | |
899 ++argiter; | |
900 } | |
901 | |
902 // regular parameters | |
903 for (int i=0; i<arguments->dim; i++,j++) | |
904 { | |
905 Expression* argexp = (Expression*)arguments->data[i]; | |
906 elem* arg = argexp->toElem(p); | |
907 | |
908 Argument* fnarg = Argument::getNth(tf->parameters, i); | |
909 | |
910 TY argty = argexp->type->ty; | |
911 if (argty == Tstruct || argty == Tdelegate || argty == Tarray) { | |
912 if (!fnarg || !fnarg->llvmCopy) { | |
913 llargs[j] = arg->getValue(); | |
914 assert(llargs[j] != 0); | |
915 } | |
916 else { | |
917 llvm::Value* allocaInst = 0; | |
918 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
919 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType()); | |
920 if (argty == Tstruct) { | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
921 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", p->topallocapoint()); |
1 | 922 TypeStruct* ts = (TypeStruct*)argexp->type; |
923 LLVM_DtoStructCopy(ts,allocaInst,arg->mem); | |
924 } | |
925 else if (argty == Tdelegate) { | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
926 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", p->topallocapoint()); |
1 | 927 LLVM_DtoDelegateCopy(allocaInst,arg->mem); |
928 } | |
929 else if (argty == Tarray) { | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
930 if (arg->type == elem::SLICE) { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
931 allocaInst = new llvm::AllocaInst(LLVM_DtoType(argexp->type), "tmpparam", p->topallocapoint()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
932 LLVM_DtoSetArray(allocaInst, arg->arg, arg->mem); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
933 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
934 else { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
935 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", p->topallocapoint()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
936 LLVM_DtoArrayAssign(allocaInst,arg->mem); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
937 } |
1 | 938 } |
939 else | |
940 assert(0); | |
941 | |
942 llargs[j] = allocaInst; | |
943 assert(llargs[j] != 0); | |
944 } | |
945 } | |
946 else if (!fnarg || fnarg->llvmCopy) { | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
947 Logger::println("regular arg"); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
948 assert(arg->type != elem::SLICE); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
949 llargs[j] = arg->arg ? arg->arg : arg->getValue(); |
1 | 950 assert(llargs[j] != 0); |
951 } | |
952 else { | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
953 Logger::println("as ptr arg"); |
5
3d60e549b0c2
[svn r9] added a preliminary rebuild profile. llvmdc-posix - very handy :)
lindquist
parents:
4
diff
changeset
|
954 llargs[j] = arg->mem ? arg->mem : arg->val; |
1 | 955 assert(llargs[j] != 0); |
956 } | |
957 | |
958 delete arg; | |
959 } | |
960 | |
961 // void returns cannot not be named | |
962 const char* varname = ""; | |
963 if (llfnty->getReturnType() != llvm::Type::VoidTy) | |
964 varname = "tmp"; | |
965 | |
966 Logger::println("%d params passed", n); | |
967 for (int i=0; i<n; ++i) | |
968 { | |
969 Logger::cout() << *llargs[i] << '\n'; | |
970 } | |
971 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
972 Logger::cout() << "Calling: " << *funcval->getType() << '\n'; |
1 | 973 |
974 // call the function | |
975 llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); | |
976 e->val = call; | |
977 | |
978 // set calling convention | |
979 if ((fn->funcdecl && (fn->funcdecl->llvmInternal != LLVMintrinsic)) || delegateCall) | |
980 call->setCallingConv(LLVM_DtoCallingConv(dlink)); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
981 else if (fn->callconv != (unsigned)-1) |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
982 call->setCallingConv(fn->callconv); |
1 | 983 |
984 delete fn; | |
985 return e; | |
986 } | |
987 | |
988 ////////////////////////////////////////////////////////////////////////////////////////// | |
989 | |
990 elem* CastExp::toElem(IRState* p) | |
991 { | |
992 Logger::print("CastExp::toElem: %s\n", toChars()); | |
993 LOG_SCOPE; | |
994 elem* e = new elem; | |
995 elem* u = e1->toElem(p); | |
996 const llvm::Type* totype = LLVM_DtoType(to); | |
997 Type* from = e1->type; | |
998 int lsz = from->size(); | |
999 int rsz = to->size(); | |
1000 | |
1001 // this makes sure the strange lvalue casts don't screw things up | |
1002 e->mem = u->mem; | |
1003 | |
1004 if (from->isintegral()) { | |
1005 if (to->isintegral()) { | |
1006 if (lsz < rsz) { | |
1007 Logger::cout() << *totype << '\n'; | |
1008 if (from->isunsigned() || from->ty == Tbool) { | |
1009 e->val = new llvm::ZExtInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1010 } else { | |
1011 e->val = new llvm::SExtInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1012 } | |
1013 } | |
1014 else if (lsz > rsz) { | |
1015 e->val = new llvm::TruncInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1016 } | |
1017 else { | |
1018 e->val = new llvm::BitCastInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1019 } | |
1020 } | |
1021 else if (to->isfloating()) { | |
1022 if (from->isunsigned()) { | |
1023 e->val = new llvm::UIToFPInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1024 } | |
1025 else { | |
1026 e->val = new llvm::SIToFPInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1027 } | |
1028 } | |
1029 else { | |
1030 assert(0); | |
1031 } | |
1032 //e->storeVal = u->storeVal ? u->storeVal : u->val; | |
1033 e->type = elem::VAL; | |
1034 } | |
1035 else if (from->isfloating()) { | |
1036 if (to->isfloating()) { | |
1037 if ((from->ty == Tfloat80 || from->ty == Tfloat64) && (to->ty == Tfloat80 || to->ty == Tfloat64)) { | |
1038 e->val = u->getValue(); | |
1039 } | |
1040 else if (lsz < rsz) { | |
1041 e->val = new llvm::FPExtInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1042 } | |
1043 else if (lsz > rsz) { | |
1044 e->val = new llvm::FPTruncInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1045 } | |
1046 else { | |
1047 assert(0); | |
1048 } | |
1049 } | |
1050 else if (to->isintegral()) { | |
1051 if (to->isunsigned()) { | |
1052 e->val = new llvm::FPToUIInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1053 } | |
1054 else { | |
1055 e->val = new llvm::FPToSIInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1056 } | |
1057 } | |
1058 else { | |
1059 assert(0); | |
1060 } | |
1061 e->type = elem::VAL; | |
1062 } | |
1063 else if (from->ty == Tclass) { | |
1064 //assert(to->ty == Tclass); | |
1065 e->val = new llvm::BitCastInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1066 e->type = elem::VAL; | |
1067 } | |
1068 else if (from->ty == Tarray || from->ty == Tsarray) { | |
1069 Logger::cout() << "from array or sarray" << '\n'; | |
1070 if (to->ty == Tpointer) { | |
1071 Logger::cout() << "to pointer" << '\n'; | |
1072 assert(from->next == to->next); | |
1073 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1074 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
6 | 1075 llvm::Value* ptr = LLVM_DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb()); |
1 | 1076 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
1077 e->type = elem::VAL; | |
1078 } | |
1079 else if (to->ty == Tarray) { | |
1080 Logger::cout() << "to array" << '\n'; | |
1081 assert(from->next->size() == to->next->size()); | |
1082 const llvm::Type* ptrty = LLVM_DtoType(to->next); | |
1083 if (ptrty == llvm::Type::VoidTy) | |
1084 ptrty = llvm::Type::Int8Ty; | |
1085 ptrty = llvm::PointerType::get(ptrty); | |
1086 | |
1087 if (u->type == elem::SLICE) { | |
1088 e->mem = new llvm::BitCastInst(u->mem, ptrty, "tmp", p->scopebb()); | |
1089 e->arg = u->arg; | |
1090 } | |
1091 else { | |
1092 llvm::Value* uval = u->getValue(); | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1093 if (from->ty == Tsarray) { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1094 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1095 assert(llvm::isa<llvm::PointerType>(uval->getType())); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1096 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(uval->getType()->getContainedType(0)); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1097 e->arg = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1098 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1099 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1100 else { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1101 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1102 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
6 | 1103 e->arg = LLVM_DtoGEP(uval,zero,zero,"tmp",p->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1104 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1105 |
6 | 1106 e->mem = LLVM_DtoGEP(uval,zero,one,"tmp",p->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1107 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1108 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1109 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1110 } |
1 | 1111 } |
1112 e->type = elem::SLICE; | |
1113 } | |
1114 else if (to->ty == Tsarray) { | |
1115 Logger::cout() << "to sarray" << '\n'; | |
1116 assert(0); | |
1117 } | |
1118 else { | |
1119 assert(0); | |
1120 } | |
1121 } | |
1122 else if (from->ty == Tpointer) { | |
1123 if (to->ty == Tpointer || to->ty == Tclass) { | |
1124 llvm::Value* src = u->getValue(); | |
1125 //Logger::cout() << *src << '|' << *totype << '\n'; | |
1126 e->val = new llvm::BitCastInst(src, totype, "tmp", p->scopebb()); | |
1127 } | |
1128 else if (to->isintegral()) { | |
1129 e->val = new llvm::PtrToIntInst(u->getValue(), totype, "tmp", p->scopebb()); | |
1130 } | |
1131 else | |
1132 assert(0); | |
1133 e->type = elem::VAL; | |
1134 } | |
1135 else { | |
1136 assert(0); | |
1137 } | |
1138 delete u; | |
1139 return e; | |
1140 } | |
1141 | |
1142 ////////////////////////////////////////////////////////////////////////////////////////// | |
1143 | |
1144 elem* SymOffExp::toElem(IRState* p) | |
1145 { | |
1146 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1147 LOG_SCOPE; | |
1148 elem* e = 0; | |
1149 if (VarDeclaration* vd = var->isVarDeclaration()) | |
1150 { | |
1151 Logger::println("VarDeclaration"); | |
23 | 1152 assert(vd->llvmValue); |
1 | 1153 if (vd->type->ty == Tstruct && !(type->ty == Tpointer && type->next == vd->type)) { |
1154 TypeStruct* vdt = (TypeStruct*)vd->type; | |
1155 e = new elem; | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1156 std::vector<unsigned> dst(1,0); |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1157 vdt->sym->offsetToIndex(offset, dst); |
1 | 1158 llvm::Value* ptr = vd->llvmValue; |
1159 assert(ptr); | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1160 e->mem = LLVM_DtoGEP(ptr,dst,"tmp",p->scopebb()); |
1 | 1161 e->type = elem::VAL; |
1162 e->field = true; | |
1163 } | |
1164 else if (vd->type->ty == Tsarray) { | |
1165 /*e = new elem; | |
1166 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1167 e->val = new llvm::GetElementPtrInst(vd->llvmValue,idx0,idx0,"tmp",p->scopebb());*/ | |
1168 e = new elem; | |
1169 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1170 //llvm::Value* idx1 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
6 | 1171 e->mem = LLVM_DtoGEP(vd->llvmValue,idx0,idx0,"tmp",p->scopebb()); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
1172 e->arg = vd->llvmValue; |
1 | 1173 e->type = elem::VAL; |
1174 } | |
1175 else if (offset == 0) { | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1176 /*if (!vd->llvmValue) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1177 vd->toObjFile();*/ |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1178 assert(vd->llvmValue); |
1 | 1179 e = new elem; |
1180 e->mem = vd->llvmValue; | |
1181 //e->vardecl = vd; | |
1182 e->type = elem::VAL; | |
1183 } | |
1184 else { | |
1185 assert(0); | |
1186 } | |
1187 } | |
1188 else if (FuncDeclaration* fd = var->isFuncDeclaration()) | |
1189 { | |
1190 Logger::println("FuncDeclaration"); | |
1191 e = new elem; | |
1192 if (fd->llvmValue == 0) | |
1193 fd->toObjFile(); | |
1194 e->val = fd->llvmValue; | |
1195 //e->aspointer = true; | |
1196 e->type = elem::FUNC; | |
1197 } | |
1198 assert(e != 0); | |
1199 assert(e->type != elem::NONE); | |
1200 return e; | |
1201 } | |
1202 | |
1203 ////////////////////////////////////////////////////////////////////////////////////////// | |
1204 | |
1205 elem* PtrExp::toElem(IRState* p) | |
1206 { | |
1207 Logger::print("PtrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1208 LOG_SCOPE; | |
1209 elem* e = new elem; | |
1210 elem* a = e1->toElem(p); | |
1211 | |
1212 if (a->mem) | |
1213 Logger::cout() << "mem: " << *a->mem << '\n'; | |
1214 if (a->val) | |
1215 Logger::cout() << "val: " << *a->val << '\n'; | |
1216 | |
1217 if (a->field) | |
1218 e->mem = a->mem; | |
1219 else | |
1220 e->mem = a->getValue(); | |
1221 e->type = elem::VAR; | |
1222 | |
1223 delete a; | |
1224 return e; | |
1225 } | |
1226 | |
1227 ////////////////////////////////////////////////////////////////////////////////////////// | |
1228 | |
1229 elem* DotVarExp::toElem(IRState* p) | |
1230 { | |
1231 Logger::print("DotVarExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1232 LOG_SCOPE; | |
1233 elem* e = new elem; | |
1234 | |
1235 elem* l = e1->toElem(p); | |
1236 | |
1237 Logger::print("e1->type=%s\n", e1->type->toChars()); | |
1238 | |
1239 if (VarDeclaration* vd = var->isVarDeclaration()) { | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1240 std::vector<unsigned> vdoffsets(1,0); |
1 | 1241 llvm::Value* src = 0; |
1242 if (e1->type->ty == Tpointer) { | |
1243 assert(e1->type->next->ty == Tstruct); | |
1244 TypeStruct* ts = (TypeStruct*)e1->type->next; | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1245 ts->sym->offsetToIndex(vd->offset, vdoffsets); |
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1246 Logger::println("Struct member offset:%d", vd->offset); |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1247 src = l->val ? l->val : l->mem; |
1 | 1248 } |
1249 else if (e1->type->ty == Tclass) { | |
1250 TypeClass* tc = (TypeClass*)e1->type; | |
1251 Logger::println("Class member offset: %d", vd->offset); | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1252 tc->sym->offsetToIndex(vd->offset, vdoffsets); |
1 | 1253 src = l->getValue(); |
1254 } | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1255 assert(vdoffsets.size() != 1); |
1 | 1256 assert(src != 0); |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1257 llvm::Value* arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb()); |
1 | 1258 e->mem = arrptr; |
1259 Logger::cout() << "mem: " << *e->mem << '\n'; | |
1260 e->type = elem::VAR; | |
1261 } | |
1262 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | |
1263 { | |
1264 if (fdecl->llvmValue == 0) | |
1265 { | |
1266 fdecl->toObjFile(); | |
1267 } | |
1268 | |
1269 llvm::Value* funcval = fdecl->llvmValue; | |
1270 e->arg = l->getValue(); | |
1271 | |
1272 // virtual call | |
1273 if (fdecl->isVirtual()) { | |
1274 assert(fdecl->vtblIndex > 0); | |
1275 assert(e1->type->ty == Tclass); | |
1276 | |
1277 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1278 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); | |
6 | 1279 funcval = LLVM_DtoGEP(e->arg, zero, zero, "tmp", p->scopebb()); |
1 | 1280 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
6 | 1281 funcval = LLVM_DtoGEP(funcval, zero, vtblidx, "tmp", p->scopebb()); |
1 | 1282 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
9 | 1283 assert(funcval->getType() == fdecl->llvmValue->getType()); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
9
diff
changeset
|
1284 e->callconv = LLVM_DtoCallingConv(fdecl->linkage); |
1 | 1285 } |
1286 e->val = funcval; | |
1287 e->type = elem::VAL; | |
1288 } | |
1289 else { | |
1290 printf("unknown: %s\n", var->toChars()); | |
1291 assert(0); | |
1292 } | |
1293 | |
1294 delete l; | |
1295 | |
1296 return e; | |
1297 } | |
1298 | |
1299 ////////////////////////////////////////////////////////////////////////////////////////// | |
1300 | |
1301 elem* ThisExp::toElem(IRState* p) | |
1302 { | |
1303 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1304 LOG_SCOPE; | |
1305 elem* e = new elem; | |
1306 | |
1307 if (VarDeclaration* vd = var->isVarDeclaration()) { | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1308 /*assert(vd->llvmValue == 0); |
1 | 1309 |
1310 llvm::Function* fn = p->topfunc(); | |
1311 assert(fn); | |
1312 | |
1313 TypeFunction* tf = p->topfunctype(); | |
1314 assert(tf); | |
1315 | |
1316 llvm::Value* v = 0; | |
1317 if (tf->llvmRetInPtr) | |
1318 v = ++fn->arg_begin(); | |
1319 else | |
1320 v = fn->arg_begin(); | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1321 assert(v);*/ |
1 | 1322 |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1323 llvm::Value* v = p->funcdecls.back()->llvmThisVar; |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1324 if (llvm::isa<llvm::AllocaInst>(v)) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1325 v = new llvm::LoadInst(v, "tmp", p->scopebb()); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1326 e->mem = v; |
1 | 1327 e->type = elem::VAL; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1328 e->isthis = true; |
1 | 1329 } |
1330 else { | |
1331 assert(0); | |
1332 } | |
1333 | |
1334 return e; | |
1335 } | |
1336 | |
1337 ////////////////////////////////////////////////////////////////////////////////////////// | |
1338 | |
1339 elem* AddrExp::toElem(IRState* p) | |
1340 { | |
1341 Logger::print("AddrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1342 LOG_SCOPE; | |
1343 elem* e = e1->toElem(p); | |
1344 e->field = true; | |
1345 return e; | |
1346 } | |
1347 | |
1348 ////////////////////////////////////////////////////////////////////////////////////////// | |
1349 | |
1350 elem* StructLiteralExp::toElem(IRState* p) | |
1351 { | |
1352 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1353 LOG_SCOPE; | |
1354 elem* e = new elem; | |
1355 | |
1356 // if there is no lval, this must be a static initializer for a global. correct? | |
1357 if (p->lvals.empty()) | |
1358 { | |
1359 // TODO | |
1360 assert(0); | |
1361 } | |
1362 // otherwise write directly in the lvalue | |
1363 else | |
1364 { | |
1365 llvm::Value* sptr = p->toplval(); | |
1366 assert(sptr); | |
1367 | |
1368 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1369 | |
1370 unsigned n = elements->dim; | |
1371 for (unsigned i=0; i<n; ++i) | |
1372 { | |
1373 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false); | |
6 | 1374 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); |
1 | 1375 |
1376 Expression* vx = (Expression*)elements->data[i]; | |
1377 if (vx != 0) { | |
1378 elem* ve = vx->toElem(p); | |
1379 //Logger::cout() << *ve->val << " | " << *arrptr << '\n'; | |
1380 new llvm::StoreInst(ve->getValue(), arrptr, p->scopebb()); | |
1381 delete ve; | |
1382 } | |
1383 else { | |
1384 assert(0); | |
1385 } | |
1386 } | |
1387 } | |
1388 | |
1389 e->inplace = true; | |
1390 | |
1391 return e; | |
1392 } | |
1393 | |
1394 ////////////////////////////////////////////////////////////////////////////////////////// | |
1395 | |
1396 elem* IndexExp::toElem(IRState* p) | |
1397 { | |
1398 Logger::print("IndexExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1399 LOG_SCOPE; | |
1400 | |
1401 elem* e = new elem; | |
1402 | |
1403 elem* l = e1->toElem(p); | |
1404 | |
1405 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine. | |
1406 elem* r = e2->toElem(p); | |
1407 p->arrays.pop_back(); | |
1408 | |
1409 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1410 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1411 | |
1412 llvm::Value* arrptr = 0; | |
1413 if (e1->type->ty == Tpointer) { | |
1414 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); | |
1415 } | |
1416 else if (e1->type->ty == Tsarray) { | |
6 | 1417 arrptr = LLVM_DtoGEP(l->mem, zero, r->getValue(),"tmp",p->scopebb()); |
1 | 1418 } |
1419 else if (e1->type->ty == Tarray) { | |
6 | 1420 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); |
1 | 1421 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); |
1422 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); | |
1423 } | |
1424 assert(arrptr); | |
1425 | |
1426 e->mem = arrptr; | |
1427 e->type = elem::VAR; | |
1428 | |
1429 delete l; | |
1430 delete r; | |
1431 | |
1432 return e; | |
1433 } | |
1434 | |
1435 ////////////////////////////////////////////////////////////////////////////////////////// | |
1436 | |
1437 elem* SliceExp::toElem(IRState* p) | |
1438 { | |
1439 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1440 LOG_SCOPE; | |
1441 | |
1442 elem* v = e1->toElem(p); | |
1443 | |
1444 elem* e = new elem; | |
1445 assert(v->mem); | |
1446 e->type = elem::SLICE; | |
1447 | |
1448 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1449 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1450 | |
1451 // partial slice | |
1452 if (lwr) | |
1453 { | |
1454 assert(upr); | |
1455 p->arrays.push_back(v->mem); | |
1456 elem* lo = lwr->toElem(p); | |
1457 | |
1458 bool lwr_is_zero = false; | |
1459 if (lo->type == elem::CONST) | |
1460 { | |
1461 assert(lo->val); | |
1462 assert(llvm::isa<llvm::ConstantInt>(lo->val)); | |
1463 | |
1464 if (e1->type->ty == Tpointer) { | |
1465 e->mem = v->getValue(); | |
1466 } | |
1467 else if (e1->type->ty == Tarray) { | |
6 | 1468 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1 | 1469 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1470 } | |
1471 else | |
1472 assert(e->mem); | |
1473 | |
1474 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val); | |
1475 if (!(lwr_is_zero = c->isZero())) { | |
1476 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb()); | |
1477 } | |
1478 } | |
1479 else | |
1480 { | |
6 | 1481 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1 | 1482 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1483 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); | |
1484 } | |
1485 | |
1486 elem* up = upr->toElem(p); | |
1487 p->arrays.pop_back(); | |
1488 | |
1489 if (up->type == elem::CONST) | |
1490 { | |
1491 assert(up->val); | |
1492 assert(llvm::isa<llvm::ConstantInt>(up->val)); | |
1493 if (lwr_is_zero) { | |
1494 e->arg = up->val; | |
1495 } | |
1496 else { | |
1497 if (lo->type == elem::CONST) { | |
1498 llvm::Constant* clo = llvm::cast<llvm::Constant>(lo->val); | |
1499 llvm::Constant* cup = llvm::cast<llvm::Constant>(up->val); | |
1500 e->arg = llvm::ConstantExpr::getSub(cup, clo); | |
1501 } | |
1502 else { | |
1503 e->arg = llvm::BinaryOperator::createSub(up->val, lo->getValue(), "tmp", p->scopebb()); | |
1504 } | |
1505 } | |
1506 } | |
1507 else | |
1508 { | |
1509 if (lwr_is_zero) { | |
1510 e->arg = up->getValue(); | |
1511 } | |
1512 else { | |
1513 e->arg = llvm::BinaryOperator::createSub(up->getValue(), lo->getValue(), "tmp", p->scopebb()); | |
1514 } | |
1515 } | |
1516 | |
1517 delete lo; | |
1518 delete up; | |
1519 } | |
1520 // full slice | |
1521 else | |
1522 { | |
1523 e->mem = v->mem; | |
1524 } | |
1525 | |
1526 delete v; | |
1527 | |
1528 return e; | |
1529 } | |
1530 | |
1531 ////////////////////////////////////////////////////////////////////////////////////////// | |
1532 | |
1533 elem* CmpExp::toElem(IRState* p) | |
1534 { | |
1535 Logger::print("CmpExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1536 LOG_SCOPE; | |
1537 | |
1538 elem* e = new elem; | |
1539 | |
1540 elem* l = e1->toElem(p); | |
1541 elem* r = e2->toElem(p); | |
1542 | |
1543 assert(e1->type == e2->type); | |
1544 | |
1545 Type* t = e1->type; | |
1546 | |
1547 if (t->isintegral()) | |
1548 { | |
1549 llvm::ICmpInst::Predicate cmpop; | |
1550 switch(op) | |
1551 { | |
1552 case TOKlt: | |
1553 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT; | |
1554 break; | |
1555 case TOKle: | |
1556 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE; | |
1557 break; | |
1558 case TOKgt: | |
1559 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT; | |
1560 break; | |
1561 case TOKge: | |
1562 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE; | |
1563 break; | |
1564 default: | |
1565 assert(0); | |
1566 } | |
1567 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1568 } | |
1569 else if (t->isfloating()) | |
1570 { | |
1571 llvm::FCmpInst::Predicate cmpop; | |
1572 switch(op) | |
1573 { | |
1574 case TOKlt: | |
1575 cmpop = llvm::FCmpInst::FCMP_OLT;break; | |
1576 case TOKle: | |
1577 cmpop = llvm::FCmpInst::FCMP_OLE;break; | |
1578 case TOKgt: | |
1579 cmpop = llvm::FCmpInst::FCMP_OGT;break; | |
1580 case TOKge: | |
1581 cmpop = llvm::FCmpInst::FCMP_OGE;break; | |
1582 case TOKunord: | |
1583 cmpop = llvm::FCmpInst::FCMP_UNO;break; | |
1584 case TOKule: | |
1585 cmpop = llvm::FCmpInst::FCMP_ULE;break; | |
1586 case TOKul: | |
1587 cmpop = llvm::FCmpInst::FCMP_ULT;break; | |
1588 case TOKuge: | |
1589 cmpop = llvm::FCmpInst::FCMP_UGE;break; | |
1590 case TOKug: | |
1591 cmpop = llvm::FCmpInst::FCMP_UGT;break; | |
1592 case TOKue: | |
1593 cmpop = llvm::FCmpInst::FCMP_UEQ;break; | |
1594 case TOKlg: | |
1595 cmpop = llvm::FCmpInst::FCMP_ONE;break; | |
1596 case TOKleg: | |
1597 cmpop = llvm::FCmpInst::FCMP_ORD;break; | |
1598 | |
1599 default: | |
1600 assert(0); | |
1601 } | |
1602 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1603 } | |
1604 else | |
1605 { | |
1606 assert(0 && "Unsupported CmpExp type"); | |
1607 } | |
1608 | |
1609 delete l; | |
1610 delete r; | |
1611 | |
1612 e->type = elem::VAL; | |
1613 | |
1614 return e; | |
1615 } | |
1616 | |
1617 ////////////////////////////////////////////////////////////////////////////////////////// | |
1618 | |
1619 elem* EqualExp::toElem(IRState* p) | |
1620 { | |
1621 Logger::print("EqualExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1622 LOG_SCOPE; | |
1623 | |
1624 elem* e = new elem; | |
1625 | |
1626 elem* l = e1->toElem(p); | |
1627 elem* r = e2->toElem(p); | |
1628 | |
1629 assert(e1->type == e2->type); | |
1630 | |
1631 Type* t = e1->type; | |
1632 | |
1633 if (t->isintegral() || t->ty == Tpointer) | |
1634 { | |
1635 llvm::ICmpInst::Predicate cmpop; | |
1636 switch(op) | |
1637 { | |
1638 case TOKequal: | |
1639 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1640 break; | |
1641 case TOKnotequal: | |
1642 cmpop = llvm::ICmpInst::ICMP_NE; | |
1643 break; | |
1644 default: | |
1645 assert(0); | |
1646 } | |
1647 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1648 } | |
1649 else if (t->isfloating()) | |
1650 { | |
1651 llvm::FCmpInst::Predicate cmpop; | |
1652 switch(op) | |
1653 { | |
1654 case TOKequal: | |
1655 cmpop = llvm::FCmpInst::FCMP_OEQ; | |
1656 break; | |
1657 case TOKnotequal: | |
1658 cmpop = llvm::FCmpInst::FCMP_UNE; | |
1659 break; | |
1660 default: | |
1661 assert(0); | |
1662 } | |
1663 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1664 } | |
1665 else if (t->ty == Tarray) | |
1666 { | |
1667 // array comparison invokes the typeinfo runtime | |
1668 assert(0); | |
1669 } | |
1670 else | |
1671 { | |
1672 assert(0 && "Unsupported EqualExp type"); | |
1673 } | |
1674 | |
1675 delete l; | |
1676 delete r; | |
1677 | |
1678 e->type = elem::VAL; | |
1679 | |
1680 return e; | |
1681 } | |
1682 | |
1683 ////////////////////////////////////////////////////////////////////////////////////////// | |
1684 | |
1685 elem* PostExp::toElem(IRState* p) | |
1686 { | |
1687 Logger::print("PostExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1688 LOG_SCOPE; | |
1689 | |
1690 elem* l = e1->toElem(p); | |
1691 elem* r = e2->toElem(p); | |
1692 | |
1693 elem* e = new elem; | |
1694 e->mem = l->mem; | |
1695 e->val = l->getValue(); | |
1696 e->type = elem::VAL; | |
1697 | |
1698 llvm::Value* val = e->val; | |
1699 llvm::Value* post = 0; | |
1700 | |
1701 if (e1->type->isintegral()) | |
1702 { | |
1703 assert(e2->type->isintegral()); | |
1704 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2->type->isunsigned()); | |
1705 if (op == TOKplusplus) { | |
1706 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
1707 } | |
1708 else if (op == TOKminusminus) { | |
1709 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
1710 } | |
1711 } | |
1712 else if (e1->type->ty == Tpointer) | |
1713 { | |
1714 assert(e2->type->isintegral()); | |
1715 llvm::Constant* minusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)-1,true); | |
1716 llvm::Constant* plusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)1,false); | |
1717 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; | |
1718 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb()); | |
1719 } | |
1720 else if (e1->type->isfloating()) | |
1721 { | |
1722 assert(e2->type->isfloating()); | |
1723 llvm::Value* one = llvm::ConstantFP::get(val->getType(), 1.0f); | |
1724 if (op == TOKplusplus) { | |
1725 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
1726 } | |
1727 else if (op == TOKminusminus) { | |
1728 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
1729 } | |
1730 } | |
1731 else | |
1732 assert(post); | |
1733 | |
1734 //llvm::Value* tostore = l->storeVal ? l->storeVal : l->val; | |
1735 new llvm::StoreInst(post,l->mem,p->scopebb()); | |
1736 | |
1737 delete l; | |
1738 delete r; | |
1739 | |
1740 return e; | |
1741 } | |
1742 | |
1743 ////////////////////////////////////////////////////////////////////////////////////////// | |
1744 | |
1745 elem* NewExp::toElem(IRState* p) | |
1746 { | |
1747 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1748 LOG_SCOPE; | |
1749 | |
1750 assert(!thisexp); | |
1751 assert(!newargs); | |
1752 assert(newtype); | |
1753 //assert(!arguments); | |
1754 //assert(!member); | |
1755 assert(!allocator); | |
1756 | |
1757 elem* e = new elem; | |
1758 | |
1759 const llvm::Type* t = LLVM_DtoType(newtype); | |
1760 | |
1761 if (onstack) { | |
1762 assert(newtype->ty == Tclass); | |
1763 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint()); | |
1764 } | |
1765 else { | |
1766 if (newtype->ty == Tclass) { | |
1767 e->mem = new llvm::MallocInst(t->getContainedType(0),"tmp",p->scopebb()); | |
1768 } | |
1769 else if (newtype->ty == Tarray) { | |
1770 t = LLVM_DtoType(newtype->next); | |
1771 assert(arguments); | |
1772 if (arguments->dim == 1) { | |
1773 elem* sz = ((Expression*)arguments->data[0])->toElem(p); | |
1774 llvm::Value* dimval = sz->getValue(); | |
1775 llvm::Value* usedimval = dimval; | |
1776 if (dimval->getType() != llvm::Type::Int32Ty) | |
1777 usedimval = new llvm::TruncInst(dimval, llvm::Type::Int32Ty,"tmp",p->scopebb()); | |
1778 e->mem = new llvm::MallocInst(t,usedimval,"tmp",p->scopebb()); | |
1779 | |
1780 LLVM_DtoSetArray(p->toplval(), dimval, e->mem); | |
1781 delete sz; | |
1782 } | |
1783 else { | |
1784 assert(0); | |
1785 } | |
1786 } | |
1787 else { | |
1788 e->mem = new llvm::MallocInst(t,"tmp",p->scopebb()); | |
1789 } | |
1790 } | |
1791 | |
1792 if (newtype->ty == Tclass) { | |
1793 // first apply the static initializer | |
1794 assert(e->mem); | |
1795 LLVM_DtoInitClass((TypeClass*)newtype, e->mem); | |
1796 | |
1797 // then call constructor | |
1798 if (arguments) { | |
1799 std::vector<llvm::Value*> ctorargs; | |
1800 ctorargs.push_back(e->mem); | |
1801 for (size_t i=0; i<arguments->dim; ++i) | |
1802 { | |
1803 Expression* ex = (Expression*)arguments->data[i]; | |
1804 Logger::println("arg=%s", ex->toChars()); | |
1805 elem* exe = ex->toElem(p); | |
1806 assert(exe->getValue()); | |
1807 ctorargs.push_back(exe->getValue()); | |
1808 delete exe; | |
1809 } | |
1810 assert(member); | |
1811 assert(member->llvmValue); | |
1812 new llvm::CallInst(member->llvmValue, ctorargs.begin(), ctorargs.end(), "", p->scopebb()); | |
1813 } | |
1814 } | |
1815 else if (newtype->ty == Tstruct) { | |
1816 TypeStruct* ts = (TypeStruct*)newtype; | |
1817 if (ts->isZeroInit()) { | |
1818 LLVM_DtoStructZeroInit(ts,e->mem); | |
1819 } | |
1820 else { | |
1821 LLVM_DtoStructCopy(ts,e->mem,ts->llvmInit); | |
1822 } | |
1823 } | |
1824 | |
1825 e->inplace = true; | |
1826 e->type = elem::VAR; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1827 |
1 | 1828 return e; |
1829 } | |
1830 | |
1831 ////////////////////////////////////////////////////////////////////////////////////////// | |
1832 | |
1833 elem* DeleteExp::toElem(IRState* p) | |
1834 { | |
1835 Logger::print("DeleteExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1836 LOG_SCOPE; | |
1837 | |
1838 //assert(e1->type->ty != Tclass); | |
1839 | |
1840 elem* v = e1->toElem(p); | |
1841 llvm::Value* val = v->getValue(); | |
1842 llvm::Value* ldval = 0; | |
1843 | |
1844 const llvm::Type* t = val->getType(); | |
1845 llvm::Constant* z = llvm::Constant::getNullValue(t); | |
1846 | |
1847 if (e1->type->ty == Tpointer) { | |
1848 ldval = v->getValue(); | |
1849 new llvm::FreeInst(ldval, p->scopebb()); | |
1850 | |
1851 Logger::cout() << *z << '\n'; | |
1852 Logger::cout() << *val << '\n'; | |
1853 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
1854 } | |
1855 else if (e1->type->ty == Tclass) { | |
1856 TypeClass* tc = (TypeClass*)e1->type; | |
1857 LLVM_DtoCallClassDtors(tc, val); | |
1858 | |
1859 if (v->vardecl && !v->vardecl->onstack) { | |
1860 new llvm::FreeInst(val, p->scopebb()); | |
1861 } | |
1862 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
1863 } | |
1864 else if (e1->type->ty == Tarray) { | |
1865 // must be on the heap (correct?) | |
1866 ldval = v->getValue(); | |
1867 | |
1868 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1869 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1870 | |
6 | 1871 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb()); |
1 | 1872 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); |
1873 new llvm::FreeInst(ptr, p->scopebb()); | |
1874 LLVM_DtoNullArray(val); | |
1875 } | |
1876 else { | |
1877 assert(0); | |
1878 } | |
1879 | |
1880 delete v; | |
1881 | |
1882 // this expression produces no useful data | |
1883 return 0; | |
1884 } | |
1885 | |
1886 ////////////////////////////////////////////////////////////////////////////////////////// | |
1887 | |
1888 elem* ArrayLengthExp::toElem(IRState* p) | |
1889 { | |
1890 Logger::print("ArrayLengthExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1891 LOG_SCOPE; | |
1892 | |
1893 elem* e = new elem; | |
1894 elem* u = e1->toElem(p); | |
1895 | |
1896 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
6 | 1897 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); |
1 | 1898 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
1899 e->type = elem::VAL; | |
1900 | |
1901 delete u; | |
1902 | |
1903 return e; | |
1904 } | |
1905 | |
1906 ////////////////////////////////////////////////////////////////////////////////////////// | |
1907 | |
1908 elem* AssertExp::toElem(IRState* p) | |
1909 { | |
1910 Logger::print("AssertExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1911 LOG_SCOPE; | |
1912 | |
1913 elem* e = new elem; | |
1914 elem* u = e1->toElem(p); | |
1915 elem* m = msg ? msg->toElem(p) : 0; | |
1916 | |
1917 std::vector<llvm::Value*> llargs; | |
1918 llargs.resize(3); | |
1919 llargs[0] = LLVM_DtoBoolean(u->getValue()); | |
1920 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); | |
1921 llargs[2] = m ? m->val : llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); | |
1922 | |
1923 delete m; | |
1924 delete u; | |
1925 | |
1926 //Logger::cout() << *llargs[0] << '|' << *llargs[1] << '\n'; | |
1927 | |
1928 llvm::Function* fn = LLVM_D_GetRuntimeFunction(p->module, "_d_assert"); | |
1929 assert(fn); | |
1930 llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", p->scopebb()); | |
1931 call->setCallingConv(llvm::CallingConv::C); | |
1932 | |
1933 return e; | |
1934 } | |
1935 | |
1936 ////////////////////////////////////////////////////////////////////////////////////////// | |
1937 | |
1938 elem* NotExp::toElem(IRState* p) | |
1939 { | |
1940 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1941 LOG_SCOPE; | |
1942 | |
1943 elem* e = new elem; | |
1944 elem* u = e1->toElem(p); | |
1945 | |
1946 llvm::Value* b = LLVM_DtoBoolean(u->getValue()); | |
1947 | |
1948 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); | |
1949 e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb()); | |
1950 e->type = elem::VAL; | |
1951 | |
1952 delete u; | |
1953 | |
1954 return e; | |
1955 } | |
1956 | |
1957 ////////////////////////////////////////////////////////////////////////////////////////// | |
1958 | |
1959 elem* AndAndExp::toElem(IRState* p) | |
1960 { | |
1961 Logger::print("AndAndExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1962 LOG_SCOPE; | |
1963 | |
1964 // allocate a temporary for the final result. failed to come up with a better way :/ | |
1965 llvm::Value* resval = 0; | |
1966 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
1967 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"andandtmp",p->topallocapoint()); | |
1968 | |
1969 elem* e = new elem; | |
1970 elem* u = e1->toElem(p); | |
1971 | |
1972 llvm::BasicBlock* oldend = p->scopeend(); | |
1973 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend); | |
1974 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend); | |
1975 | |
1976 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
1977 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
1978 new llvm::BranchInst(andand,andandend,ubool,p->scopebb()); | |
1979 | |
1980 p->scope() = IRScope(andand, andandend); | |
1981 elem* v = e2->toElem(p); | |
1982 | |
1983 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
1984 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); | |
1985 new llvm::StoreInst(uandvbool,resval,p->scopebb()); | |
1986 new llvm::BranchInst(andandend,p->scopebb()); | |
1987 | |
1988 delete u; | |
1989 delete v; | |
1990 | |
1991 p->scope() = IRScope(andandend, oldend); | |
1992 | |
1993 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
1994 e->type = elem::VAL; | |
1995 | |
1996 return e; | |
1997 } | |
1998 | |
1999 ////////////////////////////////////////////////////////////////////////////////////////// | |
2000 | |
2001 elem* OrOrExp::toElem(IRState* p) | |
2002 { | |
2003 Logger::print("OrOrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2004 LOG_SCOPE; | |
2005 | |
2006 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2007 llvm::Value* resval = 0; | |
2008 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2009 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"orortmp",p->topallocapoint()); | |
2010 | |
2011 elem* e = new elem; | |
2012 elem* u = e1->toElem(p); | |
2013 | |
2014 llvm::BasicBlock* oldend = p->scopeend(); | |
2015 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend); | |
2016 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend); | |
2017 | |
2018 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
2019 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
2020 new llvm::BranchInst(ororend,oror,ubool,p->scopebb()); | |
2021 | |
2022 p->scope() = IRScope(oror, ororend); | |
2023 elem* v = e2->toElem(p); | |
2024 | |
2025 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
2026 new llvm::StoreInst(vbool,resval,p->scopebb()); | |
2027 new llvm::BranchInst(ororend,p->scopebb()); | |
2028 | |
2029 delete u; | |
2030 delete v; | |
2031 | |
2032 p->scope() = IRScope(ororend, oldend); | |
2033 | |
2034 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2035 e->type = elem::VAL; | |
2036 | |
2037 return e; | |
2038 } | |
2039 | |
2040 ////////////////////////////////////////////////////////////////////////////////////////// | |
2041 | |
2042 #define BinBitExp(X,Y) \ | |
2043 elem* X##Exp::toElem(IRState* p) \ | |
2044 { \ | |
2045 Logger::print("%sExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2046 LOG_SCOPE; \ | |
2047 elem* e = new elem; \ | |
2048 elem* u = e1->toElem(p); \ | |
2049 elem* v = e2->toElem(p); \ | |
2050 e->val = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \ | |
2051 e->type = elem::VAL; \ | |
2052 delete u; \ | |
2053 delete v; \ | |
2054 return e; \ | |
2055 } \ | |
2056 \ | |
2057 elem* X##AssignExp::toElem(IRState* p) \ | |
2058 { \ | |
2059 Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2060 LOG_SCOPE; \ | |
2061 elem* u = e1->toElem(p); \ | |
2062 elem* v = e2->toElem(p); \ | |
2063 llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \ | |
2064 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \ | |
2065 new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \ | |
2066 delete u; \ | |
2067 delete v; \ | |
2068 elem* e = new elem; \ | |
2069 e->mem = u->mem; \ | |
2070 e->type = elem::VAR; \ | |
2071 return e; \ | |
2072 } | |
2073 | |
2074 BinBitExp(And,And); | |
2075 BinBitExp(Or,Or); | |
2076 BinBitExp(Xor,Xor); | |
2077 BinBitExp(Shl,Shl); | |
2078 BinBitExp(Shr,AShr); | |
2079 BinBitExp(Ushr,LShr); | |
2080 | |
2081 ////////////////////////////////////////////////////////////////////////////////////////// | |
2082 | |
2083 elem* HaltExp::toElem(IRState* p) | |
2084 { | |
2085 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2086 LOG_SCOPE; | |
2087 | |
2088 std::vector<llvm::Value*> llargs; | |
2089 llargs.resize(3); | |
2090 llargs[0] = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, false); | |
2091 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); | |
2092 llargs[2] = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); | |
2093 | |
2094 //Logger::cout() << *llargs[0] << '|' << *llargs[1] << '\n'; | |
2095 | |
2096 llvm::Function* fn = LLVM_D_GetRuntimeFunction(p->module, "_d_assert"); | |
2097 assert(fn); | |
2098 llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", p->scopebb()); | |
2099 call->setCallingConv(llvm::CallingConv::C); | |
2100 | |
2101 //new llvm::UnreachableInst(p->scopebb()); | |
2102 | |
2103 return 0; | |
2104 } | |
2105 | |
2106 ////////////////////////////////////////////////////////////////////////////////////////// | |
2107 | |
2108 elem* DelegateExp::toElem(IRState* p) | |
2109 { | |
2110 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2111 LOG_SCOPE; | |
2112 | |
2113 elem* e = new elem; | |
2114 elem* u = e1->toElem(p); | |
2115 | |
2116 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2117 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
2118 | |
2119 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
2120 | |
2121 llvm::Value* lval = p->toplval(); | |
2122 | |
6 | 2123 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb()); |
1 | 2124 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); |
2125 new llvm::StoreInst(castcontext, context, p->scopebb()); | |
2126 | |
6 | 2127 llvm::Value* fptr = LLVM_DtoGEP(lval,zero,one,"tmp",p->scopebb()); |
1 | 2128 |
2129 assert(func->llvmValue); | |
2130 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | |
2131 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | |
2132 | |
2133 e->inplace = true; | |
2134 | |
2135 delete u; | |
2136 return e; | |
2137 } | |
2138 | |
2139 ////////////////////////////////////////////////////////////////////////////////////////// | |
2140 | |
2141 elem* IdentityExp::toElem(IRState* p) | |
2142 { | |
2143 Logger::print("IdentityExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2144 LOG_SCOPE; | |
2145 | |
2146 elem* u = e1->toElem(p); | |
2147 elem* v = e2->toElem(p); | |
2148 | |
2149 elem* e = new elem; | |
2150 | |
2151 llvm::Value* l = u->getValue(); | |
2152 llvm::Value* r = 0; | |
2153 if (v->type == elem::NUL) | |
2154 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); | |
2155 else | |
2156 r = v->getValue(); | |
2157 | |
2158 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; | |
2159 e->val = new llvm::ICmpInst(pred, l, r, "tmp", p->scopebb()); | |
2160 e->type = elem::VAL; | |
2161 | |
2162 delete u; | |
2163 delete v; | |
2164 | |
2165 return e; | |
2166 } | |
2167 | |
2168 ////////////////////////////////////////////////////////////////////////////////////////// | |
2169 | |
2170 elem* CommaExp::toElem(IRState* p) | |
2171 { | |
2172 Logger::print("CommaExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2173 LOG_SCOPE; | |
2174 | |
2175 elem* u = e1->toElem(p); | |
2176 elem* v = e2->toElem(p); | |
2177 delete u; | |
2178 return v; | |
2179 } | |
2180 | |
2181 ////////////////////////////////////////////////////////////////////////////////////////// | |
2182 | |
2183 elem* CondExp::toElem(IRState* p) | |
2184 { | |
2185 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2186 LOG_SCOPE; | |
2187 | |
2188 const llvm::Type* resty = LLVM_DtoType(type); | |
2189 | |
2190 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2191 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2192 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); | |
2193 | |
2194 llvm::BasicBlock* oldend = p->scopeend(); | |
2195 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend); | |
2196 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend); | |
2197 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend); | |
2198 | |
2199 elem* c = econd->toElem(p); | |
2200 llvm::Value* cond_val = LLVM_DtoBoolean(c->getValue()); | |
2201 delete c; | |
2202 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb()); | |
2203 | |
2204 p->scope() = IRScope(condtrue, condfalse); | |
2205 elem* u = e1->toElem(p); | |
2206 Logger::cout() << *u->val << '|' << *resval << '\n'; \ | |
2207 new llvm::StoreInst(u->getValue(),resval,p->scopebb()); | |
2208 new llvm::BranchInst(condend,p->scopebb()); | |
2209 delete u; | |
2210 | |
2211 p->scope() = IRScope(condfalse, condend); | |
2212 elem* v = e2->toElem(p); | |
2213 new llvm::StoreInst(v->getValue(),resval,p->scopebb()); | |
2214 new llvm::BranchInst(condend,p->scopebb()); | |
2215 delete v; | |
2216 | |
2217 p->scope() = IRScope(condend, oldend); | |
2218 | |
2219 elem* e = new elem; | |
2220 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2221 e->type = elem::VAL; | |
2222 return e; | |
2223 } | |
2224 | |
2225 ////////////////////////////////////////////////////////////////////////////////////////// | |
2226 | |
2227 elem* ComExp::toElem(IRState* p) | |
2228 { | |
2229 Logger::print("ComExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2230 LOG_SCOPE; | |
2231 | |
2232 elem* e = new elem; | |
2233 elem* u = e1->toElem(p); | |
2234 | |
2235 llvm::Value* value = u->getValue(); | |
2236 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); | |
2237 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); | |
2238 | |
2239 delete u; | |
2240 | |
2241 e->type = elem::VAL; | |
2242 | |
2243 return e; | |
2244 } | |
2245 | |
2246 ////////////////////////////////////////////////////////////////////////////////////////// | |
2247 | |
23 | 2248 elem* NegExp::toElem(IRState* p) |
2249 { | |
2250 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2251 LOG_SCOPE; | |
2252 elem* e = new elem; | |
2253 elem* l = e1->toElem(p); | |
2254 llvm::Value* val = l->getValue(); | |
2255 delete l; | |
2256 | |
2257 llvm::Value* zero = 0; | |
2258 if (type->isintegral()) | |
2259 zero = llvm::ConstantInt::get(val->getType(), 0, true); | |
2260 else if (type->isfloating()) { | |
2261 if (type->ty == Tfloat32) | |
2262 zero = llvm::ConstantFP::get(val->getType(), float(0)); | |
2263 else if (type->ty == Tfloat64 || type->ty == Tfloat80) | |
2264 zero = llvm::ConstantFP::get(val->getType(), double(0)); | |
2265 else | |
2266 assert(0); | |
2267 } | |
2268 else | |
2269 assert(0); | |
2270 | |
2271 e->val = llvm::BinaryOperator::createSub(zero,val,"tmp",p->scopebb()); | |
2272 e->type = elem::VAL; | |
2273 | |
2274 return e; | |
2275 } | |
2276 | |
2277 ////////////////////////////////////////////////////////////////////////////////////////// | |
2278 | |
1 | 2279 #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } |
2280 //STUB(IdentityExp); | |
2281 //STUB(CondExp); | |
2282 //STUB(EqualExp); | |
2283 STUB(InExp); | |
2284 //STUB(CmpExp); | |
2285 //STUB(AndAndExp); | |
2286 //STUB(OrOrExp); | |
2287 //STUB(AndExp); | |
2288 //STUB(AndAssignExp); | |
2289 //STUB(OrExp); | |
2290 //STUB(OrAssignExp); | |
2291 //STUB(XorExp); | |
2292 //STUB(XorAssignExp); | |
2293 //STUB(ShrExp); | |
2294 //STUB(ShrAssignExp); | |
2295 //STUB(ShlExp); | |
2296 //STUB(ShlAssignExp); | |
2297 //STUB(UshrExp); | |
2298 //STUB(UshrAssignExp); | |
2299 //STUB(DivExp); | |
2300 //STUB(DivAssignExp); | |
2301 //STUB(MulExp); | |
2302 //STUB(MulAssignExp); | |
2303 //STUB(ModExp); | |
2304 //STUB(ModAssignExp); | |
2305 STUB(CatExp); | |
2306 STUB(CatAssignExp); | |
2307 //STUB(AddExp); | |
2308 //STUB(AddAssignExp); | |
2309 STUB(Expression); | |
2310 //STUB(MinExp); | |
2311 //STUB(MinAssignExp); | |
2312 //STUB(PostExp); | |
2313 //STUB(NullExp); | |
2314 //STUB(ThisExp); | |
2315 //STUB(CallExp); | |
2316 STUB(DotTypeExp); | |
2317 STUB(TypeDotIdExp); | |
2318 //STUB(DotVarExp); | |
2319 //STUB(AssertExp); | |
2320 STUB(FuncExp); | |
2321 //STUB(DelegateExp); | |
2322 //STUB(VarExp); | |
2323 //STUB(DeclarationExp); | |
2324 //STUB(NewExp); | |
2325 //STUB(SymOffExp); | |
2326 STUB(ScopeExp); | |
2327 //STUB(AssignExp); | |
2328 | |
2329 STUB(TypeExp); | |
2330 //STUB(RealExp); | |
2331 STUB(ComplexExp); | |
2332 //STUB(StringExp); | |
2333 //STUB(IntegerExp); | |
2334 STUB(BoolExp); | |
2335 | |
2336 //STUB(NotExp); | |
2337 //STUB(ComExp); | |
23 | 2338 //STUB(NegExp); |
1 | 2339 //STUB(PtrExp); |
2340 //STUB(AddrExp); | |
2341 //STUB(SliceExp); | |
2342 //STUB(CastExp); | |
2343 //STUB(DeleteExp); | |
2344 //STUB(IndexExp); | |
2345 //STUB(CommaExp); | |
2346 //STUB(ArrayLengthExp); | |
2347 //STUB(HaltExp); | |
2348 STUB(RemoveExp); | |
2349 STUB(ArrayLiteralExp); | |
2350 STUB(AssocArrayLiteralExp); | |
2351 //STUB(StructLiteralExp); | |
2352 | |
2353 unsigned Type::totym() { return 0; } | |
2354 | |
2355 type * | |
2356 Type::toCtype() { | |
2357 return 0; | |
2358 } | |
2359 | |
2360 type * Type::toCParamtype() | |
2361 { | |
2362 return 0; | |
2363 } | |
2364 Symbol * Type::toSymbol() | |
2365 { | |
2366 return 0; | |
2367 } | |
2368 | |
2369 type * | |
2370 TypeTypedef::toCtype() | |
2371 { | |
2372 return 0; | |
2373 } | |
2374 | |
2375 type * | |
2376 TypeTypedef::toCParamtype() | |
2377 { | |
2378 return 0; | |
2379 } | |
2380 | |
2381 void | |
2382 TypedefDeclaration::toDebug() | |
2383 { | |
2384 } | |
2385 | |
2386 | |
2387 type * | |
2388 TypeEnum::toCtype() | |
2389 { | |
2390 return 0; | |
2391 } | |
2392 | |
2393 type * | |
2394 TypeStruct::toCtype() | |
2395 { | |
2396 return 0; | |
2397 } | |
2398 | |
2399 void | |
2400 StructDeclaration::toDebug() | |
2401 { | |
2402 } | |
2403 | |
2404 Symbol * TypeClass::toSymbol() | |
2405 { | |
2406 return 0; | |
2407 } | |
2408 | |
2409 unsigned TypeFunction::totym() | |
2410 { | |
2411 return 0; | |
2412 } | |
2413 | |
2414 type * | |
2415 TypeFunction::toCtype() | |
2416 { | |
2417 return 0; | |
2418 } | |
2419 | |
2420 type * | |
2421 TypeSArray::toCtype() | |
2422 { | |
2423 return 0; | |
2424 } | |
2425 | |
2426 type *TypeSArray::toCParamtype() { return 0; } | |
2427 | |
2428 type * | |
2429 TypeDArray::toCtype() | |
2430 { | |
2431 return 0; | |
2432 } | |
2433 | |
2434 type * | |
2435 TypeAArray::toCtype() | |
2436 { | |
2437 return 0; | |
2438 } | |
2439 | |
2440 type * | |
2441 TypePointer::toCtype() | |
2442 { | |
2443 return 0; | |
2444 } | |
2445 | |
2446 type * | |
2447 TypeDelegate::toCtype() | |
2448 { | |
2449 return 0; | |
2450 } | |
2451 | |
2452 type * | |
2453 TypeClass::toCtype() | |
2454 { | |
2455 return 0; | |
2456 } | |
2457 | |
2458 void | |
2459 ClassDeclaration::toDebug() | |
2460 { | |
2461 } | |
2462 | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
11
diff
changeset
|
2463 ////////////////////////////////////////////////////////////////////////////// |
1 | 2464 |
2465 void | |
2466 EnumDeclaration::toDebug() | |
2467 { | |
2468 | |
2469 } | |
2470 | |
2471 int | |
2472 Dsymbol::cvMember(unsigned char*) | |
2473 { | |
2474 return 0; | |
2475 } | |
2476 int | |
2477 EnumDeclaration::cvMember(unsigned char*) | |
2478 { | |
2479 return 0; | |
2480 } | |
2481 int | |
2482 FuncDeclaration::cvMember(unsigned char*) | |
2483 { | |
2484 return 0; | |
2485 } | |
2486 int | |
2487 VarDeclaration::cvMember(unsigned char*) | |
2488 { | |
2489 return 0; | |
2490 } | |
2491 int | |
2492 TypedefDeclaration::cvMember(unsigned char*) | |
2493 { | |
2494 return 0; | |
2495 } | |
2496 | |
2497 void obj_includelib(char*){} | |
2498 | |
2499 AsmStatement::AsmStatement(Loc loc, Token *tokens) : | |
2500 Statement(loc) | |
2501 { | |
2502 } | |
2503 Statement *AsmStatement::syntaxCopy() { | |
2504 return 0; | |
2505 } | |
2506 | |
2507 Statement *AsmStatement::semantic(Scope *sc) | |
2508 { | |
2509 return Statement::semantic(sc); | |
2510 } | |
2511 | |
2512 | |
2513 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2514 { | |
2515 Statement::toCBuffer(buf, hgs); | |
2516 } | |
2517 | |
2518 int AsmStatement::comeFrom() | |
2519 { | |
2520 return FALSE; | |
2521 } | |
2522 | |
2523 void | |
2524 backend_init() | |
2525 { | |
2526 //LLVM_D_InitRuntime(); | |
2527 // lazily loaded | |
2528 } | |
2529 | |
2530 void | |
2531 backend_term() | |
2532 { | |
2533 LLVM_D_FreeRuntime(); | |
2534 } |