@@ -754,101 +754,81 @@ macro_rules! write_only_csr {
754
754
macro_rules! read_write_csr_field {
755
755
( $ty: ident,
756
756
$( #[ $field_doc: meta] ) +
757
- $field: ident,
758
- $( #[ $set_field_doc: meta] ) +
759
- $set_field: ident,
760
- bit: $bit: literal$( , ) ?
757
+ $field: ident: $bit: literal$( , ) ?
761
758
) => {
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
+ }
773
772
} ;
774
773
775
774
( $ty: ident,
776
775
$( #[ $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$( , ) ?
785
777
) => {
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
+ }
803
791
} ;
804
792
805
793
( $ty: ident,
806
794
$( #[ $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] $( , ) ?
811
796
) => {
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
+ }
823
810
} ;
824
811
825
812
( $ty: ident,
826
813
$( #[ $field_doc: meta] ) +
827
814
$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] ,
834
816
) => {
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
+ }
852
832
} ;
853
833
}
854
834
@@ -871,31 +851,30 @@ macro_rules! read_only_csr_field {
871
851
872
852
( $ty: ident,
873
853
$( #[ $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$( , ) ?) => {
878
855
const _: ( ) = assert!( $bit_end < usize :: BITS ) ;
879
856
const _: ( ) = assert!( $bit_start < $bit_end) ;
880
857
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
+ }
887
865
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
+ }
899
878
}
900
879
}
901
880
}
@@ -919,31 +898,30 @@ macro_rules! read_only_csr_field {
919
898
( $ty: ident,
920
899
$( #[ $field_doc: meta] ) +
921
900
$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] $( , ) ?
926
902
) => {
927
903
const _: ( ) = assert!( $field_end < usize :: BITS ) ;
928
904
const _: ( ) = assert!( $field_start <= $field_end) ;
929
905
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
+ }
936
913
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
+ ) ;
945
922
946
- $field_ty:: from_usize( value)
923
+ $field_ty:: from_usize( value)
924
+ }
947
925
}
948
926
}
949
927
} ;
@@ -959,6 +937,8 @@ macro_rules! write_only_csr_field {
959
937
960
938
impl $ty {
961
939
$( #[ $field_doc] ) +
940
+ #[ doc = "" ]
941
+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
962
942
#[ inline]
963
943
pub fn $field( & mut self , $field: bool ) {
964
944
self . bits = $crate:: bits:: bf_insert( self . bits, $bit, 1 , $field as usize ) ;
@@ -968,32 +948,35 @@ macro_rules! write_only_csr_field {
968
948
969
949
( $ty: ident,
970
950
$( #[ $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$( , ) ?) => {
975
952
const _: ( ) = assert!( $bit_end < usize :: BITS ) ;
976
953
const _: ( ) = assert!( $bit_start < $bit_end) ;
977
954
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
+ }
984
964
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
+ }
997
980
}
998
981
}
999
982
}
@@ -1007,6 +990,8 @@ macro_rules! write_only_csr_field {
1007
990
1008
991
impl $ty {
1009
992
$( #[ $field_doc] ) +
993
+ #[ doc = "" ]
994
+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
1010
995
#[ inline]
1011
996
pub fn $field( & mut self , $field: usize ) {
1012
997
self . bits = $crate:: bits:: bf_insert(
@@ -1022,14 +1007,15 @@ macro_rules! write_only_csr_field {
1022
1007
( $ty: ident,
1023
1008
$( #[ $field_doc: meta] ) +
1024
1009
$field: ident,
1025
- $field_ty: ident,
1026
- range: [ $field_start: literal : $field_end: literal] $( , ) ?
1010
+ $field_ty: ident: [ $field_start: literal : $field_end: literal] $( , ) ?
1027
1011
) => {
1028
1012
const _: ( ) = assert!( $field_end < usize :: BITS ) ;
1029
1013
const _: ( ) = assert!( $field_start <= $field_end) ;
1030
1014
1031
1015
impl $ty {
1032
1016
$( #[ $field_doc] ) +
1017
+ #[ doc = "" ]
1018
+ #[ doc = "**NOTE**: only updates in-memory values, does not write to CSR." ]
1033
1019
#[ inline]
1034
1020
pub fn $field( & mut self , $field: $field_ty) {
1035
1021
self . bits = $crate:: bits:: bf_insert(
0 commit comments