Skip to content

Commit cc9fd06

Browse files
bors[bot]burrbullEmilgardis
authored
Merge #542
542: svd-parser 0.11 r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]> Co-authored-by: Emil Gardström <[email protected]>
2 parents 69a869c + 5a30302 commit cc9fd06

File tree

10 files changed

+93
-51
lines changed

10 files changed

+93
-51
lines changed

.github/bors.toml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ block_labels = ["needs-decision", "S-waiting-on-team"]
22
delete_merged_branches = true
33
required_approvals = 1
44
status = [
5-
"ci-linux (stable, rustfmt, x86_64-unknown-linux-gnu, linux)",
6-
"ci-linux (stable, Atmel, x86_64-unknown-linux-gnu, linux)",
7-
"ci-linux (stable, Freescale, x86_64-unknown-linux-gnu, linux)",
8-
"ci-linux (stable, Fujitsu, x86_64-unknown-linux-gnu, linux)",
9-
"ci-linux (stable, Holtek, x86_64-unknown-linux-gnu, linux)",
10-
"ci-linux (stable, Nordic, x86_64-unknown-linux-gnu, linux)",
11-
"ci-linux (stable, Nuvoton, x86_64-unknown-linux-gnu, linux)",
12-
"ci-linux (stable, NXP, x86_64-unknown-linux-gnu, linux)",
13-
"ci-linux (stable, RISC-V, x86_64-unknown-linux-gnu, linux)",
14-
"ci-linux (stable, SiliconLabs, x86_64-unknown-linux-gnu, linux)",
15-
"ci-linux (stable, Spansion, x86_64-unknown-linux-gnu, linux)",
16-
"ci-linux (stable, STMicro, x86_64-unknown-linux-gnu, linux)",
17-
"ci-linux (stable, Toshiba, x86_64-unknown-linux-gnu, linux)",
18-
"ci-linux (1.46.0, Nordic, x86_64-unknown-linux-gnu, linux)",
19-
"ci-linux (stable, x86_64-apple-darwin, osx)",
20-
"ci-linux (stable, x86_64-pc-windows-msvc, windows)",
5+
"CI",
216
]
227
timeout_sec = 14400

.github/workflows/ci.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ on:
66
name: Continuous integration
77

88
jobs:
9+
ci:
10+
name: CI
11+
runs-on: ubuntu-latest
12+
needs: [ci-linux]
13+
steps:
14+
- name: Done
15+
run: exit 0
916
ci-linux:
1017
runs-on: ubuntu-latest
1118
strategy:
@@ -15,7 +22,7 @@ jobs:
1522
rust: [stable]
1623

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

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

2633
FEATURES: [""]
2734

28-
OPTIONS: [""]
29-
35+
# Options are all, none, strict and const
36+
options: [all, none]
37+
exclude:
38+
- vendor: Fujitsu
39+
options: all
40+
- vendor: Spansion
41+
options: all
42+
- vendor: STMicro
43+
options: all
44+
- vendor: Nuvoton
45+
options: all
3046
include:
3147
# Test MSRV
3248
- rust: 1.46.0
33-
VENDOR: Nordic
34-
TARGET: x86_64-unknown-linux-gnu
35-
TRAVIS_OS_NAME: linux
36-
37-
# Test features
38-
- rust: 1.51.0
39-
VENDOR: RISC-V
49+
vendor: Nordic
4050
TARGET: x86_64-unknown-linux-gnu
4151
TRAVIS_OS_NAME: linux
42-
FEATURES: "strict"
43-
OPTIONS: "--const_generic"
4452

4553
# Use nightly for architectures which don't support stable
4654
- rust: nightly
4755
experimental: true
48-
VENDOR: OTHER
56+
vendor: OTHER
4957
TARGET: x86_64-unknown-linux-gnu
5058
TRAVIS_OS_NAME: linux
5159

5260
# Use nightly for architectures which don't support stable
5361
- rust: nightly
5462
experimental: true
55-
VENDOR: Espressif
63+
vendor: Espressif
5664
TARGET: x86_64-unknown-linux-gnu
5765
TRAVIS_OS_NAME: linux
5866

@@ -75,5 +83,11 @@ jobs:
7583
target: ${{ matrix.TARGET }}
7684
override: true
7785
components: rustfmt
78-
- name: Run CI script for ${{ matrix.VENDOR }} under ${{ matrix.rust }}
79-
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} OPTIONS=${{ matrix.OPTIONS }} bash ci/script.sh
86+
- name: Run CI script for `${{ matrix.vendor }}` under rust `${{ matrix.rust }}` with options=`${{ matrix.options }}`
87+
env:
88+
TARGET: ${{ matrix.TARGET }}
89+
VENDOR: ${{ matrix.vendor }}
90+
FEATURES: ${{ matrix.FEATURES }}
91+
OPTIONS: ${{ matrix.options }}
92+
TRAVIS_OS_NAME: ${{ matrix.TRAVIS_OS_NAME }}
93+
run: bash ci/script.sh

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

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

1617
### Changed
1718

19+
- Use `svd-parser` v0.11
1820
- More Cluster arrays are now emitted as an array rather than a list of
1921
elements. An `ArrayProxy` wrapper is used when a Rust built-in array does not
2022
match the cluster layout. Requires the `--const_generic` command line option.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ repository = "https://github.com/rust-embedded/svd2rust/"
2626
version = "0.19.0"
2727
readme = "README.md"
2828

29+
[package.metadata.deb]
30+
section = "rust"
31+
2932
[[bin]]
3033
doc = false
3134
name = "svd2rust"
3235
path = "src/main.rs"
3336

3437
[dependencies]
35-
cast = "0.2"
38+
cast = "0.3"
3639
clap = "2.33"
3740
clap_conf = "0.1.5"
38-
env_logger = "~0.7"
41+
env_logger = "0.9"
3942
inflections = "1.1"
4043
log = { version = "~0.4", features = ["std"] }
4144
quote = "1.0"
@@ -44,12 +47,9 @@ anyhow = "1.0"
4447
thiserror = "1.0"
4548

4649
[dependencies.svd-parser]
47-
version = "0.10.2"
4850
features = ["derive-from"]
51+
version = "0.11"
4952

5053
[dependencies.syn]
5154
version = "1.0"
5255
features = ["full","extra-traits"]
53-
54-
[features]
55-
strict = ["svd-parser/strict"]

ci/script.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_svd() {
1010
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
1111
local cwd=$(pwd)
1212
pushd $td
13-
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i $OPTIONS ${1}.svd
13+
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust $strict $const_generic -i ${1}.svd
1414

1515
mv lib.rs src/lib.rs
1616

@@ -70,6 +70,25 @@ main() {
7070
;;
7171
esac
7272

73+
case $OPTIONS in
74+
all)
75+
const_generic="--const_generic"
76+
strict="--strict"
77+
;;
78+
strict)
79+
const_generic=""
80+
strict="--strict"
81+
;;
82+
const)
83+
const_generic="--const_generic"
84+
strict=""
85+
;;
86+
*)
87+
const_generic=""
88+
strict=""
89+
;;
90+
esac
91+
7392
# test crate
7493
cargo init --name foo $td
7594
echo 'cortex-m = "0.7.0"' >> $td/Cargo.toml

src/generate/peripheral.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ use std::cmp::Ordering;
33
use std::collections::HashMap;
44

55
use crate::svd::{
6-
Cluster, ClusterInfo, DimElement, Peripheral, Register, RegisterCluster, RegisterProperties,
6+
Cluster, ClusterInfo, DeriveFrom, DimElement, Peripheral, Register, RegisterCluster,
7+
RegisterProperties,
78
};
89
use log::warn;
9-
use proc_macro2::TokenStream;
10-
use proc_macro2::{Ident, Punct, Spacing, Span};
10+
use proc_macro2::{Ident, Punct, Spacing, Span, TokenStream};
1111
use quote::{quote, ToTokens};
12-
use svd_parser::derive_from::DeriveFrom;
1312
use syn::{parse_str, Token};
1413

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

736735
let register_size = register
736+
.properties
737737
.size
738738
.or(defs.size)
739739
.ok_or_else(|| anyhow!("Register {} has no `size` field", register.name))?;

src/generate/register.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn render(
2626
let name_uc_spec = Ident::new(&format!("{}_SPEC", &name.to_sanitized_upper_case()), span);
2727
let name_sc = Ident::new(&name.to_sanitized_snake_case(), span);
2828
let rsize = register
29+
.properties
2930
.size
3031
.or(defs.size)
3132
.ok_or_else(|| anyhow!("Register {} has no `size` field", register.name))?;
@@ -44,7 +45,11 @@ pub fn render(
4445
}))
4546
.as_ref(),
4647
);
47-
let res_val = register.reset_value.or(defs.reset_value).map(|v| v as u64);
48+
let res_val = register
49+
.properties
50+
.reset_value
51+
.or(defs.reset_value)
52+
.map(|v| v as u64);
4853

4954
let mut mod_items = TokenStream::new();
5055
let mut r_impl_items = TokenStream::new();
@@ -302,7 +307,7 @@ pub fn fields(
302307
let fty = width.to_ty()?;
303308
let evs = &f.enumerated_values;
304309

305-
let use_mask = if let Some(size) = parent.size {
310+
let use_mask = if let Some(size) = parent.properties.size {
306311
size != width
307312
} else {
308313
false

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@
500500
#![recursion_limit = "128"]
501501

502502
use quote::quote;
503-
use svd_parser as svd;
503+
use svd_parser::svd;
504504

505505
mod generate;
506506
mod util;
@@ -532,7 +532,7 @@ pub enum SvdError {
532532
pub fn generate(xml: &str, config: &Config) -> Result<Generation> {
533533
use std::fmt::Write;
534534

535-
let device = svd::parse(xml)?;
535+
let device = svd_parser::parse(xml)?;
536536
let mut device_x = String::new();
537537
let items =
538538
generate::device::render(&device, config, &mut device_x).or(Err(SvdError::Render))?;

src/main.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use log::error;
44
use std::path::PathBuf;
5-
use svd_parser as svd;
5+
use svd_parser::svd;
66

77
mod generate;
88
mod util;
@@ -78,6 +78,12 @@ fn run() -> Result<()> {
7878
.short("m")
7979
.help("Create mod.rs instead of lib.rs, without inner attributes"),
8080
)
81+
.arg(
82+
Arg::with_name("strict")
83+
.long("strict")
84+
.short("s")
85+
.help("Make advanced checks due to parsing SVD"),
86+
)
8187
.arg(
8288
Arg::with_name("log_level")
8389
.long("log")
@@ -120,8 +126,6 @@ fn run() -> Result<()> {
120126

121127
setup_logging(&cfg);
122128

123-
let device = svd::parse(xml)?;
124-
125129
let target = cfg
126130
.grab()
127131
.arg("target")
@@ -140,6 +144,7 @@ fn run() -> Result<()> {
140144
cfg.bool_flag("const_generic", Filter::Arg) || cfg.bool_flag("const_generic", Filter::Conf);
141145
let ignore_groups =
142146
cfg.bool_flag("ignore_groups", Filter::Arg) || cfg.bool_flag("ignore_groups", Filter::Conf);
147+
let strict = cfg.bool_flag("strict", Filter::Arg) || cfg.bool_flag("strict", Filter::Conf);
143148

144149
let config = Config {
145150
target,
@@ -148,9 +153,19 @@ fn run() -> Result<()> {
148153
make_mod,
149154
const_generic,
150155
ignore_groups,
156+
strict,
151157
output_dir: path.clone(),
152158
};
153159

160+
let mut parser_config = svd_parser::Config::default();
161+
parser_config.validate_level = if strict {
162+
svd::ValidateLevel::Strict
163+
} else {
164+
svd::ValidateLevel::Weak
165+
};
166+
167+
let device = svd_parser::parse_with_config(xml, &parser_config)?;
168+
154169
let mut device_x = String::new();
155170
let items = generate::device::render(&device, &config, &mut device_x)?;
156171
let filename = if make_mod { "mod.rs" } else { "lib.rs" };

src/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Config {
2222
pub make_mod: bool,
2323
pub const_generic: bool,
2424
pub ignore_groups: bool,
25+
pub strict: bool,
2526
pub output_dir: PathBuf,
2627
}
2728

@@ -34,6 +35,7 @@ impl Default for Config {
3435
make_mod: false,
3536
const_generic: false,
3637
ignore_groups: false,
38+
strict: false,
3739
output_dir: PathBuf::from("."),
3840
}
3941
}
@@ -196,7 +198,7 @@ pub fn replace_suffix(name: &str, suffix: &str) -> String {
196198
}
197199

198200
pub fn access_of(register: &Register) -> Access {
199-
register.access.unwrap_or_else(|| {
201+
register.properties.access.unwrap_or_else(|| {
200202
if let Some(fields) = &register.fields {
201203
if fields.iter().all(|f| f.access == Some(Access::ReadOnly)) {
202204
Access::ReadOnly

0 commit comments

Comments
 (0)