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