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