From 7aaac6dfaeb3427c97ea64f63174946aac67cc87 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Mon, 2 Oct 2023 09:55:37 +0300 Subject: [PATCH 1/2] allow , in spec_ind --- CHANGELOG-rust.md | 2 ++ src/patch/mod.rs | 1 + src/patch/peripheral.rs | 2 +- src/patch/register.rs | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) 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::>() From eba56722e76fce25db531eca220cfff24ddabf85 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Mon, 2 Oct 2023 10:02:08 +0300 Subject: [PATCH 2/2] allow , in python spec_ind --- svdtools/patch.py | 3 +++ 1 file changed, 3 insertions(+) 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("[")