@@ -9,7 +9,7 @@ use svd_parser::svd::{
9
9
use yaml_rust:: { yaml:: Hash , Yaml } ;
10
10
11
11
use super :: iterators:: { MatchIter , Matched } ;
12
- use super :: register:: { RegisterExt , RegisterInfoExt } ;
12
+ use super :: register:: RegisterExt ;
13
13
use super :: yaml_ext:: { AsType , GetVal , ToYaml } ;
14
14
use super :: {
15
15
check_offsets, common_description, make_dim_element, matchname, matchsubspec,
@@ -162,21 +162,43 @@ pub(crate) trait RegisterBlockExt: Name {
162
162
fn add_child ( & mut self , child : RegisterCluster ) ;
163
163
164
164
/// Delete registers and clusters matched by rspec inside ptag
165
- fn delete_child ( & mut self , rcspec : & str ) -> PatchResult {
165
+ fn delete_child ( & mut self , rcspec : & str , bpath : & BlockPath ) -> PatchResult {
166
166
if let Some ( children) = self . children_mut ( ) {
167
- children. retain ( |rc| !matchname ( rc. name ( ) , rcspec) ) ;
167
+ let mut done = false ;
168
+ children. retain ( |rc| {
169
+ let del = matchname ( rc. name ( ) , rcspec) ;
170
+ done |= del;
171
+ !del
172
+ } ) ;
173
+ if !done {
174
+ log:: info!(
175
+ "Trying to delete absent `{}` register/cluster from {}" ,
176
+ rcspec,
177
+ bpath
178
+ ) ;
179
+ }
168
180
Ok ( ( ) )
169
181
} else {
170
182
Err ( anyhow ! ( "No registers or clusters" ) )
171
183
}
172
184
}
173
185
174
186
/// Delete registers matched by rspec inside ptag
175
- fn delete_register ( & mut self , rspec : & str ) -> PatchResult {
187
+ fn delete_register ( & mut self , rspec : & str , bpath : & BlockPath ) -> PatchResult {
176
188
if let Some ( children) = self . children_mut ( ) {
177
- children. retain (
178
- |rc| !matches ! ( rc, RegisterCluster :: Register ( r) if matchname( & r. name, rspec) ) ,
179
- ) ;
189
+ let mut done = false ;
190
+ children. retain ( |rc| {
191
+ let del = matches ! ( rc, RegisterCluster :: Register ( r) if matchname( & r. name, rspec) ) ;
192
+ done |= del;
193
+ !del
194
+ } ) ;
195
+ if !done {
196
+ log:: info!(
197
+ "Trying to delete absent `{}` register from {}" ,
198
+ rspec,
199
+ bpath
200
+ ) ;
201
+ }
180
202
Ok ( ( ) )
181
203
} else {
182
204
Err ( anyhow ! ( "No registers or clusters" ) )
@@ -187,16 +209,13 @@ pub(crate) trait RegisterBlockExt: Name {
187
209
let ( cspec, ignore) = cspec. spec ( ) ;
188
210
189
211
if let Some ( children) = self . children_mut ( ) {
190
- let mut deleted = false ;
212
+ let mut done = false ;
191
213
children. retain ( |rc| {
192
- let retain =
193
- !matches ! ( rc, RegisterCluster :: Cluster ( c) if matchname( & c. name, cspec) ) ;
194
- if !retain {
195
- deleted = true ;
196
- }
197
- retain
214
+ let del = matches ! ( rc, RegisterCluster :: Cluster ( c) if matchname( & c. name, cspec) ) ;
215
+ done |= del;
216
+ !del
198
217
} ) ;
199
- if !deleted && !ignore {
218
+ if !done && !ignore {
200
219
Err ( anyhow ! ( "No matching clusters found" ) )
201
220
} else {
202
221
Ok ( ( ) )
@@ -1029,21 +1048,21 @@ impl PeripheralExt for Peripheral {
1029
1048
if let Some ( deletions) = pmod. get_yaml ( "_delete" ) {
1030
1049
match deletions {
1031
1050
Yaml :: String ( rcspec) => {
1032
- self . delete_child ( rcspec) . with_context ( || {
1051
+ self . delete_child ( rcspec, & ppath ) . with_context ( || {
1033
1052
format ! ( "Deleting registers and clusters matched to `{rcspec}`" )
1034
1053
} ) ?;
1035
1054
}
1036
1055
Yaml :: Array ( deletions) => {
1037
1056
for rcspec in deletions {
1038
1057
let rcspec = rcspec. str ( ) ?;
1039
- self . delete_child ( rcspec) . with_context ( || {
1058
+ self . delete_child ( rcspec, & ppath ) . with_context ( || {
1040
1059
format ! ( "Deleting registers and clusters matched to `{rcspec}`" )
1041
1060
} ) ?;
1042
1061
}
1043
1062
}
1044
1063
Yaml :: Hash ( deletions) => {
1045
1064
for rspec in deletions. str_vec_iter ( "_registers" ) ? {
1046
- self . delete_register ( rspec)
1065
+ self . delete_register ( rspec, & ppath )
1047
1066
. with_context ( || format ! ( "Deleting registers matched to `{rspec}`" ) ) ?;
1048
1067
}
1049
1068
for cspec in deletions. str_vec_iter ( "_clusters" ) ? {
@@ -1337,32 +1356,46 @@ impl InterruptExt for Peripheral {
1337
1356
}
1338
1357
1339
1358
fn delete_interrupt ( & mut self , ispec : & str ) -> PatchResult {
1340
- self . interrupt . retain ( |i| !( matchname ( & i. name , ispec) ) ) ;
1359
+ let mut done = false ;
1360
+ self . interrupt . retain ( |i| {
1361
+ let del = matchname ( & i. name , ispec) ;
1362
+ done |= del;
1363
+ !del
1364
+ } ) ;
1365
+ if !done {
1366
+ log:: info!(
1367
+ "Trying to delete absent `{}` interrupt from {}" ,
1368
+ ispec,
1369
+ self . name
1370
+ ) ;
1371
+ }
1341
1372
Ok ( ( ) )
1342
1373
}
1343
1374
}
1344
1375
1345
1376
impl ClusterExt for Cluster {
1346
1377
fn pre_process ( & mut self , cmod : & Hash , parent : & BlockPath , _config : & Config ) -> PatchResult {
1378
+ let cpath = parent. new_cluster ( & self . name ) ;
1379
+
1347
1380
// Handle deletions
1348
1381
if let Some ( deletions) = cmod. get_yaml ( "_delete" ) {
1349
1382
match deletions {
1350
1383
Yaml :: String ( rcspec) => {
1351
- self . delete_child ( rcspec) . with_context ( || {
1384
+ self . delete_child ( rcspec, & cpath ) . with_context ( || {
1352
1385
format ! ( "Deleting registers and clusters matched to `{rcspec}`" )
1353
1386
} ) ?;
1354
1387
}
1355
1388
Yaml :: Array ( deletions) => {
1356
1389
for rcspec in deletions {
1357
1390
let rcspec = rcspec. str ( ) ?;
1358
- self . delete_child ( rcspec) . with_context ( || {
1391
+ self . delete_child ( rcspec, & cpath ) . with_context ( || {
1359
1392
format ! ( "Deleting registers and clusters matched to `{rcspec}`" )
1360
1393
} ) ?;
1361
1394
}
1362
1395
}
1363
1396
Yaml :: Hash ( deletions) => {
1364
1397
for rspec in deletions. str_vec_iter ( "_registers" ) ? {
1365
- self . delete_register ( rspec)
1398
+ self . delete_register ( rspec, & cpath )
1366
1399
. with_context ( || format ! ( "Deleting registers matched to `{rspec}`" ) ) ?;
1367
1400
}
1368
1401
for cspec in deletions. str_vec_iter ( "_clusters" ) ? {
@@ -1386,8 +1419,6 @@ impl ClusterExt for Cluster {
1386
1419
}
1387
1420
}
1388
1421
1389
- let cpath = parent. new_cluster ( & self . name ) ;
1390
-
1391
1422
// Handle any copied peripherals
1392
1423
for ( rname, rcopy) in cmod. hash_iter ( "_copy" ) {
1393
1424
let rname = rname. str ( ) ?;
@@ -1643,10 +1674,7 @@ fn collect_in_array(
1643
1674
if !check_offsets ( & offsets, dim_increment) {
1644
1675
return Err ( anyhow ! ( "{path}: registers cannot be collected into {rspec} array. Different addressOffset increments" ) ) ;
1645
1676
}
1646
- let bitmasks = registers
1647
- . iter ( )
1648
- . map ( RegisterInfo :: get_bitmask)
1649
- . collect :: < Vec < _ > > ( ) ;
1677
+ let bitmasks = registers. iter ( ) . map ( |r| r. bitmask ( ) ) . collect :: < Vec < _ > > ( ) ;
1650
1678
if !bitmasks. iter ( ) . all ( |& m| m == bitmasks[ 0 ] ) {
1651
1679
return Err ( anyhow ! (
1652
1680
"{path}: registers cannot be collected into {rspec} array. Different bit masks"
@@ -1769,10 +1797,7 @@ fn collect_in_cluster(
1769
1797
"Some of `{rspec}` registers are arrays and some are not"
1770
1798
) ) ;
1771
1799
}
1772
- let bitmasks = registers
1773
- . iter ( )
1774
- . map ( |r| RegisterInfo :: get_bitmask ( r) )
1775
- . collect :: < Vec < _ > > ( ) ;
1800
+ let bitmasks = registers. iter ( ) . map ( |r| r. bitmask ( ) ) . collect :: < Vec < _ > > ( ) ;
1776
1801
let new_dim_index = registers
1777
1802
. iter ( )
1778
1803
. map ( |r| {
0 commit comments