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