Skip to content

Commit

Permalink
Merge pull request #162 from rust-embedded/indeces
Browse files Browse the repository at this point in the history
allow , in spec_ind
  • Loading branch information
burrbull authored Oct 2, 2023
2 parents 27cf2b1 + eba5672 commit 1ffaf7c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

* Fast fix for #161

## [v0.3.2] 2023-10-01

* `_modify` `derivedFrom` for peripherals, clusters, registers and fields
Expand Down
1 change: 1 addition & 0 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ fn make_cpu(cmod: &Hash) -> Result<CpuBuilder> {

/// Find left and right indices of enumeration token in specification string
fn spec_ind(spec: &str) -> (usize, usize) {
let spec = spec.split(',').next().unwrap_or(spec);
let li = spec
.bytes()
.position(|b| b == b'*')
Expand Down
2 changes: 1 addition & 1 deletion src/patch/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,6 @@ fn collect_in_array(
let mut registers = Vec::new();
let mut place = usize::MAX;
let mut i = 0;
let (li, ri) = spec_ind(rspec);
while i < regs.len() {
match &regs[i] {
RegisterCluster::Register(Register::Single(r)) if matchname(&r.name, rspec) => {
Expand All @@ -1136,6 +1135,7 @@ fn collect_in_array(
return Err(anyhow!("{path}: registers {rspec} not found"));
}
registers.sort_by_key(|r| r.address_offset);
let (li, ri) = spec_ind(rspec);
let dim = registers.len();
let dim_index = if rmod.contains_key(&"_start_from_zero".to_yaml()) {
(0..dim).map(|v| v.to_string()).collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion src/patch/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ impl RegisterExt for Register {
let mut fields = Vec::new();
let mut place = usize::MAX;
let mut i = 0;
let (li, ri) = spec_ind(fspec);
while i < fs.len() {
match &fs[i] {
Field::Single(f) if matchname(&f.name, fspec) => {
Expand All @@ -374,6 +373,7 @@ impl RegisterExt for Register {
return Err(anyhow!("{}: fields {fspec} not found", self.name));
}
fields.sort_by_key(|f| f.bit_range.offset);
let (li, ri) = spec_ind(fspec);
let dim = fields.len();
let dim_index = if fmod.contains_key(&"_start_from_zero".to_yaml()) {
(0..dim).map(|v| v.to_string()).collect::<Vec<_>>()
Expand Down
3 changes: 3 additions & 0 deletions svdtools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ def spec_ind(spec):
"""
Find left and right indices of enumeration token in specification string.
"""
comma = spec.find(",")
if comma > -1:
spec = spec[:comma]
li1 = spec.find("*")
li2 = spec.find("?")
li3 = spec.find("[")
Expand Down

0 comments on commit 1ffaf7c

Please sign in to comment.