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