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