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