From 46bf583cc21bd8fa34e3163149b4327fcc08057e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 19 May 2020 19:03:19 +0000 Subject: [PATCH] Handle user hardware and software tasks and some resources --- macros/src/codegen.rs | 28 +++++++++++++++++++++++++--- macros/src/codegen/hardware_tasks.rs | 19 ++++++++++++++++++- macros/src/codegen/resources.rs | 12 +++++++++++- macros/src/codegen/software_tasks.rs | 18 +++++++++++++++++- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 83e5ce8bf2..68f4fee7e1 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -89,12 +89,12 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources) = resources::codegen(app, analysis, extra); + let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); - let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) = + let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) = hardware_tasks::codegen(app, analysis, extra); - let (const_app_software_tasks, root_software_tasks, user_software_tasks) = + let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) = software_tasks::codegen(app, analysis, extra); let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); @@ -110,16 +110,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { quote!( #(#user)* + /// USER_HW_TASKS #(#user_hardware_tasks)* + /// USER_SW_TASKS #(#user_software_tasks)* + /// ROOT #(#root)* + /// MOD_RESOURCES #mod_resources + /// root_hardware_tasks #(#root_hardware_tasks)* + /// root_software_tasks #(#root_software_tasks)* /// Implementation details @@ -129,17 +135,33 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { use #device as _; #(#const_app_imports)* + /// User hardware_tasks + #(#user_hardware_tasks_imports)* + + /// User software_tasks + #(#user_software_tasks_imports)* + + /// Mod resources imports + #(#mod_resources_imports)* + + /// Const app #(#const_app)* + /// Const app resources #(#const_app_resources)* + /// Const app hw tasks #(#const_app_hardware_tasks)* + /// Const app sw tasks #(#const_app_software_tasks)* + /// Const app dispatchers #(#const_app_dispatchers)* + /// Const app spawn #(#const_app_spawn)* + /// Const app spawn end #(#const_app_timer_queue)* diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 7f14b5e17c..4f60876a2d 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -23,10 +23,13 @@ pub fn codegen( Vec, // user_hardware_tasks -- the `#[task]` functions written by the user Vec, + // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut hardware_tasks_imports = vec![]; for (name, task) in &app.hardware_tasks { let (let_instant, instant) = if app.uses_schedule() { @@ -78,6 +81,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + hardware_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -112,7 +122,14 @@ pub fn codegen( #(#stmts)* } )); + + hardware_tasks_imports.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + use super::#name; + )); + } - (const_app, root, user_tasks) + (const_app, root, user_tasks, hardware_tasks_imports) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 4196ee7aad..80e63c79f1 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -14,9 +14,12 @@ pub fn codegen( Vec, // mod_resources -- the `resources` module TokenStream2, + // mod_resources_imports -- the `resources` module imports + Vec, ) { let mut const_app = vec![]; let mut mod_resources = vec![]; + let mut mod_resources_imports = vec![]; for (name, res, expr, _) in app.resources(analysis) { let cfgs = &res.cfgs; @@ -82,6 +85,13 @@ pub fn codegen( ) }; + mod_resources_imports.push(quote!( + #[allow(non_camel_case_types)] + #(#cfgs)* + #cfg_core + use super::#name; + )); + const_app.push(util::impl_mutex( extra, cfgs, @@ -104,5 +114,5 @@ pub fn codegen( }) }; - (const_app, mod_resources) + (const_app, mod_resources, mod_resources_imports) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index b56db4199d..07edd1db86 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -22,10 +22,13 @@ pub fn codegen( Vec, // user_software_tasks -- the `#[task]` functions written by the user Vec, + // user_software_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut software_tasks_imports = vec![]; for (name, task) in &app.software_tasks { let inputs = &task.inputs; @@ -112,6 +115,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + software_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -141,6 +151,12 @@ pub fn codegen( #(#stmts)* } )); + software_tasks_imports.push(quote!( + #(#attrs)* + #(#cfgs)* + #[allow(non_snake_case)] + use super::#name; + )); root.push(module::codegen( Context::SoftwareTask(name), @@ -150,5 +166,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks) + (const_app, root, user_tasks, software_tasks_imports) }