Skip to content

Commit

Permalink
doc aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Feb 3, 2024
1 parent 140f744 commit ec3a8ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
let description = pi.description.as_deref().unwrap_or(&p.name);
let p_ty = ident(name, &config.ident_formats.peripheral, span);
let name_str = p_ty.to_string();
let doc_alias = (&name_str != name).then(|| quote!(#[doc(alias = #name)]));
let address = util::hex(pi.base_address + config.base_address_shift);
let feature_name = config.ident_formats.peripheral_feature.apply(name);
feature_names.push(feature_name.to_string());
let p_feature = config.ident_formats.peripheral_feature.apply(name);
feature_names.push(p_feature.to_string());
let mut feature_attribute_n = feature_attribute.clone();
if config.feature_peripheral {
feature_attribute_n.extend(quote! { #[cfg(feature = #feature_name)] })
feature_attribute_n.extend(quote! { #[cfg(feature = #p_feature)] })
};
// Insert the peripherals structure
out.extend(quote! {
#[doc = #description]
#doc_alias
#feature_attribute_n
pub struct #p_ty { _marker: PhantomData<*const ()> }

Expand Down Expand Up @@ -147,9 +149,9 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
}
}
Peripheral::Single(_) => {
let feature_name = config.ident_formats.peripheral_feature.apply(&name);
let p_feature = config.ident_formats.peripheral_feature.apply(&name);
if config.feature_peripheral {
feature_attribute.extend(quote! { #[cfg(feature = #feature_name)] })
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
};
// Insert the peripheral structure
out.extend(quote! {
Expand Down Expand Up @@ -244,7 +246,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
"Pushing {} register or cluster blocks into output",
ercs.len()
);
let reg_block = register_or_cluster_block(&ercs, &derive_infos, None, None, config)?;
let reg_block =
register_or_cluster_block(&ercs, &derive_infos, None, "Register block", None, config)?;

let open = Punct::new('{', Spacing::Alone);
let close = Punct::new('}', Spacing::Alone);
Expand Down Expand Up @@ -526,6 +529,7 @@ fn register_or_cluster_block(
ercs: &[RegisterCluster],
derive_infos: &[DeriveInfo],
name: Option<&str>,
doc: &str,
size: Option<u32>,
config: &Config,
) -> Result<TokenStream> {
Expand Down Expand Up @@ -630,8 +634,13 @@ fn register_or_cluster_block(
}
});

let mut doc_alias = None;
let block_ty = if let Some(name) = name {
ident(name, &config.ident_formats.cluster, span)
let ty = ident(name, &config.ident_formats.cluster, span);
if ty.to_string() != name {
doc_alias = Some(quote!(#[doc(alias = #name)]));
}
ty
} else {
Ident::new("RegisterBlock", span)
};
Expand All @@ -645,9 +654,10 @@ fn register_or_cluster_block(
});

Ok(quote! {
///Register block
#[repr(C)]
#derive_debug
#[doc = #doc]
#doc_alias
pub struct #block_ty {
#rbfs
}
Expand Down Expand Up @@ -1429,6 +1439,7 @@ fn cluster_block(
&c.children,
&mod_derive_infos,
Some(&mod_name),
&description,
cluster_size,
config,
)?;
Expand Down
2 changes: 2 additions & 0 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn render(
}
let span = Span::call_site();
let reg_ty = ident(&name, &config.ident_formats.register, span);
let doc_alias = (&reg_ty.to_string() != &name).then(|| quote!(#[doc(alias = #name)]));
let mod_ty = name.to_snake_case_ident(span);
let description = util::escape_special_chars(
util::respace(&register.description.clone().unwrap_or_else(|| {
Expand Down Expand Up @@ -108,6 +109,7 @@ pub fn render(
let mut out = TokenStream::new();
out.extend(quote! {
#[doc = #alias_doc]
#doc_alias
pub type #reg_ty = crate::Reg<#mod_ty::#regspec_ty>;
});
let mod_items = render_register_mod(
Expand Down

0 comments on commit ec3a8ec

Please sign in to comment.