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