From 751515acfcd1df9aa71198452793bf6162e5895a Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 19 Oct 2022 22:20:26 -0500 Subject: [PATCH] Switch to indexmap --- Cargo.lock | 18 +----------------- Cargo.toml | 3 +-- src/main.rs | 35 +++++++++++++++++------------------ 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ab703b..0bd6e27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -402,21 +402,6 @@ dependencies = [ "cc", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "linked_hash_set" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47186c6da4d81ca383c7c47c1bfc80f4b95f4720514d860a5407aaf4233f9588" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "linux-raw-sys" version = "0.0.46" @@ -450,10 +435,9 @@ dependencies = [ "derive-try-from-primitive", "elf", "human-repr", + "indexmap", "inventory", "itertools", - "linked-hash-map", - "linked_hash_set", "nullable-result", "parse_int", "paste", diff --git a/Cargo.toml b/Cargo.toml index 1b96f07..b71707b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,9 @@ bitvec = "1.0.0" derive-try-from-primitive = "1.0.0" elf = "0.1.0" human-repr = { version = "1.0.1", features = ["iec", "space"] } +indexmap = "1.9.1" inventory = "0.3.1" itertools = "0.10.5" -linked-hash-map = "0.5.6" -linked_hash_set = "0.1.4" nullable-result = { version = "0.7.0", features=["try_trait"] } parse_int = "0.6.0" paste = "1.0.9" diff --git a/src/main.rs b/src/main.rs index dadec71..b4187fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,9 +21,8 @@ use crate::{ }; use disas::DisassemblyError; use elf::gabi::{STT_FILE, STT_SECTION}; +use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; -use linked_hash_map::LinkedHashMap; -use linked_hash_set::LinkedHashSet; use parse_int::parse; use reedline_repl_rs::{ clap::{builder::BoolishValueParser, Arg, ArgAction, Command}, @@ -43,11 +42,11 @@ use std::{ #[derive(Debug)] pub struct SymbolTable { symbols: HashMap, - breakpoints: LinkedHashSet, + breakpoints: IndexSet, active: bool, } -pub type SymbolTables = LinkedHashMap; +pub type SymbolTables = IndexMap; #[derive(Copy, Clone, Debug)] enum PeekFormat { @@ -149,7 +148,7 @@ struct EmuConfig<'a> { struct EmuState { cpu: M68K, symbol_tables: SymbolTables, - address_breakpoints: LinkedHashSet, + address_breakpoints: IndexSet, } fn main() -> Result<(), ReplError> { @@ -162,7 +161,7 @@ fn main() -> Result<(), ReplError> { Err(e) => panic!("{}", e), }; } - let mut symbol_tables = LinkedHashMap::new(); + let mut symbol_tables = IndexMap::new(); if let Some(initial_tables) = config.symbol_tables { for path in initial_tables { let table_name = Path::new(&path).file_name().unwrap().to_str().unwrap(); @@ -170,7 +169,7 @@ fn main() -> Result<(), ReplError> { table_name.to_string(), SymbolTable { symbols: read_symbol_table(path).unwrap(), - breakpoints: LinkedHashSet::new(), + breakpoints: IndexSet::new(), active: true, }, ); @@ -179,7 +178,7 @@ fn main() -> Result<(), ReplError> { Repl::<_, Error>::new(EmuState { cpu: M68K::new(backplane), symbol_tables, - address_breakpoints: LinkedHashSet::new(), + address_breakpoints: IndexSet::new(), }) .with_name("68KEmu") .with_version("0.1.0") @@ -456,7 +455,7 @@ fn main() -> Result<(), ReplError> { if let Some(file_path) = args.get_one::("file") { let table_name = Path::new(&file_path).file_name().unwrap().to_str().unwrap(); if args.get_flag("delete") { - if state.symbol_tables.remove(table_name).is_some() { + if state.symbol_tables.shift_remove(table_name).is_some() { Ok(None) } else { Ok(Some("No such symbol table".to_string())) @@ -478,11 +477,11 @@ fn main() -> Result<(), ReplError> { .iter() .cloned() .filter(|sym| symbols.contains_key(sym)) - .collect::>(), + .collect::>(), table.active, ) } else { - (LinkedHashSet::new(), true) + (IndexSet::new(), true) }; if !args.get_flag("append") { state.symbol_tables.clear(); @@ -555,8 +554,10 @@ fn main() -> Result<(), ReplError> { .get_mut(&table) .unwrap() .breakpoints - .remove(&symbol), - Location::Address(address) => state.address_breakpoints.remove(&address), + .shift_remove(&symbol), + Location::Address(address) => { + state.address_breakpoints.shift_remove(&address) + } }; if deleted { Ok(None) @@ -570,10 +571,8 @@ fn main() -> Result<(), ReplError> { .get_mut(&table) .unwrap() .breakpoints - .insert_if_absent(symbol), - Location::Address(address) => { - state.address_breakpoints.insert_if_absent(address) - } + .insert(symbol), + Location::Address(address) => state.address_breakpoints.insert(address), }; Ok(None) } @@ -685,7 +684,7 @@ fn parse_location(location: &str, symbol_tables: &SymbolTables) -> Result, + address_breakpoints: &IndexSet, ) -> bool { address_breakpoints.contains(&addr) || symbol_tables.values().any(|table| {