2019-06-13 23:56:59 +02:00
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
2018-11-03 17:02:41 +01:00
|
|
|
use quote::quote;
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2022-12-31 14:45:13 +01:00
|
|
|
use crate::analyze::Analysis;
|
|
|
|
use crate::syntax::ast::App;
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2023-02-11 08:55:19 +01:00
|
|
|
pub mod bindings;
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
mod assertions;
|
2022-12-31 14:45:13 +01:00
|
|
|
mod async_dispatchers;
|
2019-06-13 23:56:59 +02:00
|
|
|
mod hardware_tasks;
|
|
|
|
mod idle;
|
|
|
|
mod init;
|
2021-07-05 21:40:01 +02:00
|
|
|
mod local_resources;
|
|
|
|
mod local_resources_struct;
|
2019-06-13 23:56:59 +02:00
|
|
|
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;
|
2019-06-13 23:56:59 +02:00
|
|
|
mod util;
|
|
|
|
|
2023-01-07 14:06:11 +01:00
|
|
|
mod main;
|
|
|
|
|
2023-01-07 11:24:13 +01:00
|
|
|
// 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)]
|
2022-12-31 14:45:13 +01:00
|
|
|
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
|
|
|
|
2020-10-11 19:41:57 +02:00
|
|
|
let user_imports = &app.user_imports;
|
|
|
|
let user_code = &app.user_code;
|
2019-06-13 23:56:59 +02:00
|
|
|
let name = &app.name;
|
2022-12-31 14:45:13 +01:00
|
|
|
let device = &app.args.device;
|
|
|
|
|
2020-12-13 14:52:16 +01:00
|
|
|
let rt_err = util::rt_err_ident();
|
|
|
|
|
2019-04-21 20:02:59 +02:00
|
|
|
quote!(
|
2021-02-25 17:32:12 +01:00
|
|
|
/// The RTIC application module
|
2020-10-21 20:20:26 +02:00
|
|
|
pub mod #name {
|
2019-06-13 23:56:59 +02:00
|
|
|
/// 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
|
|
|
|
2020-05-26 12:55:13 +02:00
|
|
|
#(#user_imports)*
|
2019-02-15 19:52:25 +01:00
|
|
|
|
2020-06-04 17:43:16 +02:00
|
|
|
#(#user_code)*
|
|
|
|
/// User code end
|
|
|
|
|
2023-01-07 14:26:55 +01:00
|
|
|
#init_codegen
|
2020-06-04 17:43:16 +02:00
|
|
|
|
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
|
2018-12-16 18:37:36 +01:00
|
|
|
|
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
|
2022-12-31 14:45:13 +01:00
|
|
|
|
2023-01-07 14:06:11 +01:00
|
|
|
#main
|
2020-05-19 11:55:50 +02:00
|
|
|
}
|
2018-11-03 17:02:41 +01:00
|
|
|
)
|
|
|
|
}
|