Skip to content

Commit

Permalink
fix interrupt macro
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Apr 11, 2024
1 parent 9ac2ec9 commit 245179f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions riscv-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ pub fn interrupt_riscv64(args: TokenStream, input: TokenStream) -> TokenStream {
fn interrupt(args: TokenStream, input: TokenStream, _arch: RiscvArch) -> TokenStream {
let f = parse_macro_input!(input as ItemFn);

// check the function arguments
if !f.sig.inputs.is_empty() {
return parse::Error::new(
f.sig.inputs.first().unwrap().span(),
"`#[interrupt]` function should not have arguments",
)
.to_compile_error()
.into();
}

// check the function signature
let valid_signature = f.sig.constness.is_none()
&& f.sig.asyncness.is_none()
Expand Down Expand Up @@ -362,6 +372,7 @@ fn interrupt(args: TokenStream, input: TokenStream, _arch: RiscvArch) -> TokenSt
// XXX should we blacklist other attributes?
let attrs = f.attrs;
let ident = f.sig.ident;
let export_name = format!("{:#}", ident);
let block = f.block;

#[cfg(not(feature = "v-trap"))]
Expand All @@ -371,7 +382,7 @@ fn interrupt(args: TokenStream, input: TokenStream, _arch: RiscvArch) -> TokenSt

quote!(
#start_trap
#[export_name = #ident]
#[export_name = #export_name]
#(#attrs)*
pub unsafe fn #ident() #block
)
Expand Down Expand Up @@ -404,7 +415,7 @@ mod v_trap {
"a7",
];

pub fn start_interrupt_trap_asm(
pub(crate) fn start_interrupt_trap_asm(
ident: &syn::Ident,
arch: RiscvArch,
) -> proc_macro2::TokenStream {
Expand Down

0 comments on commit 245179f

Please sign in to comment.