Skip to content

Commit

Permalink
cfg away the #[interrupt] macro when not using vectoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Jul 22, 2022
1 parent f674581 commit 0f1aaaf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 103 deletions.
2 changes: 1 addition & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ smartled = ["smart-leds-trait"]
# Implement the `embedded-hal==1.0.0-alpha.x` traits
eh1 = ["embedded-hal-1"]
# To use vectored interrupts (calling the handlers defined in the PAC)
vectored = []
vectored = ["procmacros/interrupt"]
3 changes: 2 additions & 1 deletion esp-hal-procmacros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ proc-macro-error = "1.0.4"
[features]
rtc_slow = []
xtensa = []
riscv = []
riscv = []
interrupt = []
13 changes: 8 additions & 5 deletions esp-hal-procmacros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use std::iter;

use darling::FromMeta;
use proc_macro::{self, Span, TokenStream};
use proc_macro_error::{abort, proc_macro_error};
use quote::quote;
#[cfg(feature = "interrupt")]
use syn::{
parse,
parse_macro_input,
spanned::Spanned,
AttrStyle,
Attribute,
AttributeArgs,
Ident,
ItemFn,
Meta::Path,
ReturnType,
Type,
Visibility,
};
use syn::{parse_macro_input, AttributeArgs};

#[derive(Debug, Default, FromMeta)]
#[darling(default)]
Expand Down Expand Up @@ -111,6 +109,7 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream {
/// When specified between braces (`#[interrupt(example)]`) that interrupt will
/// be used and the function can have an arbitrary name. Otherwise the name of
/// the function must be the name of the interrupt.
#[cfg(feature = "interrupt")]
#[proc_macro_attribute]
pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
let mut f: ItemFn = syn::parse(input).expect("`#[interrupt]` must be applied to a function");
Expand Down Expand Up @@ -179,7 +178,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
&format!("__esp_hal_internal_{}", f.sig.ident),
proc_macro2::Span::call_site(),
);
f.block.stmts.extend(iter::once(
f.block.stmts.extend(std::iter::once(
syn::parse2(quote! {{
// Check that this interrupt actually exists
crate::pac::Interrupt::#ident_s;
Expand Down Expand Up @@ -227,10 +226,12 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
.into()
}

#[cfg(feature = "interrupt")]
enum WhiteListCaller {
Interrupt,
}

#[cfg(feature = "interrupt")]
fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<(), TokenStream> {
let whitelist = &[
"doc",
Expand Down Expand Up @@ -267,10 +268,12 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
}

/// Returns `true` if `attr.path` matches `name`
#[cfg(feature = "interrupt")]
fn eq(attr: &Attribute, name: &str) -> bool {
attr.style == AttrStyle::Outer && attr.path.is_ident(name)
}

#[cfg(feature = "interrupt")]
fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) {
let mut cfgs = vec![];
let mut not_cfgs = vec![];
Expand Down
96 changes: 0 additions & 96 deletions esp32-hal/test.rs

This file was deleted.

0 comments on commit 0f1aaaf

Please sign in to comment.