@@ -188,8 +188,15 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
188
188
"Pushing {} register or cluster blocks into output" ,
189
189
ercs. len( )
190
190
) ;
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
+ ) ?;
193
200
194
201
out. extend ( quote ! {
195
202
#[ doc = #doc]
@@ -469,6 +476,7 @@ fn make_comment(size: u32, offset: u32, description: &str) -> String {
469
476
470
477
fn register_or_cluster_block (
471
478
ercs : & [ RegisterCluster ] ,
479
+ path : & BlockPath ,
472
480
derive_infos : & [ DeriveInfo ] ,
473
481
name : Option < & str > ,
474
482
doc : & str ,
@@ -478,7 +486,7 @@ fn register_or_cluster_block(
478
486
let mut rbfs = TokenStream :: new ( ) ;
479
487
let mut accessors = TokenStream :: new ( ) ;
480
488
481
- let ercs_expanded = expand ( ercs, derive_infos, config)
489
+ let ercs_expanded = expand ( ercs, path , derive_infos, config)
482
490
. with_context ( || "Could not expand register or cluster block" ) ?;
483
491
484
492
// Locate conflicting regions; we'll need to use unions to represent them.
@@ -612,6 +620,7 @@ fn register_or_cluster_block(
612
620
/// `RegisterBlockField`s containing `Field`s.
613
621
fn expand (
614
622
ercs : & [ RegisterCluster ] ,
623
+ path : & BlockPath ,
615
624
derive_infos : & [ DeriveInfo ] ,
616
625
config : & Config ,
617
626
) -> Result < Vec < RegisterBlockField > > {
@@ -623,14 +632,14 @@ fn expand(
623
632
match & erc {
624
633
RegisterCluster :: Register ( register) => {
625
634
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)
627
636
. with_context ( || format ! ( "can't expand register '{reg_name}'" ) ) ?;
628
637
trace ! ( "Register: {reg_name}" ) ;
629
638
ercs_expanded. extend ( expanded_reg) ;
630
639
}
631
640
RegisterCluster :: Cluster ( cluster) => {
632
641
let cluster_name = & cluster. name ;
633
- let expanded_cluster = expand_cluster ( cluster, config)
642
+ let expanded_cluster = expand_cluster ( cluster, path , config)
634
643
. with_context ( || format ! ( "can't expand cluster '{cluster_name}'" ) ) ?;
635
644
trace ! ( "Cluster: {cluster_name}" ) ;
636
645
ercs_expanded. extend ( expanded_cluster) ;
@@ -873,9 +882,9 @@ fn is_derivable(
873
882
/// Calculate the size of a Cluster. If it is an array, then the dimensions
874
883
/// tell us the size of the array. Otherwise, inspect the contents using
875
884
/// [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 > {
877
886
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) ,
879
888
// If the contained array cluster has a mismatch between the
880
889
// dimIncrement and the size of the array items, then the array
881
890
// 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> {
885
894
return Ok ( 0 ) ; // Special case!
886
895
}
887
896
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) ;
889
898
Ok ( last_offset + last_size?)
890
899
}
891
900
}
892
901
}
893
902
894
903
/// Recursively calculate the size of a ClusterInfo. A cluster's size is the
895
904
/// 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 > {
897
906
let mut size = 0 ;
898
907
899
908
for c in & info. children {
900
909
let end = match c {
901
910
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) ?
903
912
. iter ( )
904
913
. map ( |rbf| rbf. size )
905
914
. sum ( ) ;
906
915
907
916
( reg. address_offset * BITS_PER_BYTE ) + reg_size
908
917
}
909
918
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) ?
911
920
}
912
921
} ;
913
922
@@ -917,10 +926,14 @@ fn cluster_info_size_in_bits(info: &ClusterInfo, config: &Config) -> Result<u32>
917
926
}
918
927
919
928
/// 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 > > {
921
934
let mut cluster_expanded = vec ! [ ] ;
922
935
923
- let cluster_size = cluster_info_size_in_bits ( cluster, config)
936
+ let cluster_size = cluster_info_size_in_bits ( cluster, path , config)
924
937
. with_context ( || format ! ( "Can't calculate cluster {} size" , cluster. name) ) ?;
925
938
let description = cluster
926
939
. description
@@ -1087,6 +1100,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
1087
1100
/// A `DeriveInfo::Implicit(_)` will also cause an array to be expanded.
1088
1101
fn expand_register (
1089
1102
register : & Register ,
1103
+ path : & BlockPath ,
1090
1104
derive_info : & DeriveInfo ,
1091
1105
config : & Config ,
1092
1106
) -> Result < Vec < RegisterBlockField > > {
@@ -1104,7 +1118,7 @@ fn expand_register(
1104
1118
} else {
1105
1119
info_name. remove_dim ( )
1106
1120
} ;
1107
- let ty_str = ty_name. clone ( ) ;
1121
+ let mut ty_str = ty_name. clone ( ) ;
1108
1122
1109
1123
match register {
1110
1124
Register :: Single ( info) => {
@@ -1135,7 +1149,7 @@ fn expand_register(
1135
1149
|| ( register_size <= array_info. dim_increment * BITS_PER_BYTE ) ;
1136
1150
1137
1151
let convert_list = match config. keep_list {
1138
- true => info . name . contains ( "[%s]" ) ,
1152
+ true => info_name . contains ( "[%s]" ) ,
1139
1153
false => true ,
1140
1154
} ;
1141
1155
@@ -1154,13 +1168,12 @@ fn expand_register(
1154
1168
"" . into ( )
1155
1169
} ;
1156
1170
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
+ {
1162
1174
ty_name = info_name. expand_dim ( & index) ;
1163
- convert_list && sequential_indexes_from0
1175
+ ty_str = ty_name. clone ( ) ;
1176
+ false
1164
1177
}
1165
1178
_ => convert_list,
1166
1179
} ;
@@ -1207,7 +1220,7 @@ fn expand_register(
1207
1220
let idx_name = ident (
1208
1221
& util:: fullname ( & ri. name , & info. alternate_group , config. ignore_groups ) ,
1209
1222
config,
1210
- "cluster_accessor " ,
1223
+ "register_accessor " ,
1211
1224
span,
1212
1225
) ;
1213
1226
let doc = make_comment (
@@ -1374,6 +1387,7 @@ fn cluster_block(
1374
1387
} ;
1375
1388
let reg_block = register_or_cluster_block (
1376
1389
& c. children ,
1390
+ & path. new_cluster ( & c. name ) ,
1377
1391
& mod_derive_infos,
1378
1392
Some ( & mod_name) ,
1379
1393
& doc,
0 commit comments