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