mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
All codegen is now explicit
This commit is contained in:
parent
b054e871d4
commit
76595b7aed
8 changed files with 57 additions and 128 deletions
|
@ -29,21 +29,14 @@ mod main;
|
|||
pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
// Generate the `main` function
|
||||
let main = main::codegen(app, analysis);
|
||||
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);
|
||||
|
||||
let (mod_app_init, root_init, user_init) = init::codegen(app, analysis);
|
||||
|
||||
let (mod_app_idle, root_idle, user_idle) = idle::codegen(app, analysis);
|
||||
|
||||
let (mod_app_shared_resources, mod_shared_resources) = shared_resources::codegen(app, analysis);
|
||||
let (mod_app_local_resources, mod_local_resources) = local_resources::codegen(app, analysis);
|
||||
|
||||
let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
||||
hardware_tasks::codegen(app, analysis);
|
||||
|
||||
let (mod_app_software_tasks, root_software_tasks, user_software_tasks) =
|
||||
software_tasks::codegen(app, analysis);
|
||||
|
||||
let mod_app_async_dispatchers = async_dispatchers::codegen(app, analysis);
|
||||
let user_imports = &app.user_imports;
|
||||
let user_code = &app.user_code;
|
||||
let name = &app.name;
|
||||
|
@ -59,43 +52,22 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
|
||||
#(#user_imports)*
|
||||
|
||||
/// User code from within the module
|
||||
#(#user_code)*
|
||||
/// User code end
|
||||
|
||||
#(#user_hardware_tasks)*
|
||||
#init_codegen
|
||||
|
||||
#(#user_software_tasks)*
|
||||
#idle_codegen
|
||||
|
||||
#mod_app_init
|
||||
#hardware_tasks_codegen
|
||||
|
||||
#(#root_init)*
|
||||
#software_tasks_codegen
|
||||
|
||||
#user_init
|
||||
#shared_resources_codegen
|
||||
|
||||
#(#mod_app_idle)*
|
||||
#local_resources_codegen
|
||||
|
||||
#(#root_idle)*
|
||||
|
||||
#user_idle
|
||||
|
||||
#mod_shared_resources
|
||||
|
||||
#mod_local_resources
|
||||
|
||||
#(#root_hardware_tasks)*
|
||||
|
||||
#(#root_software_tasks)*
|
||||
|
||||
#(#mod_app_shared_resources)*
|
||||
|
||||
#(#mod_app_local_resources)*
|
||||
|
||||
#(#mod_app_hardware_tasks)*
|
||||
|
||||
#(#mod_app_software_tasks)*
|
||||
|
||||
#(#mod_app_async_dispatchers)*
|
||||
#async_dispatchers_codegen
|
||||
|
||||
#main
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::quote;
|
||||
|
||||
/// Generates task dispatchers
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
let mut items = vec![];
|
||||
|
||||
let interrupts = &analysis.interrupts;
|
||||
|
@ -96,5 +96,5 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
|||
));
|
||||
}
|
||||
|
||||
items
|
||||
quote!(#(#items)*)
|
||||
}
|
||||
|
|
|
@ -7,20 +7,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::quote;
|
||||
|
||||
/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s)
|
||||
pub fn codegen(
|
||||
app: &App,
|
||||
analysis: &Analysis,
|
||||
) -> (
|
||||
// mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors
|
||||
Vec<TokenStream2>,
|
||||
// root_hardware_tasks -- items that must be placed in the root of the crate:
|
||||
// - `${task}Locals` structs
|
||||
// - `${task}Resources` structs
|
||||
// - `${task}` modules
|
||||
Vec<TokenStream2>,
|
||||
// user_hardware_tasks -- the `#[task]` functions written by the user
|
||||
Vec<TokenStream2>,
|
||||
) {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
let mut mod_app = vec![];
|
||||
let mut root = vec![];
|
||||
let mut user_tasks = vec![];
|
||||
|
@ -90,5 +77,11 @@ pub fn codegen(
|
|||
}
|
||||
}
|
||||
|
||||
(mod_app, root, user_tasks)
|
||||
quote!(
|
||||
#(#mod_app)*
|
||||
|
||||
#(#root)*
|
||||
|
||||
#(#user_tasks)*
|
||||
)
|
||||
}
|
||||
|
|
|
@ -7,20 +7,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::quote;
|
||||
|
||||
/// Generates support code for `#[idle]` functions
|
||||
pub fn codegen(
|
||||
app: &App,
|
||||
analysis: &Analysis,
|
||||
) -> (
|
||||
// mod_app_idle -- the `${idle}Resources` constructor
|
||||
Vec<TokenStream2>,
|
||||
// root_idle -- items that must be placed in the root of the crate:
|
||||
// - the `${idle}Locals` struct
|
||||
// - the `${idle}Resources` struct
|
||||
// - the `${idle}` module, which contains types like `${idle}::Context`
|
||||
Vec<TokenStream2>,
|
||||
// user_idle
|
||||
Option<TokenStream2>,
|
||||
) {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
if let Some(idle) = &app.idle {
|
||||
let mut mod_app = vec![];
|
||||
let mut root_idle = vec![];
|
||||
|
@ -58,10 +45,14 @@ pub fn codegen(
|
|||
}
|
||||
));
|
||||
|
||||
(mod_app, root_idle, user_idle)
|
||||
} else {
|
||||
// TODO: No idle defined, check for 0-priority tasks and generate an executor if needed
|
||||
quote!(
|
||||
#(#mod_app)*
|
||||
|
||||
(vec![], vec![], None)
|
||||
#(#root_idle)*
|
||||
|
||||
#user_idle
|
||||
)
|
||||
} else {
|
||||
quote!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,21 +7,8 @@ use crate::{
|
|||
syntax::{ast::App, Context},
|
||||
};
|
||||
|
||||
type CodegenResult = (
|
||||
// mod_app_idle -- the `${init}Resources` constructor
|
||||
Option<TokenStream2>,
|
||||
// root_init -- items that must be placed in the root of the crate:
|
||||
// - the `${init}Locals` struct
|
||||
// - the `${init}Resources` struct
|
||||
// - the `${init}LateResources` struct
|
||||
// - the `${init}` module, which contains types like `${init}::Context`
|
||||
Vec<TokenStream2>,
|
||||
// user_init -- the `#[init]` function written by the user
|
||||
TokenStream2,
|
||||
);
|
||||
|
||||
/// Generates support code for `#[init]` functions
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> CodegenResult {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
let init = &app.init;
|
||||
let name = &init.name;
|
||||
|
||||
|
@ -98,5 +85,11 @@ pub fn codegen(app: &App, analysis: &Analysis) -> CodegenResult {
|
|||
|
||||
root_init.push(module::codegen(Context::Init, app, analysis));
|
||||
|
||||
(mod_app, root_init, user_init)
|
||||
quote!(
|
||||
#mod_app
|
||||
|
||||
#(#root_init)*
|
||||
|
||||
#user_init
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,17 +6,8 @@ use quote::quote;
|
|||
/// Generates `local` variables and local resource proxies
|
||||
///
|
||||
/// I.e. the `static` variables and theirs proxies.
|
||||
pub fn codegen(
|
||||
app: &App,
|
||||
_analysis: &Analysis,
|
||||
) -> (
|
||||
// mod_app -- the `static` variables behind the proxies
|
||||
Vec<TokenStream2>,
|
||||
// mod_resources -- the `resources` module
|
||||
TokenStream2,
|
||||
) {
|
||||
pub fn codegen(app: &App, _analysis: &Analysis) -> TokenStream2 {
|
||||
let mut mod_app = vec![];
|
||||
// let mut mod_resources: _ = vec![];
|
||||
|
||||
// All local resources declared in the `#[local]' struct
|
||||
for (name, res) in &app.local_resources {
|
||||
|
@ -70,5 +61,5 @@ pub fn codegen(
|
|||
));
|
||||
}
|
||||
|
||||
(mod_app, TokenStream2::new())
|
||||
quote!(#(#mod_app)*)
|
||||
}
|
||||
|
|
|
@ -5,15 +5,7 @@ use quote::quote;
|
|||
use std::collections::HashMap;
|
||||
|
||||
/// Generates `static` variables and shared resource proxies
|
||||
pub fn codegen(
|
||||
app: &App,
|
||||
analysis: &Analysis,
|
||||
) -> (
|
||||
// mod_app -- the `static` variables behind the proxies
|
||||
Vec<TokenStream2>,
|
||||
// mod_resources -- the `resources` module
|
||||
TokenStream2,
|
||||
) {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
let mut mod_app = vec![];
|
||||
let mut mod_resources = vec![];
|
||||
|
||||
|
@ -183,5 +175,9 @@ pub fn codegen(
|
|||
));
|
||||
}
|
||||
|
||||
(mod_app, mod_resources)
|
||||
quote!(
|
||||
#(#mod_app)*
|
||||
|
||||
#mod_resources
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,20 +6,7 @@ use crate::{
|
|||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
|
||||
pub fn codegen(
|
||||
app: &App,
|
||||
analysis: &Analysis,
|
||||
) -> (
|
||||
// mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors
|
||||
Vec<TokenStream2>,
|
||||
// root_software_tasks -- items that must be placed in the root of the crate:
|
||||
// - `${task}Locals` structs
|
||||
// - `${task}Resources` structs
|
||||
// - `${task}` modules
|
||||
Vec<TokenStream2>,
|
||||
// user_software_tasks -- the `#[task]` functions written by the user
|
||||
Vec<TokenStream2>,
|
||||
) {
|
||||
pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||
let mut mod_app = vec![];
|
||||
let mut root = vec![];
|
||||
let mut user_tasks = vec![];
|
||||
|
@ -78,5 +65,11 @@ pub fn codegen(
|
|||
root.push(module::codegen(Context::SoftwareTask(name), app, analysis));
|
||||
}
|
||||
|
||||
(mod_app, root, user_tasks)
|
||||
quote!(
|
||||
#(#mod_app)*
|
||||
|
||||
#(#root)*
|
||||
|
||||
#(#user_tasks)*
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue