rtic/rtic-macros/src/codegen.rs

78 lines
2 KiB
Rust
Raw Normal View History

use proc_macro2::TokenStream as TokenStream2;
2018-11-03 17:02:41 +01:00
use quote::quote;
use crate::analyze::Analysis;
use crate::syntax::ast::App;
pub mod bindings;
mod assertions;
mod async_dispatchers;
mod hardware_tasks;
mod idle;
mod init;
2021-07-05 21:40:01 +02:00
mod local_resources;
mod local_resources_struct;
mod module;
mod post_init;
mod pre_init;
2021-07-07 21:03:56 +02:00
mod shared_resources;
mod shared_resources_struct;
2023-01-04 20:01:05 +01:00
mod software_tasks;
mod util;
2023-01-07 14:06:11 +01:00
mod main;
// TODO: organize codegen to actual parts of code
// so `main::codegen` generates ALL the code for `fn main`,
// `software_tasks::codegen` generates ALL the code for software tasks etc...
2022-02-18 19:38:48 +01:00
#[allow(clippy::too_many_lines)]
pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
2020-09-01 19:04:55 +02:00
// Generate the `main` function
2023-01-07 14:06:11 +01:00
let main = main::codegen(app, analysis);
2023-01-07 14:26:55 +01:00
let init_codegen = init::codegen(app, analysis);
let idle_codegen = idle::codegen(app, analysis);
let shared_resources_codegen = shared_resources::codegen(app, analysis);
let local_resources_codegen = local_resources::codegen(app, analysis);
let hardware_tasks_codegen = hardware_tasks::codegen(app, analysis);
let software_tasks_codegen = software_tasks::codegen(app, analysis);
let async_dispatchers_codegen = async_dispatchers::codegen(app, analysis);
2018-11-03 17:02:41 +01:00
let user_imports = &app.user_imports;
let user_code = &app.user_code;
let name = &app.name;
let device = &app.args.device;
2020-12-13 14:52:16 +01:00
let rt_err = util::rt_err_ident();
quote!(
2021-02-25 17:32:12 +01:00
/// The RTIC application module
2020-10-21 20:20:26 +02:00
pub mod #name {
/// Always include the device crate which contains the vector table
2020-12-13 14:52:16 +01:00
use #device as #rt_err;
2020-10-15 18:50:17 +02:00
#(#user_imports)*
2019-02-15 19:52:25 +01:00
#(#user_code)*
/// User code end
2023-01-07 14:26:55 +01:00
#init_codegen
2023-01-07 14:26:55 +01:00
#idle_codegen
2023-01-04 20:01:05 +01:00
2023-01-07 14:26:55 +01:00
#hardware_tasks_codegen
2021-07-06 22:47:48 +02:00
2023-01-07 14:26:55 +01:00
#software_tasks_codegen
2018-11-03 17:02:41 +01:00
2023-01-07 14:26:55 +01:00
#shared_resources_codegen
2023-01-07 14:26:55 +01:00
#local_resources_codegen
2023-01-04 20:01:05 +01:00
2023-01-07 14:26:55 +01:00
#async_dispatchers_codegen
2023-01-07 14:06:11 +01:00
#main
}
2018-11-03 17:02:41 +01:00
)
}