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