Skip to content

Commit

Permalink
clippy && release 0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 25, 2022
1 parent f206126 commit 3fe8c4f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [v0.28.0] - 2022-12-25

- Generate atomic register code for non-MSP430 targets
- Change --nightly flag to --atomics
- Add handling for disjoint register arrays and validation of derives

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

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

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

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

- Initial version of the `svd2rust` tool

[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.27.2...HEAD
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.28.0...HEAD
[v0.28.0]: https://github.com/rust-embedded/svd2rust/compare/v0.27.2...v0.28.0
[v0.27.2]: https://github.com/rust-embedded/svd2rust/compare/v0.27.1...v0.27.2
[v0.27.1]: https://github.com/rust-embedded/svd2rust/compare/v0.27.0...v0.27.1
[v0.27.0]: https://github.com/rust-embedded/svd2rust/compare/v0.26.0...v0.27.0
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ keywords = [
license = "MIT OR Apache-2.0"
name = "svd2rust"
repository = "https://github.com/rust-embedded/svd2rust/"
version = "0.27.2"
version = "0.28.0"
readme = "README.md"
rust-version = "1.60"

Expand All @@ -45,7 +45,7 @@ yaml = ["dep:serde_yaml"]
[dependencies]
clap = { version = "4.0", optional = true }
irx-config = { version = "3.1", features = ["cmd", "toml-parser"], optional = true }
env_logger = { version = "0.9", optional = true }
env_logger = { version = "0.10", optional = true }
inflections = "1.1"
log = { version = "~0.4", features = ["std"] }
quote = "1.0"
Expand All @@ -55,7 +55,7 @@ thiserror = "1.0"
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0.85", optional = true }
serde_yaml = { version = "0.9.11", optional = true }
regex = "1.6.0"
regex = "1.7.0"

[dependencies.svd-parser]
features = ["expand"]
Expand Down
59 changes: 25 additions & 34 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,13 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
let derive_infos = check_erc_derive_infos(&mut ercs, &path, index, config)?;
let zipped = ercs.iter_mut().zip(derive_infos.iter());
for (mut erc, derive_info) in zipped {
match &mut erc {
&mut RegisterCluster::Register(register) => match derive_info {
DeriveInfo::Implicit(rpath) => {
debug!(
"register {} implicitly derives from {}",
register.name, rpath.name
);
}
_ => {}
},
_ => {}
if let RegisterCluster::Register(register) = &mut erc {
if let DeriveInfo::Implicit(rpath) = derive_info {
debug!(
"register {} implicitly derives from {}",
register.name, rpath.name
);
}
}
}

Expand Down Expand Up @@ -736,11 +732,11 @@ fn check_erc_derive_infos(
let zipped = ercs.iter_mut().zip(derive_infos_slice.iter_mut());
for (mut erc, derive_info) in zipped {
match &mut erc {
&mut RegisterCluster::Register(register) => {
RegisterCluster::Register(register) => {
let info_name = register.fullname(config.ignore_groups).to_string();
let explicit_rpath = match &mut register.derived_from.clone() {
Some(dpath) => {
let (_, root) = find_root(&dpath, path, index)?;
let (_, root) = find_root(dpath, path, index)?;
Some(root)
}
None => None,
Expand All @@ -751,7 +747,7 @@ fn check_erc_derive_infos(
*derive_info = match explicit_rpath {
None => {
match compare_this_against_prev(
&register,
register,
&ty_name,
path,
index,
Expand All @@ -776,25 +772,22 @@ fn check_erc_derive_infos(
Register::Array(..) => {
// Only match integer indeces when searching for disjoint arrays
let re_string = util::replace_suffix(&info_name, "([0-9]+|%s)");
let re = Regex::new(format!("^{re_string}$").as_str()).or_else(|_| {
Err(anyhow!(
"Error creating regex for register {}",
register.name
))
let re = Regex::new(format!("^{re_string}$").as_str()).map_err(|_| {
anyhow!("Error creating regex for register {}", register.name)
})?;
let ty_name = info_name.to_string(); // keep suffix for regex matching
*derive_info = match explicit_rpath {
None => {
match compare_this_against_prev(
&register,
register,
&ty_name,
path,
index,
&ercs_type_info,
)? {
Some(root) => DeriveInfo::Implicit(root),
None => compare_prev_against_this(
&register,
register,
&ty_name,
&re,
path,
Expand All @@ -809,7 +802,7 @@ fn check_erc_derive_infos(
}
};
}
&mut RegisterCluster::Cluster(cluster) => {
RegisterCluster::Cluster(cluster) => {
*derive_info = DeriveInfo::Cluster;
ercs_type_info.push((cluster.name.to_string(), None, erc, derive_info));
}
Expand Down Expand Up @@ -854,9 +847,9 @@ fn compare_this_against_prev(
let (prev_name, prev_regex, prev_erc, _prev_derive_info) = prev;
if let RegisterCluster::Register(_) = prev_erc {
if let Some(prev_re) = prev_regex {
if prev_re.is_match(&ty_name) {
let (source_reg, rpath) = find_root(&prev_name, path, index)?;
if is_derivable(&source_reg, &reg) {
if prev_re.is_match(ty_name) {
let (source_reg, rpath) = find_root(prev_name, path, index)?;
if is_derivable(&source_reg, reg) {
return Ok(Some(rpath));
}
}
Expand All @@ -869,7 +862,7 @@ fn compare_this_against_prev(
/// Compare the given type name against previous regexs, then inspect fields
fn compare_prev_against_this(
reg: &MaybeArray<RegisterInfo>,
ty_name: &String,
ty_name: &str,
re: &regex::Regex,
path: &BlockPath,
index: &Index,
Expand All @@ -884,12 +877,12 @@ fn compare_prev_against_this(
// Arrays are covered with compare_this_against_prev
continue;
}
if re.is_match(&prev_name) {
if re.is_match(prev_name) {
let loop_derive_info = match prev_derive_info {
DeriveInfo::Root => {
// Get the RegisterPath for reg
let (_, implicit_rpath) = find_root(&ty_name, path, index)?;
if is_derivable(&prev_reg, &reg) {
let (_, implicit_rpath) = find_root(ty_name, path, index)?;
if is_derivable(prev_reg, reg) {
**prev_derive_info = DeriveInfo::Implicit(implicit_rpath);
}
DeriveInfo::Root
Expand Down Expand Up @@ -1164,12 +1157,10 @@ fn expand_register(
// force expansion and rename if we're deriving an array that doesnt start at 0 so we don't get name collisions
let index: Cow<str> = if let Some(dim_index) = &array_info.dim_index {
dim_index.first().unwrap().into()
} else if sequential_indexes_from0 {
"0".into()
} else {
if sequential_indexes_from0 {
"0".into()
} else {
"".into()
}
"".into()
};
let array_convertible = match derive_info {
DeriveInfo::Implicit(_) => {
Expand Down
3 changes: 1 addition & 2 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub fn render(
if let MaybeArray::Array(info, array_info) = register {
if let Some(dim_index) = &array_info.dim_index {
let index: Cow<str> = dim_index.first().unwrap().into();
name =
replace_suffix(&info.fullname(config.ignore_groups), &index.to_string()).into()
name = replace_suffix(&info.fullname(config.ignore_groups), &index).into()
}
}
}
Expand Down

0 comments on commit 3fe8c4f

Please sign in to comment.