BTreeMaps to preserve ordering of generated code

Makes diffing of changes easier
This commit is contained in:
Timo Kröger 2021-07-30 17:06:58 +02:00
parent ad62900a40
commit fba8b86005

View file

@ -1,7 +1,7 @@
use chiptool::generate::CommonModule; use chiptool::generate::CommonModule;
use regex::Regex; use regex::Regex;
use serde::Deserialize; use serde::Deserialize;
use std::collections::{HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::env; use std::env;
use std::fmt::Write as _; use std::fmt::Write as _;
use std::fs; use std::fs;
@ -39,9 +39,9 @@ pub struct MemoryRegion {
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Core { pub struct Core {
pub name: String, pub name: String,
pub peripherals: HashMap<String, Peripheral>, pub peripherals: BTreeMap<String, Peripheral>,
pub interrupts: HashMap<String, u32>, pub interrupts: BTreeMap<String, u32>,
pub dma_channels: HashMap<String, DmaChannel>, pub dma_channels: BTreeMap<String, DmaChannel>,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -62,9 +62,9 @@ pub struct Peripheral {
#[serde(default)] #[serde(default)]
pub pins: Vec<Pin>, pub pins: Vec<Pin>,
#[serde(default)] #[serde(default)]
pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>, pub dma_channels: BTreeMap<String, Vec<PeripheralDmaChannel>>,
#[serde(default)] #[serde(default)]
pub interrupts: HashMap<String, String>, pub interrupts: BTreeMap<String, String>,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[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<String, u8>) { fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) {
write!( write!(
out, out,
"#[macro_export] "#[macro_export]
@ -158,7 +158,7 @@ macro_rules! peripheral_count {{
write!(out, " }}\n").unwrap(); write!(out, " }}\n").unwrap();
} }
fn make_dma_channel_counts(out: &mut String, data: &HashMap<String, u8>) { fn make_dma_channel_counts(out: &mut String, data: &BTreeMap<String, u8>) {
write!( write!(
out, out,
"#[macro_export] "#[macro_export]
@ -219,7 +219,7 @@ pub fn gen(options: Options) {
println!("cwd: {:?}", env::current_dir()); println!("cwd: {:?}", env::current_dir());
let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new();
let mut chip_cores: HashMap<String, Option<String>> = HashMap::new(); let mut chip_cores: BTreeMap<String, Option<String>> = BTreeMap::new();
for chip_name in &options.chips { for chip_name in &options.chips {
let mut s = chip_name.split('_'); let mut s = chip_name.split('_');
@ -291,7 +291,7 @@ pub fn gen(options: Options) {
} }
}); });
let mut peripheral_versions: HashMap<String, String> = HashMap::new(); let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
let mut pin_table: Vec<Vec<String>> = Vec::new(); let mut pin_table: Vec<Vec<String>> = Vec::new();
let mut interrupt_table: Vec<Vec<String>> = Vec::new(); let mut interrupt_table: Vec<Vec<String>> = Vec::new();
let mut peripherals_table: Vec<Vec<String>> = Vec::new(); let mut peripherals_table: Vec<Vec<String>> = Vec::new();
@ -299,8 +299,8 @@ pub fn gen(options: Options) {
let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new();
let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new();
let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new(); let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new();
let mut gpio_regs: HashSet<String> = HashSet::new(); let mut gpio_regs: HashSet<String> = HashSet::new();
@ -504,10 +504,10 @@ pub fn gen(options: Options) {
} }
} }
(None, Some(_)) => { (None, Some(_)) => {
print!("Unable to find enable register for {}", name) println!("Unable to find enable register for {}", name)
} }
(None, None) => { (None, None) => {
print!("Unable to find enable and reset register for {}", name) println!("Unable to find enable and reset register for {}", name)
} }
} }
} }