Skip to content

Commit 0da386b

Browse files
authored
Merge pull request #188 from rust-embedded/strip-alternate
strip in alternateRegister
2 parents 4286af9 + acfa076 commit 0da386b

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

CHANGELOG-python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This changelog tracks the Python `svdtools` project. See
66
## [Unreleased]
77

88
* `-1` for default enum value
9+
* Strip `alternateRegister` too
910

1011
## [v0.1.26] 2023-03-28
1112

CHANGELOG-rust.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This changelog tracks the Rust `svdtools` project. See
66
## [Unreleased]
77

88
* Add `--enum_derive` flag
9+
* Strip `alternateRegister` too
910

1011
## [v0.3.6] 2023-11-01
1112

src/patch/peripheral.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ impl RegisterBlockExt for Peripheral {
581581
dname.drain(..len);
582582
}
583583
}
584+
if let Some(name) = rtag.alternate_register.as_mut() {
585+
if glob.is_match(&name) {
586+
name.drain(..len);
587+
}
588+
}
584589
}
585590
Ok(())
586591
}
@@ -601,6 +606,12 @@ impl RegisterBlockExt for Peripheral {
601606
dname.truncate(nlen - len);
602607
}
603608
}
609+
if let Some(name) = rtag.alternate_register.as_mut() {
610+
if glob.is_match(&name) {
611+
let nlen = name.len();
612+
name.truncate(nlen - len);
613+
}
614+
}
604615
}
605616
Ok(())
606617
}
@@ -1040,6 +1051,11 @@ impl RegisterBlockExt for Cluster {
10401051
dname.drain(..len);
10411052
}
10421053
}
1054+
if let Some(name) = rtag.alternate_register.as_mut() {
1055+
if glob.is_match(&name) {
1056+
name.drain(..len);
1057+
}
1058+
}
10431059
}
10441060
Ok(())
10451061
}
@@ -1060,6 +1076,12 @@ impl RegisterBlockExt for Cluster {
10601076
dname.truncate(nlen - len);
10611077
}
10621078
}
1079+
if let Some(name) = rtag.alternate_register.as_mut() {
1080+
if glob.is_match(&name) {
1081+
let nlen = name.len();
1082+
name.truncate(nlen - len);
1083+
}
1084+
}
10631085
}
10641086
Ok(())
10651087
}

svdtools/patch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,10 @@ def strip(self, substr, strip_end=False):
10191019
if dnametag is not None:
10201020
dnametag.text = regex.sub("", dnametag.text)
10211021

1022+
alttag = rtag.find("alternateRegister")
1023+
if alttag is not None:
1024+
alttag.text = regex.sub("", alttag.text)
1025+
10221026
def collect_in_array(self, rspec, rmod):
10231027
"""Collect same registers in peripheral into register array."""
10241028
registers = []
@@ -1345,6 +1349,9 @@ def strip(self, substr: str, strip_end: bool = False) -> None:
13451349
if dnametag is not None:
13461350
assert isinstance(dnametag.text, str)
13471351
dnametag.text = regex.sub("", dnametag.text)
1352+
alttag = rtag.find("alternateRegister")
1353+
if alttag is not None:
1354+
alttag.text = regex.sub("", alttag.text)
13481355

13491356

13501357
def sorted_fields(fields):

0 commit comments

Comments
 (0)