@@ -38,6 +38,7 @@ pub struct FuncSig<'gcc> {
38
38
39
39
pub struct IntType < ' gcc > {
40
40
bits : u8 ,
41
+ element_size : u8 ,
41
42
typ : Type < ' gcc > ,
42
43
signed : bool ,
43
44
}
@@ -79,6 +80,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
79
80
pub sizet_type : Type < ' gcc > ,
80
81
81
82
pub native_int_types : Vec < IntType < ' gcc > > ,
83
+ pub non_native_int_types : Vec < IntType < ' gcc > > ,
82
84
83
85
pub float_type : Type < ' gcc > ,
84
86
pub double_type : Type < ' gcc > ,
@@ -141,9 +143,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
141
143
let u32_type = context. new_c_type ( CType :: UInt32t ) ;
142
144
let u64_type = context. new_c_type ( CType :: UInt64t ) ;
143
145
144
- let field1 = context. new_field ( None , u64_type, "high" ) ;
145
- let field2 = context. new_field ( None , u64_type, "low" ) ;
146
- let u128_type = context. new_struct_type ( None , "u128" , & [ field1, field2] ) . as_type ( ) ;
146
+ let u128_type = context. new_array_type ( None , u64_type, 2 ) ;
147
147
//let u128_type = context.new_c_type(CType::UInt128t).get_aligned(8); // TODO(antoyo): should the alignment be hard-coded?
148
148
149
149
let tls_model = to_gcc_tls_mode ( tcx. sess . tls_model ( ) ) ;
@@ -158,52 +158,87 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
158
158
let ulonglong_type = context. new_c_type ( CType :: ULongLong ) ;
159
159
let sizet_type = context. new_c_type ( CType :: SizeT ) ;
160
160
161
+ let mut non_native_int_types = vec ! [ ] ;
162
+
163
+ non_native_int_types. push ( IntType {
164
+ bits : 128 ,
165
+ element_size : 64 ,
166
+ signed : false ,
167
+ typ : u128_type,
168
+ } ) ;
169
+
161
170
let mut native_int_types = vec ! [ ] ;
162
171
163
172
native_int_types. push ( IntType {
164
173
bits : 64 ,
174
+ element_size : 64 ,
165
175
signed : false ,
166
176
typ : u64_type,
167
177
} ) ;
168
178
native_int_types. push ( IntType {
169
179
bits : 64 ,
180
+ element_size : 64 ,
170
181
signed : true ,
171
182
typ : i64_type,
172
183
} ) ;
173
184
174
185
native_int_types. push ( IntType {
175
186
bits : 32 ,
187
+ element_size : 32 ,
176
188
signed : false ,
177
189
typ : u32_type,
178
190
} ) ;
179
191
native_int_types. push ( IntType {
180
192
bits : 32 ,
193
+ element_size : 32 ,
181
194
signed : true ,
182
195
typ : i32_type,
183
196
} ) ;
184
197
185
198
native_int_types. push ( IntType {
186
199
bits : 16 ,
200
+ element_size : 16 ,
187
201
signed : false ,
188
202
typ : u16_type,
189
203
} ) ;
190
204
native_int_types. push ( IntType {
191
205
bits : 16 ,
206
+ element_size : 16 ,
192
207
signed : true ,
193
208
typ : i16_type,
194
209
} ) ;
195
210
196
211
native_int_types. push ( IntType {
197
212
bits : 8 ,
213
+ element_size : 8 ,
198
214
signed : false ,
199
215
typ : u8_type,
200
216
} ) ;
201
217
native_int_types. push ( IntType {
202
218
bits : 8 ,
219
+ element_size : 8 ,
203
220
signed : true ,
204
221
typ : i8_type,
205
222
} ) ;
206
223
224
+ let mut new_native_int_types = vec ! [ ] ;
225
+ let int_types = [ isize_type, usize_type, int_type, uint_type, long_type, ulong_type, ulonglong_type, sizet_type] ;
226
+ for int_type in int_types {
227
+ for native_int_type in & native_int_types {
228
+ if int_type. is_compatible_with ( native_int_type. typ ) {
229
+ new_native_int_types. push ( IntType {
230
+ bits : native_int_type. bits ,
231
+ element_size : native_int_type. element_size ,
232
+ signed : native_int_type. signed ,
233
+ typ : int_type,
234
+ } ) ;
235
+ break ;
236
+ }
237
+ }
238
+ }
239
+
240
+ native_int_types. extend ( new_native_int_types) ;
241
+
207
242
// TODO(antoyo): only have those assertions on x86_64.
208
243
assert_eq ! ( isize_type. get_size( ) , i64_type. get_size( ) ) ;
209
244
assert_eq ! ( usize_type. get_size( ) , u64_type. get_size( ) ) ;
@@ -257,6 +292,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
257
292
sizet_type,
258
293
259
294
native_int_types,
295
+ non_native_int_types,
260
296
261
297
float_type,
262
298
double_type,
@@ -290,13 +326,43 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
290
326
291
327
pub fn supports_native_int_type ( & self , typ : Type < ' gcc > ) -> bool {
292
328
for native_type in & self . native_int_types {
293
- if native_type. typ == typ {
329
+ if native_type. typ . is_compatible_with ( typ) {
294
330
return true ;
295
331
}
296
332
}
297
333
false
298
334
}
299
335
336
+ pub fn int_type_size ( & self , typ : Type < ' gcc > ) -> u8 {
337
+ for native_type in & self . native_int_types {
338
+ if native_type. typ . is_compatible_with ( typ) {
339
+ return native_type. bits ;
340
+ }
341
+ }
342
+ for non_native_type in & self . non_native_int_types {
343
+ if non_native_type. typ . is_compatible_with ( typ) {
344
+ return non_native_type. bits ;
345
+ }
346
+ }
347
+
348
+ panic ! ( "{:?} not an integer type" , typ) ;
349
+ }
350
+
351
+ pub fn int_type_element_size ( & self , typ : Type < ' gcc > ) -> u8 {
352
+ for native_type in & self . native_int_types {
353
+ if native_type. typ . is_compatible_with ( typ) {
354
+ return native_type. bits ;
355
+ }
356
+ }
357
+ for non_native_type in & self . non_native_int_types {
358
+ if non_native_type. typ . is_compatible_with ( typ) {
359
+ return non_native_type. bits ;
360
+ }
361
+ }
362
+
363
+ panic ! ( "{:?} not an integer type" , typ) ;
364
+ }
365
+
300
366
pub fn sess ( & self ) -> & Session {
301
367
& self . tcx . sess
302
368
}
0 commit comments