@@ -268,8 +268,10 @@ fn create_block(cx: block) -> @metadata<block_md> {
268
268
ret mdval;
269
269
}
270
270
271
- fn size_and_align_of < T > ( ) -> ( int , int ) {
272
- ( sys:: size_of :: < T > ( ) as int , sys:: align_of :: < T > ( ) as int )
271
+ fn size_and_align_of ( cx : crate_ctxt , t : ty:: t ) -> ( int , int ) {
272
+ let llty = type_of:: type_of ( cx, t) ;
273
+ ( shape:: llsize_of_real ( cx, llty) as int ,
274
+ shape:: llalign_of_real ( cx, llty) as int )
273
275
}
274
276
275
277
fn create_basic_type ( cx : crate_ctxt , t : ty:: t , ty : ast:: prim_ty , span : span )
@@ -282,33 +284,34 @@ fn create_basic_type(cx: crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)
282
284
option:: none { }
283
285
}
284
286
285
- let ( name, ( size , align ) , encoding) = alt check ty {
286
- ast : : ty_bool { ( "bool" , size_and_align_of :: < bool > ( ) , DW_ATE_boolean ) }
287
+ let ( name, encoding) = alt check ty {
288
+ ast : : ty_bool { ( "bool" , DW_ATE_boolean ) }
287
289
ast:: ty_int ( m) { alt m {
288
- ast : : ty_char { ( "char" , size_and_align_of :: < char > ( ) , DW_ATE_unsigned ) }
289
- ast:: ty_i { ( "int" , size_and_align_of :: < int > ( ) , DW_ATE_signed ) }
290
- ast:: ty_i8 { ( "i8" , size_and_align_of :: < i8 > ( ) , DW_ATE_signed_char ) }
291
- ast:: ty_i16 { ( "i16" , size_and_align_of :: < i16 > ( ) , DW_ATE_signed ) }
292
- ast:: ty_i32 { ( "i32" , size_and_align_of :: < i32 > ( ) , DW_ATE_signed ) }
293
- ast:: ty_i64 { ( "i64" , size_and_align_of :: < i64 > ( ) , DW_ATE_signed ) }
290
+ ast : : ty_char { ( "char" , DW_ATE_unsigned ) }
291
+ ast:: ty_i { ( "int" , DW_ATE_signed ) }
292
+ ast:: ty_i8 { ( "i8" , DW_ATE_signed_char ) }
293
+ ast:: ty_i16 { ( "i16" , DW_ATE_signed ) }
294
+ ast:: ty_i32 { ( "i32" , DW_ATE_signed ) }
295
+ ast:: ty_i64 { ( "i64" , DW_ATE_signed ) }
294
296
} }
295
297
ast:: ty_uint ( m) { alt m {
296
- ast : : ty_u { ( "uint" , size_and_align_of :: < uint > ( ) , DW_ATE_unsigned ) }
297
- ast:: ty_u8 { ( "u8" , size_and_align_of :: < u8 > ( ) , DW_ATE_unsigned_char ) }
298
- ast:: ty_u16 { ( "u16" , size_and_align_of :: < u16 > ( ) , DW_ATE_unsigned ) }
299
- ast:: ty_u32 { ( "u32" , size_and_align_of :: < u32 > ( ) , DW_ATE_unsigned ) }
300
- ast:: ty_u64 { ( "u64" , size_and_align_of :: < u64 > ( ) , DW_ATE_unsigned ) }
298
+ ast : : ty_u { ( "uint" , DW_ATE_unsigned ) }
299
+ ast:: ty_u8 { ( "u8" , DW_ATE_unsigned_char ) }
300
+ ast:: ty_u16 { ( "u16" , DW_ATE_unsigned ) }
301
+ ast:: ty_u32 { ( "u32" , DW_ATE_unsigned ) }
302
+ ast:: ty_u64 { ( "u64" , DW_ATE_unsigned ) }
301
303
} }
302
304
ast:: ty_float ( m) { alt m {
303
- ast : : ty_f { ( "float" , size_and_align_of :: < float > ( ) , DW_ATE_float ) }
304
- ast:: ty_f32 { ( "f32" , size_and_align_of :: < f32 > ( ) , DW_ATE_float ) }
305
- ast:: ty_f64 { ( "f64" , size_and_align_of :: < f64 > ( ) , DW_ATE_float ) }
305
+ ast : : ty_f { ( "float" , DW_ATE_float ) }
306
+ ast:: ty_f32 { ( "f32" , DW_ATE_float ) }
307
+ ast:: ty_f64 { ( "f64" , DW_ATE_float ) }
306
308
} }
307
309
} ;
308
310
309
311
let fname = filename_from_span ( cx, span) ;
310
312
let file_node = create_file ( cx, fname) ;
311
313
let cu_node = create_compile_unit ( cx, fname) ;
314
+ let ( size, align) = size_and_align_of ( cx, t) ;
312
315
let lldata = [ lltag ( tg) ,
313
316
cu_node. node ,
314
317
llstr ( name) ,
@@ -336,7 +339,7 @@ fn create_pointer_type(cx: crate_ctxt, t: ty::t, span: span,
336
339
option::some(md) { ret md; }
337
340
option::none {}
338
341
}*/
339
- let ( size, align) = size_and_align_of :: < libc :: intptr_t > ( ) ;
342
+ let ( size, align) = size_and_align_of ( cx , t ) ;
340
343
let fname = filename_from_span ( cx, span) ;
341
344
let file_node = create_file ( cx, fname) ;
342
345
//let cu_node = create_compile_unit(cx, fname);
@@ -410,7 +413,7 @@ fn create_record(cx: crate_ctxt, t: ty::t, fields: [ast::ty_field],
410
413
for field in fields {
411
414
let field_t = ty:: get_field ( t, field. node . ident ) . mt . ty ;
412
415
let ty_md = create_ty ( cx, field_t, field. node . mt . ty ) ;
413
- let ( size, align) = member_size_and_align ( cx. tcx , field . node . mt . ty ) ;
416
+ let ( size, align) = size_and_align_of ( cx, field_t ) ;
414
417
add_member ( scx, field. node . ident ,
415
418
line_from_span ( cx. sess . codemap , field. span ) as int ,
416
419
size as int , align as int , ty_md. node ) ;
@@ -492,7 +495,7 @@ fn create_vec(cx: crate_ctxt, vec_t: ty::t, elem_t: ty::t,
492
495
add_member ( scx, "alloc" , 0 , sys:: size_of :: < libc:: size_t > ( ) as int ,
493
496
sys:: align_of :: < libc:: size_t > ( ) as int , size_t_type. node ) ;
494
497
let subrange = llmdnode ( [ lltag ( SubrangeTag ) , lli64 ( 0 ) , lli64 ( 0 ) ] ) ;
495
- let ( arr_size, arr_align) = member_size_and_align ( cx. tcx , elem_ty ) ;
498
+ let ( arr_size, arr_align) = size_and_align_of ( cx, elem_t ) ;
496
499
let data_ptr = create_composite_type ( ArrayTypeTag , "" , file_node. node , 0 ,
497
500
arr_size, arr_align, 0 ,
498
501
option:: some ( elem_ty_md. node ) ,
@@ -503,55 +506,6 @@ fn create_vec(cx: crate_ctxt, vec_t: ty::t, elem_t: ty::t,
503
506
ret @{ node : llnode, data : { hash: ty:: type_id ( vec_t) } } ;
504
507
}
505
508
506
- fn member_size_and_align ( tcx : ty:: ctxt , ty : @ast:: ty ) -> ( int , int ) {
507
- alt ty. node {
508
- ast:: ty_path ( _, id) {
509
- alt check tcx. def_map . get ( id) {
510
- ast:: def_prim_ty ( nty) {
511
- alt check nty {
512
- ast : : ty_bool { size_and_align_of : : <bool >( ) }
513
- ast:: ty_int ( m) { alt m {
514
- ast : : ty_char { size_and_align_of : : <char >( ) }
515
- ast:: ty_i { size_and_align_of : : <int >( ) }
516
- ast:: ty_i8 { size_and_align_of : : <i8 >( ) }
517
- ast:: ty_i16 { size_and_align_of : : <i16 >( ) }
518
- ast:: ty_i32 { size_and_align_of : : <i32 >( ) }
519
- ast:: ty_i64 { size_and_align_of : : <i64 >( ) }
520
- } }
521
- ast:: ty_uint ( m) { alt m {
522
- ast : : ty_u { size_and_align_of : : <uint >( ) }
523
- ast:: ty_u8 { size_and_align_of : : <i8 >( ) }
524
- ast:: ty_u16 { size_and_align_of : : <u16 >( ) }
525
- ast:: ty_u32 { size_and_align_of : : <u32 >( ) }
526
- ast:: ty_u64 { size_and_align_of : : <u64 >( ) }
527
- } }
528
- ast:: ty_float ( m) { alt m {
529
- ast : : ty_f { size_and_align_of : : <float >( ) }
530
- ast:: ty_f32 { size_and_align_of : : <f32 >( ) }
531
- ast:: ty_f64 { size_and_align_of : : <f64 >( ) }
532
- } }
533
- }
534
- }
535
- }
536
- }
537
- ast:: ty_box ( _) | ast:: ty_uniq ( _) {
538
- size_and_align_of :: < libc:: uintptr_t > ( )
539
- }
540
- ast:: ty_rec ( fields) {
541
- let total_size = 0 ;
542
- for field in fields {
543
- let ( size, _) = member_size_and_align ( tcx, field. node . mt . ty ) ;
544
- total_size += size;
545
- }
546
- ( total_size, 64 ) //XXX different align for other arches?
547
- }
548
- ast:: ty_vec ( _) {
549
- size_and_align_of :: < libc:: uintptr_t > ( )
550
- }
551
- _ { fail "member_size_and_align: can't handle this type" ; }
552
- }
553
- }
554
-
555
509
fn create_ty ( _cx : crate_ctxt , _t : ty:: t , _ty : @ast:: ty )
556
510
-> @metadata < tydesc_md > {
557
511
/*let cache = get_cache(cx);
0 commit comments