Mercurial > projects > ldc
comparison ir/irtype.cpp @ 1571:8d086d552909
IntegerType is now contextifed.
Requires llvm >= 78969. resistor says this will be the last context API change :)
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Fri, 14 Aug 2009 00:39:18 +0200 |
parents | 755abafbf25d |
children | 40bd4a0d4870 |
comparison
equal
deleted
inserted
replaced
1570:ab03cfb3a212 | 1571:8d086d552909 |
---|---|
41 | 41 |
42 const llvm::Type * IrTypeBasic::basic2llvm(Type* t) | 42 const llvm::Type * IrTypeBasic::basic2llvm(Type* t) |
43 { | 43 { |
44 const llvm::Type* t2; | 44 const llvm::Type* t2; |
45 | 45 |
46 // FIXME: don't use getGlobalContext | |
46 switch(t->ty) | 47 switch(t->ty) |
47 { | 48 { |
48 case Tvoid: | 49 case Tvoid: |
49 return llvm::Type::VoidTy; | 50 return llvm::Type::getVoidTy(llvm::getGlobalContext()); |
50 | 51 |
51 case Tint8: | 52 case Tint8: |
52 case Tuns8: | 53 case Tuns8: |
53 case Tchar: | 54 case Tchar: |
54 return llvm::Type::Int8Ty; | 55 return llvm::Type::getInt8Ty(llvm::getGlobalContext()); |
55 | 56 |
56 case Tint16: | 57 case Tint16: |
57 case Tuns16: | 58 case Tuns16: |
58 case Twchar: | 59 case Twchar: |
59 return llvm::Type::Int16Ty; | 60 return llvm::Type::getInt16Ty(llvm::getGlobalContext()); |
60 | 61 |
61 case Tint32: | 62 case Tint32: |
62 case Tuns32: | 63 case Tuns32: |
63 case Tdchar: | 64 case Tdchar: |
64 return llvm::Type::Int32Ty; | 65 return llvm::Type::getInt32Ty(llvm::getGlobalContext()); |
65 | 66 |
66 case Tint64: | 67 case Tint64: |
67 case Tuns64: | 68 case Tuns64: |
68 return llvm::Type::Int64Ty; | 69 return llvm::Type::getInt64Ty(llvm::getGlobalContext()); |
69 | 70 |
70 /* | 71 /* |
71 case Tint128: | 72 case Tint128: |
72 case Tuns128: | 73 case Tuns128: |
73 return llvm::IntegerType::get(128); | 74 return llvm::IntegerType::get(llvm::getGlobalContext(), 128); |
74 */ | 75 */ |
75 | 76 |
76 case Tfloat32: | 77 case Tfloat32: |
77 case Timaginary32: | 78 case Timaginary32: |
78 return llvm::Type::FloatTy; | 79 return llvm::Type::getFloatTy(llvm::getGlobalContext()); |
79 | 80 |
80 case Tfloat64: | 81 case Tfloat64: |
81 case Timaginary64: | 82 case Timaginary64: |
82 return llvm::Type::DoubleTy; | 83 return llvm::Type::getDoubleTy(llvm::getGlobalContext()); |
83 | 84 |
84 case Tfloat80: | 85 case Tfloat80: |
85 case Timaginary80: | 86 case Timaginary80: |
86 // only x86 has 80bit float | 87 // only x86 has 80bit float |
87 if (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64) | 88 if (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64) |
88 return llvm::Type::X86_FP80Ty; | 89 return llvm::Type::getX86_FP80Ty(llvm::getGlobalContext()); |
89 // other platforms use 64bit reals | 90 // other platforms use 64bit reals |
90 else | 91 else |
91 return llvm::Type::DoubleTy; | 92 return llvm::Type::getDoubleTy(llvm::getGlobalContext()); |
92 | 93 |
93 case Tcomplex32: | 94 case Tcomplex32: |
94 t2 = llvm::Type::FloatTy; | 95 t2 = llvm::Type::getFloatTy(llvm::getGlobalContext()); |
95 return llvm::StructType::get(gIR->context(), t2, t2, NULL); | 96 return llvm::StructType::get(llvm::getGlobalContext(), t2, t2, NULL); |
96 | 97 |
97 case Tcomplex64: | 98 case Tcomplex64: |
98 t2 = llvm::Type::DoubleTy; | 99 t2 = llvm::Type::getDoubleTy(llvm::getGlobalContext()); |
99 return llvm::StructType::get(gIR->context(), t2, t2, NULL); | 100 return llvm::StructType::get(llvm::getGlobalContext(), t2, t2, NULL); |
100 | 101 |
101 case Tcomplex80: | 102 case Tcomplex80: |
102 t2 = (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64) | 103 t2 = (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64) |
103 ? llvm::Type::X86_FP80Ty | 104 ? llvm::Type::getX86_FP80Ty(llvm::getGlobalContext()) |
104 : llvm::Type::DoubleTy; | 105 : llvm::Type::getDoubleTy(llvm::getGlobalContext()); |
105 return llvm::StructType::get(gIR->context(), t2, t2, NULL); | 106 return llvm::StructType::get(llvm::getGlobalContext(), t2, t2, NULL); |
106 | 107 |
107 case Tbool: | 108 case Tbool: |
108 return llvm::Type::Int1Ty; | 109 return llvm::Type::getInt1Ty(llvm::getGlobalContext()); |
109 } | 110 } |
110 | 111 |
111 assert(0 && "not basic type"); | 112 assert(0 && "not basic type"); |
112 return NULL; | 113 return NULL; |
113 } | 114 } |
115 ////////////////////////////////////////////////////////////////////////////// | 116 ////////////////////////////////////////////////////////////////////////////// |
116 ////////////////////////////////////////////////////////////////////////////// | 117 ////////////////////////////////////////////////////////////////////////////// |
117 ////////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////////// |
118 | 119 |
119 IrTypePointer::IrTypePointer(Type * dt) | 120 IrTypePointer::IrTypePointer(Type * dt) |
120 : IrType(dt, llvm::OpaqueType::get()) | 121 : IrType(dt, llvm::OpaqueType::get(llvm::getGlobalContext())) |
121 { | 122 { |
122 } | 123 } |
123 | 124 |
124 ////////////////////////////////////////////////////////////////////////////// | 125 ////////////////////////////////////////////////////////////////////////////// |
125 | 126 |
135 const llvm::Type * IrTypePointer::pointer2llvm(Type * dt) | 136 const llvm::Type * IrTypePointer::pointer2llvm(Type * dt) |
136 { | 137 { |
137 assert(dt->ty == Tpointer && "not pointer type"); | 138 assert(dt->ty == Tpointer && "not pointer type"); |
138 | 139 |
139 const llvm::Type* elemType = DtoType(dt->nextOf()); | 140 const llvm::Type* elemType = DtoType(dt->nextOf()); |
140 if (elemType == llvm::Type::VoidTy) | 141 if (elemType == llvm::Type::getVoidTy(llvm::getGlobalContext())) |
141 elemType = llvm::Type::Int8Ty; | 142 elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext()); |
142 return llvm::PointerType::get(elemType, 0); | 143 return llvm::PointerType::get(elemType, 0); |
143 } | 144 } |
144 | 145 |
145 ////////////////////////////////////////////////////////////////////////////// | 146 ////////////////////////////////////////////////////////////////////////////// |
146 ////////////////////////////////////////////////////////////////////////////// | 147 ////////////////////////////////////////////////////////////////////////////// |
147 ////////////////////////////////////////////////////////////////////////////// | 148 ////////////////////////////////////////////////////////////////////////////// |
148 | 149 |
149 IrTypeSArray::IrTypeSArray(Type * dt) | 150 IrTypeSArray::IrTypeSArray(Type * dt) |
150 : IrType(dt, llvm::OpaqueType::get()) | 151 : IrType(dt, llvm::OpaqueType::get(llvm::getGlobalContext())) |
151 { | 152 { |
152 assert(dt->ty == Tsarray && "not static array type"); | 153 assert(dt->ty == Tsarray && "not static array type"); |
153 TypeSArray* tsa = (TypeSArray*)dt; | 154 TypeSArray* tsa = (TypeSArray*)dt; |
154 dim = (uint64_t)tsa->dim->toUInteger(); | 155 dim = (uint64_t)tsa->dim->toUInteger(); |
155 } | 156 } |
166 ////////////////////////////////////////////////////////////////////////////// | 167 ////////////////////////////////////////////////////////////////////////////// |
167 | 168 |
168 const llvm::Type * IrTypeSArray::sarray2llvm(Type * t) | 169 const llvm::Type * IrTypeSArray::sarray2llvm(Type * t) |
169 { | 170 { |
170 const llvm::Type* elemType = DtoType(t->nextOf()); | 171 const llvm::Type* elemType = DtoType(t->nextOf()); |
171 if (elemType == llvm::Type::VoidTy) | 172 if (elemType == llvm::Type::getVoidTy(llvm::getGlobalContext())) |
172 elemType = llvm::Type::Int8Ty; | 173 elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext()); |
173 return llvm::ArrayType::get(elemType, dim); | 174 return llvm::ArrayType::get(elemType, dim); |
174 } | 175 } |
175 | 176 |
176 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
177 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
178 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
179 | 180 |
180 IrTypeArray::IrTypeArray(Type * dt) | 181 IrTypeArray::IrTypeArray(Type * dt) |
181 : IrType(dt, llvm::OpaqueType::get()) | 182 : IrType(dt, llvm::OpaqueType::get(llvm::getGlobalContext())) |
182 { | 183 { |
183 } | 184 } |
184 | 185 |
185 ////////////////////////////////////////////////////////////////////////////// | 186 ////////////////////////////////////////////////////////////////////////////// |
186 | 187 |
197 { | 198 { |
198 assert(t->ty == Tarray && "not dynamic array type"); | 199 assert(t->ty == Tarray && "not dynamic array type"); |
199 | 200 |
200 // get .ptr type | 201 // get .ptr type |
201 const llvm::Type* elemType = DtoType(t->nextOf()); | 202 const llvm::Type* elemType = DtoType(t->nextOf()); |
202 if (elemType == llvm::Type::VoidTy) | 203 if (elemType == llvm::Type::getVoidTy(llvm::getGlobalContext())) |
203 elemType = llvm::Type::Int8Ty; | 204 elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext()); |
204 elemType = llvm::PointerType::get(elemType, 0); | 205 elemType = llvm::PointerType::get(elemType, 0); |
205 | 206 |
206 // create struct type | 207 // create struct type |
207 const llvm::Type* at = llvm::StructType::get(gIR->context(), DtoSize_t(), elemType, NULL); | 208 const llvm::Type* at = llvm::StructType::get(llvm::getGlobalContext(), DtoSize_t(), elemType, NULL); |
208 | 209 |
209 // name dynamic array types | 210 // name dynamic array types |
210 Type::sir->getState()->module->addTypeName(t->toChars(), at); | 211 Type::sir->getState()->module->addTypeName(t->toChars(), at); |
211 | 212 |
212 return at; | 213 return at; |