diff --git a/CHANGELOG-rust.md b/CHANGELOG-rust.md index 87f27323..93c10783 100644 --- a/CHANGELOG-rust.md +++ b/CHANGELOG-rust.md @@ -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 diff --git a/src/patch/mod.rs b/src/patch/mod.rs index 7d68ad42..738521b9 100644 --- a/src/patch/mod.rs +++ b/src/patch/mod.rs @@ -570,6 +570,7 @@ fn make_cpu(cmod: &Hash) -> Result { /// 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'*') diff --git a/src/patch/peripheral.rs b/src/patch/peripheral.rs index 85e76cc1..c4d70314 100644 --- a/src/patch/peripheral.rs +++ b/src/patch/peripheral.rs @@ -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 ®s[i] { RegisterCluster::Register(Register::Single(r)) if matchname(&r.name, rspec) => { @@ -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::>() diff --git a/src/patch/register.rs b/src/patch/register.rs index 894caad1..fc40abc9 100644 --- a/src/patch/register.rs +++ b/src/patch/register.rs @@ -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) => { @@ -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::>() diff --git a/svdtools/patch.py b/svdtools/patch.py index 00dfeca4..ad2e55bc 100644 --- a/svdtools/patch.py +++ b/svdtools/patch.py @@ -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("[")