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