Skip to content

Commit c267738

Browse files
committed
Better error case for multiple net drivers.
1 parent 4e9f2d0 commit c267738

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
127127
return bit == '0' || bit == '1' || bit == 'x';
128128
}
129129
const nets = new HashMap();
130+
const netnames = new HashMap();
130131
const bits = new Map();
131132
const devnets = new Map();
132133
let n = 0, pn = 0;
@@ -141,12 +142,15 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
141142
function get_net(k) {
142143
// create net if does not exist yet
143144
if (!nets.has(k))
144-
nets.set(k, {source: undefined, targets: [], name: undefined});
145+
nets.set(k, {source: undefined, targets: [], name: netnames.get(k)});
145146
return nets.get(k);
146147
}
147148
function add_net_source(k, d, p, primary) {
148149
const net = get_net(k);
149-
assert(net.source === undefined);
150+
if(net.source !== undefined) {
151+
// multiple sources driving one net, disallowed in digitaljs
152+
throw Error('Multiple sources driving net: ' + net.name);
153+
}
150154
net.source = { id: d, port: p };
151155
if (primary) for (const [nbit, bit] of k.entries()) {
152156
bits.set(bit, { id: d, port: p, num: nbit });
@@ -227,6 +231,11 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
227231
dname, portname + "en");
228232
}
229233
}
234+
// Find net names
235+
for (const [nname, data] of Object.entries(mod.netnames)) {
236+
if (data.hide_name) continue;
237+
netnames.set(data.bits, nname);
238+
}
230239
// Add inputs/outputs
231240
for (const [pname, port] of Object.entries(mod.ports)) {
232241
const dname = add_device({
@@ -587,13 +596,6 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
587596
add_net_source(nbits, dname, 'out');
588597
add_net_target(cconn, dname, 'in');
589598
}
590-
// Label nets
591-
for (const [nname, data] of Object.entries(mod.netnames)) {
592-
if (data.hide_name) continue;
593-
const net = nets.get(data.bits);
594-
if (!net) continue;
595-
net.name = nname;
596-
}
597599
// Make some simplifications in the graph
598600
// TODO multiple passes, less ad-hoc
599601
for (const [nbits, net] of nets.entries()) {

0 commit comments

Comments
 (0)