Skip to content

Commit 191bff6

Browse files
Modified the schematic-to-layout script to be better at being
used in a re-entrant manner. Applied to an existing layout, it will no longer keep generating new instances and ports over top existing ones. Could use improvement by attempting to retain the location of a device when the instance changes device type (such as when a device parameter was changed in the netlist). However, the current set of changes should help, whether the re-entrant use is purposeful or accidental.
1 parent 3691b53 commit 191bff6

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.3.462
1+
8.3.463

tcltk/toolkit.tcl

+76-9
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,46 @@ proc magic::generate_layout_add {subname subpins complist library} {
195195

196196
box 0 0 0 0
197197

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+
199204
if {[llength $subpins] > 0} {
200205
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 []
202213
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 {
203228
# Escape [ and ] in pin name
204229
set pin_esc [string map {\[ \\\[ \] \\\]} $pin]
205230
magic::create_new_pin $pin_esc $i
206231
incr i
207232
}
233+
foreach pin $rmpins {
234+
set llayer [goto $pin]
235+
select area $llayer
236+
erase label
237+
}
208238
}
209239

210240
# Set initial position for importing cells
@@ -213,6 +243,24 @@ proc magic::generate_layout_add {subname subpins complist library} {
213243
set posy [expr {round(3 / [cif scale out])}]
214244
box position ${posx}i ${posy}i
215245

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+
216264
# Seed layout with components
217265
foreach comp $complist {
218266
set pinlist {}
@@ -297,12 +345,30 @@ proc magic::generate_layout_add {subname subpins complist library} {
297345
lappend outparts [lindex $param 1]
298346
}
299347

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+
}
306372
}
307373
}
308374
save $subname
@@ -393,7 +459,8 @@ proc magic::netlist_to_layout {netfile library} {
393459
set curtop [cellname list self]
394460

395461
foreach subckt $allsubs {
396-
puts stdout "Test: pre-generating subcircuit $subckt"
462+
# Diagnostic output
463+
puts stdout "Pre-generating subcircuit $subckt placeholder"
397464
load $subckt -silent
398465
}
399466
load $curtop

0 commit comments

Comments
 (0)