diff options
author | 2021-07-07 22:50:59 +0200 | |
---|---|---|
committer | 2021-07-07 23:07:09 +0200 | |
commit | 98d2af9d73da56910c8bb6cb662fbc4d609a704a (patch) | |
tree | 46914250a980b9164b2d20cbeb08e126a86cf7ea /macros/src | |
parent | 633012190baa0801efc7e3ab2f699778c5038d54 (diff) | |
download | rtic-98d2af9d73da56910c8bb6cb662fbc4d609a704a.tar.gz rtic-98d2af9d73da56910c8bb6cb662fbc4d609a704a.tar.zst rtic-98d2af9d73da56910c8bb6cb662fbc4d609a704a.zip |
Fixing tests
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/codegen.rs | 1 | ||||
-rw-r--r-- | macros/src/codegen/dispatchers.rs | 7 | ||||
-rw-r--r-- | macros/src/codegen/hardware_tasks.rs | 8 | ||||
-rw-r--r-- | macros/src/codegen/init.rs | 11 | ||||
-rw-r--r-- | macros/src/codegen/local_resources.rs | 15 | ||||
-rw-r--r-- | macros/src/codegen/local_resources_struct.rs | 10 | ||||
-rw-r--r-- | macros/src/codegen/shared_resources_struct.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/util.rs | 28 | ||||
-rw-r--r-- | macros/src/tests/single.rs | 11 |
9 files changed, 52 insertions, 41 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 9c1ae88c..6920031a 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -20,7 +20,6 @@ mod software_tasks; mod timer_queue; mod util; -// TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut mod_app = vec![]; let mut mains = vec![]; diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index 1c311954..ac550036 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -76,13 +76,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea let inputs = util::mark_internal_ident(&inputs); let (_, tupled, pats, _) = util::regroup_inputs(&task.inputs); - // TODO Fix me - // let locals_new = if task.args.local_resources.is_empty() { - // quote!() - // } else { - // quote!(#name::Locals::new(),) - // }; - quote!( #(#cfgs)* #t::#name => { diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index c7f3e7d9..e6192e2c 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -29,13 +29,6 @@ pub fn codegen( let mut user_tasks = vec![]; for (name, task) in &app.hardware_tasks { - // TODO: Fix locals - // let locals_new = if task.args.local_resources.is_empty() { - // quote!() - // } else { - // quote!(#name::Locals::new(),) - // }; - let symbol = task.args.binds.clone(); let priority = task.args.priority; let cfgs = &task.cfgs; @@ -60,7 +53,6 @@ pub fn codegen( let mut shared_needs_lt = false; let mut local_needs_lt = false; - // TODO: Fix locals // `${task}Locals` if !task.args.local_resources.is_empty() { let (item, constructor) = local_resources_struct::codegen( diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 1bea7b7e..b6d3f72e 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -31,17 +31,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { let mut root_init = vec![]; - // TODO: Fix locals - // let mut locals_pat = None; - // let mut locals_new = None; - // if !init.locals.is_empty() { - // let (struct_, pat) = locals::codegen(Context::Init, &init.locals, app); - - // locals_new = Some(quote!(#name::Locals::new())); - // locals_pat = Some(pat); - // root_init.push(struct_); - // } - let context = &init.context; let attrs = &init.attrs; let stmts = &init.stmts; diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 70f75809..c5cddfb3 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -44,13 +44,16 @@ pub fn codegen( } // All declared `local = [NAME: TY = EXPR]` local resources - for (name, task_local) in app.declared_local_resources() { + for (task_name, resource_name, task_local) in app.declared_local_resources() { let cfgs = &task_local.cfgs; let ty = &task_local.ty; let expr = &task_local.expr; let attrs = &task_local.attrs; - let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + let mangled_name = util::mark_internal_ident(&util::declared_static_local_resource_ident( + resource_name, + &task_name, + )); // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); @@ -64,13 +67,5 @@ pub fn codegen( )); } - // let mod_resources = if mod_resources.is_empty() { - // quote!() - // } else { - // quote!(mod local_resources { - // #(#mod_resources)* - // }) - // }; - (mod_app, TokenStream2::new()) } diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs index 0283d526..4bd9e2a4 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/macros/src/codegen/local_resources_struct.rs @@ -18,6 +18,8 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources, }; + let task_name = util::get_task_name(ctxt, app); + let mut fields = vec![]; let mut values = vec![]; let mut has_cfgs = false; @@ -41,7 +43,13 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, quote!('a) }; - let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + let mangled_name = if matches!(task_local, TaskLocal::External) { + util::mark_internal_ident(&util::static_local_resource_ident(name)) + } else { + util::mark_internal_ident(&util::declared_static_local_resource_ident( + name, &task_name, + )) + }; fields.push(quote!( #(#cfgs)* diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs index df7f38de..301bef73 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/macros/src/codegen/shared_resources_struct.rs @@ -32,7 +32,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, None }; let ty = &res.ty; - let mangled_name = util::mark_internal_ident(&name); + let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name)); if !res.properties.lock_free { if access.is_shared() { diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index e3df2076..3b0b9e4f 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -212,6 +212,17 @@ pub fn regroup_inputs( } } +/// Get the ident for the name of the task +pub fn get_task_name(ctxt: Context, app: &App) -> Ident { + let s = match ctxt { + Context::Init => app.init.name.to_string(), + Context::Idle => app.idle.as_ref().unwrap().name.to_string(), + Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), + }; + + Ident::new(&s, Span::call_site()) +} + /// Generates a pre-reexport identifier for the "shared resources" struct pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { @@ -276,11 +287,24 @@ pub fn monotonic_ident(name: &str) -> Ident { } pub fn static_shared_resource_ident(name: &Ident) -> Ident { - Ident::new(&format!("shared_{}", name.to_string()), Span::call_site()) + Ident::new( + &format!("shared_resource_{}", name.to_string()), + Span::call_site(), + ) } pub fn static_local_resource_ident(name: &Ident) -> Ident { - Ident::new(&format!("local_{}", name.to_string()), Span::call_site()) + Ident::new( + &format!("local_resource_{}", name.to_string()), + Span::call_site(), + ) +} + +pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { + Ident::new( + &format!("local_{}_{}", task_name.to_string(), name.to_string()), + Span::call_site(), + ) } /// The name to get better RT flag errors diff --git a/macros/src/tests/single.rs b/macros/src/tests/single.rs index 8c026e99..27118856 100644 --- a/macros/src/tests/single.rs +++ b/macros/src/tests/single.rs @@ -10,6 +10,17 @@ fn analyze() { quote!(device = pac, dispatchers = [B, A]), quote!( mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + (Shared {}, Local {}, init::Monotonics {}) + } + #[task(priority = 1)] fn a(_: a::Context) {} |