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