diff options
author | 2023-03-04 21:10:24 +0000 | |
---|---|---|
committer | 2023-03-04 21:10:24 +0000 | |
commit | 7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (patch) | |
tree | 80a47f0dc40059014e9448c4c2eb34c54dff45fe /rtic-macros/src/syntax/optimize.rs | |
parent | 1c5db277e4161470136dbd2a11e914ff1d383581 (diff) | |
parent | 98c5490d94950608d31cd5ad9dd260f2f853735c (diff) | |
download | rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.gz rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.zst rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.zip |
Merge #694
694: RTIC 2 r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
Diffstat (limited to 'rtic-macros/src/syntax/optimize.rs')
-rw-r--r-- | rtic-macros/src/syntax/optimize.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/rtic-macros/src/syntax/optimize.rs b/rtic-macros/src/syntax/optimize.rs new file mode 100644 index 00000000..e83ba31b --- /dev/null +++ b/rtic-macros/src/syntax/optimize.rs @@ -0,0 +1,36 @@ +use std::collections::{BTreeSet, HashMap}; + +use crate::syntax::ast::App; + +pub fn app(app: &mut App, settings: &Settings) { + // "compress" priorities + // If the user specified, for example, task priorities of "1, 3, 6", + // compress them into "1, 2, 3" as to leave no gaps + if settings.optimize_priorities { + // all task priorities ordered in ascending order + let priorities = app + .hardware_tasks + .values() + .map(|task| Some(task.args.priority)) + .chain( + app.software_tasks + .values() + .map(|task| Some(task.args.priority)), + ) + .collect::<BTreeSet<_>>(); + + let map = priorities + .iter() + .cloned() + .zip(1..) + .collect::<HashMap<_, _>>(); + + for task in app.hardware_tasks.values_mut() { + task.args.priority = map[&Some(task.args.priority)]; + } + + for task in app.software_tasks.values_mut() { + task.args.priority = map[&Some(task.args.priority)]; + } + } +} |