From d532169d7c9acc0c9676411f4365b1af1a9ec53b Mon Sep 17 00:00:00 2001 From: D4VID Date: Tue, 19 Aug 2025 11:58:11 +0200 Subject: [PATCH] Use owned strings --- logicworld-subassembly | 2 +- verilog2logicworld/src/main.rs | 4 ++-- verilog2logicworld/src/verilog.rs | 23 +++++++++-------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/logicworld-subassembly b/logicworld-subassembly index 9801e5d..5c4ba46 160000 --- a/logicworld-subassembly +++ b/logicworld-subassembly @@ -1 +1 @@ -Subproject commit 9801e5d6c87db31a616de50195110266ed00c15c +Subproject commit 5c4ba463240312b81d43ed3e284aabf560d38520 diff --git a/verilog2logicworld/src/main.rs b/verilog2logicworld/src/main.rs index d56fe5b..0396139 100644 --- a/verilog2logicworld/src/main.rs +++ b/verilog2logicworld/src/main.rs @@ -94,6 +94,6 @@ fn main() { println!("{}: {:?}", module, result); } - let result = write_subassembly(); - println!("{:?}", result); + // let result = write_subassembly(); + // println!("{:?}", result); } diff --git a/verilog2logicworld/src/verilog.rs b/verilog2logicworld/src/verilog.rs index 4f899af..e3f0017 100644 --- a/verilog2logicworld/src/verilog.rs +++ b/verilog2logicworld/src/verilog.rs @@ -33,10 +33,10 @@ pub struct Module { } #[derive(Debug)] -pub struct Cell<'a> { +pub struct Cell { pub cell_type: String, - pub parameters: HashMap<&'a str, usize>, - pub connections: HashMap<&'a str, Vec>, + pub parameters: HashMap, + pub connections: HashMap>, } impl From for Error { @@ -55,7 +55,7 @@ pub fn get_modules(files: &[&str]) -> Result, Error> { return Ok(module_names); } -pub fn compile_module(module_name: &str, files: &[&str]) -> Result<(), Error> { +pub fn compile_module(module_name: &str, files: &[&str]) -> Result, Error> { let json = run_yosys("proc; flatten; wreduce; opt; fsm; opt; memory -nomap -nordff; opt; muxpack; peepopt; async2sync; wreduce; opt -mux_bool", Some(module_name), files)?; let compiled_module = &json["modules"][module_name]; let ports_json = &compiled_module["ports"]; @@ -85,28 +85,23 @@ pub fn compile_module(module_name: &str, files: &[&str]) -> Result<(), Error> { let cells = &compiled_module["cells"]; - for (_, cell) in cells.entries() { - let cell = resolve_cell(cell)?; - println!("{:?}", cell); - } - - return Ok(()); + return cells.entries().map(|(_, cell)| resolve_cell(cell)).collect::>(); } pub fn resolve_cell(cell: &JsonValue) -> Result { let json_parameters = &cell["parameters"]; - let mut parameters: HashMap<&str, usize> = HashMap::new(); + let mut parameters: HashMap = HashMap::new(); for (key, value) in json_parameters.entries() { parameters.insert( - key, + key.to_owned(), usize::from_str_radix(value.as_str().ok_or(Error::BadJson)?, 2) .map_err(|_| Error::BadJson)?, ); } let json_connections = &cell["connections"]; - let mut connections: HashMap<&str, Vec> = HashMap::new(); + let mut connections: HashMap> = HashMap::new(); for (key, bits) in json_connections.entries() { let JsonValue::Array(arr) = bits else { @@ -116,7 +111,7 @@ pub fn resolve_cell(cell: &JsonValue) -> Result { .iter() .map(|x| x.as_usize().ok_or(Error::BadJson)) .collect::>()?; - connections.insert(key, connection_bits); + connections.insert(key.to_owned(), connection_bits); } let cell_type = cell["type"].as_str().ok_or(Error::BadJson)?.to_owned();