Skip to content

Correctly handle case where register.name has "[%s]" and no dimIndex #177

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

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 1 addition & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ main() {
echo 'cortex-m = "0.4.0"' >> $td/Cargo.toml
echo 'cortex-m-rt = "0.3.0"' >> $td/Cargo.toml
echo 'vcell = "0.1.0"' >> $td/Cargo.toml
echo 'msp430 = "0.1.0"' >> $td/Cargo.toml
echo '[profile.dev]' >> $td/Cargo.toml
echo 'incremental = false' >> $td/Cargo.toml

Expand Down Expand Up @@ -386,8 +387,6 @@ main() {

# test other targets (architectures)
OTHER)
echo 'msp430 = "0.1.0"' >> $td/Cargo.toml

(
cd $td &&
curl -LO \
Expand Down
28 changes: 18 additions & 10 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,20 +566,28 @@ fn register_block(registers: &[Register], defs: &Defaults) -> Result<Tokens> {
Register::Array(ref info, ref array_info) => {
let sequential_adresses = register_size == array_info.dim_increment * BITS_PER_BYTE;

let numeral_indexes = array_info
.dim_index
.clone()
.ok_or_else(|| {
format!("Register {} has no `dim_index` field", register.name)
})?
let indexes = if register.name.contains("[%s]") {
// From: http://www.keil.com/pack/doc/CMSIS/SVD/html/elem_registers.html
// "dimIndex should not be used together with the placeholder [%s],
// but rather with %s"
(0..array_info.dim)
.map(|i| i.to_string())
.collect()
} else {
array_info
.dim_index
.clone()
.ok_or_else(|| {
format!("Register {} has no `dim_index` field", register.name)
})?
};

let numeral_indexes = indexes
.iter()
.all(|element| element.parse::<usize>().is_ok());

let sequential_indexes = if numeral_indexes && sequential_adresses {
array_info
.dim_index
.clone()
.unwrap()
indexes
.iter()
.map(|element| element.parse::<u32>().unwrap())
.collect::<Vec<u32>>()
Expand Down