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