Skip to content
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

bump svd v0.7, rm ref #300

Closed
wants to merge 1 commit 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ path = "src/main.rs"
[dependencies]
cast = "0.2.2"
clap = "2.26.0"
either = "1.0.3"
error-chain = "0.11.0"
inflections = "1.1.0"
quote = "0.3.15"
svd-parser = "0.6"
svd-parser = "0.7"
syn = "0.11.11"
5 changes: 2 additions & 3 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use quote::Tokens;
use crate::svd::Device;
use quote::Tokens;
use syn::Ident;

use crate::errors::*;
Expand Down Expand Up @@ -107,8 +107,7 @@ pub fn render(

let core_peripherals: &[_] = if fpu_present {
&[
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST",
"TPIU",
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU",
]
} else {
&[
Expand Down
2 changes: 1 addition & 1 deletion src/generate/interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;
use std::fmt::Write;

use crate::svd::Peripheral;
use cast::u64;
use quote::Tokens;
use crate::svd::Peripheral;
use syn::Ident;

use crate::errors::*;
Expand Down
79 changes: 39 additions & 40 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;
use std::cmp::Ordering;

use either::Either;
use crate::svd::{Cluster, ClusterInfo, Defaults, Peripheral, Register, RegisterCluster};
use quote::{ToTokens, Tokens};
use crate::svd::{Cluster, ClusterInfo, Defaults, Peripheral, Register};
use syn::{self, Ident};

use crate::errors::*;
Expand Down Expand Up @@ -130,9 +129,9 @@ impl Region {
let mut idents: Vec<_> = self
.fields
.iter()
.filter_map(|f| match f.field.ident {
.filter_map(|f| match &f.field.ident {
None => None,
Some(ref ident) => Some(ident.as_ref()),
Some(ident) => Some(ident.as_ref()),
})
.collect();
if idents.is_empty() {
Expand Down Expand Up @@ -171,9 +170,9 @@ impl Region {
let idents: Vec<_> = self
.fields
.iter()
.filter_map(|f| match f.field.ident {
.filter_map(|f| match &f.field.ident {
None => None,
Some(ref ident) => Some(ident.as_ref()),
Some(ident) => Some(ident.as_ref()),
})
.collect();

Expand Down Expand Up @@ -355,7 +354,7 @@ impl FieldRegions {
}

fn register_or_cluster_block(
ercs: &[Either<Register, Cluster>],
ercs: &[RegisterCluster],
defs: &Defaults,
name: Option<&str>,
nightly: bool,
Expand All @@ -368,7 +367,7 @@ fn register_or_cluster_block(
}

fn register_or_cluster_block_stable(
ercs: &[Either<Register, Cluster>],
ercs: &[RegisterCluster],
defs: &Defaults,
name: Option<&str>,
) -> Result<Tokens> {
Expand Down Expand Up @@ -432,7 +431,7 @@ fn register_or_cluster_block_stable(
}

fn register_or_cluster_block_nightly(
ercs: &[Either<Register, Cluster>],
ercs: &[RegisterCluster],
defs: &Defaults,
name: Option<&str>,
) -> Result<Tokens> {
Expand Down Expand Up @@ -551,16 +550,16 @@ fn register_or_cluster_block_nightly(
/// Expand a list of parsed `Register`s or `Cluster`s, and render them to
/// `RegisterBlockField`s containing `Field`s.
fn expand(
ercs: &[Either<Register, Cluster>],
ercs: &[RegisterCluster],
defs: &Defaults,
name: Option<&str>,
) -> Result<Vec<RegisterBlockField>> {
let mut ercs_expanded = vec![];

for erc in ercs {
ercs_expanded.extend(match erc {
Either::Left(ref register) => expand_register(register, defs, name)?,
Either::Right(ref cluster) => expand_cluster(cluster, defs)?,
ercs_expanded.extend(match &erc {
RegisterCluster::Register(register) => expand_register(register, defs, name)?,
RegisterCluster::Cluster(cluster) => expand_cluster(cluster, defs)?,
});
}

Expand All @@ -575,16 +574,16 @@ fn cluster_size_in_bits(info: &ClusterInfo, defs: &Defaults) -> Result<u32> {
let mut size = 0;

for c in &info.children {
let end = match *c {
Either::Left(ref reg) => {
let end = match c {
RegisterCluster::Register(reg) => {
let reg_size: u32 = expand_register(reg, defs, None)?
.iter()
.map(|rbf| rbf.size)
.sum();

(reg.address_offset * BITS_PER_BYTE) + reg_size
}
Either::Right(ref clust) => {
RegisterCluster::Cluster(clust) => {
(clust.address_offset * BITS_PER_BYTE) + cluster_size_in_bits(clust, defs)?
}
};
Expand All @@ -604,14 +603,14 @@ fn expand_cluster(cluster: &Cluster, defs: &Defaults) -> Result<Vec<RegisterBloc
.or_else(|_e| cluster_size_in_bits(cluster, defs))
.chain_err(|| format!("Cluster {} has no determinable `size` field", cluster.name))?;

match *cluster {
Cluster::Single(ref info) => cluster_expanded.push(RegisterBlockField {
match cluster {
Cluster::Single(info) => cluster_expanded.push(RegisterBlockField {
field: convert_svd_cluster(cluster),
description: info.description.clone(),
offset: info.address_offset,
size: cluster_size,
}),
Cluster::Array(ref info, ref array_info) => {
Cluster::Array(info, array_info) => {
let sequential_addresses = cluster_size == array_info.dim_increment * BITS_PER_BYTE;

// if dimIndex exists, test if it is a sequence of numbers from 0 to dim
Expand Down Expand Up @@ -661,14 +660,14 @@ fn expand_register(
.or(defs.size)
.ok_or_else(|| format!("Register {} has no `size` field", register.name))?;

match *register {
Register::Single(ref info) => register_expanded.push(RegisterBlockField {
match register {
Register::Single(info) => register_expanded.push(RegisterBlockField {
field: convert_svd_register(register, name),
description: info.description.clone(),
description: info.description.clone().unwrap(),
offset: info.address_offset,
size: register_size,
}),
Register::Array(ref info, ref array_info) => {
Register::Array(info, array_info) => {
let sequential_addresses = register_size == array_info.dim_increment * BITS_PER_BYTE;

// if dimIndex exists, test if it is a sequence of numbers from 0 to dim
Expand All @@ -684,15 +683,15 @@ fn expand_register(
if array_convertible {
register_expanded.push(RegisterBlockField {
field: convert_svd_register(&register, name),
description: info.description.clone(),
description: info.description.clone().unwrap(),
offset: info.address_offset,
size: register_size * array_info.dim,
});
} else {
for (field_num, field) in expand_svd_register(register, name).iter().enumerate() {
register_expanded.push(RegisterBlockField {
field: field.clone(),
description: info.description.clone(),
description: info.description.clone().unwrap(),
offset: info.address_offset + field_num as u32 * array_info.dim_increment,
size: register_size,
});
Expand All @@ -718,9 +717,9 @@ fn cluster_block(
let description = util::escape_brackets(util::respace(&c.description).as_ref());

// Generate the register block.
let mod_name = match *c {
Cluster::Single(ref info) => &info.name,
Cluster::Array(ref info, ref _ai) => &info.name,
let mod_name = match c {
Cluster::Single(info) => &info.name,
Cluster::Array(info, _ai) => &info.name,
}
.replace("[%s]", "")
.replace("%s", "");
Expand Down Expand Up @@ -785,9 +784,9 @@ fn expand_svd_register(register: &Register, name: Option<&str>) -> Vec<syn::Fiel

let mut out = vec![];

match *register {
Register::Single(ref _info) => out.push(convert_svd_register(register, name)),
Register::Array(ref info, ref array_info) => {
match register {
Register::Single(_info) => out.push(convert_svd_register(register, name)),
Register::Array(info, array_info) => {
let has_brackets = info.name.contains("[%s]");

let indices = array_info
Expand Down Expand Up @@ -856,14 +855,14 @@ fn convert_svd_register(register: &Register, name: Option<&str>) -> syn::Field {
)
};

match *register {
Register::Single(ref info) => syn::Field {
match register {
Register::Single(info) => syn::Field {
ident: Some(Ident::new(info.name.to_sanitized_snake_case())),
vis: syn::Visibility::Public,
attrs: vec![],
ty: name_to_ty(&info.name, name),
},
Register::Array(ref info, ref array_info) => {
Register::Array(info, array_info) => {
let has_brackets = info.name.contains("[%s]");

let nb_name = if has_brackets {
Expand Down Expand Up @@ -910,9 +909,9 @@ fn expand_svd_cluster(cluster: &Cluster) -> Vec<syn::Field> {

let mut out = vec![];

match *cluster {
Cluster::Single(ref _info) => out.push(convert_svd_cluster(cluster)),
Cluster::Array(ref info, ref array_info) => {
match cluster {
Cluster::Single(_info) => out.push(convert_svd_cluster(cluster)),
Cluster::Array(info, array_info) => {
let has_brackets = info.name.contains("[%s]");

let indices = array_info
Expand Down Expand Up @@ -970,14 +969,14 @@ fn convert_svd_cluster(cluster: &Cluster) -> syn::Field {
)
};

match *cluster {
Cluster::Single(ref info) => syn::Field {
match cluster {
Cluster::Single(info) => syn::Field {
ident: Some(Ident::new(info.name.to_sanitized_snake_case())),
vis: syn::Visibility::Public,
attrs: vec![],
ty: name_to_ty(&info.name),
},
Cluster::Array(ref info, ref array_info) => {
Cluster::Array(info, array_info) => {
let has_brackets = info.name.contains("[%s]");

let name = if has_brackets {
Expand Down
Loading