Mercurial > projects > ldc
annotate gen/toir.c @ 66:0c5f410d973c trunk
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
author | lindquist |
---|---|
date | Sun, 28 Oct 2007 02:03:42 +0200 |
parents | b688ad419f8c |
children | f918f3e2e99e |
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 | |
66
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1257 if (fn->funcdecl) { |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1258 int li = fn->funcdecl->llvmInternal; |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1259 if (li != LLVMintrinsic && li != LLVMva_start && li != LLVMva_intrinsic) { |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1260 call->setCallingConv(LLVM_DtoCallingConv(dlink)); |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1261 } |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1262 } |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1263 else if (delegateCall) |
1 | 1264 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
|
1265 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
|
1266 call->setCallingConv(fn->callconv); |
1 | 1267 |
1268 delete fn; | |
1269 return e; | |
1270 } | |
1271 | |
1272 ////////////////////////////////////////////////////////////////////////////////////////// | |
1273 | |
1274 elem* CastExp::toElem(IRState* p) | |
1275 { | |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1276 Logger::print("CastExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1 | 1277 LOG_SCOPE; |
1278 elem* e = new elem; | |
1279 elem* u = e1->toElem(p); | |
40 | 1280 const llvm::Type* tolltype = LLVM_DtoType(to); |
1281 Type* fromtype = LLVM_DtoDType(e1->type); | |
1282 Type* totype = LLVM_DtoDType(to); | |
1283 int lsz = fromtype->size(); | |
1284 int rsz = totype->size(); | |
1 | 1285 |
1286 // this makes sure the strange lvalue casts don't screw things up | |
1287 e->mem = u->mem; | |
1288 | |
40 | 1289 if (fromtype->isintegral()) { |
1290 if (totype->isintegral()) { | |
1 | 1291 if (lsz < rsz) { |
40 | 1292 Logger::cout() << *tolltype << '\n'; |
1293 if (fromtype->isunsigned() || fromtype->ty == Tbool) { | |
1294 e->val = new llvm::ZExtInst(u->getValue(), tolltype, "tmp", p->scopebb()); | |
1 | 1295 } else { |
40 | 1296 e->val = new llvm::SExtInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1297 } |
1298 } | |
1299 else if (lsz > rsz) { | |
40 | 1300 e->val = new llvm::TruncInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1301 } |
1302 else { | |
40 | 1303 e->val = new llvm::BitCastInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1304 } |
1305 } | |
40 | 1306 else if (totype->isfloating()) { |
1307 if (fromtype->isunsigned()) { | |
1308 e->val = new llvm::UIToFPInst(u->getValue(), tolltype, "tmp", p->scopebb()); | |
1 | 1309 } |
1310 else { | |
40 | 1311 e->val = new llvm::SIToFPInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1312 } |
1313 } | |
1314 else { | |
1315 assert(0); | |
1316 } | |
1317 //e->storeVal = u->storeVal ? u->storeVal : u->val; | |
1318 e->type = elem::VAL; | |
1319 } | |
40 | 1320 else if (fromtype->isfloating()) { |
1321 if (totype->isfloating()) { | |
1322 if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) { | |
1 | 1323 e->val = u->getValue(); |
1324 } | |
1325 else if (lsz < rsz) { | |
40 | 1326 e->val = new llvm::FPExtInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1327 } |
1328 else if (lsz > rsz) { | |
40 | 1329 e->val = new llvm::FPTruncInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1330 } |
1331 else { | |
1332 assert(0); | |
1333 } | |
1334 } | |
40 | 1335 else if (totype->isintegral()) { |
1336 if (totype->isunsigned()) { | |
1337 e->val = new llvm::FPToUIInst(u->getValue(), tolltype, "tmp", p->scopebb()); | |
1 | 1338 } |
1339 else { | |
40 | 1340 e->val = new llvm::FPToSIInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1341 } |
1342 } | |
1343 else { | |
1344 assert(0); | |
1345 } | |
1346 e->type = elem::VAL; | |
1347 } | |
40 | 1348 else if (fromtype->ty == Tclass) { |
1 | 1349 //assert(to->ty == Tclass); |
40 | 1350 e->val = new llvm::BitCastInst(u->getValue(), tolltype, "tmp", p->scopebb()); |
1 | 1351 e->type = elem::VAL; |
1352 } | |
40 | 1353 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) { |
1 | 1354 Logger::cout() << "from array or sarray" << '\n'; |
40 | 1355 if (totype->ty == Tpointer) { |
1 | 1356 Logger::cout() << "to pointer" << '\n'; |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1357 assert(fromtype->next == totype->next || totype->next->ty == Tvoid); |
1 | 1358 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1359 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
6 | 1360 llvm::Value* ptr = LLVM_DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb()); |
1 | 1361 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
|
1362 if (fromtype->next != totype->next) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1363 e->val = p->ir->CreateBitCast(e->val, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp"); |
1 | 1364 e->type = elem::VAL; |
1365 } | |
40 | 1366 else if (totype->ty == Tarray) { |
1 | 1367 Logger::cout() << "to array" << '\n'; |
40 | 1368 const llvm::Type* ptrty = LLVM_DtoType(totype->next); |
1 | 1369 if (ptrty == llvm::Type::VoidTy) |
1370 ptrty = llvm::Type::Int8Ty; | |
1371 ptrty = llvm::PointerType::get(ptrty); | |
1372 | |
52 | 1373 const llvm::Type* ety = LLVM_DtoType(fromtype->next); |
1374 if (ety == llvm::Type::VoidTy) | |
1375 ety = llvm::Type::Int8Ty; | |
1376 | |
1 | 1377 if (u->type == elem::SLICE) { |
1378 e->mem = new llvm::BitCastInst(u->mem, ptrty, "tmp", p->scopebb()); | |
52 | 1379 if (fromtype->next->size() == totype->next->size()) |
1380 e->arg = u->arg; | |
1381 else | |
1382 e->arg = LLVM_DtoArrayCastLength(u->arg, ety, ptrty->getContainedType(0)); | |
1 | 1383 } |
1384 else { | |
1385 llvm::Value* uval = u->getValue(); | |
40 | 1386 if (fromtype->ty == Tsarray) { |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1387 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
|
1388 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
|
1389 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
|
1390 e->arg = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); |
52 | 1391 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
|
1392 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
|
1393 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1394 else { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
1395 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
|
1396 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
6 | 1397 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
|
1398 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); |
52 | 1399 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
|
1400 |
6 | 1401 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
|
1402 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
|
1403 //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
|
1404 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
|
1405 } |
1 | 1406 } |
1407 e->type = elem::SLICE; | |
1408 } | |
40 | 1409 else if (totype->ty == Tsarray) { |
1 | 1410 Logger::cout() << "to sarray" << '\n'; |
1411 assert(0); | |
1412 } | |
1413 else { | |
1414 assert(0); | |
1415 } | |
1416 } | |
40 | 1417 else if (fromtype->ty == Tpointer) { |
1418 if (totype->ty == Tpointer || totype->ty == Tclass) { | |
1 | 1419 llvm::Value* src = u->getValue(); |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1420 Logger::cout() << *src << '|' << *tolltype << '\n'; |
40 | 1421 e->val = new llvm::BitCastInst(src, tolltype, "tmp", p->scopebb()); |
1 | 1422 } |
40 | 1423 else if (totype->isintegral()) { |
1424 e->val = new llvm::PtrToIntInst(u->getValue(), tolltype, "tmp", p->scopebb()); | |
1 | 1425 } |
1426 else | |
1427 assert(0); | |
1428 e->type = elem::VAL; | |
1429 } | |
1430 else { | |
1431 assert(0); | |
1432 } | |
1433 delete u; | |
1434 return e; | |
1435 } | |
1436 | |
1437 ////////////////////////////////////////////////////////////////////////////////////////// | |
1438 | |
1439 elem* SymOffExp::toElem(IRState* p) | |
1440 { | |
1441 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1442 LOG_SCOPE; | |
1443 elem* e = 0; | |
1444 if (VarDeclaration* vd = var->isVarDeclaration()) | |
1445 { | |
1446 Logger::println("VarDeclaration"); | |
52 | 1447 if (!vd->llvmTouched && vd->isDataseg()) |
1448 vd->toObjFile(); | |
1449 | |
1450 if (vd->isTypedefDeclaration()) { | |
1451 e->istypeinfo = true; | |
1452 } | |
1453 | |
23 | 1454 assert(vd->llvmValue); |
40 | 1455 Type* t = LLVM_DtoDType(type); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1456 Type* vdtype = LLVM_DtoDType(vd->type); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1457 |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1458 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
|
1459 |
40 | 1460 if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { |
1461 TypeStruct* vdt = (TypeStruct*)vdtype; | |
1 | 1462 e = new elem; |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1463 std::vector<unsigned> dst(1,0); |
40 | 1464 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
|
1465 llvm::Value* ptr = llvalue; |
1 | 1466 assert(ptr); |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1467 e->mem = LLVM_DtoGEP(ptr,dst,"tmp"); |
1 | 1468 e->type = elem::VAL; |
1469 e->field = true; | |
1470 } | |
40 | 1471 else if (vdtype->ty == Tsarray) { |
1 | 1472 e = new elem; |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1473 assert(llvalue); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1474 e->arg = llvalue; |
1 | 1475 e->type = elem::VAL; |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1476 |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1477 const llvm::Type* llt = LLVM_DtoType(t); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1478 llvm::Value* off = 0; |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1479 if (offset != 0) { |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1480 Logger::println("offset = %d\n", offset); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1481 } |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1482 if (llvalue->getType() != llt) { |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1483 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp"); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1484 if (offset != 0) |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1485 e->mem = LLVM_DtoGEPi(e->mem, offset, "tmp"); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1486 } |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1487 else { |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1488 assert(offset == 0); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1489 e->mem = LLVM_DtoGEPi(llvalue,0,0,"tmp"); |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1490 } |
1 | 1491 } |
1492 else if (offset == 0) { | |
1493 e = new elem; | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1494 e->type = elem::VAL; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1495 assert(llvalue); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
1496 e->mem = llvalue; |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1497 |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1498 const llvm::Type* llt = LLVM_DtoType(t); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1499 if (llvalue->getType() != llt) { |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1500 e->mem = p->ir->CreateBitCast(e->mem, llt, "tmp"); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1501 } |
1 | 1502 } |
1503 else { | |
1504 assert(0); | |
1505 } | |
1506 } | |
1507 else if (FuncDeclaration* fd = var->isFuncDeclaration()) | |
1508 { | |
1509 Logger::println("FuncDeclaration"); | |
1510 e = new elem; | |
1511 if (fd->llvmValue == 0) | |
1512 fd->toObjFile(); | |
1513 e->val = fd->llvmValue; | |
1514 e->type = elem::FUNC; | |
1515 } | |
1516 assert(e != 0); | |
1517 assert(e->type != elem::NONE); | |
1518 return e; | |
1519 } | |
1520 | |
1521 ////////////////////////////////////////////////////////////////////////////////////////// | |
1522 | |
1523 elem* PtrExp::toElem(IRState* p) | |
1524 { | |
1525 Logger::print("PtrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1526 LOG_SCOPE; | |
1527 elem* e = new elem; | |
1528 elem* a = e1->toElem(p); | |
1529 | |
1530 if (a->mem) | |
1531 Logger::cout() << "mem: " << *a->mem << '\n'; | |
1532 if (a->val) | |
1533 Logger::cout() << "val: " << *a->val << '\n'; | |
1534 | |
1535 if (a->field) | |
1536 e->mem = a->mem; | |
1537 else | |
1538 e->mem = a->getValue(); | |
1539 e->type = elem::VAR; | |
1540 | |
1541 delete a; | |
1542 return e; | |
1543 } | |
1544 | |
1545 ////////////////////////////////////////////////////////////////////////////////////////// | |
1546 | |
1547 elem* DotVarExp::toElem(IRState* p) | |
1548 { | |
1549 Logger::print("DotVarExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1550 LOG_SCOPE; | |
1551 elem* e = new elem; | |
1552 | |
1553 elem* l = e1->toElem(p); | |
1554 | |
40 | 1555 Type* t = LLVM_DtoDType(type); |
1556 Type* e1type = LLVM_DtoDType(e1->type); | |
1557 | |
1558 Logger::print("e1->type=%s\n", e1type->toChars()); | |
1 | 1559 |
1560 if (VarDeclaration* vd = var->isVarDeclaration()) { | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1561 std::vector<unsigned> vdoffsets(1,0); |
1 | 1562 llvm::Value* src = 0; |
40 | 1563 if (e1type->ty == Tpointer) { |
1564 assert(e1type->next->ty == Tstruct); | |
1565 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
|
1566 ts->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1567 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
|
1568 src = l->val ? l->val : l->mem; |
1 | 1569 } |
1570 else if (e1->type->ty == Tclass) { | |
40 | 1571 TypeClass* tc = (TypeClass*)e1type; |
1 | 1572 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
|
1573 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); |
1 | 1574 src = l->getValue(); |
1575 } | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1576 assert(vdoffsets.size() != 1); |
1 | 1577 assert(src != 0); |
40 | 1578 Logger::cout() << "src: " << *src << '\n'; |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
1579 llvm::Value* arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb()); |
1 | 1580 e->mem = arrptr; |
1581 Logger::cout() << "mem: " << *e->mem << '\n'; | |
1582 e->type = elem::VAR; | |
1583 } | |
1584 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | |
1585 { | |
1586 if (fdecl->llvmValue == 0) | |
1587 { | |
1588 fdecl->toObjFile(); | |
1589 } | |
1590 | |
1591 llvm::Value* funcval = fdecl->llvmValue; | |
1592 e->arg = l->getValue(); | |
1593 | |
1594 // virtual call | |
1595 if (fdecl->isVirtual()) { | |
1596 assert(fdecl->vtblIndex > 0); | |
40 | 1597 assert(e1type->ty == Tclass); |
1 | 1598 |
1599 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1600 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); | |
6 | 1601 funcval = LLVM_DtoGEP(e->arg, zero, zero, "tmp", p->scopebb()); |
1 | 1602 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1603 funcval = LLVM_DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb()); |
1 | 1604 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
9 | 1605 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
|
1606 e->callconv = LLVM_DtoCallingConv(fdecl->linkage); |
1 | 1607 } |
1608 e->val = funcval; | |
66
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1609 e->type = elem::FUNC; |
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
64
diff
changeset
|
1610 e->funcdecl = fdecl; |
1 | 1611 } |
1612 else { | |
1613 printf("unknown: %s\n", var->toChars()); | |
1614 assert(0); | |
1615 } | |
1616 | |
1617 delete l; | |
1618 | |
1619 return e; | |
1620 } | |
1621 | |
1622 ////////////////////////////////////////////////////////////////////////////////////////// | |
1623 | |
1624 elem* ThisExp::toElem(IRState* p) | |
1625 { | |
1626 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1627 LOG_SCOPE; | |
1628 elem* e = new elem; | |
1629 | |
1630 if (VarDeclaration* vd = var->isVarDeclaration()) { | |
40 | 1631 llvm::Value* v = p->func().decl->llvmThisVar; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1632 if (llvm::isa<llvm::AllocaInst>(v)) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1633 v = new llvm::LoadInst(v, "tmp", p->scopebb()); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1634 e->mem = v; |
1 | 1635 e->type = elem::VAL; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1636 e->isthis = true; |
1 | 1637 } |
1638 else { | |
1639 assert(0); | |
1640 } | |
1641 | |
1642 return e; | |
1643 } | |
1644 | |
1645 ////////////////////////////////////////////////////////////////////////////////////////// | |
1646 | |
1647 elem* AddrExp::toElem(IRState* p) | |
1648 { | |
1649 Logger::print("AddrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1650 LOG_SCOPE; | |
1651 elem* e = e1->toElem(p); | |
1652 e->field = true; | |
1653 return e; | |
1654 } | |
1655 | |
1656 ////////////////////////////////////////////////////////////////////////////////////////// | |
1657 | |
1658 elem* StructLiteralExp::toElem(IRState* p) | |
1659 { | |
1660 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1661 LOG_SCOPE; | |
1662 elem* e = new elem; | |
1663 | |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1664 llvm::Value* sptr = 0; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1665 |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1666 // 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
|
1667 if (!p->topexp() || p->topexp()->e2 != this) |
1 | 1668 { |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1669 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
|
1670 e->mem = sptr; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1671 e->type = elem::VAR; |
1 | 1672 } |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1673 // already has memory |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1674 else if (p->topexp()->e2 == this) |
1 | 1675 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1676 sptr = p->topexp()->v; |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1677 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1678 else |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1679 assert(0); |
1 | 1680 |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1681 assert(sptr); |
1 | 1682 |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1683 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
|
1684 |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1685 unsigned n = elements->dim; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1686 for (unsigned i=0; i<n; ++i) |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1687 { |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1688 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
|
1689 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); |
1 | 1690 |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1691 Expression* vx = (Expression*)elements->data[i]; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1692 if (vx != 0) { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1693 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
|
1694 elem* ve = vx->toElem(p); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
1695 p->exps.pop_back(); |
40 | 1696 |
1697 if (!ve->inplace) { | |
1698 llvm::Value* val = ve->getValue(); | |
1699 Logger::cout() << *val << " | " << *arrptr << '\n'; | |
1700 | |
1701 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
|
1702 LLVM_DtoAssign(vxtype, arrptr, val); |
1 | 1703 } |
30
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1704 delete ve; |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1705 } |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1706 else { |
881158a93592
[svn r34] * Fixed passing a struct literal as function argument
lindquist
parents:
29
diff
changeset
|
1707 assert(0); |
1 | 1708 } |
1709 } | |
1710 | |
1711 e->inplace = true; | |
1712 | |
1713 return e; | |
1714 } | |
1715 | |
1716 ////////////////////////////////////////////////////////////////////////////////////////// | |
1717 | |
40 | 1718 llvm::Constant* StructLiteralExp::toConstElem(IRState* p) |
1719 { | |
1720 Logger::print("StructLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | |
1721 LOG_SCOPE; | |
1722 | |
1723 unsigned n = elements->dim; | |
1724 std::vector<llvm::Constant*> vals(n, NULL); | |
1725 | |
1726 for (unsigned i=0; i<n; ++i) | |
1727 { | |
1728 Expression* vx = (Expression*)elements->data[i]; | |
1729 vals[i] = vx->toConstElem(p); | |
1730 } | |
1731 | |
1732 assert(LLVM_DtoDType(type)->ty == Tstruct); | |
1733 const llvm::Type* t = LLVM_DtoType(type); | |
1734 const llvm::StructType* st = llvm::cast<llvm::StructType>(t); | |
1735 return llvm::ConstantStruct::get(st,vals); | |
1736 } | |
1737 | |
1738 ////////////////////////////////////////////////////////////////////////////////////////// | |
1739 | |
1 | 1740 elem* IndexExp::toElem(IRState* p) |
1741 { | |
1742 Logger::print("IndexExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1743 LOG_SCOPE; | |
1744 | |
1745 elem* e = new elem; | |
1746 | |
1747 elem* l = e1->toElem(p); | |
1748 | |
40 | 1749 Type* e1type = LLVM_DtoDType(e1->type); |
1750 | |
1 | 1751 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine. |
1752 elem* r = e2->toElem(p); | |
1753 p->arrays.pop_back(); | |
1754 | |
1755 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1756 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1757 | |
1758 llvm::Value* arrptr = 0; | |
40 | 1759 if (e1type->ty == Tpointer) { |
1 | 1760 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
1761 } | |
40 | 1762 else if (e1type->ty == Tsarray) { |
1763 arrptr = LLVM_DtoGEP(l->getValue(), zero, r->getValue(),"tmp",p->scopebb()); | |
1 | 1764 } |
40 | 1765 else if (e1type->ty == Tarray) { |
6 | 1766 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); |
1 | 1767 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); |
1768 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); | |
1769 } | |
1770 assert(arrptr); | |
1771 | |
1772 e->mem = arrptr; | |
1773 e->type = elem::VAR; | |
1774 | |
1775 delete l; | |
1776 delete r; | |
1777 | |
1778 return e; | |
1779 } | |
1780 | |
1781 ////////////////////////////////////////////////////////////////////////////////////////// | |
1782 | |
1783 elem* SliceExp::toElem(IRState* p) | |
1784 { | |
1785 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1786 LOG_SCOPE; | |
1787 | |
52 | 1788 Type* t = LLVM_DtoDType(type); |
1789 assert(t->ty == Tarray); | |
1790 | |
1 | 1791 elem* v = e1->toElem(p); |
40 | 1792 Type* e1type = LLVM_DtoDType(e1->type); |
1 | 1793 |
1794 elem* e = new elem; | |
1795 assert(v->mem); | |
1796 e->type = elem::SLICE; | |
1797 | |
1798 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
1799 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
1800 | |
1801 // partial slice | |
1802 if (lwr) | |
1803 { | |
1804 assert(upr); | |
1805 p->arrays.push_back(v->mem); | |
1806 elem* lo = lwr->toElem(p); | |
1807 | |
1808 bool lwr_is_zero = false; | |
1809 if (lo->type == elem::CONST) | |
1810 { | |
1811 assert(lo->val); | |
1812 assert(llvm::isa<llvm::ConstantInt>(lo->val)); | |
1813 | |
40 | 1814 if (e1type->ty == Tpointer) { |
1 | 1815 e->mem = v->getValue(); |
1816 } | |
40 | 1817 else if (e1type->ty == Tarray) { |
6 | 1818 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1 | 1819 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1820 } | |
40 | 1821 else if (e1type->ty == Tsarray) { |
1822 e->mem = LLVM_DtoGEP(v->mem,zero,zero,"tmp",p->scopebb()); | |
1823 } | |
1 | 1824 else |
1825 assert(e->mem); | |
1826 | |
1827 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val); | |
1828 if (!(lwr_is_zero = c->isZero())) { | |
1829 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb()); | |
1830 } | |
1831 } | |
1832 else | |
1833 { | |
40 | 1834 if (e1type->ty == Tarray) { |
1835 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); | |
1836 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | |
1837 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); | |
1838 } | |
1839 else if (e1type->ty == Tsarray) { | |
1840 e->mem = LLVM_DtoGEP(v->mem,zero,lo->getValue(),"tmp",p->scopebb()); | |
1841 } | |
1842 else | |
1843 assert(0); | |
1 | 1844 } |
1845 | |
1846 elem* up = upr->toElem(p); | |
1847 p->arrays.pop_back(); | |
1848 | |
1849 if (up->type == elem::CONST) | |
1850 { | |
1851 assert(up->val); | |
1852 assert(llvm::isa<llvm::ConstantInt>(up->val)); | |
1853 if (lwr_is_zero) { | |
1854 e->arg = up->val; | |
1855 } | |
1856 else { | |
1857 if (lo->type == elem::CONST) { | |
1858 llvm::Constant* clo = llvm::cast<llvm::Constant>(lo->val); | |
1859 llvm::Constant* cup = llvm::cast<llvm::Constant>(up->val); | |
1860 e->arg = llvm::ConstantExpr::getSub(cup, clo); | |
1861 } | |
1862 else { | |
1863 e->arg = llvm::BinaryOperator::createSub(up->val, lo->getValue(), "tmp", p->scopebb()); | |
1864 } | |
1865 } | |
1866 } | |
1867 else | |
1868 { | |
1869 if (lwr_is_zero) { | |
1870 e->arg = up->getValue(); | |
1871 } | |
1872 else { | |
1873 e->arg = llvm::BinaryOperator::createSub(up->getValue(), lo->getValue(), "tmp", p->scopebb()); | |
1874 } | |
1875 } | |
1876 | |
1877 delete lo; | |
1878 delete up; | |
52 | 1879 |
1880 /* | |
1881 llvm::Value* tmpmem = new llvm::AllocaInst(LLVM_DtoType(t),"tmp",p->topallocapoint()); | |
1882 llvm::Value* ptr = LLVM_DtoGEPi(tmpmem,0,0,"tmp"); | |
1883 p->ir->CreateStore(e->arg, ptr); | |
1884 ptr = LLVM_DtoGEPi(tmpmem,0,1,"tmp"); | |
1885 p->ir->CreateStore(e->mem, ptr); | |
1886 e->arg = NULL; | |
1887 e->mem = tmpmem; | |
1888 */ | |
1 | 1889 } |
1890 // full slice | |
1891 else | |
1892 { | |
1893 e->mem = v->mem; | |
1894 } | |
1895 | |
1896 delete v; | |
1897 | |
1898 return e; | |
1899 } | |
1900 | |
1901 ////////////////////////////////////////////////////////////////////////////////////////// | |
1902 | |
1903 elem* CmpExp::toElem(IRState* p) | |
1904 { | |
1905 Logger::print("CmpExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
1906 LOG_SCOPE; | |
1907 | |
1908 elem* e = new elem; | |
1909 | |
1910 elem* l = e1->toElem(p); | |
1911 elem* r = e2->toElem(p); | |
1912 | |
40 | 1913 Type* t = LLVM_DtoDType(e1->type); |
1914 Type* e2t = LLVM_DtoDType(e2->type); | |
1915 assert(t == e2t); | |
1 | 1916 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1917 if (t->isintegral() || t->ty == Tpointer) |
1 | 1918 { |
1919 llvm::ICmpInst::Predicate cmpop; | |
40 | 1920 bool skip = false; |
1 | 1921 switch(op) |
1922 { | |
1923 case TOKlt: | |
40 | 1924 case TOKul: |
1 | 1925 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT; |
1926 break; | |
1927 case TOKle: | |
40 | 1928 case TOKule: |
1 | 1929 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE; |
1930 break; | |
1931 case TOKgt: | |
40 | 1932 case TOKug: |
1 | 1933 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT; |
1934 break; | |
1935 case TOKge: | |
40 | 1936 case TOKuge: |
1 | 1937 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE; |
1938 break; | |
40 | 1939 case TOKue: |
1940 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1941 break; | |
1942 case TOKlg: | |
1943 cmpop = llvm::ICmpInst::ICMP_NE; | |
1944 break; | |
1945 case TOKleg: | |
1946 skip = true; | |
1947 e->val = llvm::ConstantInt::getTrue(); | |
1948 break; | |
1949 case TOKunord: | |
1950 skip = true; | |
1951 e->val = llvm::ConstantInt::getFalse(); | |
1952 break; | |
1953 | |
1 | 1954 default: |
1955 assert(0); | |
1956 } | |
40 | 1957 if (!skip) |
1958 { | |
1959 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1960 } | |
1 | 1961 } |
1962 else if (t->isfloating()) | |
1963 { | |
1964 llvm::FCmpInst::Predicate cmpop; | |
1965 switch(op) | |
1966 { | |
1967 case TOKlt: | |
1968 cmpop = llvm::FCmpInst::FCMP_OLT;break; | |
1969 case TOKle: | |
1970 cmpop = llvm::FCmpInst::FCMP_OLE;break; | |
1971 case TOKgt: | |
1972 cmpop = llvm::FCmpInst::FCMP_OGT;break; | |
1973 case TOKge: | |
1974 cmpop = llvm::FCmpInst::FCMP_OGE;break; | |
1975 case TOKunord: | |
1976 cmpop = llvm::FCmpInst::FCMP_UNO;break; | |
1977 case TOKule: | |
1978 cmpop = llvm::FCmpInst::FCMP_ULE;break; | |
1979 case TOKul: | |
1980 cmpop = llvm::FCmpInst::FCMP_ULT;break; | |
1981 case TOKuge: | |
1982 cmpop = llvm::FCmpInst::FCMP_UGE;break; | |
1983 case TOKug: | |
1984 cmpop = llvm::FCmpInst::FCMP_UGT;break; | |
1985 case TOKue: | |
1986 cmpop = llvm::FCmpInst::FCMP_UEQ;break; | |
1987 case TOKlg: | |
1988 cmpop = llvm::FCmpInst::FCMP_ONE;break; | |
1989 case TOKleg: | |
1990 cmpop = llvm::FCmpInst::FCMP_ORD;break; | |
1991 | |
1992 default: | |
1993 assert(0); | |
1994 } | |
1995 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
1996 } | |
1997 else | |
1998 { | |
1999 assert(0 && "Unsupported CmpExp type"); | |
2000 } | |
2001 | |
2002 delete l; | |
2003 delete r; | |
2004 | |
2005 e->type = elem::VAL; | |
2006 | |
2007 return e; | |
2008 } | |
2009 | |
2010 ////////////////////////////////////////////////////////////////////////////////////////// | |
2011 | |
2012 elem* EqualExp::toElem(IRState* p) | |
2013 { | |
2014 Logger::print("EqualExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2015 LOG_SCOPE; | |
2016 | |
2017 elem* e = new elem; | |
2018 | |
2019 elem* l = e1->toElem(p); | |
2020 elem* r = e2->toElem(p); | |
2021 | |
40 | 2022 Type* t = LLVM_DtoDType(e1->type); |
2023 Type* e2t = LLVM_DtoDType(e2->type); | |
2024 assert(t == e2t); | |
1 | 2025 |
2026 if (t->isintegral() || t->ty == Tpointer) | |
2027 { | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
2028 Logger::println("integral or pointer"); |
1 | 2029 llvm::ICmpInst::Predicate cmpop; |
2030 switch(op) | |
2031 { | |
2032 case TOKequal: | |
2033 cmpop = llvm::ICmpInst::ICMP_EQ; | |
2034 break; | |
2035 case TOKnotequal: | |
2036 cmpop = llvm::ICmpInst::ICMP_NE; | |
2037 break; | |
2038 default: | |
2039 assert(0); | |
2040 } | |
2041 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
2042 } | |
2043 else if (t->isfloating()) | |
2044 { | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
2045 Logger::println("floating"); |
1 | 2046 llvm::FCmpInst::Predicate cmpop; |
2047 switch(op) | |
2048 { | |
2049 case TOKequal: | |
2050 cmpop = llvm::FCmpInst::FCMP_OEQ; | |
2051 break; | |
2052 case TOKnotequal: | |
2053 cmpop = llvm::FCmpInst::FCMP_UNE; | |
2054 break; | |
2055 default: | |
2056 assert(0); | |
2057 } | |
2058 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb()); | |
2059 } | |
40 | 2060 else if (t->ty == Tsarray) |
2061 { | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
2062 Logger::println("static array"); |
40 | 2063 e->val = LLVM_DtoStaticArrayCompare(op,l->mem,r->mem); |
2064 } | |
1 | 2065 else if (t->ty == Tarray) |
2066 { | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
2067 Logger::println("dynamic array"); |
52 | 2068 e->val = LLVM_DtoDynArrayCompare(op,l->mem,r->mem); |
1 | 2069 } |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
2070 else if (t->ty == Tdelegate) |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
2071 { |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
2072 Logger::println("delegate"); |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
2073 e->val = LLVM_DtoCompareDelegate(op,l->mem,r->mem); |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
2074 } |
1 | 2075 else |
2076 { | |
2077 assert(0 && "Unsupported EqualExp type"); | |
2078 } | |
2079 | |
2080 delete l; | |
2081 delete r; | |
2082 | |
2083 e->type = elem::VAL; | |
2084 | |
2085 return e; | |
2086 } | |
2087 | |
2088 ////////////////////////////////////////////////////////////////////////////////////////// | |
2089 | |
2090 elem* PostExp::toElem(IRState* p) | |
2091 { | |
2092 Logger::print("PostExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2093 LOG_SCOPE; | |
2094 | |
2095 elem* l = e1->toElem(p); | |
2096 elem* r = e2->toElem(p); | |
2097 | |
2098 elem* e = new elem; | |
2099 e->mem = l->mem; | |
2100 e->val = l->getValue(); | |
2101 e->type = elem::VAL; | |
2102 | |
2103 llvm::Value* val = e->val; | |
2104 llvm::Value* post = 0; | |
2105 | |
40 | 2106 Type* e1type = LLVM_DtoDType(e1->type); |
2107 Type* e2type = LLVM_DtoDType(e2->type); | |
2108 | |
2109 if (e1type->isintegral()) | |
1 | 2110 { |
40 | 2111 assert(e2type->isintegral()); |
2112 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); | |
1 | 2113 if (op == TOKplusplus) { |
2114 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
2115 } | |
2116 else if (op == TOKminusminus) { | |
2117 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
2118 } | |
2119 } | |
40 | 2120 else if (e1type->ty == Tpointer) |
1 | 2121 { |
40 | 2122 assert(e2type->isintegral()); |
1 | 2123 llvm::Constant* minusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)-1,true); |
2124 llvm::Constant* plusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)1,false); | |
2125 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; | |
2126 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb()); | |
2127 } | |
40 | 2128 else if (e1type->isfloating()) |
1 | 2129 { |
40 | 2130 assert(e2type->isfloating()); |
1 | 2131 llvm::Value* one = llvm::ConstantFP::get(val->getType(), 1.0f); |
2132 if (op == TOKplusplus) { | |
2133 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); | |
2134 } | |
2135 else if (op == TOKminusminus) { | |
2136 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); | |
2137 } | |
2138 } | |
2139 else | |
2140 assert(post); | |
2141 | |
2142 //llvm::Value* tostore = l->storeVal ? l->storeVal : l->val; | |
2143 new llvm::StoreInst(post,l->mem,p->scopebb()); | |
2144 | |
2145 delete l; | |
2146 delete r; | |
2147 | |
2148 return e; | |
2149 } | |
2150 | |
2151 ////////////////////////////////////////////////////////////////////////////////////////// | |
2152 | |
2153 elem* NewExp::toElem(IRState* p) | |
2154 { | |
2155 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2156 LOG_SCOPE; | |
2157 | |
2158 assert(!thisexp); | |
2159 assert(!newargs); | |
2160 assert(newtype); | |
2161 assert(!allocator); | |
2162 | |
2163 elem* e = new elem; | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2164 e->inplace = true; |
1 | 2165 |
40 | 2166 Type* ntype = LLVM_DtoDType(newtype); |
2167 | |
2168 const llvm::Type* t = LLVM_DtoType(ntype); | |
1 | 2169 |
2170 if (onstack) { | |
40 | 2171 assert(ntype->ty == Tclass); |
1 | 2172 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint()); |
2173 } | |
2174 else { | |
40 | 2175 if (ntype->ty == Tclass) { |
1 | 2176 e->mem = new llvm::MallocInst(t->getContainedType(0),"tmp",p->scopebb()); |
2177 } | |
40 | 2178 else if (ntype->ty == Tarray) { |
1 | 2179 assert(arguments); |
2180 if (arguments->dim == 1) { | |
2181 elem* sz = ((Expression*)arguments->data[0])->toElem(p); | |
2182 llvm::Value* dimval = sz->getValue(); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2183 Type* nnt = LLVM_DtoDType(ntype->next); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2184 if (nnt->ty == Tvoid) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2185 nnt = Type::tint8; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2186 if (!p->topexp() || p->topexp()->e2 != this) { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2187 const llvm::Type* restype = LLVM_DtoType(type); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2188 Logger::cout() << "restype = " << *restype << '\n'; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2189 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
|
2190 LLVM_DtoNewDynArray(e->mem, dimval, nnt); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2191 e->inplace = false; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2192 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2193 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
|
2194 assert(p->topexp()->v); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2195 e->mem = p->topexp()->v; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2196 LLVM_DtoNewDynArray(e->mem, dimval, nnt); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2197 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2198 else |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2199 assert(0); |
1 | 2200 delete sz; |
2201 } | |
2202 else { | |
2203 assert(0); | |
2204 } | |
2205 } | |
2206 else { | |
2207 e->mem = new llvm::MallocInst(t,"tmp",p->scopebb()); | |
2208 } | |
2209 } | |
2210 | |
40 | 2211 if (ntype->ty == Tclass) { |
1 | 2212 // first apply the static initializer |
2213 assert(e->mem); | |
40 | 2214 LLVM_DtoInitClass((TypeClass*)ntype, e->mem); |
1 | 2215 |
2216 // then call constructor | |
2217 if (arguments) { | |
40 | 2218 assert(member); |
2219 assert(member->llvmValue); | |
2220 llvm::Function* fn = llvm::cast<llvm::Function>(member->llvmValue); | |
2221 TypeFunction* tf = (TypeFunction*)LLVM_DtoDType(member->type); | |
2222 | |
1 | 2223 std::vector<llvm::Value*> ctorargs; |
2224 ctorargs.push_back(e->mem); | |
2225 for (size_t i=0; i<arguments->dim; ++i) | |
2226 { | |
2227 Expression* ex = (Expression*)arguments->data[i]; | |
40 | 2228 Argument* fnarg = Argument::getNth(tf->parameters, i); |
2229 llvm::Value* a = LLVM_DtoArgument(fn->getFunctionType()->getParamType(i+1), fnarg, ex); | |
2230 ctorargs.push_back(a); | |
1 | 2231 } |
40 | 2232 e->mem = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb()); |
1 | 2233 } |
2234 } | |
40 | 2235 else if (ntype->ty == Tstruct) { |
2236 TypeStruct* ts = (TypeStruct*)ntype; | |
1 | 2237 if (ts->isZeroInit()) { |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
2238 LLVM_DtoStructZeroInit(e->mem); |
1 | 2239 } |
2240 else { | |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
50
diff
changeset
|
2241 LLVM_DtoStructCopy(e->mem,ts->llvmInit); |
1 | 2242 } |
2243 } | |
2244 | |
2245 e->type = elem::VAR; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
2246 |
1 | 2247 return e; |
2248 } | |
2249 | |
2250 ////////////////////////////////////////////////////////////////////////////////////////// | |
2251 | |
2252 elem* DeleteExp::toElem(IRState* p) | |
2253 { | |
2254 Logger::print("DeleteExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2255 LOG_SCOPE; | |
2256 | |
2257 //assert(e1->type->ty != Tclass); | |
2258 | |
2259 elem* v = e1->toElem(p); | |
2260 llvm::Value* val = v->getValue(); | |
2261 llvm::Value* ldval = 0; | |
2262 | |
2263 const llvm::Type* t = val->getType(); | |
2264 llvm::Constant* z = llvm::Constant::getNullValue(t); | |
2265 | |
40 | 2266 Type* e1type = LLVM_DtoDType(e1->type); |
2267 | |
2268 if (e1type->ty == Tpointer) { | |
1 | 2269 ldval = v->getValue(); |
2270 new llvm::FreeInst(ldval, p->scopebb()); | |
2271 | |
2272 Logger::cout() << *z << '\n'; | |
2273 Logger::cout() << *val << '\n'; | |
2274 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
2275 } | |
40 | 2276 else if (e1type->ty == Tclass) { |
2277 TypeClass* tc = (TypeClass*)e1type; | |
1 | 2278 LLVM_DtoCallClassDtors(tc, val); |
2279 | |
2280 if (v->vardecl && !v->vardecl->onstack) { | |
2281 new llvm::FreeInst(val, p->scopebb()); | |
2282 } | |
2283 new llvm::StoreInst(z, v->mem, p->scopebb()); | |
2284 } | |
40 | 2285 else if (e1type->ty == Tarray) { |
1 | 2286 // must be on the heap (correct?) |
2287 ldval = v->getValue(); | |
2288 | |
2289 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2290 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | |
2291 | |
6 | 2292 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb()); |
1 | 2293 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); |
2294 new llvm::FreeInst(ptr, p->scopebb()); | |
2295 LLVM_DtoNullArray(val); | |
2296 } | |
2297 else { | |
2298 assert(0); | |
2299 } | |
2300 | |
2301 delete v; | |
2302 | |
2303 // this expression produces no useful data | |
2304 return 0; | |
2305 } | |
2306 | |
2307 ////////////////////////////////////////////////////////////////////////////////////////// | |
2308 | |
2309 elem* ArrayLengthExp::toElem(IRState* p) | |
2310 { | |
2311 Logger::print("ArrayLengthExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2312 LOG_SCOPE; | |
2313 | |
2314 elem* e = new elem; | |
2315 elem* u = e1->toElem(p); | |
2316 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2317 if (p->topexp() && p->topexp()->e1 == this) |
34 | 2318 { |
2319 e->mem = u->mem; | |
2320 e->type = elem::ARRAYLEN; | |
2321 } | |
2322 else | |
2323 { | |
2324 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
2325 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); | |
2326 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | |
2327 e->type = elem::VAL; | |
2328 } | |
1 | 2329 delete u; |
2330 | |
2331 return e; | |
2332 } | |
2333 | |
2334 ////////////////////////////////////////////////////////////////////////////////////////// | |
2335 | |
2336 elem* AssertExp::toElem(IRState* p) | |
2337 { | |
2338 Logger::print("AssertExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2339 LOG_SCOPE; | |
2340 | |
2341 elem* u = e1->toElem(p); | |
34 | 2342 elem* m = msg ? msg->toElem(p) : NULL; |
1 | 2343 |
34 | 2344 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); |
2345 LLVM_DtoAssert(u->getValue(), loca, m ? m->val : NULL); | |
2346 | |
1 | 2347 delete m; |
2348 delete u; | |
2349 | |
34 | 2350 return new elem; |
1 | 2351 } |
2352 | |
2353 ////////////////////////////////////////////////////////////////////////////////////////// | |
2354 | |
2355 elem* NotExp::toElem(IRState* p) | |
2356 { | |
2357 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2358 LOG_SCOPE; | |
2359 | |
2360 elem* e = new elem; | |
2361 elem* u = e1->toElem(p); | |
2362 | |
2363 llvm::Value* b = LLVM_DtoBoolean(u->getValue()); | |
2364 | |
2365 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); | |
40 | 2366 e->val = p->ir->CreateICmpEQ(b,zero); |
2367 //e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb()); | |
1 | 2368 e->type = elem::VAL; |
2369 | |
2370 delete u; | |
2371 | |
2372 return e; | |
2373 } | |
2374 | |
2375 ////////////////////////////////////////////////////////////////////////////////////////// | |
2376 | |
2377 elem* AndAndExp::toElem(IRState* p) | |
2378 { | |
2379 Logger::print("AndAndExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2380 LOG_SCOPE; | |
2381 | |
2382 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2383 llvm::Value* resval = 0; | |
2384 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2385 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"andandtmp",p->topallocapoint()); | |
2386 | |
2387 elem* e = new elem; | |
2388 elem* u = e1->toElem(p); | |
2389 | |
2390 llvm::BasicBlock* oldend = p->scopeend(); | |
2391 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend); | |
2392 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend); | |
2393 | |
2394 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
2395 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
2396 new llvm::BranchInst(andand,andandend,ubool,p->scopebb()); | |
2397 | |
2398 p->scope() = IRScope(andand, andandend); | |
2399 elem* v = e2->toElem(p); | |
2400 | |
2401 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
2402 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); | |
2403 new llvm::StoreInst(uandvbool,resval,p->scopebb()); | |
2404 new llvm::BranchInst(andandend,p->scopebb()); | |
2405 | |
2406 delete u; | |
2407 delete v; | |
2408 | |
2409 p->scope() = IRScope(andandend, oldend); | |
2410 | |
2411 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2412 e->type = elem::VAL; | |
2413 | |
2414 return e; | |
2415 } | |
2416 | |
2417 ////////////////////////////////////////////////////////////////////////////////////////// | |
2418 | |
2419 elem* OrOrExp::toElem(IRState* p) | |
2420 { | |
2421 Logger::print("OrOrExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2422 LOG_SCOPE; | |
2423 | |
2424 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2425 llvm::Value* resval = 0; | |
2426 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2427 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"orortmp",p->topallocapoint()); | |
2428 | |
2429 elem* e = new elem; | |
2430 elem* u = e1->toElem(p); | |
2431 | |
2432 llvm::BasicBlock* oldend = p->scopeend(); | |
2433 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend); | |
2434 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend); | |
2435 | |
2436 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue()); | |
2437 new llvm::StoreInst(ubool,resval,p->scopebb()); | |
2438 new llvm::BranchInst(ororend,oror,ubool,p->scopebb()); | |
2439 | |
2440 p->scope() = IRScope(oror, ororend); | |
2441 elem* v = e2->toElem(p); | |
2442 | |
2443 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue()); | |
2444 new llvm::StoreInst(vbool,resval,p->scopebb()); | |
2445 new llvm::BranchInst(ororend,p->scopebb()); | |
2446 | |
2447 delete u; | |
2448 delete v; | |
2449 | |
2450 p->scope() = IRScope(ororend, oldend); | |
2451 | |
2452 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb()); | |
2453 e->type = elem::VAL; | |
2454 | |
2455 return e; | |
2456 } | |
2457 | |
2458 ////////////////////////////////////////////////////////////////////////////////////////// | |
2459 | |
2460 #define BinBitExp(X,Y) \ | |
2461 elem* X##Exp::toElem(IRState* p) \ | |
2462 { \ | |
2463 Logger::print("%sExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2464 LOG_SCOPE; \ | |
2465 elem* e = new elem; \ | |
2466 elem* u = e1->toElem(p); \ | |
2467 elem* v = e2->toElem(p); \ | |
2468 e->val = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \ | |
2469 e->type = elem::VAL; \ | |
2470 delete u; \ | |
2471 delete v; \ | |
2472 return e; \ | |
2473 } \ | |
2474 \ | |
2475 elem* X##AssignExp::toElem(IRState* p) \ | |
2476 { \ | |
2477 Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ | |
2478 LOG_SCOPE; \ | |
2479 elem* u = e1->toElem(p); \ | |
2480 elem* v = e2->toElem(p); \ | |
42 | 2481 llvm::Value* uval = u->getValue(); \ |
2482 assert(uval); \ | |
2483 llvm::Value* vval = v->getValue(); \ | |
2484 assert(vval); \ | |
2485 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
|
2486 if (u->mem == 0) \ |
253a5fc4033a
[svn r33] * Added support for assignment to function arguments
lindquist
parents:
28
diff
changeset
|
2487 LLVM_DtoGiveArgumentStorage(u); \ |
42 | 2488 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \ |
1 | 2489 new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \ |
2490 delete u; \ | |
2491 delete v; \ | |
2492 elem* e = new elem; \ | |
2493 e->mem = u->mem; \ | |
2494 e->type = elem::VAR; \ | |
2495 return e; \ | |
2496 } | |
2497 | |
2498 BinBitExp(And,And); | |
2499 BinBitExp(Or,Or); | |
2500 BinBitExp(Xor,Xor); | |
2501 BinBitExp(Shl,Shl); | |
2502 BinBitExp(Shr,AShr); | |
2503 BinBitExp(Ushr,LShr); | |
2504 | |
2505 ////////////////////////////////////////////////////////////////////////////////////////// | |
2506 | |
2507 elem* HaltExp::toElem(IRState* p) | |
2508 { | |
2509 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2510 LOG_SCOPE; | |
2511 | |
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
|
2512 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
|
2513 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
|
2514 |
40 | 2515 new llvm::UnreachableInst(p->scopebb()); |
1 | 2516 return 0; |
2517 } | |
2518 | |
2519 ////////////////////////////////////////////////////////////////////////////////////////// | |
2520 | |
2521 elem* DelegateExp::toElem(IRState* p) | |
2522 { | |
2523 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2524 LOG_SCOPE; | |
2525 | |
2526 elem* e = new elem; | |
2527 elem* u = e1->toElem(p); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2528 |
1 | 2529 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
2530 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
|
2531 |
1 | 2532 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
2533 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2534 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
|
2535 llvm::Value* lval = p->topexp()->v; |
1 | 2536 |
6 | 2537 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb()); |
1 | 2538 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); |
2539 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
|
2540 |
6 | 2541 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
|
2542 |
1 | 2543 assert(func->llvmValue); |
2544 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | |
2545 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
|
2546 |
1 | 2547 e->inplace = true; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2548 |
1 | 2549 delete u; |
2550 return e; | |
2551 } | |
2552 | |
2553 ////////////////////////////////////////////////////////////////////////////////////////// | |
2554 | |
2555 elem* IdentityExp::toElem(IRState* p) | |
2556 { | |
2557 Logger::print("IdentityExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2558 LOG_SCOPE; | |
2559 | |
2560 elem* u = e1->toElem(p); | |
2561 elem* v = e2->toElem(p); | |
2562 | |
2563 elem* e = new elem; | |
2564 | |
2565 llvm::Value* l = u->getValue(); | |
2566 llvm::Value* r = 0; | |
2567 if (v->type == elem::NUL) | |
2568 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); | |
2569 else | |
2570 r = v->getValue(); | |
2571 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2572 Type* t1 = LLVM_DtoDType(e1->type); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2573 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2574 if (t1->ty == Tarray) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2575 assert(l->getType() == r->getType()); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2576 e->val = LLVM_DtoDynArrayIs(op,l,r); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2577 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2578 else { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2579 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
|
2580 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
|
2581 } |
1 | 2582 e->type = elem::VAL; |
2583 | |
2584 delete u; | |
2585 delete v; | |
2586 | |
2587 return e; | |
2588 } | |
2589 | |
2590 ////////////////////////////////////////////////////////////////////////////////////////// | |
2591 | |
2592 elem* CommaExp::toElem(IRState* p) | |
2593 { | |
2594 Logger::print("CommaExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2595 LOG_SCOPE; | |
2596 | |
2597 elem* u = e1->toElem(p); | |
2598 elem* v = e2->toElem(p); | |
2599 delete u; | |
2600 return v; | |
2601 } | |
2602 | |
2603 ////////////////////////////////////////////////////////////////////////////////////////// | |
2604 | |
2605 elem* CondExp::toElem(IRState* p) | |
2606 { | |
2607 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2608 LOG_SCOPE; | |
2609 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2610 Type* dtype = LLVM_DtoDType(type); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2611 const llvm::Type* resty = LLVM_DtoType(dtype); |
1 | 2612 |
2613 // allocate a temporary for the final result. failed to come up with a better way :/ | |
2614 llvm::BasicBlock* entryblock = &p->topfunc()->front(); | |
2615 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); | |
2616 | |
2617 llvm::BasicBlock* oldend = p->scopeend(); | |
2618 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend); | |
2619 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend); | |
2620 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend); | |
2621 | |
2622 elem* c = econd->toElem(p); | |
2623 llvm::Value* cond_val = LLVM_DtoBoolean(c->getValue()); | |
2624 delete c; | |
2625 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb()); | |
2626 | |
2627 p->scope() = IRScope(condtrue, condfalse); | |
2628 elem* u = e1->toElem(p); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2629 LLVM_DtoAssign(dtype, resval, u->getValue()); |
1 | 2630 new llvm::BranchInst(condend,p->scopebb()); |
2631 delete u; | |
2632 | |
2633 p->scope() = IRScope(condfalse, condend); | |
2634 elem* v = e2->toElem(p); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2635 LLVM_DtoAssign(dtype, resval, v->getValue()); |
1 | 2636 new llvm::BranchInst(condend,p->scopebb()); |
2637 delete v; | |
2638 | |
2639 p->scope() = IRScope(condend, oldend); | |
2640 | |
2641 elem* e = new elem; | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2642 e->mem = resval; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2643 e->type = elem::VAR; |
1 | 2644 return e; |
2645 } | |
2646 | |
2647 ////////////////////////////////////////////////////////////////////////////////////////// | |
2648 | |
2649 elem* ComExp::toElem(IRState* p) | |
2650 { | |
2651 Logger::print("ComExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2652 LOG_SCOPE; | |
2653 | |
2654 elem* e = new elem; | |
2655 elem* u = e1->toElem(p); | |
2656 | |
2657 llvm::Value* value = u->getValue(); | |
2658 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); | |
2659 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); | |
2660 | |
2661 delete u; | |
2662 | |
2663 e->type = elem::VAL; | |
2664 | |
2665 return e; | |
2666 } | |
2667 | |
2668 ////////////////////////////////////////////////////////////////////////////////////////// | |
2669 | |
23 | 2670 elem* NegExp::toElem(IRState* p) |
2671 { | |
2672 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2673 LOG_SCOPE; | |
2674 elem* e = new elem; | |
2675 elem* l = e1->toElem(p); | |
2676 llvm::Value* val = l->getValue(); | |
2677 delete l; | |
2678 | |
40 | 2679 Type* t = LLVM_DtoDType(type); |
2680 | |
23 | 2681 llvm::Value* zero = 0; |
40 | 2682 if (t->isintegral()) |
23 | 2683 zero = llvm::ConstantInt::get(val->getType(), 0, true); |
40 | 2684 else if (t->isfloating()) { |
2685 if (t->ty == Tfloat32) | |
23 | 2686 zero = llvm::ConstantFP::get(val->getType(), float(0)); |
40 | 2687 else if (t->ty == Tfloat64 || t->ty == Tfloat80) |
23 | 2688 zero = llvm::ConstantFP::get(val->getType(), double(0)); |
2689 else | |
2690 assert(0); | |
2691 } | |
2692 else | |
2693 assert(0); | |
2694 | |
2695 e->val = llvm::BinaryOperator::createSub(zero,val,"tmp",p->scopebb()); | |
2696 e->type = elem::VAL; | |
2697 | |
2698 return e; | |
2699 } | |
2700 | |
2701 ////////////////////////////////////////////////////////////////////////////////////////// | |
2702 | |
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
|
2703 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
|
2704 { |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2705 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
|
2706 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
|
2707 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2708 Type* t = LLVM_DtoDType(type); |
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 bool inplace = false; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2711 llvm::Value* dst = 0; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2712 IRExp* ex = p->topexp(); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2713 if (ex && ex->e2 == this) { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2714 assert(ex->v); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2715 dst = ex->v; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2716 inplace = true; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2717 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2718 else { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2719 assert(t->ty == Tarray); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2720 const llvm::Type* arrty = LLVM_DtoType(t); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2721 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
|
2722 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2723 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2724 LLVM_DtoCatArrays(dst,e1,e2); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2725 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2726 elem* e = new elem; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2727 e->mem = dst; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2728 e->type = elem::VAR; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2729 e->inplace = inplace; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2730 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2731 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
|
2732 } |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2733 |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2734 ////////////////////////////////////////////////////////////////////////////////////////// |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2735 |
40 | 2736 elem* CatAssignExp::toElem(IRState* p) |
2737 { | |
2738 Logger::print("CatAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2739 LOG_SCOPE; | |
2740 | |
2741 elem* l = e1->toElem(p); | |
2742 assert(l->mem); | |
2743 | |
2744 Type* e1type = LLVM_DtoDType(e1->type); | |
2745 Type* elemtype = LLVM_DtoDType(e1type->next); | |
2746 Type* e2type = LLVM_DtoDType(e2->type); | |
2747 | |
2748 if (e2type == elemtype) { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
2749 LLVM_DtoCatAssignElement(l->mem,e2); |
40 | 2750 } |
2751 else | |
2752 assert(0 && "only one element at a time right now"); | |
2753 | |
2754 return 0; | |
2755 } | |
2756 | |
2757 ////////////////////////////////////////////////////////////////////////////////////////// | |
2758 | |
2759 elem* ArrayLiteralExp::toElem(IRState* p) | |
2760 { | |
2761 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2762 LOG_SCOPE; | |
2763 | |
2764 const llvm::Type* t = LLVM_DtoType(type); | |
2765 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | |
2766 | |
2767 llvm::Value* mem = 0; | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2768 if (!p->topexp() || p->topexp()->e2 != this) { |
40 | 2769 assert(LLVM_DtoDType(type)->ty == Tsarray); |
2770 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint()); | |
2771 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2772 else if (p->topexp()->e2 == this) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2773 mem = p->topexp()->v; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2774 assert(mem); |
40 | 2775 if (!llvm::isa<llvm::PointerType>(mem->getType()) || |
2776 !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0))) | |
2777 { | |
2778 error("TODO array literals can currently only be used to initialise static arrays"); | |
2779 fatal(); | |
2780 } | |
2781 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2782 else |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2783 assert(0); |
40 | 2784 |
2785 for (unsigned i=0; i<elements->dim; ++i) | |
2786 { | |
2787 Expression* expr = (Expression*)elements->data[i]; | |
2788 llvm::Value* elemAddr = LLVM_DtoGEPi(mem,0,i,"tmp",p->scopebb()); | |
2789 elem* e = expr->toElem(p); | |
2790 new llvm::StoreInst(e->getValue(), elemAddr, p->scopebb()); | |
2791 } | |
2792 | |
2793 elem* e = new elem; | |
2794 e->mem = mem; | |
2795 e->type = elem::VAL; | |
2796 e->inplace = true; | |
2797 | |
2798 return e; | |
2799 } | |
2800 | |
2801 ////////////////////////////////////////////////////////////////////////////////////////// | |
2802 | |
2803 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) | |
2804 { | |
2805 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | |
2806 LOG_SCOPE; | |
2807 | |
2808 const llvm::Type* t = LLVM_DtoType(type); | |
2809 Logger::cout() << "array literal has llvm type: " << *t << '\n'; | |
2810 assert(llvm::isa<llvm::ArrayType>(t)); | |
2811 const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t); | |
2812 | |
2813 assert(arrtype->getNumElements() == elements->dim); | |
2814 std::vector<llvm::Constant*> vals(elements->dim, NULL); | |
2815 for (unsigned i=0; i<elements->dim; ++i) | |
2816 { | |
2817 Expression* expr = (Expression*)elements->data[i]; | |
2818 vals[i] = expr->toConstElem(p); | |
2819 } | |
2820 | |
2821 return llvm::ConstantArray::get(arrtype, vals); | |
2822 } | |
2823 | |
2824 ////////////////////////////////////////////////////////////////////////////////////////// | |
2825 | |
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
|
2826 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
|
2827 { |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2828 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
|
2829 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
|
2830 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2831 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
|
2832 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2833 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
|
2834 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
|
2835 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2836 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
|
2837 |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2838 llvm::Value* lval = NULL; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2839 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
|
2840 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
|
2841 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
|
2842 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
|
2843 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2844 else if (p->topexp()->e2 == this) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2845 lval = p->topexp()->v; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2846 assert(lval); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2847 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2848 else |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2849 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
|
2850 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2851 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
|
2852 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2853 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
|
2854 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
|
2855 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
|
2856 if (llvmNested == NULL) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2857 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
|
2858 p->ir->CreateStore(nullcontext, context); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2859 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2860 else { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2861 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
|
2862 p->ir->CreateStore(nestedcontext, context); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2863 } |
49
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2864 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2865 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
|
2866 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2867 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
|
2868 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
|
2869 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
|
2870 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2871 e->inplace = true; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2872 e->mem = lval; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
2873 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
|
2874 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2875 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
|
2876 } |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2877 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2878 ////////////////////////////////////////////////////////////////////////////////////////// |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2879 |
1 | 2880 #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } |
2881 //STUB(IdentityExp); | |
2882 //STUB(CondExp); | |
2883 //STUB(EqualExp); | |
2884 STUB(InExp); | |
2885 //STUB(CmpExp); | |
2886 //STUB(AndAndExp); | |
2887 //STUB(OrOrExp); | |
2888 //STUB(AndExp); | |
2889 //STUB(AndAssignExp); | |
2890 //STUB(OrExp); | |
2891 //STUB(OrAssignExp); | |
2892 //STUB(XorExp); | |
2893 //STUB(XorAssignExp); | |
2894 //STUB(ShrExp); | |
2895 //STUB(ShrAssignExp); | |
2896 //STUB(ShlExp); | |
2897 //STUB(ShlAssignExp); | |
2898 //STUB(UshrExp); | |
2899 //STUB(UshrAssignExp); | |
2900 //STUB(DivExp); | |
2901 //STUB(DivAssignExp); | |
2902 //STUB(MulExp); | |
2903 //STUB(MulAssignExp); | |
2904 //STUB(ModExp); | |
2905 //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
|
2906 //STUB(CatExp); |
40 | 2907 //STUB(CatAssignExp); |
1 | 2908 //STUB(AddExp); |
2909 //STUB(AddAssignExp); | |
2910 STUB(Expression); | |
2911 //STUB(MinExp); | |
2912 //STUB(MinAssignExp); | |
2913 //STUB(PostExp); | |
2914 //STUB(NullExp); | |
2915 //STUB(ThisExp); | |
2916 //STUB(CallExp); | |
2917 STUB(DotTypeExp); | |
2918 STUB(TypeDotIdExp); | |
2919 //STUB(DotVarExp); | |
2920 //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
|
2921 //STUB(FuncExp); |
1 | 2922 //STUB(DelegateExp); |
2923 //STUB(VarExp); | |
2924 //STUB(DeclarationExp); | |
2925 //STUB(NewExp); | |
2926 //STUB(SymOffExp); | |
2927 STUB(ScopeExp); | |
2928 //STUB(AssignExp); | |
2929 | |
2930 STUB(TypeExp); | |
2931 //STUB(RealExp); | |
2932 STUB(ComplexExp); | |
2933 //STUB(StringExp); | |
2934 //STUB(IntegerExp); | |
2935 STUB(BoolExp); | |
2936 | |
2937 //STUB(NotExp); | |
2938 //STUB(ComExp); | |
23 | 2939 //STUB(NegExp); |
1 | 2940 //STUB(PtrExp); |
2941 //STUB(AddrExp); | |
2942 //STUB(SliceExp); | |
2943 //STUB(CastExp); | |
2944 //STUB(DeleteExp); | |
2945 //STUB(IndexExp); | |
2946 //STUB(CommaExp); | |
2947 //STUB(ArrayLengthExp); | |
2948 //STUB(HaltExp); | |
2949 STUB(RemoveExp); | |
40 | 2950 //STUB(ArrayLiteralExp); |
1 | 2951 STUB(AssocArrayLiteralExp); |
2952 //STUB(StructLiteralExp); | |
2953 | |
40 | 2954 #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; } |
2955 CONSTSTUB(Expression); | |
2956 //CONSTSTUB(IntegerExp); | |
2957 //CONSTSTUB(RealExp); | |
2958 //CONSTSTUB(NullExp); | |
2959 //CONSTSTUB(StringExp); | |
2960 //CONSTSTUB(VarExp); | |
2961 //CONSTSTUB(ArrayLiteralExp); | |
2962 CONSTSTUB(AssocArrayLiteralExp); | |
2963 //CONSTSTUB(StructLiteralExp); | |
2964 | |
1 | 2965 unsigned Type::totym() { return 0; } |
2966 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2967 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
|
2968 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2969 assert(0); |
1 | 2970 return 0; |
2971 } | |
2972 | |
2973 type * Type::toCParamtype() | |
2974 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2975 assert(0); |
1 | 2976 return 0; |
2977 } | |
2978 Symbol * Type::toSymbol() | |
2979 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
2980 assert(0); |
1 | 2981 return 0; |
2982 } | |
2983 | |
2984 type * | |
2985 TypeTypedef::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 TypeTypedef::toCParamtype() | |
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 TypedefDeclaration::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 | |
3005 type * | |
3006 TypeEnum::toCtype() | |
3007 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3008 assert(0); |
1 | 3009 return 0; |
3010 } | |
3011 | |
3012 type * | |
3013 TypeStruct::toCtype() | |
3014 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3015 assert(0); |
1 | 3016 return 0; |
3017 } | |
3018 | |
3019 void | |
3020 StructDeclaration::toDebug() | |
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 assert(0); |
1 | 3023 } |
3024 | |
3025 Symbol * TypeClass::toSymbol() | |
3026 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3027 assert(0); |
1 | 3028 return 0; |
3029 } | |
3030 | |
3031 unsigned TypeFunction::totym() | |
3032 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3033 assert(0); |
1 | 3034 return 0; |
3035 } | |
3036 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3037 type * TypeFunction::toCtype() |
1 | 3038 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3039 assert(0); |
1 | 3040 return 0; |
3041 } | |
3042 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3043 type * TypeSArray::toCtype() |
1 | 3044 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3045 assert(0); |
1 | 3046 return 0; |
3047 } | |
3048 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3049 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
|
3050 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3051 assert(0); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3052 return 0; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3053 } |
1 | 3054 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3055 type * TypeDArray::toCtype() |
1 | 3056 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3057 assert(0); |
1 | 3058 return 0; |
3059 } | |
3060 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3061 type * TypeAArray::toCtype() |
1 | 3062 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3063 assert(0); |
1 | 3064 return 0; |
3065 } | |
3066 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3067 type * TypePointer::toCtype() |
1 | 3068 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3069 assert(0); |
1 | 3070 return 0; |
3071 } | |
3072 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3073 type * TypeDelegate::toCtype() |
1 | 3074 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3075 assert(0); |
1 | 3076 return 0; |
3077 } | |
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 type * TypeClass::toCtype() |
1 | 3080 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3081 assert(0); |
1 | 3082 return 0; |
3083 } | |
3084 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3085 void ClassDeclaration::toDebug() |
1 | 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 assert(0); |
1 | 3088 } |
3089 | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
11
diff
changeset
|
3090 ////////////////////////////////////////////////////////////////////////////// |
1 | 3091 |
3092 void | |
3093 EnumDeclaration::toDebug() | |
3094 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3095 assert(0); |
1 | 3096 } |
3097 | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3098 int Dsymbol::cvMember(unsigned char*) |
1 | 3099 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3100 assert(0); |
1 | 3101 return 0; |
3102 } | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3103 int EnumDeclaration::cvMember(unsigned char*) |
1 | 3104 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3105 assert(0); |
1 | 3106 return 0; |
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 int FuncDeclaration::cvMember(unsigned char*) |
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 assert(0); |
1 | 3111 return 0; |
3112 } | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3113 int VarDeclaration::cvMember(unsigned char*) |
1 | 3114 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3115 assert(0); |
1 | 3116 return 0; |
3117 } | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3118 int TypedefDeclaration::cvMember(unsigned char*) |
1 | 3119 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3120 assert(0); |
1 | 3121 return 0; |
3122 } | |
3123 | |
3124 void obj_includelib(char*){} | |
3125 | |
3126 AsmStatement::AsmStatement(Loc loc, Token *tokens) : | |
3127 Statement(loc) | |
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 } |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3131 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
|
3132 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3133 assert(0); |
1 | 3134 return 0; |
3135 } | |
3136 | |
3137 Statement *AsmStatement::semantic(Scope *sc) | |
3138 { | |
3139 return Statement::semantic(sc); | |
3140 } | |
3141 | |
3142 | |
3143 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
3144 { | |
3145 Statement::toCBuffer(buf, hgs); | |
3146 } | |
3147 | |
3148 int AsmStatement::comeFrom() | |
3149 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3150 assert(0); |
1 | 3151 return FALSE; |
3152 } | |
3153 | |
3154 void | |
3155 backend_init() | |
3156 { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
3157 // now lazily loaded |
1 | 3158 //LLVM_D_InitRuntime(); |
3159 } | |
3160 | |
3161 void | |
3162 backend_term() | |
3163 { | |
3164 LLVM_D_FreeRuntime(); | |
3165 } |