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