@@ -195,16 +195,46 @@ proc magic::generate_layout_add {subname subpins complist library} {
195
195
196
196
box 0 0 0 0
197
197
198
- # Generate pins
198
+ # Generate pins. This routine can be made re-entrant; if a
199
+ # cell exists, then its contents are compared to the incoming
200
+ # netlist contents. Pins that exist in the netlist but not
201
+ # the layout are added. Pins that exist in the layout but not
202
+ # in the netlist are removed.
203
+
199
204
if {[llength $subpins ] > 0} {
200
205
set pinlist [split $subpins ]
201
- set i 0
206
+
207
+ # Determine if this cell already has pins.
208
+ set existpins []
209
+ for {set i [port first]} {$i > -1} {set i [port $i next]} {
210
+ lappend existpins [port $i name]
211
+ }
212
+ set addpins []
202
213
foreach pin $pinlist {
214
+ if {[lsearch $existpins $pin ] == -1} {
215
+ lappend addpins $pin
216
+ }
217
+ }
218
+
219
+ set rmpins []
220
+ foreach pin $existpins {
221
+ if {[lsearch $pinlist $pin ] == -1} {
222
+ lappend rmpins $pin
223
+ }
224
+ }
225
+
226
+ set i 0
227
+ foreach pin $addpins {
203
228
# Escape [ and ] in pin name
204
229
set pin_esc [string map {\[ \\\[ \] \\\] } $pin ]
205
230
magic::create_new_pin $pin_esc $i
206
231
incr i
207
232
}
233
+ foreach pin $rmpins {
234
+ set llayer [goto $pin ]
235
+ select area $llayer
236
+ erase label
237
+ }
208
238
}
209
239
210
240
# Set initial position for importing cells
@@ -213,6 +243,24 @@ proc magic::generate_layout_add {subname subpins complist library} {
213
243
set posy [expr {round(3 / [cif scale out])}]
214
244
box position ${posx} i ${posy} i
215
245
246
+ # Find all instances in the circuit
247
+ select top cell
248
+ set compexist [instance list children]
249
+ set compcells []
250
+ # Find the matching cell defs
251
+ foreach comp $compexist {
252
+ lappend compcells [instance list celldef $comp ]
253
+ }
254
+
255
+ # Diagnostic
256
+ puts stdout " Cells already in the layout of ${subname} :"
257
+ for {set i 0} {$i < [llength $compexist ]} {incr i} {
258
+ set comp [lindex $compexist $i ]
259
+ set ccell [lindex $compcells $i ]
260
+ puts stdout " ${comp} (${ccell} )"
261
+ }
262
+ flush stdout
263
+
216
264
# Seed layout with components
217
265
foreach comp $complist {
218
266
set pinlist {}
@@ -297,12 +345,30 @@ proc magic::generate_layout_add {subname subpins complist library} {
297
345
lappend outparts [lindex $param 1]
298
346
}
299
347
300
- if {[catch {eval [join $outparts ]}]} {
301
- # Assume this is not a gencell, and get an instance.
302
- magic::get_and_move_inst $devtype $instname $mult
303
- } else {
304
- # Move forward for next gencell
305
- magic::move_forward_by_width $instname
348
+ set inst_exists false
349
+ set existidx [lsearch $compexist $instname ]
350
+ if {$existidx > -1} {
351
+ set existcell [lindex $compcells $existidx ]
352
+ if {$devtype == $existcell } {
353
+ set inst_exists true
354
+ } else {
355
+ # Instance name exists but is the wrong device type.
356
+ # To do: Attempt to maintain the same position
357
+ pushbox
358
+ select cell $instname
359
+ delete
360
+ popbox
361
+ }
362
+ }
363
+
364
+ if {$inst_exists == false} {
365
+ if {[catch {eval [join $outparts ]}]} {
366
+ # Assume this is not a gencell, and get an instance.
367
+ magic::get_and_move_inst $devtype $instname $mult
368
+ } else {
369
+ # Move forward for next gencell
370
+ magic::move_forward_by_width $instname
371
+ }
306
372
}
307
373
}
308
374
save $subname
@@ -393,7 +459,8 @@ proc magic::netlist_to_layout {netfile library} {
393
459
set curtop [cellname list self]
394
460
395
461
foreach subckt $allsubs {
396
- puts stdout " Test: pre-generating subcircuit $subckt "
462
+ # Diagnostic output
463
+ puts stdout " Pre-generating subcircuit $subckt placeholder"
397
464
load $subckt -silent
398
465
}
399
466
load $curtop
0 commit comments