Skip to content

Commit 27eebb4

Browse files
bors[bot]burrbull
andauthored
Merge #702
702: clippy && release 0.28 r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents f206126 + 3fe8c4f commit 27eebb4

File tree

4 files changed

+34
-41
lines changed

4 files changed

+34
-41
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.28.0] - 2022-12-25
11+
1012
- Generate atomic register code for non-MSP430 targets
1113
- Change --nightly flag to --atomics
14+
- Add handling for disjoint register arrays and validation of derives
1215

1316
## [v0.27.2] - 2022-11-06
1417

@@ -17,7 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1720
- Test patched STM32
1821
- simplify ci strategy
1922
- Fix generated code for MSP430 atomics
20-
- Add handling for disjoint register arrays and validation of derives
2123

2224
## [v0.27.1] - 2022-10-25
2325

@@ -778,7 +780,8 @@ peripheral.register.write(|w| w.field().set());
778780

779781
- Initial version of the `svd2rust` tool
780782

781-
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.27.2...HEAD
783+
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.28.0...HEAD
784+
[v0.28.0]: https://github.com/rust-embedded/svd2rust/compare/v0.27.2...v0.28.0
782785
[v0.27.2]: https://github.com/rust-embedded/svd2rust/compare/v0.27.1...v0.27.2
783786
[v0.27.1]: https://github.com/rust-embedded/svd2rust/compare/v0.27.0...v0.27.1
784787
[v0.27.0]: https://github.com/rust-embedded/svd2rust/compare/v0.26.0...v0.27.0

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ keywords = [
2323
license = "MIT OR Apache-2.0"
2424
name = "svd2rust"
2525
repository = "https://github.com/rust-embedded/svd2rust/"
26-
version = "0.27.2"
26+
version = "0.28.0"
2727
readme = "README.md"
2828
rust-version = "1.60"
2929

@@ -45,7 +45,7 @@ yaml = ["dep:serde_yaml"]
4545
[dependencies]
4646
clap = { version = "4.0", optional = true }
4747
irx-config = { version = "3.1", features = ["cmd", "toml-parser"], optional = true }
48-
env_logger = { version = "0.9", optional = true }
48+
env_logger = { version = "0.10", optional = true }
4949
inflections = "1.1"
5050
log = { version = "~0.4", features = ["std"] }
5151
quote = "1.0"
@@ -55,7 +55,7 @@ thiserror = "1.0"
5555
serde = { version = "1.0", optional = true }
5656
serde_json = { version = "1.0.85", optional = true }
5757
serde_yaml = { version = "0.9.11", optional = true }
58-
regex = "1.6.0"
58+
regex = "1.7.0"
5959

6060
[dependencies.svd-parser]
6161
features = ["expand"]

src/generate/peripheral.rs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,13 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
202202
let derive_infos = check_erc_derive_infos(&mut ercs, &path, index, config)?;
203203
let zipped = ercs.iter_mut().zip(derive_infos.iter());
204204
for (mut erc, derive_info) in zipped {
205-
match &mut erc {
206-
&mut RegisterCluster::Register(register) => match derive_info {
207-
DeriveInfo::Implicit(rpath) => {
208-
debug!(
209-
"register {} implicitly derives from {}",
210-
register.name, rpath.name
211-
);
212-
}
213-
_ => {}
214-
},
215-
_ => {}
205+
if let RegisterCluster::Register(register) = &mut erc {
206+
if let DeriveInfo::Implicit(rpath) = derive_info {
207+
debug!(
208+
"register {} implicitly derives from {}",
209+
register.name, rpath.name
210+
);
211+
}
216212
}
217213
}
218214

@@ -736,11 +732,11 @@ fn check_erc_derive_infos(
736732
let zipped = ercs.iter_mut().zip(derive_infos_slice.iter_mut());
737733
for (mut erc, derive_info) in zipped {
738734
match &mut erc {
739-
&mut RegisterCluster::Register(register) => {
735+
RegisterCluster::Register(register) => {
740736
let info_name = register.fullname(config.ignore_groups).to_string();
741737
let explicit_rpath = match &mut register.derived_from.clone() {
742738
Some(dpath) => {
743-
let (_, root) = find_root(&dpath, path, index)?;
739+
let (_, root) = find_root(dpath, path, index)?;
744740
Some(root)
745741
}
746742
None => None,
@@ -751,7 +747,7 @@ fn check_erc_derive_infos(
751747
*derive_info = match explicit_rpath {
752748
None => {
753749
match compare_this_against_prev(
754-
&register,
750+
register,
755751
&ty_name,
756752
path,
757753
index,
@@ -776,25 +772,22 @@ fn check_erc_derive_infos(
776772
Register::Array(..) => {
777773
// Only match integer indeces when searching for disjoint arrays
778774
let re_string = util::replace_suffix(&info_name, "([0-9]+|%s)");
779-
let re = Regex::new(format!("^{re_string}$").as_str()).or_else(|_| {
780-
Err(anyhow!(
781-
"Error creating regex for register {}",
782-
register.name
783-
))
775+
let re = Regex::new(format!("^{re_string}$").as_str()).map_err(|_| {
776+
anyhow!("Error creating regex for register {}", register.name)
784777
})?;
785778
let ty_name = info_name.to_string(); // keep suffix for regex matching
786779
*derive_info = match explicit_rpath {
787780
None => {
788781
match compare_this_against_prev(
789-
&register,
782+
register,
790783
&ty_name,
791784
path,
792785
index,
793786
&ercs_type_info,
794787
)? {
795788
Some(root) => DeriveInfo::Implicit(root),
796789
None => compare_prev_against_this(
797-
&register,
790+
register,
798791
&ty_name,
799792
&re,
800793
path,
@@ -809,7 +802,7 @@ fn check_erc_derive_infos(
809802
}
810803
};
811804
}
812-
&mut RegisterCluster::Cluster(cluster) => {
805+
RegisterCluster::Cluster(cluster) => {
813806
*derive_info = DeriveInfo::Cluster;
814807
ercs_type_info.push((cluster.name.to_string(), None, erc, derive_info));
815808
}
@@ -854,9 +847,9 @@ fn compare_this_against_prev(
854847
let (prev_name, prev_regex, prev_erc, _prev_derive_info) = prev;
855848
if let RegisterCluster::Register(_) = prev_erc {
856849
if let Some(prev_re) = prev_regex {
857-
if prev_re.is_match(&ty_name) {
858-
let (source_reg, rpath) = find_root(&prev_name, path, index)?;
859-
if is_derivable(&source_reg, &reg) {
850+
if prev_re.is_match(ty_name) {
851+
let (source_reg, rpath) = find_root(prev_name, path, index)?;
852+
if is_derivable(&source_reg, reg) {
860853
return Ok(Some(rpath));
861854
}
862855
}
@@ -869,7 +862,7 @@ fn compare_this_against_prev(
869862
/// Compare the given type name against previous regexs, then inspect fields
870863
fn compare_prev_against_this(
871864
reg: &MaybeArray<RegisterInfo>,
872-
ty_name: &String,
865+
ty_name: &str,
873866
re: &regex::Regex,
874867
path: &BlockPath,
875868
index: &Index,
@@ -884,12 +877,12 @@ fn compare_prev_against_this(
884877
// Arrays are covered with compare_this_against_prev
885878
continue;
886879
}
887-
if re.is_match(&prev_name) {
880+
if re.is_match(prev_name) {
888881
let loop_derive_info = match prev_derive_info {
889882
DeriveInfo::Root => {
890883
// Get the RegisterPath for reg
891-
let (_, implicit_rpath) = find_root(&ty_name, path, index)?;
892-
if is_derivable(&prev_reg, &reg) {
884+
let (_, implicit_rpath) = find_root(ty_name, path, index)?;
885+
if is_derivable(prev_reg, reg) {
893886
**prev_derive_info = DeriveInfo::Implicit(implicit_rpath);
894887
}
895888
DeriveInfo::Root
@@ -1164,12 +1157,10 @@ fn expand_register(
11641157
// force expansion and rename if we're deriving an array that doesnt start at 0 so we don't get name collisions
11651158
let index: Cow<str> = if let Some(dim_index) = &array_info.dim_index {
11661159
dim_index.first().unwrap().into()
1160+
} else if sequential_indexes_from0 {
1161+
"0".into()
11671162
} else {
1168-
if sequential_indexes_from0 {
1169-
"0".into()
1170-
} else {
1171-
"".into()
1172-
}
1163+
"".into()
11731164
};
11741165
let array_convertible = match derive_info {
11751166
DeriveInfo::Implicit(_) => {

src/generate/register.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ pub fn render(
3232
if let MaybeArray::Array(info, array_info) = register {
3333
if let Some(dim_index) = &array_info.dim_index {
3434
let index: Cow<str> = dim_index.first().unwrap().into();
35-
name =
36-
replace_suffix(&info.fullname(config.ignore_groups), &index.to_string()).into()
35+
name = replace_suffix(&info.fullname(config.ignore_groups), &index).into()
3736
}
3837
}
3938
}

0 commit comments

Comments
 (0)