Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "topstitch"
version = "0.93.0"
version = "0.94.0"
edition = "2024"
license = "Apache-2.0"
description = "Stitch together Verilog modules with Rust"
Expand All @@ -20,6 +20,7 @@ fixedbitset = "0.5.7"
paste = "1.0.15"
geo = "0.31.0"
rstar = "0.12.2"
parking_lot = "0.12"

[dev-dependencies]
cargo_metadata = "0.18"
Expand Down
24 changes: 12 additions & 12 deletions src/connection/port_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl PortSliceConnection {
None => return result,
};
for next in &port_connections
.borrow()
.read()
.slice(port_slice.msb, port_slice.lsb)
{
if let ConnectedItem::PortSlice(next_other) = &next.other
Expand Down Expand Up @@ -259,7 +259,7 @@ mod tests {
a.slice(3, 0).connect(&b.slice(7, 4));
a.slice(11, 8).connect(&b.slice(3, 0));

let mut overlaps = a.get_port_connections().unwrap().borrow().slice(5, 2);
let mut overlaps = a.get_port_connections().unwrap().read().slice(5, 2);
sort_for_test(&mut overlaps);

assert_eq!(overlaps.len(), 2);
Expand All @@ -268,10 +268,10 @@ mod tests {
assert_eq!(overlaps[1].this, a.slice(5, 4));
assert_eq!(overlaps[1].other, b.slice(13, 12));

let empty = a.get_port_connections().unwrap().borrow().slice(13, 12);
let empty = a.get_port_connections().unwrap().read().slice(13, 12);
assert_eq!(empty.len(), 0);

let edge = a.get_port_connections().unwrap().borrow().slice(8, 8);
let edge = a.get_port_connections().unwrap().read().slice(8, 8);
assert_eq!(edge.len(), 1);
assert_eq!(edge[0].this, a.bit(8));
assert_eq!(edge[0].other, b.bit(0));
Expand All @@ -294,7 +294,7 @@ mod tests {
.get_port("x")
.get_port_connections()
.unwrap()
.borrow()
.read()
.slice(5, 2)
.trace();
sort_for_test(&mut traced);
Expand Down Expand Up @@ -337,7 +337,7 @@ mod tests {
.get_port("i")
.get_port_connections()
.unwrap()
.borrow()
.read()
.slice(3, 2)
.trace();
sort_for_test(&mut traced);
Expand All @@ -360,7 +360,7 @@ mod tests {
let p = m.add_port("p", IO::Input(8));
p.tieoff(0xaau32);

let overlaps = p.get_port_connections().unwrap().borrow().slice(6, 1);
let overlaps = p.get_port_connections().unwrap().read().slice(6, 1);
assert_eq!(overlaps.len(), 1);
assert_eq!(overlaps[0].this, p.slice(6, 1));
assert_eq!(
Expand All @@ -378,7 +378,7 @@ mod tests {
let segments = q
.get_port_connections()
.unwrap()
.borrow()
.read()
.make_non_overlapping();
// resolve should panic for Output with Unused
let _ = segments[0].to_expression_source();
Expand All @@ -397,7 +397,7 @@ mod tests {
.get_port("i")
.get_port_connections()
.unwrap()
.borrow()
.read()
.make_non_overlapping();
assert_eq!(segments.len(), 1);
assert_eq!(segments[0][0].this, ai.get_port("i").slice(1, 0));
Expand All @@ -415,7 +415,7 @@ mod tests {
let segments = y
.get_port_connections()
.unwrap()
.borrow()
.read()
.make_non_overlapping();
assert_eq!(segments.len(), 1);
assert_eq!(segments[0][0].this, y.slice(1, 0));
Expand All @@ -441,7 +441,7 @@ mod tests {
.get_port("b_io")
.get_port_connections()
.unwrap()
.borrow()
.read()
.trace()
.make_non_overlapping();
assert_eq!(segments.len(), 1);
Expand Down Expand Up @@ -548,7 +548,7 @@ mod tests {
let mut non_overlapping = port
.get_port_connections()
.unwrap()
.borrow()
.read()
.trace()
.make_non_overlapping();
assert_eq!(non_overlapping.len(), segments.len());
Expand Down
32 changes: 16 additions & 16 deletions src/intf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::cell::RefCell;
use std::rc::{Rc, Weak};
use parking_lot::RwLock;
use std::sync::{Arc, Weak};

use indexmap::IndexMap;

Expand All @@ -25,7 +25,7 @@ mod width;
pub enum Intf {
ModDef {
name: String,
mod_def_core: Weak<RefCell<ModDefCore>>,
mod_def_core: Weak<RwLock<ModDefCore>>,
},
ModInst {
intf_name: String,
Expand All @@ -42,7 +42,7 @@ impl Intf {
}
}

pub(crate) fn get_mod_def_core(&self) -> Rc<RefCell<ModDefCore>> {
pub(crate) fn get_mod_def_core(&self) -> Arc<RwLock<ModDefCore>> {
match self {
Intf::ModDef { mod_def_core, .. } => mod_def_core.upgrade().unwrap(),
Intf::ModInst { hierarchy, .. } => hierarchy
Expand All @@ -60,7 +60,7 @@ impl Intf {
mod_def_core, name, ..
} => {
let core = mod_def_core.upgrade().unwrap();
let binding = core.borrow();
let binding = core.read();
let mod_def = ModDef { core: core.clone() };
let mapping = binding.interfaces.get(name).unwrap();
mapping
Expand All @@ -82,7 +82,7 @@ impl Intf {
hierarchy: hierarchy.clone(),
};
let inst_core = inst.mod_def_core_of_instance();
let inst_binding = inst_core.borrow();
let inst_binding = inst_core.read();
let inst_mapping = inst_binding.interfaces.get(intf_name).unwrap();
inst_mapping
.iter()
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Intf {
mod_def_core, name, ..
} => {
let core = mod_def_core.upgrade().unwrap();
let binding = core.borrow();
let binding = core.read();
let mod_def = ModDef { core: core.clone() };
let mapping = binding.interfaces.get(name)?;
mapping
Expand All @@ -127,7 +127,7 @@ impl Intf {
hierarchy: hierarchy.clone(),
};
let inst_core = inst.mod_def_core_of_instance();
let inst_binding = inst_core.borrow();
let inst_binding = inst_core.read();
let inst_mapping = inst_binding.interfaces.get(intf_name)?;
inst_mapping
.get(func_name)
Expand All @@ -146,7 +146,7 @@ impl Intf {
let core = mod_def_core.upgrade().unwrap();
let mod_def = ModDef { core: core.clone() };
let removed = {
let mut binding = core.borrow_mut();
let mut binding = core.write();
let mapping = binding.interfaces.get_mut(name)?;
mapping.shift_remove(func_name)
};
Expand All @@ -162,7 +162,7 @@ impl Intf {
};
let inst_core = inst.mod_def_core_of_instance();
let removed = {
let mut inst_binding = inst_core.borrow_mut();
let mut inst_binding = inst_core.write();
let inst_mapping = inst_binding.interfaces.get_mut(intf_name)?;
inst_mapping.shift_remove(func_name)
};
Expand Down Expand Up @@ -203,7 +203,7 @@ impl Intf {
match self {
Intf::ModDef { .. } => {
let core_rc = self.get_mod_def_core();
let mut core = core_rc.borrow_mut();
let mut core = core_rc.write();
core.mod_def_intf_metadata
.entry(self.get_intf_name())
.or_default()
Expand All @@ -216,7 +216,7 @@ impl Intf {
.inst_name
.to_string();
let core_rc = self.get_mod_def_core();
let mut core = core_rc.borrow_mut();
let mut core = core_rc.write();
core.mod_inst_intf_metadata
.entry(inst_name)
.or_default()
Expand All @@ -232,7 +232,7 @@ impl Intf {
match self {
Intf::ModDef { .. } => {
let core_rc = self.get_mod_def_core();
let core = core_rc.borrow();
let core = core_rc.read();
core.mod_def_intf_metadata
.get(&self.get_intf_name())
.and_then(|metadata| metadata.get(key.as_ref()).cloned())
Expand All @@ -244,7 +244,7 @@ impl Intf {
.inst_name
.as_str();
let core_rc = self.get_mod_def_core();
let core = core_rc.borrow();
let core = core_rc.read();
core.mod_inst_intf_metadata
.get(inst_name)
.and_then(|intfs| intfs.get(&self.get_intf_name()))
Expand All @@ -257,7 +257,7 @@ impl Intf {
match self {
Intf::ModDef { .. } => {
let core_rc = self.get_mod_def_core();
let mut core = core_rc.borrow_mut();
let mut core = core_rc.write();
if let Some(metadata) = core.mod_def_intf_metadata.get_mut(&self.get_intf_name()) {
metadata.remove(key.as_ref());
if metadata.is_empty() {
Expand All @@ -272,7 +272,7 @@ impl Intf {
.inst_name
.as_str();
let core_rc = self.get_mod_def_core();
let mut core = core_rc.borrow_mut();
let mut core = core_rc.write();
if let Some(intfs) = core.mod_inst_intf_metadata.get_mut(inst_name) {
let intf_name = self.get_intf_name();
if let Some(metadata) = intfs.get_mut(&intf_name) {
Expand Down
6 changes: 3 additions & 3 deletions src/intf/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::Intf;
impl std::fmt::Debug for Intf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mod_def_core = self.get_mod_def_core();
let core = mod_def_core.borrow();
let core = mod_def_core.read();
match self {
Intf::ModDef { name, .. } => {
writeln!(f, "Interface Mapping:")?;
Expand All @@ -27,7 +27,7 @@ impl std::fmt::Debug for Intf {
.inst_name
.as_str();
let inst_core = core.instances.get(inst_name).unwrap();
let inst_binding = inst_core.borrow();
let inst_binding = inst_core.read();
writeln!(f, "Interface Mapping:")?;
for (func_name, (port_name, msb, lsb)) in
inst_binding.interfaces.get(intf_name).unwrap()
Expand All @@ -48,7 +48,7 @@ impl Intf {
pub(crate) fn debug_string(&self) -> String {
match self {
Intf::ModDef { name, .. } => {
format!("{}.{}", self.get_mod_def_core().borrow().name, name)
format!("{}.{}", self.get_mod_def_core().read().name, name)
}
Intf::ModInst {
intf_name,
Expand Down
Loading