Skip to content

Commit 76bd2cf

Browse files
authored
Merge pull request #89 from burrbull/strip_move
move _strips before _modify
2 parents bb884ab + b7b8e05 commit 76bd2cf

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

CHANGELOG-python.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This changelog tracks the Python `svdtools` project. See
55

66
## [Unreleased]
77

8+
* Move `_strip`, `_strip_end` before `_modify`
9+
810
## [v0.1.23] 2022-05-01
911

1012
* Add support for `modifiedWriteValues` & `readAction` for fields

CHANGELOG-rust.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This changelog tracks the Rust `svdtools` project. See
55

66
## [Unreleased]
77

8+
* Move `_strip`, `_strip_end` before `_modify`
9+
810
## [v0.2.5] 2022-07-23
911

1012
* update `svd-rs` crates to 0.14

src/patch/peripheral.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ impl PeripheralExt for Peripheral {
170170
.with_context(|| format!("Copying register `{}`", rname))?
171171
}
172172

173+
// Handle strips
174+
for prefix in pmod.str_vec_iter("_strip") {
175+
self.strip_start(prefix)
176+
.with_context(|| format!("Stripping prefix `{}` from register names", prefix))?;
177+
}
178+
for suffix in pmod.str_vec_iter("_strip_end") {
179+
self.strip_end(suffix)
180+
.with_context(|| format!("Stripping suffix `{}` from register names", suffix))?;
181+
}
182+
173183
// Handle modifications
174184
for (rspec, rmod) in pmod.hash_iter("_modify") {
175185
let rmod = rmod.hash()?;
@@ -204,16 +214,6 @@ impl PeripheralExt for Peripheral {
204214
}
205215
}
206216

207-
// Handle strips
208-
for prefix in pmod.str_vec_iter("_strip") {
209-
self.strip_start(prefix)
210-
.with_context(|| format!("Stripping prefix `{}` from register names", prefix))?;
211-
}
212-
for suffix in pmod.str_vec_iter("_strip_end") {
213-
self.strip_end(suffix)
214-
.with_context(|| format!("Stripping suffix `{}` from register names", suffix))?;
215-
}
216-
217217
// Handle field clearing
218218
for rspec in pmod.str_vec_iter("_clear_fields") {
219219
self.clear_fields(rspec).with_context(|| {

src/patch/register.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ impl RegisterExt for Register {
9999
.with_context(|| format!("Deleting fields matched to `{}`", fspec))?;
100100
}
101101

102+
// Handle strips
103+
for prefix in rmod.str_vec_iter("_strip") {
104+
self.strip_start(prefix)
105+
.with_context(|| format!("Stripping prefix `{}` from field names", prefix))?;
106+
}
107+
for suffix in rmod.str_vec_iter("_strip_end") {
108+
self.strip_end(suffix)
109+
.with_context(|| format!("Stripping suffix `{}` from field names", suffix))?;
110+
}
111+
102112
// Handle field clearing
103113
for fspec in rmod.str_vec_iter("_clear") {
104114
self.clear_field(fspec)
@@ -156,16 +166,6 @@ impl RegisterExt for Register {
156166
_ => {}
157167
}
158168

159-
// Handle strips
160-
for prefix in rmod.str_vec_iter("_strip") {
161-
self.strip_start(prefix)
162-
.with_context(|| format!("Stripping prefix `{}` from field names", prefix))?;
163-
}
164-
for suffix in rmod.str_vec_iter("_strip_end") {
165-
self.strip_end(suffix)
166-
.with_context(|| format!("Stripping suffix `{}` from field names", suffix))?;
167-
}
168-
169169
// Handle fields
170170
if update_fields {
171171
for (fspec, field) in rmod {

svdtools/patch.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ def process_peripheral(self, pspec, peripheral, update_fields=True):
671671
for rname in peripheral.get("_copy", {}):
672672
rderive = peripheral["_copy"][rname]
673673
p.copy_register(rname, rderive)
674+
# Handle strips
675+
for prefix in peripheral.get("_strip", []):
676+
p.strip(prefix)
677+
for suffix in peripheral.get("_strip_end", []):
678+
p.strip(suffix, strip_end=True)
674679
# Handle modifications
675680
for rspec in peripheral.get("_modify", {}):
676681
rmod = peripheral["_modify"][rspec]
@@ -685,11 +690,6 @@ def process_peripheral(self, pspec, peripheral, update_fields=True):
685690
p.modify_cluster(cspec, rmod[cspec])
686691
else:
687692
p.modify_register(rspec, rmod)
688-
# Handle strips
689-
for prefix in peripheral.get("_strip", []):
690-
p.strip(prefix)
691-
for suffix in peripheral.get("_strip_end", []):
692-
p.strip(suffix, strip_end=True)
693693
# Handle field clearing
694694
for rspec in peripheral.get("_clear_fields", []):
695695
p.clear_fields(rspec)
@@ -1120,6 +1120,11 @@ def process_register(self, rspec, register, update_fields=True):
11201120
# Handle deletions
11211121
for fspec in register.get("_delete", []):
11221122
r.delete_field(fspec)
1123+
# Handle strips
1124+
for prefix in register.get("_strip", []):
1125+
r.strip(prefix)
1126+
for suffix in register.get("_strip_end", []):
1127+
r.strip(suffix, strip_end=True)
11231128
# Handle field clearing
11241129
for fspec in register.get("_clear", []):
11251130
r.clear_field(fspec)
@@ -1147,11 +1152,6 @@ def process_register(self, rspec, register, update_fields=True):
11471152
else {}
11481153
)
11491154
r.split_fields(fspec, fsplit)
1150-
# Handle strips
1151-
for prefix in register.get("_strip", []):
1152-
r.strip(prefix)
1153-
for suffix in register.get("_strip_end", []):
1154-
r.strip(suffix, strip_end=True)
11551155
# Handle fields
11561156
if update_fields:
11571157
for fspec in register:

0 commit comments

Comments
 (0)