From d06cf91acc1126e66002f8884b1e7b7a65a9b24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 1 Sep 2020 17:04:55 +0000 Subject: Remove stale code, fix comment styling --- macros/src/codegen/assertions.rs | 16 ---- macros/src/codegen/dispatchers.rs | 6 +- macros/src/codegen/hardware_tasks.rs | 6 +- macros/src/codegen/idle.rs | 4 +- macros/src/codegen/init.rs | 2 - macros/src/codegen/locals.rs | 8 -- macros/src/codegen/module.rs | 4 - macros/src/codegen/post_init.rs | 149 ++------------------------------- macros/src/codegen/pre_init.rs | 59 +++---------- macros/src/codegen/resources.rs | 14 ---- macros/src/codegen/resources_struct.rs | 8 +- macros/src/codegen/schedule.rs | 6 +- macros/src/codegen/software_tasks.rs | 10 +-- macros/src/codegen/spawn.rs | 9 +- macros/src/codegen/timer_queue.rs | 10 --- macros/src/codegen/util.rs | 58 ++----------- 16 files changed, 32 insertions(+), 337 deletions(-) (limited to 'macros/src/codegen') diff --git a/macros/src/codegen/assertions.rs b/macros/src/codegen/assertions.rs index ab1b26c..4d9aae4 100644 --- a/macros/src/codegen/assertions.rs +++ b/macros/src/codegen/assertions.rs @@ -7,29 +7,13 @@ use crate::analyze::Analysis; pub fn codegen(analysis: &Analysis) -> Vec { let mut stmts = vec![]; - // we don't generate *all* assertions on all cores because the user could conditionally import a - // type only on some core (e.g. `#[cfg(core = "0")] use some::Type;`) - - //if let Some(types) = analysis.send_types { for ty in &analysis.send_types { stmts.push(quote!(rtic::export::assert_send::<#ty>();)); } - //} - //if let Some(types) = analysis.sync_types { for ty in &analysis.sync_types { stmts.push(quote!(rtic::export::assert_sync::<#ty>();)); } - //} - - // if the `schedule` API is used in more than one core then we need to check that the - // `monotonic` timer can be used in multi-core context - /* - if analysis.timer_queues.len() > 1 && analysis.timer_queues.contains_key(&core) { - let monotonic = extra.monotonic(); - stmts.push(quote!(rtic::export::assert_multicore::<#monotonic>();)); - } - */ stmts } diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index fdeb615..300aa99 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -42,13 +42,12 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec), quote!(rtic::export::Queue(unsafe { rtic::export::iQueue::u8_sc() })), - util::link_section("bss"), ) }; @@ -58,7 +57,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec ! { use rtic::Mutex as _; diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 94f57af..e0b7d69 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -81,12 +81,10 @@ pub fn codegen( let context = &init.context; let attrs = &init.attrs; let stmts = &init.stmts; - let section = util::link_section("text"); let locals_pat = locals_pat.iter(); let user_init = Some(quote!( #(#attrs)* #[allow(non_snake_case)] - #section fn #name(#(#locals_pat,)* #context: #name::Context) #ret { #(#stmts)* } diff --git a/macros/src/codegen/locals.rs b/macros/src/codegen/locals.rs index b3c593a..336c0b2 100644 --- a/macros/src/codegen/locals.rs +++ b/macros/src/codegen/locals.rs @@ -41,13 +41,6 @@ pub fn codegen( let cfgs = &local.cfgs; has_cfgs |= !cfgs.is_empty(); - /* - let section = if local.shared && cfg!(feature = "heterogeneous") { - Some(quote!(#[rtic::export::shared])) - } else { - util::link_section("data", core) - }; - */ let expr = &local.expr; let ty = &local.ty; fields.push(quote!( @@ -56,7 +49,6 @@ pub fn codegen( )); items.push(quote!( #(#cfgs)* - //#section static mut #name: #ty = #expr )); values.push(quote!( diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 4b3d0cf..863f6c5 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -11,7 +11,6 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> let name = ctxt.ident(app); - //let core = ctxt.core(app); let mut needs_instant = false; let mut lt = None; match ctxt { @@ -312,12 +311,9 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> )); if !items.is_empty() { - //let cfg_core = util::cfg_core(ctxt.core(app), app.args.cores); - quote!( #[allow(non_snake_case)] #[doc = #doc] - //#cfg_core pub mod #name { #(#items)* } diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 93d5704..c35c697 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -5,19 +5,14 @@ use rtic_syntax::ast::App; use crate::analyze::Analysis; /// Generates code that runs after `#[init]` returns -pub fn codegen(app: &App, analysis: &Analysis) -> (Vec, Vec) { - //#TODO remove - let const_app = vec![]; +pub fn codegen(app: &App, analysis: &Analysis) -> Vec { let mut stmts = vec![]; - // initialize late resources - //if let Some(late_resources) = analysis.late_resources { - //for name in late_resources { + // Initialize late resources if analysis.late_resources.len() > 0 { - // #TODO, check soundness of this, why the wrapping // BTreeSet wrapped in a vector - for name in &analysis.late_resources[0] { - // if it's live + for name in analysis.late_resources.first().unwrap() { + // If it's live let cfgs = app.late_resources[name].cfgs.clone(); if analysis.locations.get(name).is_some() { // Need to also include the cfgs @@ -29,140 +24,8 @@ pub fn codegen(app: &App, analysis: &Analysis) -> (Vec, Vec::reset(); - )); - } else { - // in the multi-core case we need a rendezvous (RV) barrier between *all* the cores that - // use the `schedule` API; otherwise one of the cores could observe the before-reset - // value of the monotonic counter - // (this may be easier to implement with `AtomicU8.fetch_sub` but that API is not - // available on ARMv6-M) - - // this core will reset the monotonic counter - const FIRST: u8 = 0; - - if core == FIRST { - for &i in analysis.timer_queues.keys() { - let rv = util::rendezvous_ident(i); - let shared = if cfg!(feature = "heterogeneous") { - Some(quote!( - #[rtic::export::shared] - )) - } else { - None - }; - - const_app.push(quote!( - #shared - static #rv: rtic::export::Barrier = rtic::export::Barrier::new(); - )); - - // wait until all the other cores have reached the RV point - if i != FIRST { - stmts.push(quote!( - #rv.wait(); - )); - } - } - - let rv = util::rendezvous_ident(core); - stmts.push(quote!( - // the compiler fences are used to prevent `reset` from being re-ordering wrt to - // the atomic operations -- we don't know if `reset` contains load or store - // operations - - core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst); - - // reset the counter - <#m as rtic::Monotonic>::reset(); - - core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst); - - // now unblock all the other cores - #rv.release(); - )); - } else { - let rv = util::rendezvous_ident(core); - - // let the first core know that we have reached the RV point - stmts.push(quote!( - #rv.release(); - )); - - let rv = util::rendezvous_ident(FIRST); - - // wait until the first core has reset the monotonic timer - stmts.push(quote!( - #rv.wait(); - )); - } - } - } - */ - - // enable the interrupts -- this completes the `init`-ialization phase + // Enable the interrupts -- this completes the `init`-ialization phase stmts.push(quote!(rtic::export::interrupt::enable();)); - (const_app, stmts) + stmts } diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 80849ae..9c5f35e 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -8,10 +8,10 @@ use crate::{analyze::Analysis, check::Extra, codegen::util}; pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec { let mut stmts = vec![]; - // disable interrupts -- `init` must run with interrupts disabled + // Disable interrupts -- `init` must run with interrupts disabled stmts.push(quote!(rtic::export::interrupt::disable();)); - // populate the FreeQueue + // Populate the FreeQueue for fq in &analysis.free_queues { // Get the task name let name = fq.0; @@ -33,7 +33,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Vec Vec Vec Vec ( - None, - if expr.is_none() { - util::link_section_uninit(true) - } else { - None - }, - ), - }; - */ let (ty, expr) = if let Some(expr) = expr { (quote!(#ty), quote!(#expr)) @@ -56,7 +43,6 @@ pub fn codegen( #[allow(non_upper_case_globals)] #(#attrs)* #(#cfgs)* - //#loc_attr #section static mut #name: #ty = #expr; )); diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs index 0c5efd3..dbbba30 100644 --- a/macros/src/codegen/resources_struct.rs +++ b/macros/src/codegen/resources_struct.rs @@ -39,7 +39,7 @@ pub fn codegen( if ctxt.is_init() { if !analysis.ownerships.contains_key(name) { - // owned by `init` + // Owned by `init` fields.push(quote!( #(#cfgs)* pub #name: &'static #mut_ #ty @@ -50,7 +50,7 @@ pub fn codegen( #name: &#mut_ #name )); } else { - // owned by someone else + // Owned by someone else lt = Some(quote!('a)); fields.push(quote!( @@ -75,7 +75,7 @@ pub fn codegen( pub #name: &'a #ty )); } else { - // resource proxy + // Resource proxy lt = Some(quote!('a)); fields.push(quote!( @@ -136,7 +136,7 @@ pub fn codegen( if lt.is_some() { *needs_lt = true; - // the struct could end up empty due to `cfg`s leading to an error due to `'a` being unused + // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused if has_cfgs { fields.push(quote!( #[doc(hidden)] diff --git a/macros/src/codegen/schedule.rs b/macros/src/codegen/schedule.rs index b6cb6b9..46b0f38 100644 --- a/macros/src/codegen/schedule.rs +++ b/macros/src/codegen/schedule.rs @@ -32,10 +32,8 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec { let body = schedule_body::codegen(scheduler, &name, app); - let section = util::link_section("text"); methods.push(quote!( #(#cfgs)* - #section fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> { #body } @@ -44,15 +42,13 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec { let schedule = util::schedule_ident(name); if !seen.contains(name) { - // generate a `schedule_${name}_S${sender}` function + // Generate a `schedule_${name}_S${sender}` function seen.insert(name); let body = schedule_body::codegen(scheduler, &name, app); - let section = util::link_section("text"); items.push(quote!( #(#cfgs)* - #section unsafe fn #schedule( priority: &rtic::export::Priority, instant: #instant diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 2566280..b56db41 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -35,26 +35,22 @@ pub fn codegen( let cap_lit = util::capacity_literal(cap); let cap_ty = util::capacity_typenum(cap, true); - // create free queues and inputs / instants buffers - //if let Some(free_queues) = analysis.free_queues.get(name) { - //for (&sender, &ceiling) in free_queues { + // Create free queues and inputs / instants buffers if let Some(&ceiling) = analysis.free_queues.get(name) { let fq = util::fq_ident(name); - let (fq_ty, fq_expr, bss, mk_uninit): (_, _, _, Box Option<_>>) = { + let (fq_ty, fq_expr, mk_uninit): (_, _, Box Option<_>>) = { ( quote!(rtic::export::SCFQ<#cap_ty>), quote!(rtic::export::Queue(unsafe { rtic::export::iQueue::u8_sc() })), - util::link_section("bss"), Box::new(|| util::link_section_uninit(true)), ) }; const_app.push(quote!( /// Queue version of a free-list that keeps track of empty slots in /// the following buffers - #bss static mut #fq: #fq_ty = #fq_expr; )); @@ -130,7 +126,6 @@ pub fn codegen( root.push(struct_); } - let section = util::link_section("text"); let context = &task.context; let attrs = &task.attrs; let cfgs = &task.cfgs; @@ -140,7 +135,6 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #[allow(non_snake_case)] - #section fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { use rtic::Mutex as _; diff --git a/macros/src/codegen/spawn.rs b/macros/src/codegen/spawn.rs index 6cad809..4b824f5 100644 --- a/macros/src/codegen/spawn.rs +++ b/macros/src/codegen/spawn.rs @@ -20,7 +20,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Result<(), #ty> { #let_instant #body @@ -52,7 +49,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Vec #spawner::Spawn<#lt> { #(#methods)* } diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index 41f5520..030158e 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -9,7 +9,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Vec); - let section = util::link_section("bss"); items.push(quote!( - //#cfg_sender #[doc = #doc] - #section static mut #tq: #tq_ty = rtic::export::TimerQueue( rtic::export::BinaryHeap( rtic::export::iBinaryHeap::new() ) ); - //#cfg_sender struct #tq<'a> { priority: &'a rtic::export::Priority, } @@ -68,7 +62,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec TokenSt quote!(rtic::export::consts::#ident) } -/* -/// Generates a `#[cfg(core = "0")]` attribute if we are in multi-core mode -pub fn cfg_core(core: Core, cores: u8) -> Option { - if cores == 1 { - None - } else if cfg!(feature = "heterogeneous") { - let core = core.to_string(); - Some(quote!(#[cfg(core = #core)])) - } else { - None - } -} -*/ - /// Identifier for the free queue -/// -/// There may be more than one free queue per task because we need one for each sender core so we -/// include the sender (e.g. `S0`) in the name pub fn fq_ident(task: &Ident) -> Ident { Ident::new(&format!("{}_FQ", task.to_string()), Span::call_site()) } @@ -51,7 +34,6 @@ pub fn fq_ident(task: &Ident) -> Ident { pub fn impl_mutex( extra: &Extra, cfgs: &[Attribute], - //cfg_core: Option<&TokenStream2>, resources_prefix: bool, name: &Ident, ty: TokenStream2, @@ -67,7 +49,6 @@ pub fn impl_mutex( let device = extra.device; quote!( #(#cfgs)* - //#cfg_core impl<'a> rtic::Mutex for #path<'a> { type T = #ty; @@ -90,13 +71,6 @@ pub fn impl_mutex( ) } -/* -/// Generates an identifier for a cross-initialization barrier -pub fn init_barrier(initializer: Core) -> Ident { - Ident::new(&format!("IB{}", initializer), Span::call_site()) -} -*/ - /// Generates an identifier for the `INPUTS` buffer (`spawn` & `schedule` API) pub fn inputs_ident(task: &Ident) -> Ident { Ident::new(&format!("{}_INPUTS", task), Span::call_site()) @@ -138,18 +112,6 @@ fn link_section_index() -> usize { INDEX.fetch_add(1, Ordering::Relaxed) } -pub fn link_section(_section: &str) -> Option { - /* - if cfg!(feature = "homogeneous") { - let section = format!(".{}_{}.rtic{}", section, core, link_section_index()); - Some(quote!(#[link_section = #section])) - } else { - None - } - */ - None -} - // NOTE `None` means in shared memory pub fn link_section_uninit(empty_expr: bool) -> Option { let section = if empty_expr { @@ -175,13 +137,6 @@ pub fn locals_ident(ctxt: Context, app: &App) -> Ident { Ident::new(&s, Span::call_site()) } -/* -/// Generates an identifier for a rendezvous barrier -pub fn rendezvous_ident() -> Ident { - Ident::new(&format!("RV"), Span::call_site()) -} -*/ - // Regroups the inputs of a task // // `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] @@ -246,17 +201,15 @@ pub fn resources_ident(ctxt: Context, app: &App) -> Ident { /// Generates an identifier for a ready queue /// -/// Each core may have several task dispatchers, one for each priority level. Each task dispatcher -/// in turn may use more than one ready queue because the queues are SPSC queues so one is needed -/// per sender core. +/// There may be several task dispatchers, one for each priority level. +/// The ready queues are SPSC queues pub fn rq_ident(priority: u8) -> Ident { Ident::new(&format!("P{}_RQ", priority), Span::call_site()) } /// Generates an identifier for a "schedule" function /// -/// The methods of the `Schedule` structs invoke these functions. As one task may be `schedule`-ed -/// by different cores we need one "schedule" function per possible task-sender pair +/// The methods of the `Schedule` structs invoke these functions. pub fn schedule_ident(name: &Ident) -> Ident { Ident::new(&format!("schedule_{}", name.to_string()), Span::call_site()) } @@ -268,8 +221,7 @@ pub fn schedule_t_ident() -> Ident { /// Generates an identifier for a "spawn" function /// -/// The methods of the `Spawn` structs invoke these functions. As one task may be `spawn`-ed by -/// different cores we need one "spawn" function per possible task-sender pair +/// The methods of the `Spawn` structs invoke these functions. pub fn spawn_ident(name: &Ident) -> Ident { Ident::new(&format!("spawn_{}", name.to_string()), Span::call_site()) } @@ -289,7 +241,7 @@ pub fn suffixed(name: &str) -> Ident { /// Generates an identifier for a timer queue /// -/// At most there's one timer queue per core +/// At most there is one timer queue pub fn tq_ident() -> Ident { Ident::new(&format!("TQ"), Span::call_site()) } -- cgit v1.2.3