Skip to content
Snippets Groups Projects
Commit b25d8835 authored by Per Lindgren's avatar Per Lindgren
Browse files

trustall

parent 9b867ab9
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,18 @@ ...@@ -26,6 +26,18 @@
"problemMatcher": [ "problemMatcher": [
"$rustc" "$rustc"
] ]
},
{
"label": "cargo run --example trustall",
"type": "shell",
"command": "cargo run --example trustall",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$rustc"
]
} }
] ]
} }
\ No newline at end of file
use proc_collect::*;
trustall! {
fn hello() {
println!("in trust hello");
ext_hello();
}
#[entry]
#[inline(always)]
fn entry() {
hello();
}
#[interrupt]
fn i1() {
println!("i1");
}
#[interrupt]
fn i2() {
println!("i2");
}
#[exception]
fn exception() {
println!("exc");
}
}
fn ext_hello() {
println!("ext_hello");
}
...@@ -103,3 +103,64 @@ pub fn trust(_args: TokenStream, input: TokenStream) -> TokenStream { ...@@ -103,3 +103,64 @@ pub fn trust(_args: TokenStream, input: TokenStream) -> TokenStream {
}) })
.into() .into()
} }
#[derive(Debug)]
struct TrustMod2 {
items: Vec<Item>,
entries: Vec<Entry>,
}
impl Parse for TrustMod2 {
fn parse(input: ParseStream) -> Result<Self> {
let mut items = vec![];
while let Ok(i) = input.parse() {
items.push(i);
}
let mut e = vec![];
for i in &items {
match i {
Item::Fn(ref item_fn) => {
for a in &item_fn.attrs {
for s in &a.path.segments {
match s.ident.to_string().as_str() {
"entry" => e.push(Entry::Entry(item_fn.sig.ident.clone())),
"interrupt" => e.push(Entry::Interrupt(item_fn.sig.ident.clone())),
"exception" => e.push(Entry::Exception(item_fn.sig.ident.clone())),
_ => (),
}
}
}
}
_ => (),
}
}
Ok(TrustMod2 { items, entries: e })
}
}
#[proc_macro]
pub fn trustall(input: TokenStream) -> TokenStream {
let i = input.clone();
let trust = parse_macro_input!(i as TrustMod2);
let mut calls = vec![];
for e in trust.entries {
let id = match e {
Entry::Entry(id) => id,
Entry::Interrupt(id) => id,
Entry::Exception(id) => id,
};
calls.push(quote! { let _ = #id(); });
}
let items = trust.items;
(quote! {
#(#items)*
fn main() {
#(#calls)*
}
})
.into()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment