rtic_macros/
codegen.rs
1use proc_macro2::TokenStream as TokenStream2;
2use quote::quote;
3
4use crate::analyze::Analysis;
5use crate::syntax::ast::App;
6
7pub mod bindings;
8
9mod assertions;
10mod async_dispatchers;
11mod extra_mods;
12mod hardware_tasks;
13mod idle;
14mod init;
15mod local_resources;
16mod local_resources_struct;
17mod module;
18mod post_init;
19mod pre_init;
20mod shared_resources;
21mod shared_resources_struct;
22mod software_tasks;
23mod util;
24
25mod main;
26
27#[allow(clippy::too_many_lines)]
32pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
33 let main = main::codegen(app, analysis);
35 let init_codegen = init::codegen(app, analysis);
36 let idle_codegen = idle::codegen(app, analysis);
37 let shared_resources_codegen = shared_resources::codegen(app, analysis);
38 let local_resources_codegen = local_resources::codegen(app, analysis);
39 let hardware_tasks_codegen = hardware_tasks::codegen(app, analysis);
40 let software_tasks_codegen = software_tasks::codegen(app, analysis);
41 let async_dispatchers_codegen = async_dispatchers::codegen(app, analysis);
42
43 let user_imports = &app.user_imports;
44 let user_code = &app.user_code;
45 let name = &app.name;
46 let device = &app.args.device;
47
48 let rt_err = util::rt_err_ident();
49 let async_limit = bindings::async_prio_limit(app, analysis);
50
51 quote!(
52 pub mod #name {
54 use #device as #rt_err;
56
57 #(#async_limit)*
58
59 #(#user_imports)*
60
61 #(#user_code)*
62 #init_codegen
65
66 #idle_codegen
67
68 #hardware_tasks_codegen
69
70 #software_tasks_codegen
71
72 #shared_resources_codegen
73
74 #local_resources_codegen
75
76 #async_dispatchers_codegen
77
78 #main
79 }
80 )
81}