Open zhuguiyuan opened 4 months ago
Thanks for posting this. This definitely needs to be fixed.
A quick fix for now should could be to uniquify the netlist before flattening.
from spydrnet.uniquify import uniquify
uniquify(netlist)
flatten(netlist)
sdn.compose(netlist, "demo_flat_uniquify.v")
The result is
//Generated from netlist by SpyDrNet
//netlist name: netlist
module top
(
.O0({cable_in_top_0}),
.O1({cable_in_top_1}),
.I0({cable_in_top_2}),
.I1({cable_in_top_3})
);
output cable_in_top_0;
output cable_in_top_1;
input cable_in_top_2;
input cable_in_top_3;
wire foo1/cable_in_Foo_1;
wire foo1/cable_in_Foo_0;
wire foo0/cable_in_Foo_1;
wire foo0/cable_in_Foo_0;
wire cable_in_top_3;
wire cable_in_top_2;
wire cable_in_top_1;
wire cable_in_top_0;
INV foo0/inv
(
.O(cable_in_top_0),
.I(cable_in_top_2)
);
INV foo1/inv
(
.O(cable_in_top_1),
.I(cable_in_top_3)
);
endmodule
Looking at it a little closer, it seems that you must run uniquify before flattening. So I don't think this is a bug. The documentation should be improved to indicate the uniquify requirement.
Here is the hierarchy structure of instances, and in the parentheses is the corresponding definition.
top |- inst0 (Foo) `- inst1 (Foo)
Foo `- inv (INV)
The flatten function cannot handle this case, because it remove cables and pins in Foo when meet top/inst0. Then when meet inst1, it cannot reconnect the wires again for top/inst1
Here is an example.
Generate EDIF:
EDIF:
Flatten Netlist: