Skip to content

svd-parser 0.11 #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions .github/bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ block_labels = ["needs-decision", "S-waiting-on-team"]
delete_merged_branches = true
required_approvals = 1
status = [
"ci-linux (stable, rustfmt, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Atmel, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Freescale, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Fujitsu, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Holtek, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Nordic, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, Nuvoton, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, NXP, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, RISC-V, x86_64-unknown-linux-gnu, linux)",
"ci-linux (stable, SiliconLabs, x86_64-unknown-linux-gnu, linux)",
"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.46.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)",
"CI",
]
timeout_sec = 14400
46 changes: 30 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
name: Continuous integration

jobs:
ci:
name: CI
runs-on: ubuntu-latest
needs: [ci-linux]
steps:
- name: Done
run: exit 0
ci-linux:
runs-on: ubuntu-latest
strategy:
Expand All @@ -15,7 +22,7 @@ jobs:
rust: [stable]

# All vendor files we want to test on stable
VENDOR: [rustfmt, Atmel, Freescale, Fujitsu, Holtek, Microchip, Nordic, Nuvoton, NXP, RISC-V, SiliconLabs, Spansion, STMicro, Toshiba]
vendor: [rustfmt, Atmel, Freescale, Fujitsu, Holtek, Microchip, Nordic, Nuvoton, NXP, RISC-V, SiliconLabs, Spansion, STMicro, Toshiba]

# The default target we're compiling on and for
TARGET: [x86_64-unknown-linux-gnu]
Expand All @@ -25,34 +32,35 @@ jobs:

FEATURES: [""]

OPTIONS: [""]

# Options are all, none, strict and const
options: [all, none]
exclude:
- vendor: Fujitsu
options: all
- vendor: Spansion
options: all
- vendor: STMicro
options: all
- vendor: Nuvoton
options: all
include:
# Test MSRV
- rust: 1.46.0
VENDOR: Nordic
TARGET: x86_64-unknown-linux-gnu
TRAVIS_OS_NAME: linux

# Test features
- rust: 1.51.0
VENDOR: RISC-V
vendor: Nordic
TARGET: x86_64-unknown-linux-gnu
TRAVIS_OS_NAME: linux
FEATURES: "strict"
OPTIONS: "--const_generic"

# Use nightly for architectures which don't support stable
- rust: nightly
experimental: true
VENDOR: OTHER
vendor: OTHER
TARGET: x86_64-unknown-linux-gnu
TRAVIS_OS_NAME: linux

# Use nightly for architectures which don't support stable
- rust: nightly
experimental: true
VENDOR: Espressif
vendor: Espressif
TARGET: x86_64-unknown-linux-gnu
TRAVIS_OS_NAME: linux

Expand All @@ -75,5 +83,11 @@ jobs:
target: ${{ matrix.TARGET }}
override: true
components: rustfmt
- name: Run CI script for ${{ matrix.VENDOR }} under ${{ matrix.rust }}
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} OPTIONS=${{ matrix.OPTIONS }} bash ci/script.sh
- name: Run CI script for `${{ matrix.vendor }}` under rust `${{ matrix.rust }}` with options=`${{ matrix.options }}`
env:
TARGET: ${{ matrix.TARGET }}
VENDOR: ${{ matrix.vendor }}
FEATURES: ${{ matrix.FEATURES }}
OPTIONS: ${{ matrix.options }}
TRAVIS_OS_NAME: ${{ matrix.TRAVIS_OS_NAME }}
run: bash ci/script.sh
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- `strict` option
- Missing `inline` on field reader constructors
- Support for device.x generation for riscv targets and `__EXTERNAL_INTERRUPTS` vector table
- Re-export base's module for derived peripherals

### Changed

- Use `svd-parser` v0.11
- More Cluster arrays are now emitted as an array rather than a list of
elements. An `ArrayProxy` wrapper is used when a Rust built-in array does not
match the cluster layout. Requires the `--const_generic` command line option.
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ repository = "https://github.com/rust-embedded/svd2rust/"
version = "0.19.0"
readme = "README.md"

[package.metadata.deb]
section = "rust"

[[bin]]
doc = false
name = "svd2rust"
path = "src/main.rs"

[dependencies]
cast = "0.2"
cast = "0.3"
clap = "2.33"
clap_conf = "0.1.5"
env_logger = "~0.7"
env_logger = "0.9"
inflections = "1.1"
log = { version = "~0.4", features = ["std"] }
quote = "1.0"
Expand All @@ -44,12 +47,9 @@ anyhow = "1.0"
thiserror = "1.0"

[dependencies.svd-parser]
version = "0.10.2"
features = ["derive-from"]
version = "0.11"

[dependencies.syn]
version = "1.0"
features = ["full","extra-traits"]

[features]
strict = ["svd-parser/strict"]
21 changes: 20 additions & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_svd() {
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
local cwd=$(pwd)
pushd $td
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i $OPTIONS ${1}.svd
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust $strict $const_generic -i ${1}.svd

mv lib.rs src/lib.rs

Expand Down Expand Up @@ -70,6 +70,25 @@ main() {
;;
esac

case $OPTIONS in
all)
const_generic="--const_generic"
strict="--strict"
;;
strict)
const_generic=""
strict="--strict"
;;
const)
const_generic="--const_generic"
strict=""
;;
*)
const_generic=""
strict=""
;;
esac

# test crate
cargo init --name foo $td
echo 'cortex-m = "0.7.0"' >> $td/Cargo.toml
Expand Down
8 changes: 4 additions & 4 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use std::cmp::Ordering;
use std::collections::HashMap;

use crate::svd::{
Cluster, ClusterInfo, DimElement, Peripheral, Register, RegisterCluster, RegisterProperties,
Cluster, ClusterInfo, DeriveFrom, DimElement, Peripheral, Register, RegisterCluster,
RegisterProperties,
};
use log::warn;
use proc_macro2::TokenStream;
use proc_macro2::{Ident, Punct, Spacing, Span};
use proc_macro2::{Ident, Punct, Spacing, Span, TokenStream};
use quote::{quote, ToTokens};
use svd_parser::derive_from::DeriveFrom;
use syn::{parse_str, Token};

use crate::util::{
Expand Down Expand Up @@ -734,6 +733,7 @@ fn expand_register(
let mut register_expanded = vec![];

let register_size = register
.properties
.size
.or(defs.size)
.ok_or_else(|| anyhow!("Register {} has no `size` field", register.name))?;
Expand Down
9 changes: 7 additions & 2 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn render(
let name_uc_spec = Ident::new(&format!("{}_SPEC", &name.to_sanitized_upper_case()), span);
let name_sc = Ident::new(&name.to_sanitized_snake_case(), span);
let rsize = register
.properties
.size
.or(defs.size)
.ok_or_else(|| anyhow!("Register {} has no `size` field", register.name))?;
Expand All @@ -44,7 +45,11 @@ pub fn render(
}))
.as_ref(),
);
let res_val = register.reset_value.or(defs.reset_value).map(|v| v as u64);
let res_val = register
.properties
.reset_value
.or(defs.reset_value)
.map(|v| v as u64);

let mut mod_items = TokenStream::new();
let mut r_impl_items = TokenStream::new();
Expand Down Expand Up @@ -302,7 +307,7 @@ pub fn fields(
let fty = width.to_ty()?;
let evs = &f.enumerated_values;

let use_mask = if let Some(size) = parent.size {
let use_mask = if let Some(size) = parent.properties.size {
size != width
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
#![recursion_limit = "128"]

use quote::quote;
use svd_parser as svd;
use svd_parser::svd;

mod generate;
mod util;
Expand Down Expand Up @@ -532,7 +532,7 @@ pub enum SvdError {
pub fn generate(xml: &str, config: &Config) -> Result<Generation> {
use std::fmt::Write;

let device = svd::parse(xml)?;
let device = svd_parser::parse(xml)?;
let mut device_x = String::new();
let items =
generate::device::render(&device, config, &mut device_x).or(Err(SvdError::Render))?;
Expand Down
21 changes: 18 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use log::error;
use std::path::PathBuf;
use svd_parser as svd;
use svd_parser::svd;

mod generate;
mod util;
Expand Down Expand Up @@ -78,6 +78,12 @@ fn run() -> Result<()> {
.short("m")
.help("Create mod.rs instead of lib.rs, without inner attributes"),
)
.arg(
Arg::with_name("strict")
.long("strict")
.short("s")
.help("Make advanced checks due to parsing SVD"),
)
.arg(
Arg::with_name("log_level")
.long("log")
Expand Down Expand Up @@ -120,8 +126,6 @@ fn run() -> Result<()> {

setup_logging(&cfg);

let device = svd::parse(xml)?;

let target = cfg
.grab()
.arg("target")
Expand All @@ -140,6 +144,7 @@ fn run() -> Result<()> {
cfg.bool_flag("const_generic", Filter::Arg) || cfg.bool_flag("const_generic", Filter::Conf);
let ignore_groups =
cfg.bool_flag("ignore_groups", Filter::Arg) || cfg.bool_flag("ignore_groups", Filter::Conf);
let strict = cfg.bool_flag("strict", Filter::Arg) || cfg.bool_flag("strict", Filter::Conf);

let config = Config {
target,
Expand All @@ -148,9 +153,19 @@ fn run() -> Result<()> {
make_mod,
const_generic,
ignore_groups,
strict,
output_dir: path.clone(),
};

let mut parser_config = svd_parser::Config::default();
parser_config.validate_level = if strict {
svd::ValidateLevel::Strict
} else {
svd::ValidateLevel::Weak
};

let device = svd_parser::parse_with_config(xml, &parser_config)?;

let mut device_x = String::new();
let items = generate::device::render(&device, &config, &mut device_x)?;
let filename = if make_mod { "mod.rs" } else { "lib.rs" };
Expand Down
4 changes: 3 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Config {
pub make_mod: bool,
pub const_generic: bool,
pub ignore_groups: bool,
pub strict: bool,
pub output_dir: PathBuf,
}

Expand All @@ -34,6 +35,7 @@ impl Default for Config {
make_mod: false,
const_generic: false,
ignore_groups: false,
strict: false,
output_dir: PathBuf::from("."),
}
}
Expand Down Expand Up @@ -196,7 +198,7 @@ pub fn replace_suffix(name: &str, suffix: &str) -> String {
}

pub fn access_of(register: &Register) -> Access {
register.access.unwrap_or_else(|| {
register.properties.access.unwrap_or_else(|| {
if let Some(fields) = &register.fields {
if fields.iter().all(|f| f.access == Some(Access::ReadOnly)) {
Access::ReadOnly
Expand Down