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