rtic/macros/src/lib.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

#![deny(warnings)]
2017-07-04 18:26:11 +02:00
extern crate proc_macro;
use proc_macro::TokenStream;
use std::{fs, path::Path};
use rtfm_syntax::Settings;
mod analyze;
2017-07-04 18:26:11 +02:00
mod check;
2018-11-03 17:02:41 +01:00
mod codegen;
#[cfg(test)]
mod tests;
2017-07-12 06:44:54 +02:00
2018-11-03 17:02:41 +01:00
#[proc_macro_attribute]
pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
2019-06-20 06:19:59 +02:00
let mut settings = Settings::default();
settings.optimize_priorities = true;
settings.parse_binds = true;
settings.parse_cores = cfg!(feature = "heterogeneous") || cfg!(feature = "homogeneous");
settings.parse_extern_interrupt = true;
settings.parse_schedule = true;
let (app, analysis) = match rtfm_syntax::parse(args, input, settings) {
2018-11-03 17:02:41 +01:00
Err(e) => return e.to_compile_error().into(),
Ok(x) => x,
2018-11-03 17:02:41 +01:00
};
let extra = match check::app(&app, &analysis) {
Err(e) => return e.to_compile_error().into(),
Ok(x) => x,
};
let analysis = analyze::app(analysis, &app);
2017-07-04 18:26:11 +02:00
let ts = codegen::app(&app, &analysis, &extra);
// Try to write the expanded code to disk
if Path::new("target").exists() {
fs::write("target/rtfm-expansion.rs", ts.to_string()).ok();
}
ts.into()
2017-07-04 18:26:11 +02:00
}