Skip to content

Commit

Permalink
Better error case for multiple net drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Aug 3, 2019
1 parent 4e9f2d0 commit c267738
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
return bit == '0' || bit == '1' || bit == 'x';
}
const nets = new HashMap();
const netnames = new HashMap();
const bits = new Map();
const devnets = new Map();
let n = 0, pn = 0;
Expand All @@ -141,12 +142,15 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
function get_net(k) {
// create net if does not exist yet
if (!nets.has(k))
nets.set(k, {source: undefined, targets: [], name: undefined});
nets.set(k, {source: undefined, targets: [], name: netnames.get(k)});
return nets.get(k);
}
function add_net_source(k, d, p, primary) {
const net = get_net(k);
assert(net.source === undefined);
if(net.source !== undefined) {
// multiple sources driving one net, disallowed in digitaljs
throw Error('Multiple sources driving net: ' + net.name);
}
net.source = { id: d, port: p };
if (primary) for (const [nbit, bit] of k.entries()) {
bits.set(bit, { id: d, port: p, num: nbit });
Expand Down Expand Up @@ -227,6 +231,11 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
dname, portname + "en");
}
}
// Find net names
for (const [nname, data] of Object.entries(mod.netnames)) {
if (data.hide_name) continue;
netnames.set(data.bits, nname);
}
// Add inputs/outputs
for (const [pname, port] of Object.entries(mod.ports)) {
const dname = add_device({
Expand Down Expand Up @@ -587,13 +596,6 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
add_net_source(nbits, dname, 'out');
add_net_target(cconn, dname, 'in');
}
// Label nets
for (const [nname, data] of Object.entries(mod.netnames)) {
if (data.hide_name) continue;
const net = nets.get(data.bits);
if (!net) continue;
net.name = nname;
}
// Make some simplifications in the graph
// TODO multiple passes, less ad-hoc
for (const [nbits, net] of nets.entries()) {
Expand Down

0 comments on commit c267738

Please sign in to comment.