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