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