@@ -2,6 +2,7 @@ use anyhow::{anyhow, Context};
22use svd_parser:: svd:: { Device , Peripheral , PeripheralInfo } ;
33use yaml_rust:: { yaml:: Hash , Yaml } ;
44
5+ use std:: collections:: HashSet ;
56use std:: { fs:: File , io:: Read , path:: Path } ;
67
78use super :: iterators:: { MatchIter , Matched } ;
@@ -220,7 +221,10 @@ impl DeviceExt for Device {
220221 }
221222
222223 fn modify_peripheral ( & mut self , pspec : & str , pmod : & Hash ) -> PatchResult {
224+ let mut modified = HashSet :: new ( ) ;
223225 for ptag in self . iter_peripherals ( pspec) {
226+ modified. insert ( ptag. name . clone ( ) ) ;
227+
224228 ptag. modify_from ( make_peripheral ( pmod, true ) ?, VAL_LVL ) ?;
225229 if let Some ( ints) = pmod. get_hash ( "interrupts" ) ? {
226230 for ( iname, val) in ints {
@@ -245,6 +249,17 @@ impl DeviceExt for Device {
245249 ptag. address_block = Some ( make_address_blocks ( abmod) ?) ;
246250 }
247251 }
252+ // If this peripheral has derivations, update the derived
253+ // peripherals to reference the new name.
254+ if let Some ( value) = pmod. get_str ( "name" ) ? {
255+ for p in self . peripherals . iter_mut ( ) {
256+ if let Some ( old_name) = p. derived_from . as_mut ( ) {
257+ if modified. contains ( old_name) {
258+ * old_name = value. into ( ) ;
259+ }
260+ }
261+ }
262+ }
248263 Ok ( ( ) )
249264 }
250265
0 commit comments