Skip to content

Commit 6a9a0f5

Browse files
bors[bot]n8tlarsen
andauthored
Merge #703
703: Fix dangling implicit derives r=Emilgardis a=n8tlarsen While working on R7FA6M5BH.svd I found that the generated code does not compile because P0%sPFS_BY got thrown away while implicitly deriving registers. Looking through the debug log I found this: ``` [DEBUG svd2rust::generate::device] Rendering peripheral PFS [DEBUG svd2rust::generate::peripheral] Checking derivation information [DEBUG svd2rust::generate::peripheral] register P009PFS_BY implicitly derives from P00%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P010PFS implicitly derives from P0%sPFS [DEBUG svd2rust::generate::peripheral] register P010PFS_HA implicitly derives from P0%sPFS_HA [DEBUG svd2rust::generate::peripheral] register P010PFS_BY implicitly derives from P0%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P0%sPFS_BY implicitly derives from P00%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P200PFS implicitly derives from P20%sPFS [DEBUG svd2rust::generate::peripheral] register P200PFS_HA implicitly derives from P20%sPFS_HA [DEBUG svd2rust::generate::peripheral] register P200PFS_BY implicitly derives from P20%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P2%sPFS implicitly derives from P20%sPFS [DEBUG svd2rust::generate::peripheral] register P2%sPFS_HA implicitly derives from P20%sPFS_HA [DEBUG svd2rust::generate::peripheral] register P2%sPFS_BY implicitly derives from P20%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P70%sPFS implicitly derives from P70%sPFS [DEBUG svd2rust::generate::peripheral] register P70%sPFS_HA implicitly derives from P70%sPFS_HA [DEBUG svd2rust::generate::peripheral] register P70%sPFS_BY implicitly derives from P70%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P90%sPFS implicitly derives from P90%sPFS [DEBUG svd2rust::generate::peripheral] register P90%sPFS_HA implicitly derives from P90%sPFS_HA [DEBUG svd2rust::generate::peripheral] register P90%sPFS_BY implicitly derives from P90%sPFS_BY [DEBUG svd2rust::generate::peripheral] register PA0%sPFS implicitly derives from PA0%sPFS [DEBUG svd2rust::generate::peripheral] register PA0%sPFS_HA implicitly derives from PA0%sPFS_HA [DEBUG svd2rust::generate::peripheral] register PA0%sPFS_BY implicitly derives from PA0%sPFS_BY [DEBUG svd2rust::generate::peripheral] register P%sSAR implicitly derives from P%sSAR [DEBUG svd2rust::generate::peripheral] Pushing cluster & register information into output [DEBUG svd2rust::generate::peripheral] Pushing 95 register or cluster blocks into output ``` P010PFS_BY implicitly derives from P0%sPFS_BY and P0%sPFS_BY implicitly derives from P00%sPFS_BY, which leaves P0%sPFS_BY dangling (P0%sPFS_BY regex matched to P009PFS_BY and implicitly derived from the root P00%sPFS_BY). The fix checks for would-be dangling derives while checking previous names against the "P0%sPFS_BY" regex, and replaces the derive with the new root. Co-authored-by: Nathan <[email protected]>
2 parents 27eebb4 + 8adf03f commit 6a9a0f5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
9+
- Fix dangling implicit derives
910

1011
## [v0.28.0] - 2022-12-25
1112

src/generate/peripheral.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ fn compare_this_against_prev(
859859
Ok(None)
860860
}
861861

862-
/// Compare the given type name against previous regexs, then inspect fields
862+
/// Compare previous type names against the given regex, then inspect fields
863863
fn compare_prev_against_this(
864864
reg: &MaybeArray<RegisterInfo>,
865865
ty_name: &str,
@@ -913,6 +913,21 @@ fn compare_prev_against_this(
913913
}
914914
}
915915
}
916+
if let DeriveInfo::Implicit(my_rpath) = &my_derive_info {
917+
match prev_derive_info {
918+
DeriveInfo::Implicit(their_rpath) => {
919+
if their_rpath.name == ty_name {
920+
(_, *their_rpath) = find_root(&my_rpath.name, path, index)?;
921+
}
922+
}
923+
DeriveInfo::Explicit(their_rpath) => {
924+
if their_rpath.name == ty_name {
925+
(_, *their_rpath) = find_root(&my_rpath.name, path, index)?;
926+
}
927+
}
928+
_ => {}
929+
}
930+
}
916931
}
917932
}
918933
Ok(my_derive_info)

0 commit comments

Comments
 (0)