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