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