@@ -269,7 +269,7 @@ pub fn fields(
269269 mod_items : & mut TokenStream ,
270270 r_impl_items : & mut TokenStream ,
271271 w_impl_items : & mut TokenStream ,
272- _config : & Config ,
272+ config : & Config ,
273273) -> Result < ( ) > {
274274 let span = Span :: call_site ( ) ;
275275 let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
@@ -569,7 +569,6 @@ pub fn fields(
569569 if can_write {
570570 let new_pc_aw = Ident :: new ( & ( name_pc. clone ( ) + "_AW" ) , span) ;
571571 let name_pc_w = Ident :: new ( & ( name_pc. clone ( ) + "_W" ) , span) ;
572- #[ cfg( feature = "const-generic" ) ]
573572 let name_pc_cgw = Ident :: new ( & ( name_pc. clone ( ) + "_CGW" ) , span) ;
574573
575574 let mut proxy_items = TokenStream :: new ( ) ;
@@ -648,7 +647,6 @@ pub fn fields(
648647 }
649648
650649 let mut proxy_items_fa = TokenStream :: new ( ) ;
651- #[ cfg( feature = "const-generic" ) ]
652650 let mut proxy_items_cg = TokenStream :: new ( ) ;
653651 if field_dim. is_some ( ) {
654652 proxy_items_fa. extend ( quote ! {
@@ -659,15 +657,16 @@ pub fn fields(
659657 self . w
660658 }
661659 } ) ;
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+ }
671670 } else {
672671 proxy_items. extend ( if offset != 0 {
673672 let offset = & util:: unsuffixed ( offset) ;
@@ -691,11 +690,9 @@ pub fn fields(
691690 } ) ;
692691 }
693692
694- #[ cfg( feature = "const-generic" ) ]
695693 let mut cgdoc = String :: new ( ) ;
696694 let doc = if let Some ( ( _, _, _, _, suffixes_str) ) = & field_dim {
697- #[ cfg( feature = "const-generic" ) ]
698- {
695+ if config. const_generic {
699696 cgdoc = format ! (
700697 "Fields `{}` const generic writer - {}" ,
701698 util:: replace_suffix( & f. name, suffixes_str) ,
@@ -725,18 +722,19 @@ pub fn fields(
725722 }
726723 } ) ;
727724
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+ }
734731
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+ }
740738 } else {
741739 mod_items. extend ( quote ! {
742740 #[ doc = #doc]
@@ -771,22 +769,23 @@ pub fn fields(
771769 & suffix,
772770 ) ;
773771 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+ }
790789 }
791790 } else {
792791 let doc = description_with_bits ( & description, offset, width) ;
0 commit comments