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