Mercurial > projects > ldc
annotate gen/toir.c @ 44:ea65e12b0dd0 trunk
[svn r48] fixed some storage problems
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 16:05:06 +0200 |
parents | 0b9b286b67b6 |
children | 6d60e6049c4e |
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 } | |
1517 else | |
1518 new llvm::StoreInst(val, arrptr, p->scopebb()); | |
1 | 1519 } |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1520 delete ve; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1521 } |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1522 else { |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1523 assert(0); |
1 | 1524 } |
1525 } | |
1526 | |
1527 e->inplace = true; | |
1528 | |
1529 return e; | |
1530 } | |
1531 | |
1532 ////////////////////////////////////////////////////////////////////////////////////////// | |
1533 | |
40 | 1534 llvm::Constant* StructLiteralExp::toConstElem(IRState* p) |
1535 { | |
1536 Logger::print("StructLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | |
1537 LOG_SCOPE; | |
1538 | |
1539 unsigned n = elements->dim; | |
1540 std::vector<llvm::Constant*> vals(n, NULL); | |
1541 | |
1542 for (unsigned i=0; i<n; ++i) | |
1543 { | |
1544 Expression* vx = (Expression*)elements->data[i]; | |
1545 vals[i] = vx->toConstElem(p); | |
1546 } | |
1547 | |
1548 assert(LLVM_DtoDType(type)->ty == Tstruct); | |
1549 const llvm::Type* t = LLVM_DtoType(type); | |
1550 const llvm::StructType* st = llvm::cast<llvm::StructType>(t); | |
1551 return llvm::ConstantStruct::get(st,vals); | |
1552 } | |
1553 | |
1554 ////////////////////////////////////////////////////////////////////////////////////////// | |
1555 | |
1 | 1556 elem* IndexExp::toElem(IRState* p) |
1557 { | |
1558 Logger::print("IndexExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1559 LOG_SCOPE; | |
1560 | |
1561 elem* e = new elem; | |
1562 | |
1563 elem* l = e1->toElem(p); | |
1564 | |
40 | 1565 Type* e1type = LLVM_DtoDType(e1->type); |
1566 | |
1 | 1567 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine. |
1568 elem* r = e2->toElem(p); | |
1569 p->arrays.pop_back(); | |
1570 | |
1571 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1572 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1573 | |
1574 llvm::Value* arrptr = 0; | |
40 | 1575 if (e1type->ty == Tpointer) { |
1 | 1576 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
1577 } | |
40 | 1578 else if (e1type->ty == Tsarray) { |
1579 arrptr = LLVM_DtoGEP(l->getValue(), zero, r->getValue(),"tmp",p->scopebb()); | |
1 | 1580 } |
40 | 1581 else if (e1type->ty == Tarray) { |
6 | 1582 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); |
1 | 1583 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); |
1584 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); | |
1585 } | |
1586 assert(arrptr); | |
1587 | |
1588 e->mem = arrptr; | |
1589 e->type = elem::VAR; | |
1590 | |
1591 delete l; | |
1592 delete r; | |
1593 | |
1594 return e; | |
1595 } | |
1596 | |
1597 ////////////////////////////////////////////////////////////////////////////////////////// | |
1598 | |
1599 elem* SliceExp::toElem(IRState* p) | |
1600 { | |
1601 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1602 LOG_SCOPE; | |
1603 | |
1604 elem* v = e1->toElem(p); | |
40 | 1605 Type* e1type = LLVM_DtoDType(e1->type); |
1 | 1606 |
1607 elem* e = new elem; | |
1608 assert(v->mem); | |
1609 e->type = elem::SLICE; | |
1610 | |
1611 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1612 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1613 | |
1614 // partial slice | |
1615 if (lwr) | |
1616 { | |
1617 assert(upr); | |
1618 p->arrays.push_back(v->mem); | |
1619 elem* lo = lwr->toElem(p); | |
1620 | |
1621 bool lwr_is_zero = false; | |
1622 if (lo->type == elem::CONST) | |
1623 { | |
1624 assert(lo->val); | |
1625 assert(llvm::isa<llvm::ConstantInt>(lo->val)); | |
1626 | |
40 | 1627 if (e1type->ty == Tpointer) { |
1 | 1628 e->mem = v->getValue(); |
1629 } | |
40 | 1630 else if (e1type->ty == Tarray) { |
6 | 1631 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1 | 1632 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1633 } | |
40 | 1634 else if (e1type->ty == Tsarray) { |
1635 e->mem = LLVM_DtoGEP(v->mem,zero,zero,"tmp",p->scopebb()); | |
1636 } | |
1 | 1637 else |
1638 assert(e->mem); | |
1639 | |
1640 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val); | |
1641 if (!(lwr_is_zero = c->isZero())) { | |
1642 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb()); | |
1643 } | |
1644 } | |
1645 else | |
1646 { | |
40 | 1647 if (e1type->ty == Tarray) { |
1648 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); | |
1649 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | |
1650 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); | |
1651 } | |
1652 else if (e1type->ty == Tsarray) { | |
1653 e->mem = LLVM_DtoGEP(v->mem,zero,lo->getValue(),"tmp",p->scopebb()); | |
1654 } | |
1655 else | |
1656 assert(0); | |
1 | 1657 } |
1658 | |
1659 elem* up = upr->toElem(p); | |
1660 p->arrays.pop_back(); | |
1661 | |
1662 if (up->type == elem::CONST) | |
1663 { | |
1664 assert(up->val); | |
1665 assert(llvm::isa<llvm::ConstantInt>(up->val)); | |
1666 if (lwr_is_zero) { | |
1667 e->arg = up->val; | |
1668 } | |
1669 else { | |
1670 if (lo->type == elem::CONST) { | |
1671 llvm::Constant* clo = llvm::cast<llvm::Constant>(lo->val); | |
1672 llvm::Constant* cup = llvm::cast<llvm::Constant>(up->val); | |
1673 e->arg = llvm::ConstantExpr::getSub(cup, clo); | |
1674 } | |
1675 else { | |
1676 e->arg = llvm::BinaryOperator::createSub(up->val, lo->getValue(), "tmp", p->scopebb()); | |
1677 } | |
1678 } | |
1679 } | |
1680 else | |
1681 { | |
1682 if (lwr_is_zero) { | |
1683 e->arg = up->getValue(); | |
1684 } | |
1685 else { | |
1686 e->arg = llvm::BinaryOperator::createSub(up->getValue(), lo->getValue(), "tmp", p->scopebb()); | |
1687 } | |
1688 } | |
1689 | |
1690 delete lo; | |
1691 delete up; | |
1692 } | |
1693 // full slice | |
1694 else | |
1695 { | |
1696 e->mem = v->mem; | |
1697 } | |
1698 | |
1699 delete v; | |
1700 | |
1701 return e; | |
1702 } | |
1703 | |
1704 ////////////////////////////////////////////////////////////////////////////////////////// | |
1705 | |
1706 elem* CmpExp::toElem(IRState* p) | |
1707 { | |
1708 Logger::print("CmpExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1709 LOG_SCOPE; | |
1710 | |
1711 elem* e = new elem; | |
1712 | |
1713 elem* l = e1->toElem(p); | |
1714 elem* r = e2->toElem(p); | |
1715 | |
40 | 1716 Type* t = LLVM_DtoDType(e1->type); |
1717 Type* e2t = LLVM_DtoDType(e2->type); | |
1718 assert(t == e2t); | |
1 | 1719 |
1720 if (t->isintegral()) | |
1721 { | |
1722 llvm::ICmpInst::Predicate cmpop; | |
40 | 1723 bool skip = false; |
1 | 1724 switch(op) |
1725 { | |
1726 case TOKlt: | |
40 | 1727 case TOKul: |
1 | 1728 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT; |
1729 break; | |
1730 case TOKle: | |
40 | 1731 case TOKule: |
1 | 1732 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE; |
1733 break; | |
1734 case TOKgt: | |
40 | 1735 case TOKug: |
1 | 1736 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT; |
1737 break; | |
1738 case TOKge: | |
40 | 1739 case TOKuge: |
1 | 1740 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE; |
1741 break; | |
40 | 1742 case TOKue: |
1743 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1744 break; | |
1745 case TOKlg: | |
1746 cmpop = llvm::ICmpInst::ICMP_NE; | |
1747 break; | |
1748 case TOKleg: | |
1749 skip = true; | |
1750 e->val = llvm::ConstantInt::getTrue(); | |
1751 break; | |
1752 case TOKunord: | |
1753 skip = true; | |
1754 e->val = llvm::ConstantInt::getFalse(); | |
1755 break; | |
1756 | |
1 | 1757 default: |
1758 assert(0); | |
1759 } | |
40 | 1760 if (!skip) |
1761 { | |
1762 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1763 } | |
1 | 1764 } |
1765 else if (t->isfloating()) | |
1766 { | |
1767 llvm::FCmpInst::Predicate cmpop; | |
1768 switch(op) | |
1769 { | |
1770 case TOKlt: | |
1771 cmpop = llvm::FCmpInst::FCMP_OLT;break; | |
1772 case TOKle: | |
1773 cmpop = llvm::FCmpInst::FCMP_OLE;break; | |
1774 case TOKgt: | |
1775 cmpop = llvm::FCmpInst::FCMP_OGT;break; | |
1776 case TOKge: | |
1777 cmpop = llvm::FCmpInst::FCMP_OGE;break; | |
1778 case TOKunord: | |
1779 cmpop = llvm::FCmpInst::FCMP_UNO;break; | |
1780 case TOKule: | |
1781 cmpop = llvm::FCmpInst::FCMP_ULE;break; | |
1782 case TOKul: | |
1783 cmpop = llvm::FCmpInst::FCMP_ULT;break; | |
1784 case TOKuge: | |
1785 cmpop = llvm::FCmpInst::FCMP_UGE;break; | |
1786 case TOKug: | |
1787 cmpop = llvm::FCmpInst::FCMP_UGT;break; | |
1788 case TOKue: | |
1789 cmpop = llvm::FCmpInst::FCMP_UEQ;break; | |
1790 case TOKlg: | |
1791 cmpop = llvm::FCmpInst::FCMP_ONE;break; | |
1792 case TOKleg: | |
1793 cmpop = llvm::FCmpInst::FCMP_ORD;break; | |
1794 | |
1795 default: | |
1796 assert(0); | |
1797 } | |
1798 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1799 } | |
1800 else | |
1801 { | |
1802 assert(0 && "Unsupported CmpExp type"); | |
1803 } | |
1804 | |
1805 delete l; | |
1806 delete r; | |
1807 | |
1808 e->type = elem::VAL; | |
1809 | |
1810 return e; | |
1811 } | |
1812 | |
1813 ////////////////////////////////////////////////////////////////////////////////////////// | |
1814 | |
1815 elem* EqualExp::toElem(IRState* p) | |
1816 { | |
1817 Logger::print("EqualExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1818 LOG_SCOPE; | |
1819 | |
1820 elem* e = new elem; | |
1821 | |
1822 elem* l = e1->toElem(p); | |
1823 elem* r = e2->toElem(p); | |
1824 | |
40 | 1825 Type* t = LLVM_DtoDType(e1->type); |
1826 Type* e2t = LLVM_DtoDType(e2->type); | |
1827 assert(t == e2t); | |
1 | 1828 |
1829 if (t->isintegral() || t->ty == Tpointer) | |
1830 { | |
1831 llvm::ICmpInst::Predicate cmpop; | |
1832 switch(op) | |
1833 { | |
1834 case TOKequal: | |
1835 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1836 break; | |
1837 case TOKnotequal: | |
1838 cmpop = llvm::ICmpInst::ICMP_NE; | |
1839 break; | |
1840 default: | |
1841 assert(0); | |
1842 } | |
1843 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1844 } | |
1845 else if (t->isfloating()) | |
1846 { | |
1847 llvm::FCmpInst::Predicate cmpop; | |
1848 switch(op) | |
1849 { | |
1850 case TOKequal: | |
1851 cmpop = llvm::FCmpInst::FCMP_OEQ; | |
1852 break; | |
1853 case TOKnotequal: | |
1854 cmpop = llvm::FCmpInst::FCMP_UNE; | |
1855 break; | |
1856 default: | |
1857 assert(0); | |
1858 } | |
1859 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1860 } | |
40 | 1861 else if (t->ty == Tsarray) |
1862 { | |
1863 e->val = LLVM_DtoStaticArrayCompare(op,l->mem,r->mem); | |
1864 } | |
1 | 1865 else if (t->ty == Tarray) |
1866 { | |
40 | 1867 assert(0 && "array comparison invokes the typeinfo runtime"); |
1 | 1868 } |
1869 else | |
1870 { | |
1871 assert(0 && "Unsupported EqualExp type"); | |
1872 } | |
1873 | |
1874 delete l; | |
1875 delete r; | |
1876 | |
1877 e->type = elem::VAL; | |
1878 | |
1879 return e; | |
1880 } | |
1881 | |
1882 ////////////////////////////////////////////////////////////////////////////////////////// | |
1883 | |
1884 elem* PostExp::toElem(IRState* p) | |
1885 { | |
1886 Logger::print("PostExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1887 LOG_SCOPE; | |
1888 | |
1889 elem* l = e1->toElem(p); | |
1890 elem* r = e2->toElem(p); | |
1891 | |
1892 elem* e = new elem; | |
1893 e->mem = l->mem; | |
1894 e->val = l->getValue(); | |
1895 e->type = elem::VAL; | |
1896 | |
1897 llvm::Value* val = e->val; | |
1898 llvm::Value* post = 0; | |
1899 | |
40 | 1900 Type* e1type = LLVM_DtoDType(e1->type); |
1901 Type* e2type = LLVM_DtoDType(e2->type); | |
1902 | |
1903 if (e1type->isintegral()) | |
1 | 1904 { |
40 | 1905 assert(e2type->isintegral()); |
1906 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); | |
1 | 1907 if (op == TOKplusplus) { |
1908 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
1909 } | |
1910 else if (op == TOKminusminus) { | |
1911 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
1912 } | |
1913 } | |
40 | 1914 else if (e1type->ty == Tpointer) |
1 | 1915 { |
40 | 1916 assert(e2type->isintegral()); |
1 | 1917 llvm::Constant* minusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)-1,true); |
1918 llvm::Constant* plusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)1,false); | |
1919 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; | |
1920 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb()); | |
1921 } | |
40 | 1922 else if (e1type->isfloating()) |
1 | 1923 { |
40 | 1924 assert(e2type->isfloating()); |
1 | 1925 llvm::Value* one = llvm::ConstantFP::get(val->getType(), 1.0f); |
1926 if (op == TOKplusplus) { | |
1927 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
1928 } | |
1929 else if (op == TOKminusminus) { | |
1930 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
1931 } | |
1932 } | |
1933 else | |
1934 assert(post); | |
1935 | |
1936 //llvm::Value* tostore = l->storeVal ? l->storeVal : l->val; | |
1937 new llvm::StoreInst(post,l->mem,p->scopebb()); | |
1938 | |
1939 delete l; | |
1940 delete r; | |
1941 | |
1942 return e; | |
1943 } | |
1944 | |
1945 ////////////////////////////////////////////////////////////////////////////////////////// | |
1946 | |
1947 elem* NewExp::toElem(IRState* p) | |
1948 { | |
1949 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1950 LOG_SCOPE; | |
1951 | |
1952 assert(!thisexp); | |
1953 assert(!newargs); | |
1954 assert(newtype); | |
1955 assert(!allocator); | |
1956 | |
1957 elem* e = new elem; | |
1958 | |
40 | 1959 Type* ntype = LLVM_DtoDType(newtype); |
1960 | |
1961 const llvm::Type* t = LLVM_DtoType(ntype); | |
1 | 1962 |
1963 if (onstack) { | |
40 | 1964 assert(ntype->ty == Tclass); |
1 | 1965 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint()); |
1966 } | |
1967 else { | |
40 | 1968 if (ntype->ty == Tclass) { |
1 | 1969 e->mem = new llvm::MallocInst(t->getContainedType(0),"tmp",p->scopebb()); |
1970 } | |
40 | 1971 else if (ntype->ty == Tarray) { |
1 | 1972 assert(arguments); |
1973 if (arguments->dim == 1) { | |
1974 elem* sz = ((Expression*)arguments->data[0])->toElem(p); | |
1975 llvm::Value* dimval = sz->getValue(); | |
40 | 1976 LLVM_DtoNewDynArray(p->toplval(), dimval, ntype->next); |
1 | 1977 delete sz; |
1978 } | |
1979 else { | |
1980 assert(0); | |
1981 } | |
1982 } | |
1983 else { | |
1984 e->mem = new llvm::MallocInst(t,"tmp",p->scopebb()); | |
1985 } | |
1986 } | |
1987 | |
40 | 1988 if (ntype->ty == Tclass) { |
1 | 1989 // first apply the static initializer |
1990 assert(e->mem); | |
40 | 1991 LLVM_DtoInitClass((TypeClass*)ntype, e->mem); |
1 | 1992 |
1993 // then call constructor | |
1994 if (arguments) { | |
40 | 1995 assert(member); |
1996 assert(member->llvmValue); | |
1997 llvm::Function* fn = llvm::cast<llvm::Function>(member->llvmValue); | |
1998 TypeFunction* tf = (TypeFunction*)LLVM_DtoDType(member->type); | |
1999 | |
1 | 2000 std::vector<llvm::Value*> ctorargs; |
2001 ctorargs.push_back(e->mem); | |
2002 for (size_t i=0; i<arguments->dim; ++i) | |
2003 { | |
2004 Expression* ex = (Expression*)arguments->data[i]; | |
40 | 2005 Argument* fnarg = Argument::getNth(tf->parameters, i); |
2006 llvm::Value* a = LLVM_DtoArgument(fn->getFunctionType()->getParamType(i+1), fnarg, ex); | |
2007 ctorargs.push_back(a); | |
1 | 2008 } |
40 | 2009 e->mem = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb()); |
1 | 2010 } |
2011 } | |
40 | 2012 else if (ntype->ty == Tstruct) { |
2013 TypeStruct* ts = (TypeStruct*)ntype; | |
1 | 2014 if (ts->isZeroInit()) { |
2015 LLVM_DtoStructZeroInit(ts,e->mem); | |
2016 } | |
2017 else { | |
2018 LLVM_DtoStructCopy(ts,e->mem,ts->llvmInit); | |
2019 } | |
2020 } | |
2021 | |
2022 e->inplace = true; | |
2023 e->type = elem::VAR; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
2024 |
1 | 2025 return e; |
2026 } | |
2027 | |
2028 ////////////////////////////////////////////////////////////////////////////////////////// | |
2029 | |
2030 elem* DeleteExp::toElem(IRState* p) | |
2031 { | |
2032 Logger::print("DeleteExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2033 LOG_SCOPE; | |
2034 | |
2035 //assert(e1->type->ty != Tclass); | |
2036 | |
2037 elem* v = e1->toElem(p); | |
2038 llvm::Value* val = v->getValue(); | |
2039 llvm::Value* ldval = 0; | |
2040 | |
2041 const llvm::Type* t = val->getType(); | |
2042 llvm::Constant* z = llvm::Constant::getNullValue(t); | |
2043 | |
40 | 2044 Type* e1type = LLVM_DtoDType(e1->type); |
2045 | |
2046 if (e1type->ty == Tpointer) { | |
1 | 2047 ldval = v->getValue(); |
2048 new llvm::FreeInst(ldval, p->scopebb()); | |
2049 | |
2050 Logger::cout() << *z << '\n'; | |
2051 Logger::cout() << *val << '\n'; | |
2052 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
2053 } | |
40 | 2054 else if (e1type->ty == Tclass) { |
2055 TypeClass* tc = (TypeClass*)e1type; | |
1 | 2056 LLVM_DtoCallClassDtors(tc, val); |
2057 | |
2058 if (v->vardecl && !v->vardecl->onstack) { | |
2059 new llvm::FreeInst(val, p->scopebb()); | |
2060 } | |
2061 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
2062 } | |
40 | 2063 else if (e1type->ty == Tarray) { |
1 | 2064 // must be on the heap (correct?) |
2065 ldval = v->getValue(); | |
2066 | |
2067 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2068 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
2069 | |
6 | 2070 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb()); |
1 | 2071 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); |
2072 new llvm::FreeInst(ptr, p->scopebb()); | |
2073 LLVM_DtoNullArray(val); | |
2074 } | |
2075 else { | |
2076 assert(0); | |
2077 } | |
2078 | |
2079 delete v; | |
2080 | |
2081 // this expression produces no useful data | |
2082 return 0; | |
2083 } | |
2084 | |
2085 ////////////////////////////////////////////////////////////////////////////////////////// | |
2086 | |
2087 elem* ArrayLengthExp::toElem(IRState* p) | |
2088 { | |
2089 Logger::print("ArrayLengthExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2090 LOG_SCOPE; | |
2091 | |
2092 elem* e = new elem; | |
2093 elem* u = e1->toElem(p); | |
2094 | |
34 | 2095 if (p->inLvalue) |
2096 { | |
2097 e->mem = u->mem; | |
2098 e->type = elem::ARRAYLEN; | |
2099 } | |
2100 else | |
2101 { | |
2102 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2103 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); | |
2104 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | |
2105 e->type = elem::VAL; | |
2106 } | |
1 | 2107 delete u; |
2108 | |
2109 return e; | |
2110 } | |
2111 | |
2112 ////////////////////////////////////////////////////////////////////////////////////////// | |
2113 | |
2114 elem* AssertExp::toElem(IRState* p) | |
2115 { | |
2116 Logger::print("AssertExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2117 LOG_SCOPE; | |
2118 | |
2119 elem* u = e1->toElem(p); | |
34 | 2120 elem* m = msg ? msg->toElem(p) : NULL; |
1 | 2121 |
34 | 2122 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); |
2123 LLVM_DtoAssert(u->getValue(), loca, m ? m->val : NULL); | |
2124 | |
1 | 2125 delete m; |
2126 delete u; | |
2127 | |
34 | 2128 return new elem; |
1 | 2129 } |
2130 | |
2131 ////////////////////////////////////////////////////////////////////////////////////////// | |
2132 | |
2133 elem* NotExp::toElem(IRState* p) | |
2134 { | |
2135 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2136 LOG_SCOPE; | |
2137 | |
2138 elem* e = new elem; | |
2139 elem* u = e1->toElem(p); | |
2140 | |
2141 llvm::Value* b = LLVM_DtoBoolean(u->getValue()); | |
2142 | |
2143 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); | |
40 | 2144 e->val = p->ir->CreateICmpEQ(b,zero); |
2145 //e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb()); | |
1 | 2146 e->type = elem::VAL; |
2147 | |
2148 delete u; | |
2149 | |
2150 return e; | |
2151 } | |
2152 | |
2153 ////////////////////////////////////////////////////////////////////////////////////////// | |
2154 | |
2155 elem* AndAndExp::toElem(IRState* p) | |
2156 { | |
2157 Logger::print("AndAndExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2158 LOG_SCOPE; | |
2159 | |
2160 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2161 llvm::Value* resval = 0; | |
2162 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2163 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"andandtmp",p->topallocapoint()); | |
2164 | |
2165 elem* e = new elem; | |
2166 elem* u = e1->toElem(p); | |
2167 | |
2168 llvm::BasicBlock* oldend = p->scopeend(); | |
2169 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend); | |
2170 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend); | |
2171 | |
2172 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
2173 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
2174 new llvm::BranchInst(andand,andandend,ubool,p->scopebb()); | |
2175 | |
2176 p->scope() = IRScope(andand, andandend); | |
2177 elem* v = e2->toElem(p); | |
2178 | |
2179 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
2180 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); | |
2181 new llvm::StoreInst(uandvbool,resval,p->scopebb()); | |
2182 new llvm::BranchInst(andandend,p->scopebb()); | |
2183 | |
2184 delete u; | |
2185 delete v; | |
2186 | |
2187 p->scope() = IRScope(andandend, oldend); | |
2188 | |
2189 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2190 e->type = elem::VAL; | |
2191 | |
2192 return e; | |
2193 } | |
2194 | |
2195 ////////////////////////////////////////////////////////////////////////////////////////// | |
2196 | |
2197 elem* OrOrExp::toElem(IRState* p) | |
2198 { | |
2199 Logger::print("OrOrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2200 LOG_SCOPE; | |
2201 | |
2202 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2203 llvm::Value* resval = 0; | |
2204 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2205 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"orortmp",p->topallocapoint()); | |
2206 | |
2207 elem* e = new elem; | |
2208 elem* u = e1->toElem(p); | |
2209 | |
2210 llvm::BasicBlock* oldend = p->scopeend(); | |
2211 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend); | |
2212 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend); | |
2213 | |
2214 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
2215 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
2216 new llvm::BranchInst(ororend,oror,ubool,p->scopebb()); | |
2217 | |
2218 p->scope() = IRScope(oror, ororend); | |
2219 elem* v = e2->toElem(p); | |
2220 | |
2221 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
2222 new llvm::StoreInst(vbool,resval,p->scopebb()); | |
2223 new llvm::BranchInst(ororend,p->scopebb()); | |
2224 | |
2225 delete u; | |
2226 delete v; | |
2227 | |
2228 p->scope() = IRScope(ororend, oldend); | |
2229 | |
2230 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2231 e->type = elem::VAL; | |
2232 | |
2233 return e; | |
2234 } | |
2235 | |
2236 ////////////////////////////////////////////////////////////////////////////////////////// | |
2237 | |
2238 #define BinBitExp(X,Y) \ | |
2239 elem* X##Exp::toElem(IRState* p) \ | |
2240 { \ | |
2241 Logger::print("%sExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2242 LOG_SCOPE; \ | |
2243 elem* e = new elem; \ | |
2244 elem* u = e1->toElem(p); \ | |
2245 elem* v = e2->toElem(p); \ | |
2246 e->val = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \ | |
2247 e->type = elem::VAL; \ | |
2248 delete u; \ | |
2249 delete v; \ | |
2250 return e; \ | |
2251 } \ | |
2252 \ | |
2253 elem* X##AssignExp::toElem(IRState* p) \ | |
2254 { \ | |
2255 Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2256 LOG_SCOPE; \ | |
2257 elem* u = e1->toElem(p); \ | |
2258 elem* v = e2->toElem(p); \ | |
42 | 2259 llvm::Value* uval = u->getValue(); \ |
2260 assert(uval); \ | |
2261 llvm::Value* vval = v->getValue(); \ | |
2262 assert(vval); \ | |
2263 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
|
2264 if (u->mem == 0) \ |
253a5fc4033a
[svn r33] * Added support for assignment to function arguments
lindquist
parents:
28
diff
changeset
|
2265 LLVM_DtoGiveArgumentStorage(u); \ |
42 | 2266 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \ |
1 | 2267 new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \ |
2268 delete u; \ | |
2269 delete v; \ | |
2270 elem* e = new elem; \ | |
2271 e->mem = u->mem; \ | |
2272 e->type = elem::VAR; \ | |
2273 return e; \ | |
2274 } | |
2275 | |
2276 BinBitExp(And,And); | |
2277 BinBitExp(Or,Or); | |
2278 BinBitExp(Xor,Xor); | |
2279 BinBitExp(Shl,Shl); | |
2280 BinBitExp(Shr,AShr); | |
2281 BinBitExp(Ushr,LShr); | |
2282 | |
2283 ////////////////////////////////////////////////////////////////////////////////////////// | |
2284 | |
2285 elem* HaltExp::toElem(IRState* p) | |
2286 { | |
2287 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2288 LOG_SCOPE; | |
2289 | |
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
|
2290 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
|
2291 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
|
2292 |
40 | 2293 new llvm::UnreachableInst(p->scopebb()); |
1 | 2294 return 0; |
2295 } | |
2296 | |
2297 ////////////////////////////////////////////////////////////////////////////////////////// | |
2298 | |
2299 elem* DelegateExp::toElem(IRState* p) | |
2300 { | |
2301 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2302 LOG_SCOPE; | |
2303 | |
2304 elem* e = new elem; | |
2305 elem* u = e1->toElem(p); | |
2306 | |
2307 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2308 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
2309 | |
2310 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
2311 | |
2312 llvm::Value* lval = p->toplval(); | |
2313 | |
6 | 2314 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb()); |
1 | 2315 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); |
2316 new llvm::StoreInst(castcontext, context, p->scopebb()); | |
2317 | |
6 | 2318 llvm::Value* fptr = LLVM_DtoGEP(lval,zero,one,"tmp",p->scopebb()); |
1 | 2319 |
2320 assert(func->llvmValue); | |
2321 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | |
2322 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | |
2323 | |
2324 e->inplace = true; | |
2325 | |
2326 delete u; | |
2327 return e; | |
2328 } | |
2329 | |
2330 ////////////////////////////////////////////////////////////////////////////////////////// | |
2331 | |
2332 elem* IdentityExp::toElem(IRState* p) | |
2333 { | |
2334 Logger::print("IdentityExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2335 LOG_SCOPE; | |
2336 | |
2337 elem* u = e1->toElem(p); | |
2338 elem* v = e2->toElem(p); | |
2339 | |
2340 elem* e = new elem; | |
2341 | |
2342 llvm::Value* l = u->getValue(); | |
2343 llvm::Value* r = 0; | |
2344 if (v->type == elem::NUL) | |
2345 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); | |
2346 else | |
2347 r = v->getValue(); | |
2348 | |
2349 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; | |
2350 e->val = new llvm::ICmpInst(pred, l, r, "tmp", p->scopebb()); | |
2351 e->type = elem::VAL; | |
2352 | |
2353 delete u; | |
2354 delete v; | |
2355 | |
2356 return e; | |
2357 } | |
2358 | |
2359 ////////////////////////////////////////////////////////////////////////////////////////// | |
2360 | |
2361 elem* CommaExp::toElem(IRState* p) | |
2362 { | |
2363 Logger::print("CommaExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2364 LOG_SCOPE; | |
2365 | |
2366 elem* u = e1->toElem(p); | |
2367 elem* v = e2->toElem(p); | |
2368 delete u; | |
2369 return v; | |
2370 } | |
2371 | |
2372 ////////////////////////////////////////////////////////////////////////////////////////// | |
2373 | |
2374 elem* CondExp::toElem(IRState* p) | |
2375 { | |
2376 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2377 LOG_SCOPE; | |
2378 | |
2379 const llvm::Type* resty = LLVM_DtoType(type); | |
2380 | |
2381 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2382 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2383 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); | |
2384 | |
2385 llvm::BasicBlock* oldend = p->scopeend(); | |
2386 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend); | |
2387 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend); | |
2388 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend); | |
2389 | |
2390 elem* c = econd->toElem(p); | |
2391 llvm::Value* cond_val = LLVM_DtoBoolean(c->getValue()); | |
2392 delete c; | |
2393 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb()); | |
2394 | |
2395 p->scope() = IRScope(condtrue, condfalse); | |
2396 elem* u = e1->toElem(p); | |
2397 new llvm::StoreInst(u->getValue(),resval,p->scopebb()); | |
2398 new llvm::BranchInst(condend,p->scopebb()); | |
2399 delete u; | |
2400 | |
2401 p->scope() = IRScope(condfalse, condend); | |
2402 elem* v = e2->toElem(p); | |
2403 new llvm::StoreInst(v->getValue(),resval,p->scopebb()); | |
2404 new llvm::BranchInst(condend,p->scopebb()); | |
2405 delete v; | |
2406 | |
2407 p->scope() = IRScope(condend, oldend); | |
2408 | |
2409 elem* e = new elem; | |
2410 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2411 e->type = elem::VAL; | |
2412 return e; | |
2413 } | |
2414 | |
2415 ////////////////////////////////////////////////////////////////////////////////////////// | |
2416 | |
2417 elem* ComExp::toElem(IRState* p) | |
2418 { | |
2419 Logger::print("ComExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2420 LOG_SCOPE; | |
2421 | |
2422 elem* e = new elem; | |
2423 elem* u = e1->toElem(p); | |
2424 | |
2425 llvm::Value* value = u->getValue(); | |
2426 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); | |
2427 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); | |
2428 | |
2429 delete u; | |
2430 | |
2431 e->type = elem::VAL; | |
2432 | |
2433 return e; | |
2434 } | |
2435 | |
2436 ////////////////////////////////////////////////////////////////////////////////////////// | |
2437 | |
23 | 2438 elem* NegExp::toElem(IRState* p) |
2439 { | |
2440 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2441 LOG_SCOPE; | |
2442 elem* e = new elem; | |
2443 elem* l = e1->toElem(p); | |
2444 llvm::Value* val = l->getValue(); | |
2445 delete l; | |
2446 | |
40 | 2447 Type* t = LLVM_DtoDType(type); |
2448 | |
23 | 2449 llvm::Value* zero = 0; |
40 | 2450 if (t->isintegral()) |
23 | 2451 zero = llvm::ConstantInt::get(val->getType(), 0, true); |
40 | 2452 else if (t->isfloating()) { |
2453 if (t->ty == Tfloat32) | |
23 | 2454 zero = llvm::ConstantFP::get(val->getType(), float(0)); |
40 | 2455 else if (t->ty == Tfloat64 || t->ty == Tfloat80) |
23 | 2456 zero = llvm::ConstantFP::get(val->getType(), double(0)); |
2457 else | |
2458 assert(0); | |
2459 } | |
2460 else | |
2461 assert(0); | |
2462 | |
2463 e->val = llvm::BinaryOperator::createSub(zero,val,"tmp",p->scopebb()); | |
2464 e->type = elem::VAL; | |
2465 | |
2466 return e; | |
2467 } | |
2468 | |
2469 ////////////////////////////////////////////////////////////////////////////////////////// | |
2470 | |
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
|
2471 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
|
2472 { |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2473 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
|
2474 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
|
2475 |
40 | 2476 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
|
2477 |
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 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
|
2479 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
|
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 // 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
|
2482 |
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 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
|
2484 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
|
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 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
|
2487 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
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 |
40 | 2491 elem* CatAssignExp::toElem(IRState* p) |
2492 { | |
2493 Logger::print("CatAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2494 LOG_SCOPE; | |
2495 | |
2496 elem* l = e1->toElem(p); | |
2497 assert(l->mem); | |
2498 | |
2499 Type* e1type = LLVM_DtoDType(e1->type); | |
2500 Type* elemtype = LLVM_DtoDType(e1type->next); | |
2501 Type* e2type = LLVM_DtoDType(e2->type); | |
2502 | |
2503 if (e2type == elemtype) { | |
2504 LLVM_DtoCatArrayElement(l->mem,e2); | |
2505 } | |
2506 else | |
2507 assert(0 && "only one element at a time right now"); | |
2508 | |
2509 return 0; | |
2510 } | |
2511 | |
2512 ////////////////////////////////////////////////////////////////////////////////////////// | |
2513 | |
2514 elem* ArrayLiteralExp::toElem(IRState* p) | |
2515 { | |
2516 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2517 LOG_SCOPE; | |
2518 | |
2519 const llvm::Type* t = LLVM_DtoType(type); | |
2520 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | |
2521 | |
2522 llvm::Value* mem = 0; | |
44 | 2523 if (p->lvals.empty() || !p->toplval()) { |
40 | 2524 assert(LLVM_DtoDType(type)->ty == Tsarray); |
2525 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint()); | |
2526 } | |
2527 else { | |
2528 mem = p->toplval(); | |
2529 if (!llvm::isa<llvm::PointerType>(mem->getType()) || | |
2530 !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0))) | |
2531 { | |
2532 error("TODO array literals can currently only be used to initialise static arrays"); | |
2533 fatal(); | |
2534 } | |
2535 } | |
2536 | |
2537 for (unsigned i=0; i<elements->dim; ++i) | |
2538 { | |
2539 Expression* expr = (Expression*)elements->data[i]; | |
2540 llvm::Value* elemAddr = LLVM_DtoGEPi(mem,0,i,"tmp",p->scopebb()); | |
2541 elem* e = expr->toElem(p); | |
2542 new llvm::StoreInst(e->getValue(), elemAddr, p->scopebb()); | |
2543 } | |
2544 | |
2545 elem* e = new elem; | |
2546 e->mem = mem; | |
2547 e->type = elem::VAL; | |
2548 e->inplace = true; | |
2549 | |
2550 return e; | |
2551 } | |
2552 | |
2553 ////////////////////////////////////////////////////////////////////////////////////////// | |
2554 | |
2555 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) | |
2556 { | |
2557 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | |
2558 LOG_SCOPE; | |
2559 | |
2560 const llvm::Type* t = LLVM_DtoType(type); | |
2561 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | |
2562 assert(llvm::isa<llvm::ArrayType>(t)); | |
2563 const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t); | |
2564 | |
2565 assert(arrtype->getNumElements() == elements->dim); | |
2566 std::vector<llvm::Constant*> vals(elements->dim, NULL); | |
2567 for (unsigned i=0; i<elements->dim; ++i) | |
2568 { | |
2569 Expression* expr = (Expression*)elements->data[i]; | |
2570 vals[i] = expr->toConstElem(p); | |
2571 } | |
2572 | |
2573 return llvm::ConstantArray::get(arrtype, vals); | |
2574 } | |
2575 | |
2576 ////////////////////////////////////////////////////////////////////////////////////////// | |
2577 | |
1 | 2578 #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } |
2579 //STUB(IdentityExp); | |
2580 //STUB(CondExp); | |
2581 //STUB(EqualExp); | |
2582 STUB(InExp); | |
2583 //STUB(CmpExp); | |
2584 //STUB(AndAndExp); | |
2585 //STUB(OrOrExp); | |
2586 //STUB(AndExp); | |
2587 //STUB(AndAssignExp); | |
2588 //STUB(OrExp); | |
2589 //STUB(OrAssignExp); | |
2590 //STUB(XorExp); | |
2591 //STUB(XorAssignExp); | |
2592 //STUB(ShrExp); | |
2593 //STUB(ShrAssignExp); | |
2594 //STUB(ShlExp); | |
2595 //STUB(ShlAssignExp); | |
2596 //STUB(UshrExp); | |
2597 //STUB(UshrAssignExp); | |
2598 //STUB(DivExp); | |
2599 //STUB(DivAssignExp); | |
2600 //STUB(MulExp); | |
2601 //STUB(MulAssignExp); | |
2602 //STUB(ModExp); | |
2603 //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
|
2604 //STUB(CatExp); |
40 | 2605 //STUB(CatAssignExp); |
1 | 2606 //STUB(AddExp); |
2607 //STUB(AddAssignExp); | |
2608 STUB(Expression); | |
2609 //STUB(MinExp); | |
2610 //STUB(MinAssignExp); | |
2611 //STUB(PostExp); | |
2612 //STUB(NullExp); | |
2613 //STUB(ThisExp); | |
2614 //STUB(CallExp); | |
2615 STUB(DotTypeExp); | |
2616 STUB(TypeDotIdExp); | |
2617 //STUB(DotVarExp); | |
2618 //STUB(AssertExp); | |
2619 STUB(FuncExp); | |
2620 //STUB(DelegateExp); | |
2621 //STUB(VarExp); | |
2622 //STUB(DeclarationExp); | |
2623 //STUB(NewExp); | |
2624 //STUB(SymOffExp); | |
2625 STUB(ScopeExp); | |
2626 //STUB(AssignExp); | |
2627 | |
2628 STUB(TypeExp); | |
2629 //STUB(RealExp); | |
2630 STUB(ComplexExp); | |
2631 //STUB(StringExp); | |
2632 //STUB(IntegerExp); | |
2633 STUB(BoolExp); | |
2634 | |
2635 //STUB(NotExp); | |
2636 //STUB(ComExp); | |
23 | 2637 //STUB(NegExp); |
1 | 2638 //STUB(PtrExp); |
2639 //STUB(AddrExp); | |
2640 //STUB(SliceExp); | |
2641 //STUB(CastExp); | |
2642 //STUB(DeleteExp); | |
2643 //STUB(IndexExp); | |
2644 //STUB(CommaExp); | |
2645 //STUB(ArrayLengthExp); | |
2646 //STUB(HaltExp); | |
2647 STUB(RemoveExp); | |
40 | 2648 //STUB(ArrayLiteralExp); |
1 | 2649 STUB(AssocArrayLiteralExp); |
2650 //STUB(StructLiteralExp); | |
2651 | |
40 | 2652 #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; } |
2653 CONSTSTUB(Expression); | |
2654 //CONSTSTUB(IntegerExp); | |
2655 //CONSTSTUB(RealExp); | |
2656 //CONSTSTUB(NullExp); | |
2657 //CONSTSTUB(StringExp); | |
2658 //CONSTSTUB(VarExp); | |
2659 //CONSTSTUB(ArrayLiteralExp); | |
2660 CONSTSTUB(AssocArrayLiteralExp); | |
2661 //CONSTSTUB(StructLiteralExp); | |
2662 | |
1 | 2663 unsigned Type::totym() { return 0; } |
2664 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2665 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
|
2666 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2667 assert(0); |
1 | 2668 return 0; |
2669 } | |
2670 | |
2671 type * Type::toCParamtype() | |
2672 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2673 assert(0); |
1 | 2674 return 0; |
2675 } | |
2676 Symbol * Type::toSymbol() | |
2677 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2678 assert(0); |
1 | 2679 return 0; |
2680 } | |
2681 | |
2682 type * | |
2683 TypeTypedef::toCtype() | |
2684 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2685 assert(0); |
1 | 2686 return 0; |
2687 } | |
2688 | |
2689 type * | |
2690 TypeTypedef::toCParamtype() | |
2691 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2692 assert(0); |
1 | 2693 return 0; |
2694 } | |
2695 | |
2696 void | |
2697 TypedefDeclaration::toDebug() | |
2698 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2699 assert(0); |
1 | 2700 } |
2701 | |
2702 | |
2703 type * | |
2704 TypeEnum::toCtype() | |
2705 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2706 assert(0); |
1 | 2707 return 0; |
2708 } | |
2709 | |
2710 type * | |
2711 TypeStruct::toCtype() | |
2712 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2713 assert(0); |
1 | 2714 return 0; |
2715 } | |
2716 | |
2717 void | |
2718 StructDeclaration::toDebug() | |
2719 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2720 assert(0); |
1 | 2721 } |
2722 | |
2723 Symbol * TypeClass::toSymbol() | |
2724 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2725 assert(0); |
1 | 2726 return 0; |
2727 } | |
2728 | |
2729 unsigned TypeFunction::totym() | |
2730 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2731 assert(0); |
1 | 2732 return 0; |
2733 } | |
2734 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2735 type * TypeFunction::toCtype() |
1 | 2736 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2737 assert(0); |
1 | 2738 return 0; |
2739 } | |
2740 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2741 type * TypeSArray::toCtype() |
1 | 2742 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2743 assert(0); |
1 | 2744 return 0; |
2745 } | |
2746 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2747 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
|
2748 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2749 assert(0); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2750 return 0; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2751 } |
1 | 2752 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2753 type * TypeDArray::toCtype() |
1 | 2754 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2755 assert(0); |
1 | 2756 return 0; |
2757 } | |
2758 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2759 type * TypeAArray::toCtype() |
1 | 2760 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2761 assert(0); |
1 | 2762 return 0; |
2763 } | |
2764 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2765 type * TypePointer::toCtype() |
1 | 2766 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2767 assert(0); |
1 | 2768 return 0; |
2769 } | |
2770 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2771 type * TypeDelegate::toCtype() |
1 | 2772 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2773 assert(0); |
1 | 2774 return 0; |
2775 } | |
2776 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2777 type * TypeClass::toCtype() |
1 | 2778 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2779 assert(0); |
1 | 2780 return 0; |
2781 } | |
2782 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2783 void ClassDeclaration::toDebug() |
1 | 2784 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2785 assert(0); |
1 | 2786 } |
2787 | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
11
diff
changeset
|
2788 ////////////////////////////////////////////////////////////////////////////// |
1 | 2789 |
2790 void | |
2791 EnumDeclaration::toDebug() | |
2792 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2793 assert(0); |
1 | 2794 } |
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 int Dsymbol::cvMember(unsigned char*) |
1 | 2797 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2798 assert(0); |
1 | 2799 return 0; |
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 int EnumDeclaration::cvMember(unsigned char*) |
1 | 2802 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2803 assert(0); |
1 | 2804 return 0; |
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 int FuncDeclaration::cvMember(unsigned char*) |
1 | 2807 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2808 assert(0); |
1 | 2809 return 0; |
2810 } | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2811 int VarDeclaration::cvMember(unsigned char*) |
1 | 2812 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2813 assert(0); |
1 | 2814 return 0; |
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 int TypedefDeclaration::cvMember(unsigned char*) |
1 | 2817 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2818 assert(0); |
1 | 2819 return 0; |
2820 } | |
2821 | |
2822 void obj_includelib(char*){} | |
2823 | |
2824 AsmStatement::AsmStatement(Loc loc, Token *tokens) : | |
2825 Statement(loc) | |
2826 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2827 assert(0); |
1 | 2828 } |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2829 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
|
2830 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2831 assert(0); |
1 | 2832 return 0; |
2833 } | |
2834 | |
2835 Statement *AsmStatement::semantic(Scope *sc) | |
2836 { | |
2837 return Statement::semantic(sc); | |
2838 } | |
2839 | |
2840 | |
2841 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2842 { | |
2843 Statement::toCBuffer(buf, hgs); | |
2844 } | |
2845 | |
2846 int AsmStatement::comeFrom() | |
2847 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2848 assert(0); |
1 | 2849 return FALSE; |
2850 } | |
2851 | |
2852 void | |
2853 backend_init() | |
2854 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2855 // now lazily loaded |
1 | 2856 //LLVM_D_InitRuntime(); |
2857 } | |
2858 | |
2859 void | |
2860 backend_term() | |
2861 { | |
2862 LLVM_D_FreeRuntime(); | |
2863 } |