annotate gen/tollvm.cpp @ 102:027b8d8b71ec trunk

[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up. Basically it tries to do the following in order: Resolve types, Declare symbols, Create constant initializers, Apply initializers, Generate functions bodies. ClassInfo is now has the most useful(biased?) members working. Probably other stuf...
author lindquist
date Sun, 18 Nov 2007 06:52:57 +0100
parents 5071469303d4
children 855adfdb8d38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1 #include <iostream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
3 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 #include "dsymbol.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
11 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
12 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
13 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
14 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
15 #include "gen/arrays.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
16 #include "gen/dvalue.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
17 #include "gen/functions.h"
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
18 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
19 #include "gen/classes.h"
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
20 #include "gen/typeinf.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
22 bool DtoIsPassedByRef(Type* type)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
23 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
24 TY t = DtoDType(type)->ty;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
25 return (t == Tstruct || t == Tarray || t == Tdelegate || t == Tsarray);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
26 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
27
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
28 Type* DtoDType(Type* t)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
29 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
30 if (t->ty == Ttypedef) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
31 Type* bt = t->toBasetype();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
32 assert(bt);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
33 return DtoDType(bt);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
34 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
35 return t;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
36 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
37
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
38 const llvm::Type* DtoType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40 assert(t);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41 switch (t->ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
42 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43 // integers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
44 case Tint8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
45 case Tuns8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46 case Tchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
47 return (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 case Tint16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 case Tuns16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 case Twchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51 return (const llvm::Type*)llvm::Type::Int16Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52 case Tint32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 case Tuns32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54 case Tdchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
55 return (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 case Tint64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 case Tuns64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58 return (const llvm::Type*)llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
60 case Tbool:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
61 return (const llvm::Type*)llvm::ConstantInt::getTrue()->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
63 // floats
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 case Tfloat32:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
65 case Timaginary32:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66 return llvm::Type::FloatTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67 case Tfloat64:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
68 case Timaginary64:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
69 case Tfloat80:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
70 case Timaginary80:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
71 return llvm::Type::DoubleTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
72
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
73 // complex
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
74 case Tcomplex32:
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
75 return DtoComplexType(llvm::Type::FloatTy);
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
76 case Tcomplex64:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
77 case Tcomplex80:
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
78 return DtoComplexType(llvm::Type::DoubleTy);
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
79
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 // pointers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81 case Tpointer: {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
82 assert(t->next);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
83 if (t->next->ty == Tvoid)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
84 return (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
85 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
86 return (const llvm::Type*)llvm::PointerType::get(DtoType(t->next));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
88
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89 // arrays
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90 case 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
91 return DtoArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92 case Tsarray:
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
93 return DtoStaticArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 // void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 case Tvoid:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 return llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 // aggregates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 case Tstruct: {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
101 if (!t->llvmType || *t->llvmType == NULL) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 // recursive or cyclic declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103 if (!gIR->structs.empty())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 IRStruct* found = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
108 if (t == (*i)->type)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
110 return (*i)->recty.get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
114
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 // forward declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116 TypeStruct* ts = (TypeStruct*)t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117 assert(ts->sym);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
118 DtoResolveDsymbol(ts->sym);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
119 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
120 return t->llvmType->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
121 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
122
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
123 case Tclass: {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
124 if (!t->llvmType || *t->llvmType == NULL) {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
125 // recursive or cyclic declaration
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
126 if (!gIR->structs.empty())
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
127 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
128 IRStruct* found = 0;
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
129 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
130 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
131 if (t == (*i)->type)
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
132 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
133 return llvm::PointerType::get((*i)->recty.get());
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
134 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
135 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
136 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
137
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
138 // forward declaration
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
139 TypeClass* tc = (TypeClass*)t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
140 assert(tc->sym);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
141 DtoResolveDsymbol(tc->sym);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
142 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
143 return llvm::PointerType::get(t->llvmType->get());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
146 // functions
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
147 case Tfunction:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
148 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
149 if (!t->llvmType || *t->llvmType == 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
150 return DtoFunctionType(t,NULL);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 else {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
153 return t->llvmType->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
155 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
156
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 // delegates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158 case Tdelegate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
159 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
160 if (!t->llvmType || *t->llvmType == 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
161 return DtoDelegateType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
162 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
163 else {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
164 return t->llvmType->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
165 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
166 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
168 // typedefs
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
169 // enum
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
170 case Ttypedef:
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
171 case Tenum:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
172 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
173 Type* bt = t->toBasetype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
174 assert(bt);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
175 return DtoType(bt);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
176 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
177
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
178 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
179 printf("trying to convert unknown type with value %d\n", t->ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
180 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
181 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
182 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
183 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
184
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
186
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
187 const llvm::StructType* DtoDelegateType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
188 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
189 const llvm::Type* i8ptr = llvm::PointerType::get(llvm::Type::Int8Ty);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
190 const llvm::Type* func = DtoFunctionType(t->next, i8ptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
191 const llvm::Type* funcptr = llvm::PointerType::get(func);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
192
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
193 std::vector<const llvm::Type*> types;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
194 types.push_back(i8ptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
195 types.push_back(funcptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
196 return llvm::StructType::get(types);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
197 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
198
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
199 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
200
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
201 const llvm::StructType* DtoComplexType(const llvm::Type* base)
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
202 {
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
203 std::vector<const llvm::Type*> types;
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
204 types.push_back(base);
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
205 types.push_back(base);
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
206 return llvm::StructType::get(types);
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
207 }
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
208
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
209 //////////////////////////////////////////////////////////////////////////////////////////
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
210
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
211 static llvm::Function* LLVM_DeclareMemIntrinsic(const char* name, int bits, bool set=false)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
212 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
213 assert(bits == 32 || bits == 64);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
214 const llvm::Type* int8ty = (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 const llvm::Type* int32ty = (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
216 const llvm::Type* int64ty = (const llvm::Type*)llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217 const llvm::Type* int8ptrty = (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218 const llvm::Type* voidty = (const llvm::Type*)llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
219
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
221 assert(gIR->module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
222
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
223 // parameter types
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
224 std::vector<const llvm::Type*> pvec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
225 pvec.push_back(int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
226 pvec.push_back(set?int8ty:int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
227 pvec.push_back(bits==32?int32ty:int64ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
228 pvec.push_back(int32ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
229 llvm::FunctionType* functype = llvm::FunctionType::get(voidty, pvec, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
230 return new llvm::Function(functype, llvm::GlobalValue::ExternalLinkage, name, gIR->module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
231 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
232
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
233 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
234
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
235 // llvm.memset.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
236 llvm::Function* LLVM_DeclareMemSet32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
237 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
238 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
239 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
240 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i32", 32, true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
241 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
242 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
243 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
244
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
245 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
246
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
247 llvm::Function* LLVM_DeclareMemSet64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
248 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
249 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
250 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
251 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i64", 64, true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
252 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
253 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
254 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
255
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
256 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
257
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
258 // llvm.memcpy.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
259 llvm::Function* LLVM_DeclareMemCpy32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
260 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
261 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
262 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
263 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i32", 32);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
264 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
265 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
266 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
267
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
268 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
269
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
270 // llvm.memcpy.i64
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
271 llvm::Function* LLVM_DeclareMemCpy64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
272 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
273 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
274 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
275 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i64", 64);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
276 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
277 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
278 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
279
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
280 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
281
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
282 llvm::Value* DtoNullDelegate(llvm::Value* v)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
283 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
284 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
285 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
286
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
287 llvm::Type* i8p_ty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
288
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
289 llvm::Value* arr = new llvm::BitCastInst(v,i8p_ty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
290
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
291 llvm::Function* fn = LLVM_DeclareMemSet32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
292 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
293 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
294 llargs[0] = arr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
295 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
296 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
297 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
298
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
299 llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
300
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
301 return ret;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
302 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
303
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
304 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
305
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
306 llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
307 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
308 assert(dst->getType() == src->getType());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
309 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
310
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
311 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
312
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
313 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
314
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
315 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
316 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
317
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
318 llvm::Function* fn = LLVM_DeclareMemCpy32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
319 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
320 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
321 llargs[0] = dstarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
322 llargs[1] = srcarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
323 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
324 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
325
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
326 return new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
327 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
328
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
329 //////////////////////////////////////////////////////////////////////////////////////////
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
330
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
331 llvm::Value* DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs)
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
332 {
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
333 llvm::ICmpInst::Predicate pred = (op == TOKequal) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
334 llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
335 llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp");
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
336 llvm::Value* b1 = gIR->ir->CreateICmp(pred,l,r,"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
337 l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
338 r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp");
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
339 llvm::Value* b2 = gIR->ir->CreateICmp(pred,l,r,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
340 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
341 if (op == TOKnotequal)
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
342 return gIR->ir->CreateNot(b,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
343 return b;
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
344 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
345
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
346 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
347
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
348 llvm::GlobalValue::LinkageTypes DtoLinkage(PROT prot, uint stc)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
349 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
350 switch(prot)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
351 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
352 case PROTprivate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
353 return llvm::GlobalValue::InternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
354
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
355 case PROTpublic:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
356 case PROTpackage:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
357 case PROTprotected:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
358 case PROTexport:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
359 return llvm::GlobalValue::ExternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
360
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
361 case PROTundefined:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
362 case PROTnone:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
363 assert(0 && "Unsupported linkage type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
364 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
365 return llvm::GlobalValue::ExternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
366
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
367 /* ExternalLinkage = 0, LinkOnceLinkage, WeakLinkage, AppendingLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
368 InternalLinkage, DLLImportLinkage, DLLExportLinkage, ExternalWeakLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
369 GhostLinkage */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
370 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
371
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
372 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
373
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
374 unsigned DtoCallingConv(LINK l)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
375 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
376 if (l == LINKc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
377 return llvm::CallingConv::C;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
378 else if (l == LINKd || l == LINKdefault)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
379 return llvm::CallingConv::Fast;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
380 else if (l == LINKwindows)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
381 return llvm::CallingConv::X86_StdCall;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
382 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
383 assert(0 && "Unsupported calling convention");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
384 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
385
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
386 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
387
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
388 llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
389 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
390 const llvm::Type* ptrTy = ptr->getType()->getContainedType(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
391 const llvm::Type* valTy = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
392 // ptr points to val's type
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
393 if (ptrTy == valTy)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
394 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
395 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
396 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
397 // ptr is integer pointer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
398 else if (ptrTy->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
399 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
400 // val is integer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
401 assert(valTy->isInteger());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
402 const llvm::IntegerType* pt = llvm::cast<const llvm::IntegerType>(ptrTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
403 const llvm::IntegerType* vt = llvm::cast<const llvm::IntegerType>(valTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
404 if (pt->getBitWidth() < vt->getBitWidth()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
405 return new llvm::TruncInst(val, pt, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
406 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
407 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
408 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
409 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
410 // something else unsupported
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
411 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
412 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
413 Logger::cout() << *ptrTy << '|' << *valTy << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
414 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
415 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
416 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
417 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
418
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
419 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
420
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
421 llvm::Value* DtoBoolean(llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
422 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
423 const llvm::Type* t = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
424 if (t->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
425 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
426 if (t == llvm::Type::Int1Ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
427 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
428 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
429 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
430 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
431 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
432 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
433 else if (isaPointer(t)) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
434 const llvm::Type* st = DtoSize_t();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
435 llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
436 llvm::Value* zero = llvm::ConstantInt::get(st, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
437 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, ptrasint, zero, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
438 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
439 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
440 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
441 Logger::cout() << *t << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
442 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
443 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
444 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
445 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
446
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
447 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
448
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
449 const llvm::Type* DtoSize_t()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
450 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
451 if (global.params.is64bit)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
452 return llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
453 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
454 return llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
455 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
456
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
457 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
458
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
459 llvm::Constant* DtoConstInitializer(Type* type, Initializer* init)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
460 {
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
461 llvm::Constant* _init = 0; // may return zero
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
462 if (!init)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
463 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
464 Logger::println("const default initializer for %s", type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
465 _init = type->defaultInit()->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
466 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
467 else if (ExpInitializer* ex = init->isExpInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
468 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
469 Logger::println("const expression initializer");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
470 _init = ex->exp->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
471 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
472 else if (StructInitializer* si = init->isStructInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
473 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
474 Logger::println("const struct initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
475 _init = DtoConstStructInitializer(si);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
476 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
477 else if (ArrayInitializer* ai = init->isArrayInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
478 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
479 Logger::println("const array initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
480 _init = DtoConstArrayInitializer(ai);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
481 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
482 else if (init->isVoidInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
483 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
484 Logger::println("const void initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
485 const llvm::Type* ty = DtoType(type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
486 _init = llvm::Constant::getNullValue(ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
487 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
488 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
489 Logger::println("unsupported const initializer: %s", init->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
490 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
491 return _init;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
492 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
493
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
494 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
495
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
496 llvm::Constant* DtoConstFieldInitializer(Type* t, Initializer* init)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
497 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
498 Logger::println("DtoConstFieldInitializer");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
499 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
500
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
501 const llvm::Type* _type = DtoType(t);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
502
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
503 llvm::Constant* _init = DtoConstInitializer(t, init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
504 assert(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
505 if (_type != _init->getType())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
506 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
507 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
508 if (t->ty == Tsarray)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
509 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
510 const llvm::ArrayType* arrty = isaArray(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
511 uint64_t n = arrty->getNumElements();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
512 std::vector<llvm::Constant*> vals(n,_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
513 _init = llvm::ConstantArray::get(arrty, vals);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
514 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
515 else if (t->ty == Tarray)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
516 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
517 assert(isaStruct(_type));
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
518 _init = llvm::ConstantAggregateZero::get(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
519 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
520 else if (t->ty == Tstruct)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
521 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
522 const llvm::StructType* structty = isaStruct(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
523 TypeStruct* ts = (TypeStruct*)t;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
524 assert(ts);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
525 assert(ts->sym);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
526 assert(ts->sym->llvmInitZ);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
527 _init = ts->sym->llvmInitZ;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
528 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
529 else if (t->ty == Tclass)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
530 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
531 _init = llvm::Constant::getNullValue(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
532 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
533 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
534 Logger::println("failed for type %s", t->toChars());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
535 assert(0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
536 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
537 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
538
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
539 return _init;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
540 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
541
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
542 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
543
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
544 DValue* DtoInitializer(Initializer* init)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
545 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
546 if (ExpInitializer* ex = init->isExpInitializer())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
547 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
548 Logger::println("expression initializer");
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
549 assert(ex->exp);
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
550 return ex->exp->toElem(gIR);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
551 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
552 else if (init->isVoidInitializer())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
553 {
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
554 // do nothing
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
555 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
556 else {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
557 Logger::println("unsupported initializer: %s", init->toChars());
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
558 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
559 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
560 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
561 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
562
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
563 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
564
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
565 llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb)
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
566 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
567 std::vector<llvm::Value*> v(2);
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
568 v[0] = i0;
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
569 v[1] = i1;
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
570 //Logger::cout() << "DtoGEP: " << *ptr << '\n';
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
571 return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
572 }
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
573
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
574 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
575
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
576 llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb)
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
577 {
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
578 size_t n = src.size();
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
579 std::vector<llvm::Value*> dst(n, NULL);
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
580 //std::ostream& ostr = Logger::cout();
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
581 //ostr << "indices for '" << *ptr << "':";
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
582 for (size_t i=0; i<n; ++i)
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
583 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
584 //ostr << ' ' << i;
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
585 dst[i] = llvm::ConstantInt::get(llvm::Type::Int32Ty, src[i], false);
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
586 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
587 //ostr << '\n';*/
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
588 return new llvm::GetElementPtrInst(ptr, dst.begin(), dst.end(), var, bb?bb:gIR->scopebb());
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
589 }
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
590
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
591 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
592
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
593 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i, const std::string& var, llvm::BasicBlock* bb)
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
594 {
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
595 return new llvm::GetElementPtrInst(ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false), var, bb?bb:gIR->scopebb());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
596 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
597
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
598 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
599
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
600 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb)
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
601 {
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
602 std::vector<llvm::Value*> v(2);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
603 v[0] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i0, false);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
604 v[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i1, false);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
605 return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
606 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
607
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
608 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
609
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
610 llvm::Value* DtoRealloc(llvm::Value* ptr, const llvm::Type* ty)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
611 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
612 /*size_t sz = gTargetData->getTypeSize(ty);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
613 llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
614 if (ptr == 0) {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
615 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
616 ptr = llvm::ConstantPointerNull::get(i8pty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
617 }
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
618 return DtoRealloc(ptr, n);*/
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
619 return NULL;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
620 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
621
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
622 //////////////////////////////////////////////////////////////////////////////////////////
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
623
81
3587401b6eeb [svn r85] Fixed: if a return statement 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 llvm::Value* DtoRealloc(llvm::Value* ptr, llvm::Value* n)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
625 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
626 assert(ptr);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
627 assert(n);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
628
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
629 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_realloc");
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
630 assert(fn);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
631
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
632 llvm::Value* newptr = ptr;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
633
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
634 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
635 if (ptr->getType() != i8pty) {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
636 newptr = new llvm::BitCastInst(ptr,i8pty,"tmp",gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
637 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
638
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
639 std::vector<llvm::Value*> args;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
640 args.push_back(newptr);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
641 args.push_back(n);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
642 llvm::Value* ret = new llvm::CallInst(fn, args.begin(), args.end(), "tmprealloc", gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
643
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
644 return ret->getType() == ptr->getType() ? ret : new llvm::BitCastInst(ret,ptr->getType(),"tmp",gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
645 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
646
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
647 //////////////////////////////////////////////////////////////////////////////////////////
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
648
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
649 void DtoAssert(llvm::Value* cond, Loc* loc, DValue* msg)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
650 {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
651 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_assert");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
652 const llvm::FunctionType* fnt = fn->getFunctionType();
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
653
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
654 std::vector<llvm::Value*> llargs;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
655 llargs.resize(3);
81
3587401b6eeb [svn r85] Fixed: if a return statement 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 llargs[0] = cond ? DtoBoolean(cond) : llvm::ConstantInt::getFalse();
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
657 llargs[1] = DtoConstUint(loc->linnum);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
658 if (msg)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
659 llargs[2] = msg->getRVal();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
660 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
661 llvm::Constant* c = DtoConstSlice(DtoConstSize_t(0), DtoConstNullPtr(llvm::Type::Int8Ty));
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
662 static llvm::AllocaInst* alloc = 0;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
663 if (!alloc || alloc->getParent()->getParent() != gIR->func()->func) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
664 alloc = new llvm::AllocaInst(c->getType(), "assertnullparam", gIR->topallocapoint());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
665 DtoSetArrayToNull(alloc);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
666 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
667 llargs[2] = alloc;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
668 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
669
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
670 assert(fn);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
671 llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
672 call->setCallingConv(llvm::CallingConv::C);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
673 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
674
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
675 //////////////////////////////////////////////////////////////////////////////////////////
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
676
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
677 llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
678 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
679 llvm::Value* retval = 0;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
680
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
681 bool haslvals = !gIR->exps.empty();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
682 if (haslvals)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
683 gIR->exps.push_back(IRExp(NULL,NULL,NULL));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
684
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
685 DValue* arg = argexp->toElem(gIR);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
686
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
687 if (haslvals)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
688 gIR->exps.pop_back();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
689
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
690 if (arg->inPlace()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
691 retval = arg->getRVal();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
692 return retval;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
693 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
694
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
695 Type* realtype = DtoDType(argexp->type);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
696 TY argty = realtype->ty;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
697 if (DtoIsPassedByRef(realtype)) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
698 if (!fnarg || !fnarg->llvmCopy) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
699 if (DSliceValue* sv = arg->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
700 retval = new llvm::AllocaInst(DtoType(realtype), "tmpparam", gIR->topallocapoint());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
701 DtoSetArray(retval, DtoArrayLen(sv), DtoArrayPtr(sv));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
702 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
703 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
704 retval = arg->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
705 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
706 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
707 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
708 llvm::Value* allocaInst = 0;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
709 llvm::BasicBlock* entryblock = &gIR->topfunc()->front();
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
710
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
711 const llvm::Type* realtypell = DtoType(realtype);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
712 const llvm::PointerType* pty = llvm::PointerType::get(realtypell);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
713 if (argty == Tstruct) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
714 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
715 DValue* dst = new DVarValue(realtype, allocaInst, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
716 DtoAssign(dst,arg);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
717 delete dst;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
718 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
719 else if (argty == Tdelegate) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
720 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
721 DValue* dst = new DVarValue(realtype, allocaInst, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
722 DtoAssign(dst,arg);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
723 delete dst;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
724 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
725 else if (argty == Tarray) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
726 if (arg->isSlice()) {
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
727 allocaInst = new llvm::AllocaInst(realtypell, "tmpparam", gIR->topallocapoint());
83
339422268de1 [svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)
lindquist
parents: 82
diff changeset
728 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
729 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
730 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
731 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
732 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
733 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
734 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
735
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
736 DValue* dst = new DVarValue(realtype, allocaInst, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
737 DtoAssign(dst,arg);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
738 delete dst;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
739
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
740 retval = allocaInst;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
741 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
742 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
743 else if (!fnarg || fnarg->llvmCopy) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
744 Logger::println("regular arg");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
745 if (DSliceValue* sl = arg->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
746 if (sl->ptr) Logger::cout() << "ptr = " << *sl->ptr << '\n';
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
747 if (sl->len) Logger::cout() << "len = " << *sl->len << '\n';
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
748 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
749 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
750 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
751 retval = arg->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
752 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
753 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
754 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
755 Logger::println("as ptr arg");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
756 retval = arg->getLVal();
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
757 if (paramtype && retval->getType() != paramtype)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
758 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
759 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
760 /*assert(retval->getType() == paramtype->getContainedType(0));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
761 new llvm::StoreInst(retval, arg->getLVal(), gIR->scopebb());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
762 retval = arg->getLVal();*/
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
763 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
764 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
765
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
766 if (fnarg && paramtype && retval->getType() != paramtype) {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
767 // this is unfortunately needed with the way SymOffExp is overused
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
768 // and static arrays can end up being a pointer to their element type
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
769 if (arg->isField()) {
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
770 retval = gIR->ir->CreateBitCast(retval, paramtype, "tmp");
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
771 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
772 else {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
773 Logger::cout() << "got '" << *retval->getType() << "' expected '" << *paramtype << "'\n";
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
774 assert(0 && "parameter type that was actually passed is invalid");
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
775 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
776 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
777
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
778 delete arg;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
779
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
780 return retval;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
781 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
782
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
783 //////////////////////////////////////////////////////////////////////////////////////////
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
784
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
785 llvm::Value* DtoNestedVariable(VarDeclaration* vd)
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
786 {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
787 FuncDeclaration* fd = vd->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
788 assert(fd != NULL);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
789
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
790 IRFunction* fcur = gIR->func();
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
791 FuncDeclaration* f = fcur->decl;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
792
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
793 // on this stack
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
794 if (fd == f) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
795 llvm::Value* v = DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
796 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
797 Logger::cout() << "1267 loading: " << *v << '\n';
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
798 v = gIR->ir->CreateLoad(v,"tmp");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
799 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
800 return v;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
801 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
802
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
803 // on a caller stack
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
804 llvm::Value* ptr = f->llvmThisVar;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
805 assert(ptr);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
806
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
807 f = f->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
808 assert(f);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
809 assert(f->llvmNested);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
810 const llvm::Type* nesttype = f->llvmNested->getType();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
811 assert(nesttype);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
812
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
813 ptr = gIR->ir->CreateBitCast(ptr, nesttype, "tmp");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
814
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
815 Logger::cout() << "nested var reference:" << '\n' << *ptr << *nesttype << '\n';
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
816
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
817 while (f) {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
818 if (fd == f) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
819 llvm::Value* v = DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
820 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
821 Logger::cout() << "1291 loading: " << *v << '\n';
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
822 v = gIR->ir->CreateLoad(v,"tmp");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
823 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
824 return v;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
825 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
826 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
827 ptr = DtoGEPi(ptr,0,0,"tmp");
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
828 ptr = gIR->ir->CreateLoad(ptr,"tmp");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
829 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
830 f = f->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
831 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
832
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
833 assert(0 && "nested var not found");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
834 return NULL;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
835 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
836
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
837 //////////////////////////////////////////////////////////////////////////////////////////
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
838
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
839 void DtoAssign(DValue* lhs, DValue* rhs)
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
840 {
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
841 Logger::cout() << "DtoAssign(...);\n";
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
842 Type* t = DtoDType(lhs->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
843 Type* t2 = DtoDType(rhs->getType());
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
844
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
845 if (t->ty == Tstruct) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
846 if (t2 != t) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
847 // TODO: fix this, use 'rhs' for something
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
848 DtoStructZeroInit(lhs->getLVal());
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 else if (!rhs->inPlace()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
851 DtoStructCopy(lhs->getLVal(),rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
852 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
853 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
854 else if (t->ty == Tarray) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
855 // lhs is slice
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
856 if (DSliceValue* s = lhs->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
857 if (DSliceValue* s2 = rhs->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
858 DtoArrayCopy(s, s2);
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 if (t->next == t2) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
861 if (s->len)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
862 DtoArrayInit(s->ptr, s->len, rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
863 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
864 DtoArrayInit(s->ptr, rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
865 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
866 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
867 assert(rhs->inPlace());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
868 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
869 // rhs is slice
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
870 else if (DSliceValue* s = rhs->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
871 DtoSetArray(lhs->getLVal(),s->len,s->ptr);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
872 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
873 // null
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
874 else if (rhs->isNull()) {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
875 DtoSetArrayToNull(lhs->getLVal());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
876 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
877 // reference assignment
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
878 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
879 DtoArrayAssign(lhs->getLVal(), rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
880 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
881 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
882 else if (t->ty == Tsarray) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
883 DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal());
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
884 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
885 else if (t->ty == Tdelegate) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
886 if (rhs->isNull())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
887 DtoNullDelegate(lhs->getLVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
888 else if (!rhs->inPlace())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
889 DtoDelegateCopy(lhs->getLVal(), rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
890 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
891 else if (t->ty == Tclass) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
892 assert(t2->ty == Tclass);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
893 // assignment to this in constructor special case
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
894 if (lhs->isThis()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
895 llvm::Value* tmp = rhs->getRVal();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
896 FuncDeclaration* fdecl = gIR->func()->decl;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
897 // respecify the this param
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
898 if (!llvm::isa<llvm::AllocaInst>(fdecl->llvmThisVar))
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
899 fdecl->llvmThisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
900 DtoStore(tmp, fdecl->llvmThisVar);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
901 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
902 // regular class ref -> class ref assignment
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
903 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
904 DtoStore(rhs->getRVal(), lhs->getLVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
905 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
906 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
907 else {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
908 llvm::Value* r = rhs->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
909 llvm::Value* l = lhs->getLVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
910 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
911 const llvm::Type* lit = l->getType()->getContainedType(0);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
912 if (r->getType() != lit) {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
913 r = DtoBitCast(r, lit);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
914 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
915 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
916 gIR->ir->CreateStore(r, l);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
917 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
918 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
919
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
920 //////////////////////////////////////////////////////////////////////////////////////////
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
921 DValue* DtoCastInt(DValue* val, Type* _to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
922 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
923 const llvm::Type* tolltype = DtoType(_to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
924
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
925 Type* to = DtoDType(_to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
926 Type* from = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
927 assert(from->isintegral());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
928
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
929 size_t fromsz = from->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
930 size_t tosz = to->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
931
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
932 llvm::Value* rval;
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
933
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
934 if (to->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
935 if (fromsz < tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
936 Logger::cout() << "cast to: " << *tolltype << '\n';
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
937 if (from->isunsigned() || from->ty == Tbool) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
938 rval = new llvm::ZExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
939 } else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
940 rval = new llvm::SExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
941 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
942 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
943 else if (fromsz > tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
944 rval = new llvm::TruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
945 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
946 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
947 rval = new llvm::BitCastInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
948 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
949 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
950 else if (to->isfloating()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
951 if (from->isunsigned()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
952 rval = new llvm::UIToFPInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
953 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
954 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
955 rval = new llvm::SIToFPInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
956 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
957 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
958 else if (to->ty == Tpointer) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
959 rval = gIR->ir->CreateIntToPtr(val->getRVal(), tolltype, "tmp");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
960 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
961 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
962 assert(0 && "bad int cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
963 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
964
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
965 return new DImValue(_to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
966 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
967
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
968 DValue* DtoCastPtr(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
969 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
970 const llvm::Type* tolltype = DtoType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
971
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
972 Type* totype = DtoDType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
973 Type* fromtype = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
974 assert(fromtype->ty == Tpointer);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
975
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
976 llvm::Value* rval;
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
977
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
978 if (totype->ty == Tpointer || totype->ty == Tclass) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
979 llvm::Value* src = val->getRVal();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
980 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n';
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
981 rval = new llvm::BitCastInst(src, tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
982 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
983 else if (totype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
984 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
985 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
986 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
987 assert(0);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
988 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
989
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
990 return new DImValue(to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
991 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
992
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
993 DValue* DtoCastFloat(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
994 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
995 const llvm::Type* tolltype = DtoType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
996
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
997 Type* totype = DtoDType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
998 Type* fromtype = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
999 assert(fromtype->isfloating());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1000
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1001 size_t fromsz = fromtype->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1002 size_t tosz = totype->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1003
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1004 llvm::Value* rval;
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1005
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1006 if (totype->isfloating()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1007 if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1008 rval = val->getRVal();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1009 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1010 else if (fromsz < tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1011 rval = new llvm::FPExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1012 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1013 else if (fromsz > tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1014 rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1015 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1016 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1017 assert(0 && "bad float cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1018 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1019 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1020 else if (totype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1021 if (totype->isunsigned()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1022 rval = new llvm::FPToUIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1023 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1024 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1025 rval = new llvm::FPToSIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1026 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1027 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1028 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1029 assert(0 && "bad float cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1030 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1031
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1032 return new DImValue(to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1033 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1034
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1035 DValue* DtoCastClass(DValue* val, Type* _to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1036 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1037 const llvm::Type* tolltype = DtoType(_to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1038 Type* to = DtoDType(_to);
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1039 assert(to->ty == Tclass || to->ty == Tpointer);
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1040 llvm::Value* rval = new llvm::BitCastInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1041 return new DImValue(_to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1042 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1043
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1044 DValue* DtoCast(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1045 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1046 Type* fromtype = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1047 if (fromtype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1048 return DtoCastInt(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1049 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1050 else if (fromtype->isfloating()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1051 return DtoCastFloat(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1052 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1053 else if (fromtype->ty == Tclass) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1054 return DtoCastClass(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1055 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1056 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1057 return DtoCastArray(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1058 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1059 else if (fromtype->ty == Tpointer) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1060 return DtoCastPtr(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1061 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1062 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1063 assert(0);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1064 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1065 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1066
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1067 //////////////////////////////////////////////////////////////////////////////////////////
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1068
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1069 llvm::ConstantInt* DtoConstSize_t(size_t i)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1070 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1071 return llvm::ConstantInt::get(DtoSize_t(), i, false);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1072 }
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1073 llvm::ConstantInt* DtoConstUint(unsigned i)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1074 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1075 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1076 }
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1077 llvm::ConstantInt* DtoConstInt(int i)
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1078 {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1079 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, 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
1080 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1081 llvm::Constant* DtoConstBool(bool b)
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1082 {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1083 return llvm::ConstantInt::get(llvm::Type::Int1Ty, b, 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
1084 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1085
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1086 //////////////////////////////////////////////////////////////////////////////////////////
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1087
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1088 llvm::Constant* DtoConstString(const char* str)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1089 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1090 std::string s(str);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1091 llvm::Constant* init = llvm::ConstantArray::get(s, true);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1092 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1093 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1094 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1095 return DtoConstSlice(
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1096 DtoConstSize_t(s.length()),
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1097 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1098 );
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1099 }
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
1100 llvm::Constant* DtoConstStringPtr(const char* str, const char* section)
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
1101 {
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
1102 std::string s(str);
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
1103 llvm::Constant* init = llvm::ConstantArray::get(s, true);
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
1104 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
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
1105 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
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
1106 if (section) gvar->setSection(section);
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
1107 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
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
1108 return llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
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
1109 }
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1110
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1111 //////////////////////////////////////////////////////////////////////////////////////////
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1112
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1113 llvm::Constant* DtoConstNullPtr(const llvm::Type* t)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1114 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1115 return llvm::ConstantPointerNull::get(
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1116 llvm::PointerType::get(t)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1117 );
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1118 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1119
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1120 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1121
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1122 void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1123 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1124 assert(dst->getType() == src->getType());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1125
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1126 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1127 llvm::Value *dstarr, *srcarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1128 if (dst->getType() == arrty)
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1129 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1130 dstarr = dst;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1131 srcarr = src;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1132 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1133 else
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1134 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1135 dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1136 srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1137 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1138
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1139 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1140 std::vector<llvm::Value*> llargs;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1141 llargs.resize(4);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1142 llargs[0] = dstarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1143 llargs[1] = srcarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1144 llargs[2] = nbytes;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1145 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1146
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1147 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1148 }
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1149
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1150 //////////////////////////////////////////////////////////////////////////////////////////
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1151
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1152 llvm::Value* DtoLoad(llvm::Value* src)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1153 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1154 return gIR->ir->CreateLoad(src,"tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1155 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1156
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1157 void DtoStore(llvm::Value* src, llvm::Value* dst)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1158 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1159 gIR->ir->CreateStore(src,dst);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1160 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1161
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1162 bool DtoCanLoad(llvm::Value* ptr)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1163 {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1164 if (isaPointer(ptr->getType())) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1165 return ptr->getType()->getContainedType(0)->isFirstClassType();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1166 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1167 return false;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1168 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1169
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1170 llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1171 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1172 if (v->getType() == t)
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1173 return v;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1174 return gIR->ir->CreateBitCast(v, t, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1175 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1176
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1177 const llvm::PointerType* isaPointer(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1178 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1179 return llvm::dyn_cast<llvm::PointerType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1180 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1181
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1182 const llvm::PointerType* isaPointer(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1183 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1184 return llvm::dyn_cast<llvm::PointerType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1185 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1186
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1187 const llvm::ArrayType* isaArray(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1188 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1189 return llvm::dyn_cast<llvm::ArrayType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1190 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1191
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1192 const llvm::ArrayType* isaArray(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1193 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1194 return llvm::dyn_cast<llvm::ArrayType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1195 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1196
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1197 const llvm::StructType* isaStruct(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1198 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1199 return llvm::dyn_cast<llvm::StructType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1200 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1201
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1202 const llvm::StructType* isaStruct(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1203 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1204 return llvm::dyn_cast<llvm::StructType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1205 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1206
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1207 llvm::Constant* isaConstant(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1208 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1209 return llvm::dyn_cast<llvm::Constant>(v);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1210 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1211
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1212 llvm::ConstantInt* isaConstantInt(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1213 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1214 return llvm::dyn_cast<llvm::ConstantInt>(v);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1215 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1216
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1217 llvm::Argument* isaArgument(llvm::Value* v)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1218 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1219 return llvm::dyn_cast<llvm::Argument>(v);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1220 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1221
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1222 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1223
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1224 bool DtoIsTemplateInstance(Dsymbol* s)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1225 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1226 if (!s) return false;
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1227 if (s->isTemplateInstance() && !s->isTemplateMixin())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1228 return true;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1229 else if (s->parent)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1230 return DtoIsTemplateInstance(s->parent);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1231 return false;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1232 }
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1233
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1234 //////////////////////////////////////////////////////////////////////////////////////////
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1235
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1236 void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1237 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1238 // create a flag to make sure initialization only happens once
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1239 llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1240 std::string gflagname(gvar->getName());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1241 gflagname.append("__initflag");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1242 llvm::GlobalVariable* gflag = new llvm::GlobalVariable(llvm::Type::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1243
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1244 // check flag and do init if not already done
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1245 llvm::BasicBlock* oldend = gIR->scopeend();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1246 llvm::BasicBlock* initbb = new llvm::BasicBlock("ifnotinit",gIR->topfunc(),oldend);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1247 llvm::BasicBlock* endinitbb = new llvm::BasicBlock("ifnotinitend",gIR->topfunc(),oldend);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1248 llvm::Value* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false));
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1249 gIR->ir->CreateCondBr(cond, initbb, endinitbb);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1250 gIR->scope() = IRScope(initbb,endinitbb);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1251 DValue* ie = DtoInitializer(init);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1252 if (!ie->inPlace()) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1253 DValue* dst = new DVarValue(t, gvar, true);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1254 DtoAssign(dst, ie);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1255 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1256 gIR->ir->CreateStore(DtoConstBool(true), gflag);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1257 gIR->ir->CreateBr(endinitbb);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1258 gIR->scope() = IRScope(endinitbb,oldend);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1259 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1260
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1261 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1262
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1263 void DtoResolveDsymbol(Dsymbol* dsym)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1264 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1265 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1266 DtoResolveStruct(sd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1267 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1268 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1269 DtoResolveClass(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1270 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1271 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1272 DtoResolveFunction(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1273 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1274 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1275 DtoResolveTypeInfo(fd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1276 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1277 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1278 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1279 assert(0 && "unsupported dsymbol for DtoResolveDsymbol");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1280 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1281 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1282
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1283 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1284
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1285 void DtoDeclareDsymbol(Dsymbol* dsym)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1286 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1287 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1288 DtoDeclareStruct(sd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1289 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1290 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1291 DtoDeclareClass(cd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1292 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1293 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1294 DtoDeclareFunction(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1295 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1296 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1297 DtoDeclareTypeInfo(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1298 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1299 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1300 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1301 assert(0 && "unsupported dsymbol for DtoDeclareDsymbol");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1302 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1303 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1304
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1305 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1306
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1307 void DtoConstInitDsymbol(Dsymbol* dsym)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1308 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1309 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1310 DtoConstInitStruct(sd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1311 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1312 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1313 DtoConstInitClass(cd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1314 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1315 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1316 DtoConstInitTypeInfo(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1317 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1318 else if (VarDeclaration* vd = dsym->isVarDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1319 DtoConstInitGlobal(vd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1320 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1321 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1322 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1323 assert(0 && "unsupported dsymbol for DtoConstInitDsymbol");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1324 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1325 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1326
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1327 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1328
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1329 void DtoDefineDsymbol(Dsymbol* dsym)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1330 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1331 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1332 DtoDefineStruct(sd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1333 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1334 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1335 DtoDefineClass(cd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1336 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1337 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1338 DtoDefineFunc(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1339 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1340 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1341 DtoDefineTypeInfo(fd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1342 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1343 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1344 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1345 assert(0 && "unsupported dsymbol for DtoDefineDsymbol");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1346 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1347 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1348
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1349 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1350
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1351 void DtoConstInitGlobal(VarDeclaration* vd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1352 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1353 if (vd->llvmInitialized) return;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1354 vd->llvmInitialized = gIR->dmodule;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1355
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1356 Logger::println("* DtoConstInitGlobal(%s)", vd->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1357 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1358
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1359 bool emitRTstaticInit = false;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1360
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1361 llvm::Constant* _init = 0;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1362 if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1363 _init = DtoConstInitializer(vd->type, NULL);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1364 emitRTstaticInit = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1365 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1366 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1367 _init = DtoConstInitializer(vd->type, vd->init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1368 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1369
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1370 const llvm::Type* _type = DtoType(vd->type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1371 Type* t = DtoDType(vd->type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1372
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1373 //Logger::cout() << "initializer: " << *_init << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1374 if (_type != _init->getType()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1375 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n";
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1376 // zero initalizer
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1377 if (_init->isNullValue())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1378 _init = llvm::Constant::getNullValue(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1379 // pointer to global constant (struct.init)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1380 else if (llvm::isa<llvm::GlobalVariable>(_init))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1381 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1382 assert(_init->getType()->getContainedType(0) == _type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1383 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1384 assert(t->ty == Tstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1385 TypeStruct* ts = (TypeStruct*)t;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1386 assert(ts->sym->llvmInitZ);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1387 _init = ts->sym->llvmInitZ;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1388 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1389 // array single value init
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1390 else if (isaArray(_type))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1391 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1392 _init = DtoConstStaticArray(_type, _init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1393 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1394 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1395 Logger::cout() << "Unexpected initializer type: " << *_type << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1396 //assert(0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1397 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1398 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1399
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1400 bool istempl = false;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1401 if ((vd->storage_class & STCcomdat) || (vd->parent && DtoIsTemplateInstance(vd->parent))) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1402 istempl = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1403 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1404
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1405 if (_init && _init->getType() != _type)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1406 _type = _init->getType();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1407 llvm::cast<llvm::OpaqueType>(vd->llvmIRGlobal->type.get())->refineAbstractTypeTo(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1408 _type = vd->llvmIRGlobal->type.get();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1409 assert(!_type->isAbstract());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1410
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1411 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->llvmValue);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1412 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1413 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1414 gvar->setInitializer(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1415 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1416
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1417 if (emitRTstaticInit)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1418 DtoLazyStaticInit(istempl, gvar, vd->init, t);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1419 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1420
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1421 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1422
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1423 void DtoEmptyResolveList()
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1424 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1425 //Logger::println("DtoEmptyResolveList()");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1426 Dsymbol* dsym;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1427 while (!gIR->resolveList.empty()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1428 dsym = gIR->resolveList.front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1429 gIR->resolveList.pop_front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1430 DtoResolveDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1431 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1432 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1433
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1434 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1435
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1436 void DtoEmptyDeclareList()
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1437 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1438 //Logger::println("DtoEmptyDeclareList()");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1439 Dsymbol* dsym;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1440 while (!gIR->declareList.empty()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1441 dsym = gIR->declareList.front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1442 gIR->declareList.pop_front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1443 DtoDeclareDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1444 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1445 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1446
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1447 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1448
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1449 void DtoEmptyConstInitList()
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1450 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1451 //Logger::println("DtoEmptyConstInitList()");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1452 Dsymbol* dsym;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1453 while (!gIR->constInitList.empty()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1454 dsym = gIR->constInitList.front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1455 gIR->constInitList.pop_front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1456 DtoConstInitDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1457 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1458 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1459
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1460 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1461
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1462 void DtoEmptyDefineList()
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1463 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1464 //Logger::println("DtoEmptyDefineList()");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1465 Dsymbol* dsym;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1466 while (!gIR->defineList.empty()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1467 dsym = gIR->defineList.front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1468 gIR->defineList.pop_front();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1469 DtoDefineDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1470 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1471 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1472
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1473 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1474
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1475 void DtoForceDeclareDsymbol(Dsymbol* dsym)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1476 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1477 if (dsym->llvmDeclared) return;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1478 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1479 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1480 DtoResolveDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1481
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1482 DtoEmptyResolveList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1483
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1484 DtoDeclareDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1485 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1486
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1487 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1488
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1489 void DtoForceConstInitDsymbol(Dsymbol* dsym)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1490 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1491 if (dsym->llvmInitialized) return;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1492 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1493 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1494 DtoResolveDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1495
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1496 DtoEmptyResolveList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1497 DtoEmptyDeclareList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1498
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1499 DtoConstInitDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1500 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1501
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1502 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1503
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1504 void DtoForceDefineDsymbol(Dsymbol* dsym)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1505 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1506 if (dsym->llvmDefined) return;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1507 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toChars());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1508 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1509 DtoResolveDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1510
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1511 DtoEmptyResolveList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1512 DtoEmptyDeclareList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1513 DtoEmptyConstInitList();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1514
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1515 DtoDefineDsymbol(dsym);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1516 }