Skip to content

Commit fa896aa

Browse files
authored
one more DFS fix (#53)
1 parent 60f62db commit fa896aa

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "safety-net"
3-
version = "0.2.8"
3+
version = "0.2.9"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66

src/netlist.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,8 @@ pub mod iter {
19081908
self.stack
19091909
.push(NetRef::wrap(self.netlist.index_weak(&operand.root())));
19101910
}
1911+
} else {
1912+
self.cycles = true;
19111913
}
19121914

19131915
return if self.stack.contains(&item) {

tests/analysis.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ fn and_gate() -> Gate {
1313
Gate::new_logical("AND".into(), vec!["A".into(), "B".into()], "Y".into())
1414
}
1515

16+
fn reg() -> Gate {
17+
Gate::new_logical("REG".into(), vec!["D".into()], "Q".into())
18+
}
19+
1620
fn get_simple_example() -> Rc<GateNetlist> {
1721
let netlist = Netlist::new("example".to_string());
1822

@@ -28,6 +32,28 @@ fn get_simple_example() -> Rc<GateNetlist> {
2832
netlist
2933
}
3034

35+
fn divider_netlist() -> Rc<GateNetlist> {
36+
let netlist = Netlist::new("example".to_string());
37+
38+
// Add the the input
39+
let a = netlist.insert_input("a".into());
40+
41+
// Instantiate a reg
42+
let reg = netlist.insert_gate_disconnected(reg(), "inst_0".into());
43+
44+
// And last val and input
45+
let and = netlist
46+
.insert_gate(and_gate(), "inst_1".into(), &[a, reg.get_output(0)])
47+
.unwrap();
48+
49+
reg.find_input(&"D".into()).unwrap().connect(and.into());
50+
51+
// Make this Reg an output
52+
reg.expose_with_name("y".into());
53+
54+
netlist
55+
}
56+
3157
#[test]
3258
fn test_detect_cycles() {
3359
let netlist = get_simple_example();
@@ -54,6 +80,14 @@ fn test_detect_cycles() {
5480
assert!(dfs_iter.detect_cycles());
5581
}
5682

83+
#[test]
84+
fn test_detect_cycles2() {
85+
let netlist = divider_netlist();
86+
87+
let dfs_iter = DFSIterator::new(&netlist, netlist.last().unwrap());
88+
assert!(dfs_iter.detect_cycles());
89+
}
90+
5791
#[test]
5892
fn test_attr_filter() {
5993
let netlist = GateNetlist::new("example".to_string());

0 commit comments

Comments
 (0)