@@ -366,6 +366,9 @@ pub struct BindgenContext {
366
366
/// The translation unit for parsing.
367
367
translation_unit : clang:: TranslationUnit ,
368
368
369
+ /// Target information that can be useful for some stuff.
370
+ target_info : Option < clang:: TargetInfo > ,
371
+
369
372
/// The options given by the user via cli or other medium.
370
373
options : BindgenOptions ,
371
374
@@ -503,6 +506,9 @@ impl<'ctx> WhitelistedItemsTraversal<'ctx> {
503
506
}
504
507
}
505
508
509
+ const HOST_TARGET : & ' static str =
510
+ include_str ! ( concat!( env!( "OUT_DIR" ) , "/host-target.txt" ) ) ;
511
+
506
512
/// Returns the effective target, and whether it was explicitly specified on the
507
513
/// clang flags.
508
514
fn find_effective_target ( clang_args : & [ String ] ) -> ( String , bool ) {
@@ -521,8 +527,6 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
521
527
return ( t, false )
522
528
}
523
529
524
- const HOST_TARGET : & ' static str =
525
- include_str ! ( concat!( env!( "OUT_DIR" ) , "/host-target.txt" ) ) ;
526
530
( HOST_TARGET . to_owned ( ) , false )
527
531
}
528
532
@@ -561,6 +565,17 @@ impl BindgenContext {
561
565
) . expect ( "TranslationUnit::parse failed" )
562
566
} ;
563
567
568
+ let target_info = clang:: TargetInfo :: new ( & translation_unit) ;
569
+
570
+ #[ cfg( debug_assertions) ]
571
+ {
572
+ if let Some ( ref ti) = target_info {
573
+ if effective_target == HOST_TARGET {
574
+ assert_eq ! ( ti. pointer_width / 8 , mem:: size_of:: <* mut ( ) >( ) ) ;
575
+ }
576
+ }
577
+ }
578
+
564
579
let root_module = Self :: build_root_module ( ItemId ( 0 ) ) ;
565
580
let root_module_id = root_module. id ( ) . as_module_id_unchecked ( ) ;
566
581
@@ -578,9 +593,10 @@ impl BindgenContext {
578
593
replacements : Default :: default ( ) ,
579
594
collected_typerefs : false ,
580
595
in_codegen : false ,
581
- index : index,
582
- translation_unit : translation_unit,
583
- options : options,
596
+ index,
597
+ translation_unit,
598
+ target_info,
599
+ options,
584
600
generated_bindegen_complex : Cell :: new ( false ) ,
585
601
whitelisted : None ,
586
602
codegen_items : None ,
@@ -611,6 +627,15 @@ impl BindgenContext {
611
627
Timer :: new ( name) . with_output ( self . options . time_phases )
612
628
}
613
629
630
+ /// Returns the pointer width to use for the target for the current
631
+ /// translation.
632
+ pub fn target_pointer_size ( & self ) -> usize {
633
+ if let Some ( ref ti) = self . target_info {
634
+ return ti. pointer_width / 8 ;
635
+ }
636
+ mem:: size_of :: < * mut ( ) > ( )
637
+ }
638
+
614
639
/// Get the stack of partially parsed types that we are in the middle of
615
640
/// parsing.
616
641
pub fn currently_parsed_types ( & self ) -> & [ PartialType ] {
0 commit comments