Mercurial > projects > ldc
comparison ir/irtype.cpp @ 1228:79758fd2f48a
Added Doxygen file.
Completely seperated type and symbol generation. Should fix a lot of bugs, but is not yet 100% complete.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Wed, 15 Apr 2009 20:06:25 +0200 |
parents | 3251ce06c820 |
children | 46f6365a50d7 |
comparison
equal
deleted
inserted
replaced
1215:08f87d8cd101 | 1228:79758fd2f48a |
---|---|
1 #include "llvm/DerivedTypes.h" | 1 #include "llvm/DerivedTypes.h" |
2 #include "ir/irtype.h" | |
3 | |
4 #include "mars.h" | 2 #include "mars.h" |
5 #include "mtype.h" | 3 #include "mtype.h" |
4 #include "gen/irstate.h" | |
5 #include "gen/logger.h" | |
6 #include "ir/irtype.h" | |
7 | |
8 ////////////////////////////////////////////////////////////////////////////// | |
9 | |
10 extern const llvm::Type* DtoType(Type* dt); | |
11 extern const llvm::Type* DtoSize_t(); | |
12 | |
13 ////////////////////////////////////////////////////////////////////////////// | |
6 | 14 |
7 IrType::IrType(Type* dt, const llvm::Type* lt) | 15 IrType::IrType(Type* dt, const llvm::Type* lt) |
8 : dtype(dt), | 16 : dtype(dt), |
9 pa(lt) | 17 pa(lt) |
10 { | 18 { |
11 assert(dt && "null D Type"); | 19 assert(dt && "null D Type"); |
12 assert(lt && "null LLVM Type"); | 20 assert(lt && "null LLVM Type"); |
21 assert(dt->ir.type == NULL && "llvm type (old one) already set"); | |
22 dt->ir.type = &pa; | |
13 } | 23 } |
14 | 24 |
15 ////////////////////////////////////////////////////////////////////////////// | 25 ////////////////////////////////////////////////////////////////////////////// |
16 ////////////////////////////////////////////////////////////////////////////// | 26 ////////////////////////////////////////////////////////////////////////////// |
17 ////////////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////////////// |
18 | 28 |
19 IrTypeBasic::IrTypeBasic(Type * dt) | 29 IrTypeBasic::IrTypeBasic(Type * dt) |
20 : IrType(dt, basic2llvm(dt)) | 30 : IrType(dt, basic2llvm(dt)) |
21 { | 31 { |
32 } | |
33 | |
34 ////////////////////////////////////////////////////////////////////////////// | |
35 | |
36 const llvm::Type * IrTypeBasic::buildType() | |
37 { | |
38 return pa.get(); | |
22 } | 39 } |
23 | 40 |
24 ////////////////////////////////////////////////////////////////////////////// | 41 ////////////////////////////////////////////////////////////////////////////// |
25 | 42 |
26 const llvm::Type * IrTypeBasic::basic2llvm(Type* t) | 43 const llvm::Type * IrTypeBasic::basic2llvm(Type* t) |
99 ////////////////////////////////////////////////////////////////////////////// | 116 ////////////////////////////////////////////////////////////////////////////// |
100 ////////////////////////////////////////////////////////////////////////////// | 117 ////////////////////////////////////////////////////////////////////////////// |
101 ////////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////////// |
102 | 119 |
103 IrTypePointer::IrTypePointer(Type * dt) | 120 IrTypePointer::IrTypePointer(Type * dt) |
104 : IrType(dt, pointer2llvm(dt)) | 121 : IrType(dt, llvm::OpaqueType::get()) |
105 { | 122 { |
106 } | 123 } |
107 | 124 |
108 ////////////////////////////////////////////////////////////////////////////// | 125 ////////////////////////////////////////////////////////////////////////////// |
109 | 126 |
110 extern const llvm::Type* DtoType(Type* dt); | 127 const llvm::Type * IrTypePointer::buildType() |
111 | 128 { |
112 const llvm::Type * IrTypePointer::pointer2llvm(Type * t) | 129 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo( |
113 { | 130 pointer2llvm(dtype)); |
114 assert(t->ty == Tpointer && "not pointer type"); | 131 return pa.get(); |
115 | 132 } |
116 const llvm::Type* elemType = DtoType(t->nextOf()); | 133 |
134 ////////////////////////////////////////////////////////////////////////////// | |
135 | |
136 const llvm::Type * IrTypePointer::pointer2llvm(Type * dt) | |
137 { | |
138 assert(dt->ty == Tpointer && "not pointer type"); | |
139 | |
140 const llvm::Type* elemType = DtoType(dt->nextOf()); | |
117 if (elemType == llvm::Type::VoidTy) | 141 if (elemType == llvm::Type::VoidTy) |
118 elemType = llvm::Type::Int8Ty; | 142 elemType = llvm::Type::Int8Ty; |
119 return llvm::PointerType::get(elemType, 0); | 143 return llvm::PointerType::get(elemType, 0); |
120 } | 144 } |
121 | 145 |
122 ////////////////////////////////////////////////////////////////////////////// | 146 ////////////////////////////////////////////////////////////////////////////// |
123 ////////////////////////////////////////////////////////////////////////////// | 147 ////////////////////////////////////////////////////////////////////////////// |
124 ////////////////////////////////////////////////////////////////////////////// | 148 ////////////////////////////////////////////////////////////////////////////// |
125 | 149 |
126 IrTypeSArray::IrTypeSArray(Type * dt) | 150 IrTypeSArray::IrTypeSArray(Type * dt) |
127 : IrType(dt, sarray2llvm(dt)) | 151 : IrType(dt, llvm::OpaqueType::get()) |
128 { | 152 { |
153 assert(dt->ty == Tsarray && "not static array type"); | |
129 TypeSArray* tsa = (TypeSArray*)dt; | 154 TypeSArray* tsa = (TypeSArray*)dt; |
130 uint64_t d = (uint64_t)tsa->dim->toUInteger(); | 155 dim = (uint64_t)tsa->dim->toUInteger(); |
131 assert(d == dim); | 156 } |
157 | |
158 ////////////////////////////////////////////////////////////////////////////// | |
159 | |
160 const llvm::Type * IrTypeSArray::buildType() | |
161 { | |
162 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo( | |
163 sarray2llvm(dtype)); | |
164 return pa.get(); | |
132 } | 165 } |
133 | 166 |
134 ////////////////////////////////////////////////////////////////////////////// | 167 ////////////////////////////////////////////////////////////////////////////// |
135 | 168 |
136 const llvm::Type * IrTypeSArray::sarray2llvm(Type * t) | 169 const llvm::Type * IrTypeSArray::sarray2llvm(Type * t) |
137 { | 170 { |
138 assert(t->ty == Tsarray && "not static array type"); | |
139 | |
140 TypeSArray* tsa = (TypeSArray*)t; | |
141 dim = (uint64_t)tsa->dim->toUInteger(); | |
142 const llvm::Type* elemType = DtoType(t->nextOf()); | 171 const llvm::Type* elemType = DtoType(t->nextOf()); |
143 if (elemType == llvm::Type::VoidTy) | 172 if (elemType == llvm::Type::VoidTy) |
144 elemType = llvm::Type::Int8Ty; | 173 elemType = llvm::Type::Int8Ty; |
145 return llvm::ArrayType::get(elemType, dim); | 174 return llvm::ArrayType::get(elemType, dim); |
146 } | 175 } |
148 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
149 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
150 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
151 | 180 |
152 IrTypeArray::IrTypeArray(Type * dt) | 181 IrTypeArray::IrTypeArray(Type * dt) |
153 : IrType(dt, array2llvm(dt)) | 182 : IrType(dt, llvm::OpaqueType::get()) |
154 { | 183 { |
155 } | 184 } |
156 | 185 |
157 ////////////////////////////////////////////////////////////////////////////// | 186 ////////////////////////////////////////////////////////////////////////////// |
158 | 187 |
159 extern const llvm::Type* DtoSize_t(); | 188 const llvm::Type * IrTypeArray::buildType() |
189 { | |
190 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo( | |
191 array2llvm(dtype)); | |
192 return pa.get(); | |
193 } | |
194 | |
195 ////////////////////////////////////////////////////////////////////////////// | |
160 | 196 |
161 const llvm::Type * IrTypeArray::array2llvm(Type * t) | 197 const llvm::Type * IrTypeArray::array2llvm(Type * t) |
162 { | 198 { |
163 assert(t->ty == Tarray && "not dynamic array type"); | 199 assert(t->ty == Tarray && "not dynamic array type"); |
164 | 200 |
201 // get .ptr type | |
165 const llvm::Type* elemType = DtoType(t->nextOf()); | 202 const llvm::Type* elemType = DtoType(t->nextOf()); |
166 if (elemType == llvm::Type::VoidTy) | 203 if (elemType == llvm::Type::VoidTy) |
167 elemType = llvm::Type::Int8Ty; | 204 elemType = llvm::Type::Int8Ty; |
168 elemType = llvm::PointerType::get(elemType, 0); | 205 elemType = llvm::PointerType::get(elemType, 0); |
169 return llvm::StructType::get(DtoSize_t(), elemType, NULL); | 206 |
170 } | 207 // create struct type |
171 | 208 const llvm::Type* at = llvm::StructType::get(DtoSize_t(), elemType, NULL); |
172 ////////////////////////////////////////////////////////////////////////////// | 209 |
173 | 210 // name dynamic array types |
211 Type::sir->getState()->module->addTypeName(t->toChars(), at); | |
212 | |
213 return at; | |
214 } | |
215 | |
216 ////////////////////////////////////////////////////////////////////////////// | |
217 |