2018-12-16 18:37:36 +01:00
|
|
|
#![deny(warnings)]
|
2017-07-04 18:26:11 +02:00
|
|
|
|
|
|
|
extern crate proc_macro;
|
|
|
|
|
2017-07-15 01:54:54 +02:00
|
|
|
use proc_macro::TokenStream;
|
2019-05-08 14:08:09 +02:00
|
|
|
use std::{fs, path::Path};
|
|
|
|
|
2020-06-11 19:18:29 +02:00
|
|
|
use rtic_syntax::Settings;
|
2017-07-15 01:54:54 +02:00
|
|
|
|
|
|
|
mod analyze;
|
2017-07-04 18:26:11 +02:00
|
|
|
mod check;
|
2018-11-03 17:02:41 +01:00
|
|
|
mod codegen;
|
2019-06-13 23:56:59 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2017-07-12 06:44:54 +02:00
|
|
|
|
2020-06-11 19:18:29 +02:00
|
|
|
/// Attribute used to declare a RTIC application
|
2019-08-21 12:19:38 +02:00
|
|
|
///
|
2020-11-19 19:11:43 +01:00
|
|
|
/// For user documentation see the [RTIC book](rtic.rs)
|
2020-08-27 13:21:56 +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_extern_interrupt = true;
|
|
|
|
|
2020-06-11 19:18:29 +02:00
|
|
|
let (app, analysis) = match rtic_syntax::parse(args, input, settings) {
|
2018-11-03 17:02:41 +01:00
|
|
|
Err(e) => return e.to_compile_error().into(),
|
2019-06-13 23:56:59 +02:00
|
|
|
Ok(x) => x,
|
2018-11-03 17:02:41 +01:00
|
|
|
};
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
let extra = match check::app(&app, &analysis) {
|
|
|
|
Err(e) => return e.to_compile_error().into(),
|
|
|
|
Ok(x) => x,
|
|
|
|
};
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
let analysis = analyze::app(analysis, &app);
|
2017-07-04 18:26:11 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
let ts = codegen::app(&app, &analysis, &extra);
|
2019-05-08 14:08:09 +02:00
|
|
|
|
|
|
|
// Try to write the expanded code to disk
|
|
|
|
if Path::new("target").exists() {
|
2020-06-11 19:18:29 +02:00
|
|
|
fs::write("target/rtic-expansion.rs", ts.to_string()).ok();
|
2019-05-08 14:08:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ts.into()
|
2017-07-04 18:26:11 +02:00
|
|
|
}
|