@@ -269,7 +269,7 @@ pub fn fields(
269
269
mod_items : & mut TokenStream ,
270
270
r_impl_items : & mut TokenStream ,
271
271
w_impl_items : & mut TokenStream ,
272
- _config : & Config ,
272
+ config : & Config ,
273
273
) -> Result < ( ) > {
274
274
let span = Span :: call_site ( ) ;
275
275
let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
@@ -569,7 +569,6 @@ pub fn fields(
569
569
if can_write {
570
570
let new_pc_aw = Ident :: new ( & ( name_pc. clone ( ) + "_AW" ) , span) ;
571
571
let name_pc_w = Ident :: new ( & ( name_pc. clone ( ) + "_W" ) , span) ;
572
- #[ cfg( feature = "const-generic" ) ]
573
572
let name_pc_cgw = Ident :: new ( & ( name_pc. clone ( ) + "_CGW" ) , span) ;
574
573
575
574
let mut proxy_items = TokenStream :: new ( ) ;
@@ -648,7 +647,6 @@ pub fn fields(
648
647
}
649
648
650
649
let mut proxy_items_fa = TokenStream :: new ( ) ;
651
- #[ cfg( feature = "const-generic" ) ]
652
650
let mut proxy_items_cg = TokenStream :: new ( ) ;
653
651
if field_dim. is_some ( ) {
654
652
proxy_items_fa. extend ( quote ! {
@@ -659,15 +657,16 @@ pub fn fields(
659
657
self . w
660
658
}
661
659
} ) ;
662
- #[ cfg( feature="const-generic" ) ]
663
- proxy_items_cg. extend ( quote ! {
664
- ///Writes raw bits to the field
665
- #inline
666
- pub #unsafety fn #bits( self , value: #fty) -> & ' a mut W {
667
- self . w. bits = ( self . w. bits & !( #hexmask << O ) ) | ( ( value as #rty & #hexmask) << O ) ;
668
- self . w
669
- }
670
- } ) ;
660
+ if config. const_generic {
661
+ proxy_items_cg. extend ( quote ! {
662
+ ///Writes raw bits to the field
663
+ #inline
664
+ pub #unsafety fn #bits( self , value: #fty) -> & ' a mut W {
665
+ self . w. bits = ( self . w. bits & !( #hexmask << O ) ) | ( ( value as #rty & #hexmask) << O ) ;
666
+ self . w
667
+ }
668
+ } ) ;
669
+ }
671
670
} else {
672
671
proxy_items. extend ( if offset != 0 {
673
672
let offset = & util:: unsuffixed ( offset) ;
@@ -691,11 +690,9 @@ pub fn fields(
691
690
} ) ;
692
691
}
693
692
694
- #[ cfg( feature = "const-generic" ) ]
695
693
let mut cgdoc = String :: new ( ) ;
696
694
let doc = if let Some ( ( _, _, _, _, suffixes_str) ) = & field_dim {
697
- #[ cfg( feature = "const-generic" ) ]
698
- {
695
+ if config. const_generic {
699
696
cgdoc = format ! (
700
697
"Fields `{}` const generic writer - {}" ,
701
698
util:: replace_suffix( & f. name, suffixes_str) ,
@@ -725,18 +722,19 @@ pub fn fields(
725
722
}
726
723
} ) ;
727
724
728
- # [ cfg ( feature = "const-generic" ) ]
729
- mod_items. extend ( quote ! {
730
- #[ doc = #cgdoc]
731
- pub struct #name_pc_cgw<' a, const O : usize > {
732
- w: & ' a mut W ,
733
- }
725
+ if config . const_generic {
726
+ mod_items. extend ( quote ! {
727
+ #[ doc = #cgdoc]
728
+ pub struct #name_pc_cgw<' a, const O : usize > {
729
+ w: & ' a mut W ,
730
+ }
734
731
735
- impl <' a, const O : usize > #name_pc_cgw<' a, O > {
736
- #proxy_items
737
- #proxy_items_cg
738
- }
739
- } ) ;
732
+ impl <' a, const O : usize > #name_pc_cgw<' a, O > {
733
+ #proxy_items
734
+ #proxy_items_cg
735
+ }
736
+ } ) ;
737
+ }
740
738
} else {
741
739
mod_items. extend ( quote ! {
742
740
#[ doc = #doc]
@@ -771,22 +769,23 @@ pub fn fields(
771
769
& suffix,
772
770
) ;
773
771
let sub_offset = util:: unsuffixed ( sub_offset as u64 ) ;
774
- #[ cfg( not( feature = "const-generic" ) ) ]
775
- w_impl_items. extend ( quote ! {
776
- #[ doc = #doc]
777
- #inline
778
- pub fn #name_sc_n( & mut self ) -> #name_pc_w {
779
- #name_pc_w { w: self , offset: #sub_offset }
780
- }
781
- } ) ;
782
- #[ cfg( feature = "const-generic" ) ]
783
- w_impl_items. extend ( quote ! {
784
- #[ doc = #doc]
785
- #inline
786
- pub fn #name_sc_n( & mut self ) -> #name_pc_cgw<#sub_offset> {
787
- #name_pc_cgw { w: self }
788
- }
789
- } ) ;
772
+ if !config. const_generic {
773
+ w_impl_items. extend ( quote ! {
774
+ #[ doc = #doc]
775
+ #inline
776
+ pub fn #name_sc_n( & mut self ) -> #name_pc_w {
777
+ #name_pc_w { w: self , offset: #sub_offset }
778
+ }
779
+ } ) ;
780
+ } else {
781
+ w_impl_items. extend ( quote ! {
782
+ #[ doc = #doc]
783
+ #inline
784
+ pub fn #name_sc_n( & mut self ) -> #name_pc_cgw<#sub_offset> {
785
+ #name_pc_cgw { w: self }
786
+ }
787
+ } ) ;
788
+ }
790
789
}
791
790
} else {
792
791
let doc = description_with_bits ( & description, offset, width) ;
0 commit comments