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