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