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