@@ -754,101 +754,81 @@ macro_rules! write_only_csr {
754754macro_rules! read_write_csr_field {
755755 ( $ty: ident,
756756 $( #[ $field_doc: meta] ) +
757- $field: ident,
758- $( #[ $set_field_doc: meta] ) +
759- $set_field: ident,
760- bit: $bit: literal$( , ) ?
757+ $field: ident: $bit: literal$( , ) ?
761758 ) => {
762- $crate:: read_only_csr_field!(
763- $ty,
764- $( #[ $field_doc] ) +
765- $field: $bit,
766- ) ;
767-
768- $crate:: write_only_csr_field!(
769- $ty,
770- $( #[ $set_field_doc] ) +
771- $set_field: $bit,
772- ) ;
759+ paste:: paste! {
760+ $crate:: read_only_csr_field!(
761+ $ty,
762+ $( #[ $field_doc] ) +
763+ $field: $bit,
764+ ) ;
765+
766+ $crate:: write_only_csr_field!(
767+ $ty,
768+ $( #[ $field_doc] ) +
769+ [ <set_ $field>] : $bit,
770+ ) ;
771+ }
773772 } ;
774773
775774 ( $ty: ident,
776775 $( #[ $field_doc: meta] ) +
777- $field: ident,
778- $( #[ $try_field_doc: meta] ) +
779- $try_field: ident,
780- $( #[ $set_field_doc: meta] ) +
781- $set_field: ident,
782- $( #[ $try_set_field_doc: meta] ) +
783- $try_set_field: ident,
784- range: $bit_start: literal ..= $bit_end: literal$( , ) ?
776+ $field: ident: $bit_start: literal ..= $bit_end: literal$( , ) ?
785777 ) => {
786- $crate:: read_only_csr_field!(
787- $ty,
788- $( #[ $field_doc] ) +
789- $field,
790- $( #[ $try_field_doc] ) +
791- $try_field,
792- range: $bit_start ..= $bit_end,
793- ) ;
794-
795- $crate:: write_only_csr_field!(
796- $ty,
797- $( #[ $set_field_doc] ) +
798- $set_field,
799- $( #[ $try_set_field_doc] ) +
800- $try_set_field,
801- range: $bit_start ..= $bit_end,
802- ) ;
778+ paste:: paste! {
779+ $crate:: read_only_csr_field!(
780+ $ty,
781+ $( #[ $field_doc] ) +
782+ $field: $bit_start ..= $bit_end,
783+ ) ;
784+
785+ $crate:: write_only_csr_field!(
786+ $ty,
787+ $( #[ $field_doc] ) +
788+ [ <set_ $field>] : $bit_start ..= $bit_end,
789+ ) ;
790+ }
803791 } ;
804792
805793 ( $ty: ident,
806794 $( #[ $field_doc: meta] ) +
807- $field: ident,
808- $( #[ $set_field_doc: meta] ) +
809- $set_field: ident,
810- range: [ $bit_start: literal : $bit_end: literal] $( , ) ?
795+ $field: ident: [ $bit_start: literal : $bit_end: literal] $( , ) ?
811796 ) => {
812- $crate:: read_only_csr_field!(
813- $ty,
814- $( #[ $field_doc] ) +
815- $field: [ $bit_start : $bit_end] ,
816- ) ;
817-
818- $crate:: write_only_csr_field!(
819- $ty,
820- $( #[ $set_field_doc] ) +
821- $set_field: [ $bit_start : $bit_end] ,
822- ) ;
797+ paste:: paste! {
798+ $crate:: read_only_csr_field!(
799+ $ty,
800+ $( #[ $field_doc] ) +
801+ $field: [ $bit_start : $bit_end] ,
802+ ) ;
803+
804+ $crate:: write_only_csr_field!(
805+ $ty,
806+ $( #[ $field_doc] ) +
807+ [ <set_ $field>] : [ $bit_start : $bit_end] ,
808+ ) ;
809+ }
823810 } ;
824811
825812 ( $ty: ident,
826813 $( #[ $field_doc: meta] ) +
827814 $field: ident,
828- $( #[ $try_field_doc: meta] ) +
829- $try_field: ident,
830- $( #[ $set_field_doc: meta] ) +
831- $set_field: ident,
832- $field_ty: ident,
833- range: [ $field_start: literal : $field_end: literal] ,
815+ $field_ty: ident: [ $field_start: literal : $field_end: literal] ,
834816 ) => {
835- $crate:: read_only_csr_field!(
836- $ty,
837- $( #[ $field_doc] ) +
838- $field,
839- $( #[ $try_field_doc] ) +
840- $try_field,
841- $field_ty,
842- range: [ $field_start : $field_end] ,
843- ) ;
844-
845- $crate:: write_only_csr_field!(
846- $ty,
847- $( #[ $set_field_doc] ) +
848- $set_field,
849- $field_ty,
850- range: [ $field_start : $field_end] ,
851- ) ;
817+ paste:: paste! {
818+ $crate:: read_only_csr_field!(
819+ $ty,
820+ $( #[ $field_doc] ) +
821+ $field,
822+ $field_ty: [ $field_start : $field_end] ,
823+ ) ;
824+
825+ $crate:: write_only_csr_field!(
826+ $ty,
827+ $( #[ $field_doc] ) +
828+ [ <set_ $field>] ,
829+ $field_ty: [ $field_start : $field_end] ,
830+ ) ;
831+ }
852832 } ;
853833}
854834
@@ -871,31 +851,30 @@ macro_rules! read_only_csr_field {
871851
872852 ( $ty: ident,
873853 $( #[ $field_doc: meta] ) +
874- $field: ident,
875- $( #[ $try_field_doc: meta] ) +
876- $try_field: ident,
877- range: $bit_start: literal..=$bit_end: literal$( , ) ?) => {
854+ $field: ident: $bit_start: literal..=$bit_end: literal$( , ) ?) => {
878855 const _: ( ) = assert!( $bit_end < usize :: BITS ) ;
879856 const _: ( ) = assert!( $bit_start < $bit_end) ;
880857
881- impl $ty {
882- $( #[ $field_doc] ) +
883- #[ inline]
884- pub fn $field( & self , index: usize ) -> bool {
885- self . $try_field( index) . unwrap( )
886- }
858+ paste:: paste! {
859+ impl $ty {
860+ $( #[ $field_doc] ) +
861+ #[ inline]
862+ pub fn $field( & self , index: usize ) -> bool {
863+ self . [ <try_ $field>] ( index) . unwrap( )
864+ }
887865
888- $( #[ $try_field_doc] ) +
889- #[ inline]
890- pub fn $try_field( & self , index: usize ) -> $crate:: result:: Result <bool > {
891- if ( $bit_start..=$bit_end) . contains( & index) {
892- Ok ( $crate:: bits:: bf_extract( self . bits, index, 1 ) != 0 )
893- } else {
894- Err ( $crate:: result:: Error :: IndexOutOfBounds {
895- index,
896- min: $bit_start,
897- max: $bit_end,
898- } )
866+ $( #[ $field_doc] ) +
867+ #[ inline]
868+ pub fn [ <try_ $field>] ( & self , index: usize ) -> $crate:: result:: Result <bool > {
869+ if ( $bit_start..=$bit_end) . contains( & index) {
870+ Ok ( $crate:: bits:: bf_extract( self . bits, index, 1 ) != 0 )
871+ } else {
872+ Err ( $crate:: result:: Error :: IndexOutOfBounds {
873+ index,
874+ min: $bit_start,
875+ max: $bit_end,
876+ } )
877+ }
899878 }
900879 }
901880 }
@@ -919,31 +898,30 @@ macro_rules! read_only_csr_field {
919898 ( $ty: ident,
920899 $( #[ $field_doc: meta] ) +
921900 $field: ident,
922- $( #[ $try_field_doc: meta] ) +
923- $try_field: ident,
924- $field_ty: ident,
925- range: [ $field_start: literal : $field_end: literal] $( , ) ?
901+ $field_ty: ident: [ $field_start: literal : $field_end: literal] $( , ) ?
926902 ) => {
927903 const _: ( ) = assert!( $field_end < usize :: BITS ) ;
928904 const _: ( ) = assert!( $field_start <= $field_end) ;
929905
930- impl $ty {
931- $( #[ $field_doc] ) +
932- #[ inline]
933- pub fn $field( & self ) -> $field_ty {
934- self . $try_field( ) . unwrap( )
935- }
906+ paste:: paste! {
907+ impl $ty {
908+ $( #[ $field_doc] ) +
909+ #[ inline]
910+ pub fn $field( & self ) -> $field_ty {
911+ self . [ <try_ $field>] ( ) . unwrap( )
912+ }
936913
937- $( #[ $try_field_doc ] ) +
938- #[ inline]
939- pub fn $try_field ( & self ) -> $crate:: result:: Result <$field_ty> {
940- let value = $crate:: bits:: bf_extract(
941- self . bits,
942- $field_start,
943- $field_end - $field_start + 1 ,
944- ) ;
914+ $( #[ $field_doc ] ) +
915+ #[ inline]
916+ pub fn [ <try_ $field> ] ( & self ) -> $crate:: result:: Result <$field_ty> {
917+ let value = $crate:: bits:: bf_extract(
918+ self . bits,
919+ $field_start,
920+ $field_end - $field_start + 1 ,
921+ ) ;
945922
946- $field_ty:: from_usize( value)
923+ $field_ty:: from_usize( value)
924+ }
947925 }
948926 }
949927 } ;
@@ -959,6 +937,8 @@ macro_rules! write_only_csr_field {
959937
960938 impl $ty {
961939 $( #[ $field_doc] ) +
940+ #[ doc = "" ]
941+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
962942 #[ inline]
963943 pub fn $field( & mut self , $field: bool ) {
964944 self . bits = $crate:: bits:: bf_insert( self . bits, $bit, 1 , $field as usize ) ;
@@ -968,32 +948,35 @@ macro_rules! write_only_csr_field {
968948
969949 ( $ty: ident,
970950 $( #[ $field_doc: meta] ) +
971- $field: ident,
972- $( #[ $try_field_doc: meta] ) +
973- $try_field: ident,
974- range: $bit_start: literal..=$bit_end: literal$( , ) ?) => {
951+ $field: ident: $bit_start: literal..=$bit_end: literal$( , ) ?) => {
975952 const _: ( ) = assert!( $bit_end < usize :: BITS ) ;
976953 const _: ( ) = assert!( $bit_start < $bit_end) ;
977954
978- impl $ty {
979- $( #[ $field_doc] ) +
980- #[ inline]
981- pub fn $field( & mut self , index: usize , $field: bool ) {
982- self . $try_field( index, $field) . unwrap( ) ;
983- }
955+ paste:: paste! {
956+ impl $ty {
957+ $( #[ $field_doc] ) +
958+ #[ doc = "" ]
959+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
960+ #[ inline]
961+ pub fn $field( & mut self , index: usize , $field: bool ) {
962+ self . [ <try_ $field>] ( index, $field) . unwrap( ) ;
963+ }
984964
985- $( #[ $try_field_doc] ) +
986- #[ inline]
987- pub fn $try_field( & mut self , index: usize , $field: bool ) -> $crate:: result:: Result <( ) > {
988- if ( $bit_start..=$bit_end) . contains( & index) {
989- self . bits = $crate:: bits:: bf_insert( self . bits, index, 1 , $field as usize ) ;
990- Ok ( ( ) )
991- } else {
992- Err ( $crate:: result:: Error :: IndexOutOfBounds {
993- index,
994- min: $bit_start,
995- max: $bit_end,
996- } )
965+ $( #[ $field_doc] ) +
966+ #[ doc = "" ]
967+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
968+ #[ inline]
969+ pub fn [ <try_ $field>] ( & mut self , index: usize , $field: bool ) -> $crate:: result:: Result <( ) > {
970+ if ( $bit_start..=$bit_end) . contains( & index) {
971+ self . bits = $crate:: bits:: bf_insert( self . bits, index, 1 , $field as usize ) ;
972+ Ok ( ( ) )
973+ } else {
974+ Err ( $crate:: result:: Error :: IndexOutOfBounds {
975+ index,
976+ min: $bit_start,
977+ max: $bit_end,
978+ } )
979+ }
997980 }
998981 }
999982 }
@@ -1007,6 +990,8 @@ macro_rules! write_only_csr_field {
1007990
1008991 impl $ty {
1009992 $( #[ $field_doc] ) +
993+ #[ doc = "" ]
994+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
1010995 #[ inline]
1011996 pub fn $field( & mut self , $field: usize ) {
1012997 self . bits = $crate:: bits:: bf_insert(
@@ -1022,14 +1007,15 @@ macro_rules! write_only_csr_field {
10221007 ( $ty: ident,
10231008 $( #[ $field_doc: meta] ) +
10241009 $field: ident,
1025- $field_ty: ident,
1026- range: [ $field_start: literal : $field_end: literal] $( , ) ?
1010+ $field_ty: ident: [ $field_start: literal : $field_end: literal] $( , ) ?
10271011 ) => {
10281012 const _: ( ) = assert!( $field_end < usize :: BITS ) ;
10291013 const _: ( ) = assert!( $field_start <= $field_end) ;
10301014
10311015 impl $ty {
10321016 $( #[ $field_doc] ) +
1017+ #[ doc = "" ]
1018+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
10331019 #[ inline]
10341020 pub fn $field( & mut self , $field: $field_ty) {
10351021 self . bits = $crate:: bits:: bf_insert(
0 commit comments