From fba8b86005958fafa7e188b20b4212773ce912cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Fri, 30 Jul 2021 17:06:58 +0200 Subject: [PATCH] BTreeMaps to preserve ordering of generated code Makes diffing of changes easier --- stm32-metapac-gen/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 5e0cc58d..8a2698d8 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -1,7 +1,7 @@ use chiptool::generate::CommonModule; use regex::Regex; use serde::Deserialize; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::env; use std::fmt::Write as _; use std::fs; @@ -39,9 +39,9 @@ pub struct MemoryRegion { #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] pub struct Core { pub name: String, - pub peripherals: HashMap, - pub interrupts: HashMap, - pub dma_channels: HashMap, + pub peripherals: BTreeMap, + pub interrupts: BTreeMap, + pub dma_channels: BTreeMap, } #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] @@ -62,9 +62,9 @@ pub struct Peripheral { #[serde(default)] pub pins: Vec, #[serde(default)] - pub dma_channels: HashMap>, + pub dma_channels: BTreeMap>, #[serde(default)] - pub interrupts: HashMap, + pub interrupts: BTreeMap, } #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] @@ -144,7 +144,7 @@ fn find_reg_for_field<'c>( }) } -fn make_peripheral_counts(out: &mut String, data: &HashMap) { +fn make_peripheral_counts(out: &mut String, data: &BTreeMap) { write!( out, "#[macro_export] @@ -158,7 +158,7 @@ macro_rules! peripheral_count {{ write!(out, " }}\n").unwrap(); } -fn make_dma_channel_counts(out: &mut String, data: &HashMap) { +fn make_dma_channel_counts(out: &mut String, data: &BTreeMap) { write!( out, "#[macro_export] @@ -219,7 +219,7 @@ pub fn gen(options: Options) { println!("cwd: {:?}", env::current_dir()); let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); - let mut chip_cores: HashMap> = HashMap::new(); + let mut chip_cores: BTreeMap> = BTreeMap::new(); for chip_name in &options.chips { let mut s = chip_name.split('_'); @@ -291,7 +291,7 @@ pub fn gen(options: Options) { } }); - let mut peripheral_versions: HashMap = HashMap::new(); + let mut peripheral_versions: BTreeMap = BTreeMap::new(); let mut pin_table: Vec> = Vec::new(); let mut interrupt_table: Vec> = Vec::new(); let mut peripherals_table: Vec> = Vec::new(); @@ -299,8 +299,8 @@ pub fn gen(options: Options) { let mut peripheral_rcc_table: Vec> = Vec::new(); let mut dma_channels_table: Vec> = Vec::new(); let mut peripheral_dma_channels_table: Vec> = Vec::new(); - let mut peripheral_counts: HashMap = HashMap::new(); - let mut dma_channel_counts: HashMap = HashMap::new(); + let mut peripheral_counts: BTreeMap = BTreeMap::new(); + let mut dma_channel_counts: BTreeMap = BTreeMap::new(); let mut dbgmcu_table: Vec> = Vec::new(); let mut gpio_rcc_table: Vec> = Vec::new(); let mut gpio_regs: HashSet = HashSet::new(); @@ -504,10 +504,10 @@ pub fn gen(options: Options) { } } (None, Some(_)) => { - print!("Unable to find enable register for {}", name) + println!("Unable to find enable register for {}", name) } (None, None) => { - print!("Unable to find enable and reset register for {}", name) + println!("Unable to find enable and reset register for {}", name) } } }