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