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