From 2e4cbcb027fdf06534921a2486c4d45222553a31 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Tue, 2 Jun 2020 13:06:38 +0300 Subject: [PATCH 1/3] update_svd_parser --- .github/bors.toml | 2 +- .github/workflows/ci.yml | 2 +- Cargo.toml | 5 ++- ci/script.sh | 89 +--------------------------------------- 4 files changed, 7 insertions(+), 91 deletions(-) diff --git a/.github/bors.toml b/.github/bors.toml index c83d10e8..8fc522d4 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -15,7 +15,7 @@ status = [ "ci-linux (stable, Spansion, x86_64-unknown-linux-gnu, linux)", "ci-linux (stable, STMicro, x86_64-unknown-linux-gnu, linux)", "ci-linux (stable, Toshiba, x86_64-unknown-linux-gnu, linux)", - "ci-linux (1.37.0, Nordic, x86_64-unknown-linux-gnu, linux)", + "ci-linux (1.40.0, Nordic, x86_64-unknown-linux-gnu, linux)", "ci-linux (stable, x86_64-apple-darwin, osx)", "ci-linux (stable, x86_64-pc-windows-msvc, windows)", ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b51e4c64..d7cb3b36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: include: # Test MSRV - - rust: 1.37.0 + - rust: 1.40.0 VENDOR: Nordic TARGET: x86_64-unknown-linux-gnu TRAVIS_OS_NAME: linux diff --git a/Cargo.toml b/Cargo.toml index b498a932..6f750325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,9 +43,12 @@ anyhow = "1.0.19" thiserror = "1.0.5" [dependencies.svd-parser] -version = "0.9" +version = "0.10" features = ["derive-from"] [dependencies.syn] version = "1.0" features = ["full","extra-traits"] + +[features] +strict = ["svd-parser/strict"] diff --git a/ci/script.sh b/ci/script.sh index f8d48aa6..52d4c9d0 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -524,97 +524,10 @@ main() { Spansion) # OK - test_svd MB9AF12xK - test_svd MB9AF12xL - test_svd MB9AF42xK - test_svd MB9AF42xL - test_svd MB9BF12xJ - test_svd MB9BF12xS - test_svd MB9BF12xT - test_svd MB9BF16xx - test_svd MB9BF32xS - test_svd MB9BF32xT + # See Fujitsu for other chips test_svd MB9BF36xx - test_svd MB9BF42xS - test_svd MB9BF42xT test_svd MB9BF46xx - test_svd MB9BF52xS - test_svd MB9BF52xT test_svd MB9BF56xx - - # #102 regression tests - # # NOTE it would take too long to test all these so we only test half - # test_svd MB9AF10xN - test_svd MB9AF10xR - # test_svd MB9AF11xK - test_svd MB9AF11xL - # test_svd MB9AF11xM - test_svd MB9AF11xN - # test_svd MB9AF13xK - test_svd MB9AF13xL - # test_svd MB9AF13xM - test_svd MB9AF13xN - # test_svd MB9AF14xL - test_svd MB9AF14xM - # test_svd MB9AF14xN - test_svd MB9AF15xM - # test_svd MB9AF15xN - test_svd MB9AF15xR - # test_svd MB9AF31xK - test_svd MB9AF31xL - # test_svd MB9AF31xM - test_svd MB9AF31xN - # test_svd MB9AF34xL - test_svd MB9AF34xM - # test_svd MB9AF34xN - test_svd MB9AFA3xL - # test_svd MB9AFA3xM - test_svd MB9AFA3xN - # test_svd MB9AFA4xL - test_svd MB9AFA4xM - # test_svd MB9AFA4xN - test_svd MB9AFB4xL - # test_svd MB9AFB4xM - test_svd MB9AFB4xN - # test_svd MB9BF10xN - test_svd MB9BF10xR - # test_svd MB9BF11xN - test_svd MB9BF11xR - # test_svd MB9BF11xS - test_svd MB9BF11xT - # test_svd MB9BF12xK - test_svd MB9BF12xL - # test_svd MB9BF12xM - test_svd MB9BF21xS - # test_svd MB9BF21xT - test_svd MB9BF30xN - # test_svd MB9BF30xR - test_svd MB9BF31xN - # test_svd MB9BF31xR - test_svd MB9BF31xS - # test_svd MB9BF31xT - test_svd MB9BF32xK - # test_svd MB9BF32xL - test_svd MB9BF32xM - # test_svd MB9BF40xN - test_svd MB9BF40xR - # test_svd MB9BF41xN - test_svd MB9BF41xR - # test_svd MB9BF41xS - test_svd MB9BF41xT - # test_svd MB9BF50xN - test_svd MB9BF50xR - # test_svd MB9BF51xN - test_svd MB9BF51xR - # test_svd MB9BF51xS - test_svd MB9BF51xT - # test_svd MB9BF52xK - test_svd MB9BF52xL - # test_svd MB9BF52xM - test_svd MB9BF61xS - # test_svd MB9BF61xT - test_svd MB9BFD1xS - # test_svd MB9BFD1xT ;; STMicro) From 09150465218909809224d508a59184bc41e062f2 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Mon, 5 Apr 2021 22:41:00 +0300 Subject: [PATCH 2/3] deps --- Cargo.toml | 4 ++-- ci/script.sh | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6f750325..c1b91bb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,8 @@ inflections = "1.1" log = { version = "~0.4", features = ["std"] } quote = "1.0" proc-macro2 = "1.0" -anyhow = "1.0.19" -thiserror = "1.0.5" +anyhow = "1.0" +thiserror = "1.0" [dependencies.svd-parser] version = "0.10" diff --git a/ci/script.sh b/ci/script.sh index 52d4c9d0..c587eae5 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -419,7 +419,7 @@ main() { Microchip) echo '[dependencies.bare-metal]' >> $td/Cargo.toml - echo 'version = "0.2.0"' >> $td/Cargo.toml + echo 'version = "1.0.0"' >> $td/Cargo.toml echo '[dependencies.mips-mcu]' >> $td/Cargo.toml echo 'version = "0.1.0"' >> $td/Cargo.toml @@ -493,13 +493,13 @@ main() { # Community-provided RISC-V SVDs RISC-V) echo '[dependencies.bare-metal]' >> $td/Cargo.toml - echo 'version = "0.2.0"' >> $td/Cargo.toml + echo 'version = "1.0.0"' >> $td/Cargo.toml echo '[dependencies.riscv]' >> $td/Cargo.toml - echo 'version = "0.5.0"' >> $td/Cargo.toml + echo 'version = "0.6.0"' >> $td/Cargo.toml echo '[dependencies.riscv-rt]' >> $td/Cargo.toml - echo 'version = "0.6.0"' >> $td/Cargo.toml + echo 'version = "0.8.0"' >> $td/Cargo.toml test_svd_for_target riscv https://raw.githubusercontent.com/riscv-rust/e310x/master/e310x.svd test_svd_for_target riscv https://raw.githubusercontent.com/riscv-rust/k210-pac/master/k210.svd @@ -583,7 +583,7 @@ main() { Espressif) echo '[dependencies.bare-metal]' >> $td/Cargo.toml - echo 'version = "0.2.0"' >> $td/Cargo.toml + echo 'version = "1.0.0"' >> $td/Cargo.toml echo '[dependencies.xtensa-lx]' >> $td/Cargo.toml echo 'version = "0.3.0"' >> $td/Cargo.toml From 1d4a93539e1d11e900d89776d71fa7c449126b8b Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Mon, 5 Apr 2021 23:06:52 +0300 Subject: [PATCH 3/3] clippy --- src/generate/peripheral.rs | 6 ++---- src/generate/register.rs | 18 +++++++++--------- src/lib.rs | 10 ++-------- src/util.rs | 5 +++-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 38e7b25d..50f5456c 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -426,14 +426,12 @@ impl FieldRegions { .filter(|r| { r.fields.len() > 1 && (idents.iter().filter(|ident| **ident == r.ident).count() > 1) }) - .inspect(|r| { + .for_each(|r| { warn!( "Found type name conflict with region {:?}, renamed to {:?}", r.ident, r.shortest_ident() - ) - }) - .for_each(|r| { + ); r.ident = r.shortest_ident(); }); Ok(()) diff --git a/src/generate/register.rs b/src/generate/register.rs index e3b4bc98..925f1cb8 100644 --- a/src/generate/register.rs +++ b/src/generate/register.rs @@ -3,6 +3,7 @@ use crate::svd::{ RegisterProperties, Usage, WriteConstraint, }; use cast::u64; +use core::u64; use log::warn; use proc_macro2::{Ident, Punct, Spacing, Span, TokenStream}; use quote::{quote, ToTokens}; @@ -254,6 +255,7 @@ pub fn render( Ok(out) } +#[allow(clippy::too_many_arguments)] pub fn fields( fields: &[Field], parent: &Register, @@ -291,7 +293,7 @@ pub fn fields( && (f.access != Some(Access::WriteOnce)); let can_write = can_write && (f.access != Some(Access::ReadOnly)); - let mask = 1u64.wrapping_neg() >> (64 - width); + let mask = u64::MAX >> (64 - width); let hexmask = &util::hex(mask); let offset = u64::from(offset); let rv = reset_value.map(|rv| (rv >> offset) & mask); @@ -749,8 +751,7 @@ pub fn fields( fn unsafety(write_constraint: Option<&WriteConstraint>, width: u32) -> Option { match &write_constraint { Some(&WriteConstraint::Range(range)) - if u64::from(range.min) == 0 - && u64::from(range.max) == 1u64.wrapping_neg() >> (64 - width) => + if range.min == 0 && range.max == u64::MAX >> (64 - width) => { // the SVD has acknowledged that it's safe to write // any value that can fit in the field @@ -1052,8 +1053,7 @@ fn lookup_in_peripheral<'p>( if let Some(register) = all_registers.iter().find(|r| r.name == base_register) { if let Some(field) = register .fields - .as_ref() - .map(|fs| &**fs) + .as_deref() .unwrap_or(&[]) .iter() .find(|f| f.name == base_field) @@ -1082,7 +1082,7 @@ fn lookup_in_field<'f>( field: &'f Field, ) -> Result<(&'f EnumeratedValues, Option>)> { for evs in &field.enumerated_values { - if evs.name.as_ref().map(|s| &**s) == Some(base_evs) { + if evs.name.as_deref() == Some(base_evs) { return Ok(( evs, Some(Base { @@ -1107,11 +1107,11 @@ fn lookup_in_register<'r>( ) -> Result<(&'r EnumeratedValues, Option>)> { let mut matches = vec![]; - for f in register.fields.as_ref().map(|v| &**v).unwrap_or(&[]) { + for f in register.fields.as_deref().unwrap_or(&[]) { if let Some(evs) = f .enumerated_values .iter() - .find(|evs| evs.name.as_ref().map(|s| &**s) == Some(base_evs)) + .find(|evs| evs.name.as_deref() == Some(base_evs)) { matches.push((evs, &f.name)) } @@ -1168,7 +1168,7 @@ fn lookup_in_peripherals<'p>( } } -fn periph_all_registers<'a>(p: &'a Peripheral) -> Vec<&'a Register> { +fn periph_all_registers(p: &Peripheral) -> Vec<&Register> { let mut par: Vec<&Register> = Vec::new(); let mut rem: Vec<&RegisterCluster> = Vec::new(); if p.registers.is_none() { diff --git a/src/lib.rs b/src/lib.rs index d6632a92..424e72c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -484,20 +484,16 @@ mod util; pub use crate::util::Target; +#[non_exhaustive] pub struct Generation { pub lib_rs: String, pub device_specific: Option, - - // Reserve the right to add more fields to this struct - _extensible: (), } +#[non_exhaustive] pub struct DeviceSpecific { pub device_x: String, pub build_rs: String, - - // Reserve the right to add more fields to this struct - _extensible: (), } use anyhow::Result; @@ -534,14 +530,12 @@ pub fn generate(xml: &str, target: Target, nightly: bool) -> Result Some(DeviceSpecific { device_x, build_rs: util::build_rs().to_string(), - _extensible: (), }) }; Ok(Generation { lib_rs, device_specific, - _extensible: (), }) } diff --git a/src/util.rs b/src/util.rs index d77aafc5..541bf1ac 100644 --- a/src/util.rs +++ b/src/util.rs @@ -13,6 +13,7 @@ pub const BITS_PER_BYTE: u32 = 8; /// that are not valid in Rust ident const BLACKLIST_CHARS: &[char] = &['(', ')', '[', ']', '/', ' ', '-']; +#[allow(non_camel_case_types)] #[derive(Clone, Copy, PartialEq)] pub enum Target { CortexM, @@ -166,7 +167,7 @@ pub fn respace(s: &str) -> String { pub fn escape_brackets(s: &str) -> String { s.split('[') .fold("".to_string(), |acc, x| { - if acc == "" { + if acc.is_empty() { x.to_string() } else if acc.ends_with('\\') { acc + "[" + x @@ -176,7 +177,7 @@ pub fn escape_brackets(s: &str) -> String { }) .split(']') .fold("".to_string(), |acc, x| { - if acc == "" { + if acc.is_empty() { x.to_string() } else if acc.ends_with('\\') { acc + "]" + x