@@ -188,8 +188,15 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
188188 "Pushing {} register or cluster blocks into output" ,
189189 ercs. len( )
190190 ) ;
191- let reg_block =
192- register_or_cluster_block ( & ercs, & derive_infos, None , "Register block" , None , config) ?;
191+ let reg_block = register_or_cluster_block (
192+ & ercs,
193+ & BlockPath :: new ( & p. name ) ,
194+ & derive_infos,
195+ None ,
196+ "Register block" ,
197+ None ,
198+ config,
199+ ) ?;
193200
194201 out. extend ( quote ! {
195202 #[ doc = #doc]
@@ -469,6 +476,7 @@ fn make_comment(size: u32, offset: u32, description: &str) -> String {
469476
470477fn register_or_cluster_block (
471478 ercs : & [ RegisterCluster ] ,
479+ path : & BlockPath ,
472480 derive_infos : & [ DeriveInfo ] ,
473481 name : Option < & str > ,
474482 doc : & str ,
@@ -478,7 +486,7 @@ fn register_or_cluster_block(
478486 let mut rbfs = TokenStream :: new ( ) ;
479487 let mut accessors = TokenStream :: new ( ) ;
480488
481- let ercs_expanded = expand ( ercs, derive_infos, config)
489+ let ercs_expanded = expand ( ercs, path , derive_infos, config)
482490 . with_context ( || "Could not expand register or cluster block" ) ?;
483491
484492 // Locate conflicting regions; we'll need to use unions to represent them.
@@ -612,6 +620,7 @@ fn register_or_cluster_block(
612620/// `RegisterBlockField`s containing `Field`s.
613621fn expand (
614622 ercs : & [ RegisterCluster ] ,
623+ path : & BlockPath ,
615624 derive_infos : & [ DeriveInfo ] ,
616625 config : & Config ,
617626) -> Result < Vec < RegisterBlockField > > {
@@ -623,14 +632,14 @@ fn expand(
623632 match & erc {
624633 RegisterCluster :: Register ( register) => {
625634 let reg_name = & register. name ;
626- let expanded_reg = expand_register ( register, derive_info, config)
635+ let expanded_reg = expand_register ( register, path , derive_info, config)
627636 . with_context ( || format ! ( "can't expand register '{reg_name}'" ) ) ?;
628637 trace ! ( "Register: {reg_name}" ) ;
629638 ercs_expanded. extend ( expanded_reg) ;
630639 }
631640 RegisterCluster :: Cluster ( cluster) => {
632641 let cluster_name = & cluster. name ;
633- let expanded_cluster = expand_cluster ( cluster, config)
642+ let expanded_cluster = expand_cluster ( cluster, path , config)
634643 . with_context ( || format ! ( "can't expand cluster '{cluster_name}'" ) ) ?;
635644 trace ! ( "Cluster: {cluster_name}" ) ;
636645 ercs_expanded. extend ( expanded_cluster) ;
@@ -873,9 +882,9 @@ fn is_derivable(
873882/// Calculate the size of a Cluster. If it is an array, then the dimensions
874883/// tell us the size of the array. Otherwise, inspect the contents using
875884/// [cluster_info_size_in_bits].
876- fn cluster_size_in_bits ( cluster : & Cluster , config : & Config ) -> Result < u32 > {
885+ fn cluster_size_in_bits ( cluster : & Cluster , path : & BlockPath , config : & Config ) -> Result < u32 > {
877886 match cluster {
878- Cluster :: Single ( info) => cluster_info_size_in_bits ( info, config) ,
887+ Cluster :: Single ( info) => cluster_info_size_in_bits ( info, path , config) ,
879888 // If the contained array cluster has a mismatch between the
880889 // dimIncrement and the size of the array items, then the array
881890 // will get expanded in expand_cluster below. The overall size
@@ -885,29 +894,29 @@ fn cluster_size_in_bits(cluster: &Cluster, config: &Config) -> Result<u32> {
885894 return Ok ( 0 ) ; // Special case!
886895 }
887896 let last_offset = ( dim. dim - 1 ) * dim. dim_increment * BITS_PER_BYTE ;
888- let last_size = cluster_info_size_in_bits ( info, config) ;
897+ let last_size = cluster_info_size_in_bits ( info, path , config) ;
889898 Ok ( last_offset + last_size?)
890899 }
891900 }
892901}
893902
894903/// Recursively calculate the size of a ClusterInfo. A cluster's size is the
895904/// maximum end position of its recursive children.
896- fn cluster_info_size_in_bits ( info : & ClusterInfo , config : & Config ) -> Result < u32 > {
905+ fn cluster_info_size_in_bits ( info : & ClusterInfo , path : & BlockPath , config : & Config ) -> Result < u32 > {
897906 let mut size = 0 ;
898907
899908 for c in & info. children {
900909 let end = match c {
901910 RegisterCluster :: Register ( reg) => {
902- let reg_size: u32 = expand_register ( reg, & DeriveInfo :: Root , config) ?
911+ let reg_size: u32 = expand_register ( reg, path , & DeriveInfo :: Root , config) ?
903912 . iter ( )
904913 . map ( |rbf| rbf. size )
905914 . sum ( ) ;
906915
907916 ( reg. address_offset * BITS_PER_BYTE ) + reg_size
908917 }
909918 RegisterCluster :: Cluster ( clust) => {
910- ( clust. address_offset * BITS_PER_BYTE ) + cluster_size_in_bits ( clust, config) ?
919+ ( clust. address_offset * BITS_PER_BYTE ) + cluster_size_in_bits ( clust, path , config) ?
911920 }
912921 } ;
913922
@@ -917,10 +926,14 @@ fn cluster_info_size_in_bits(info: &ClusterInfo, config: &Config) -> Result<u32>
917926}
918927
919928/// Render a given cluster (and any children) into `RegisterBlockField`s
920- fn expand_cluster ( cluster : & Cluster , config : & Config ) -> Result < Vec < RegisterBlockField > > {
929+ fn expand_cluster (
930+ cluster : & Cluster ,
931+ path : & BlockPath ,
932+ config : & Config ,
933+ ) -> Result < Vec < RegisterBlockField > > {
921934 let mut cluster_expanded = vec ! [ ] ;
922935
923- let cluster_size = cluster_info_size_in_bits ( cluster, config)
936+ let cluster_size = cluster_info_size_in_bits ( cluster, path , config)
924937 . with_context ( || format ! ( "Can't calculate cluster {} size" , cluster. name) ) ?;
925938 let description = cluster
926939 . description
@@ -1087,6 +1100,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10871100/// A `DeriveInfo::Implicit(_)` will also cause an array to be expanded.
10881101fn expand_register (
10891102 register : & Register ,
1103+ path : & BlockPath ,
10901104 derive_info : & DeriveInfo ,
10911105 config : & Config ,
10921106) -> Result < Vec < RegisterBlockField > > {
@@ -1104,7 +1118,7 @@ fn expand_register(
11041118 } else {
11051119 info_name. remove_dim ( )
11061120 } ;
1107- let ty_str = ty_name. clone ( ) ;
1121+ let mut ty_str = ty_name. clone ( ) ;
11081122
11091123 match register {
11101124 Register :: Single ( info) => {
@@ -1135,7 +1149,7 @@ fn expand_register(
11351149 || ( register_size <= array_info. dim_increment * BITS_PER_BYTE ) ;
11361150
11371151 let convert_list = match config. keep_list {
1138- true => info . name . contains ( "[%s]" ) ,
1152+ true => info_name . contains ( "[%s]" ) ,
11391153 false => true ,
11401154 } ;
11411155
@@ -1154,13 +1168,12 @@ fn expand_register(
11541168 "" . into ( )
11551169 } ;
11561170 let ac = match derive_info {
1157- DeriveInfo :: Implicit ( _) => {
1158- ty_name = info_name. expand_dim ( & index) ;
1159- convert_list && sequential_indexes_from0
1160- }
1161- DeriveInfo :: Explicit ( _) => {
1171+ DeriveInfo :: Implicit ( di) | DeriveInfo :: Explicit ( di)
1172+ if path == & di. block && !info_name. contains ( "[%s]" ) =>
1173+ {
11621174 ty_name = info_name. expand_dim ( & index) ;
1163- convert_list && sequential_indexes_from0
1175+ ty_str = ty_name. clone ( ) ;
1176+ false
11641177 }
11651178 _ => convert_list,
11661179 } ;
@@ -1207,7 +1220,7 @@ fn expand_register(
12071220 let idx_name = ident (
12081221 & util:: fullname ( & ri. name , & info. alternate_group , config. ignore_groups ) ,
12091222 config,
1210- "cluster_accessor " ,
1223+ "register_accessor " ,
12111224 span,
12121225 ) ;
12131226 let doc = make_comment (
@@ -1374,6 +1387,7 @@ fn cluster_block(
13741387 } ;
13751388 let reg_block = register_or_cluster_block (
13761389 & c. children ,
1390+ & path. new_cluster ( & c. name ) ,
13771391 & mod_derive_infos,
13781392 Some ( & mod_name) ,
13791393 & doc,
0 commit comments