@@ -127,6 +127,7 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
127
127
return bit == '0' || bit == '1' || bit == 'x' ;
128
128
}
129
129
const nets = new HashMap ( ) ;
130
+ const netnames = new HashMap ( ) ;
130
131
const bits = new Map ( ) ;
131
132
const devnets = new Map ( ) ;
132
133
let n = 0 , pn = 0 ;
@@ -141,12 +142,15 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
141
142
function get_net ( k ) {
142
143
// create net if does not exist yet
143
144
if ( ! nets . has ( k ) )
144
- nets . set ( k , { source : undefined , targets : [ ] , name : undefined } ) ;
145
+ nets . set ( k , { source : undefined , targets : [ ] , name : netnames . get ( k ) } ) ;
145
146
return nets . get ( k ) ;
146
147
}
147
148
function add_net_source ( k , d , p , primary ) {
148
149
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
+ }
150
154
net . source = { id : d , port : p } ;
151
155
if ( primary ) for ( const [ nbit , bit ] of k . entries ( ) ) {
152
156
bits . set ( bit , { id : d , port : p , num : nbit } ) ;
@@ -227,6 +231,11 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
227
231
dname , portname + "en" ) ;
228
232
}
229
233
}
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
+ }
230
239
// Add inputs/outputs
231
240
for ( const [ pname , port ] of Object . entries ( mod . ports ) ) {
232
241
const dname = add_device ( {
@@ -587,13 +596,6 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
587
596
add_net_source ( nbits , dname , 'out' ) ;
588
597
add_net_target ( cconn , dname , 'in' ) ;
589
598
}
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
- }
597
599
// Make some simplifications in the graph
598
600
// TODO multiple passes, less ad-hoc
599
601
for ( const [ nbits , net ] of nets . entries ( ) ) {
0 commit comments