mkk | 91ada92 | 2020-12-02 09:08:26 -0800 | [diff] [blame] | 1 | #!/bin/sh |
agorararmard | 5d91acf | 2020-12-10 18:57:03 +0200 | [diff] [blame] | 2 | # SPDX-FileCopyrightText: 2014, 2015, 2020 Efabless Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | # SPDX-License-Identifier: Apache-2.0 |
mkk | 91ada92 | 2020-12-02 09:08:26 -0800 | [diff] [blame] | 17 | # Copyright (C) 2014, 2015, 2020 efabless Corporation. All Rights Reserved. |
| 18 | # send a very-first -T FILE to magic's startup, hide all other args from magic-startup |
| 19 | # for-bash\ |
| 20 | export _M0= ;\ |
| 21 | for i in "$@" ; do _M0="$_M0${_M0:+ }\"${i//\"/\\\"}\""; done ;\ |
| 22 | case "$1" in -T) tch="$2"; shift; shift; _MARGS="$*" exec magic -dnull -noconsole -T "$tch" <"$0" ;; esac |
| 23 | # hide next line from magic(tclsh):\ |
| 24 | _MARGS="$*" exec magic -dnull -noconsole <"$0" |
| 25 | # |
| 26 | # magicDRC: run magic-DRC in batch on a GDS file, tabulate/pareto the error counts. |
| 27 | # |
| 28 | # rb@ef 2014-08-28 author |
| 29 | # rb 2020-02-19 embed some library functions, to standalone from efabless-opengalaxy env, test via magic-8.2.188 |
| 30 | # |
| 31 | # todo: support "-" as GDS file arg, to mean GDS from stdin |
| 32 | # |
| 33 | |
| 34 | set ::Prog "magicGdrc" |
| 35 | set argv [eval "list $env(_M0)"] ;# orig. mix of native plus custom args, for logging all args to script |
| 36 | # set argv [split $env(_MARGS)] ;# (currently unused) |
| 37 | |
| 38 | proc usage {args} { |
| 39 | if {[llength $args] > 0} { |
| 40 | puts "ERROR: ${::Prog}: [join $args]" |
| 41 | } |
| 42 | puts {usage: [ -T techfilePath ] [-S <drcStyleName>] [-I <cifIStyleName>] [-km FILE_NAME] [-l FILE_NAME] [-L FILE_NAME] gdsFileName [topCellName]} |
| 43 | puts " -T if given, must be very first" |
| 44 | puts " -S if given, changes from techfile's default/1st drc style (perhaps \"drc(fast)\") to named style, for example: -S \"drc(full)\"" |
| 45 | puts " -I if given, changes from techfile's default/1st cifinput style (perhaps \"vendorimport\" or \"import(exact)\") to named style, for example: -I \"import(magic)\"" |
| 46 | puts " -path-sub do 'gds path subcell yes' (default:no). Make unique subcell for each path: cut #tiles cost of angles." |
| 47 | puts " -poly-sub do 'gds polygon subcell yes' (default:no). Make unique subcell for each polygon: cut #tiles cost of angles." |
| 48 | # gds polygon subcell [yes|no] |
| 49 | puts " -pps Short hand, equivalent to giving both: -path-sub -poly-sub" |
| 50 | puts "" |
| 51 | puts " Error tabulation: By default (slowest, most detail): Report table of counts-by-errorString for all cells." |
| 52 | puts " Stdout logs a pareto of error-type by count unless disabled for some/all cells by below; topcell last." |
| 53 | puts " -tt Table of counts-by-errorString for ONLY topcell; and just lumped total error count per subcell." |
| 54 | puts " -tc Just lumped error counts per cell including topcell (fastest, least detail)." |
| 55 | puts " Cells NOT tabulating count-by-errorString can't appear in other output error files: feedback(*.drtcl), -l, -km." |
| 56 | puts " For lumped error counts, overlapped error shapes from unique error-types are merged further reducing count." |
| 57 | puts "" |
| 58 | puts " cell-type +-- (default) --+-- option -tt --+-- option -tc" |
| 59 | puts " subcell | count-by-errorString | lumped-error-count | lumped-error-count" |
| 60 | puts " topcell | count-by-errorString | count-by-errorString | lumped-error-count" |
| 61 | puts "" |
| 62 | puts " -km if given, write to FILE_NAME EVERY individual error bbox (MICRONS) in klayout Marker database(XML) format (suggest *.lyrdb)" |
| 63 | puts " -l if given, enumerates EVERY individual error bbox (MICRONS) to FILE_NAME, emulates $::CAD_ROOT/magic/tcl/drc.tcl" |
| 64 | puts " -L same as -l above, but outputs bbox-es in LAMBDA coordinates, not microns" |
| 65 | puts " -nf Do NOT write *.drtcl per-cell feedback files. Can be source-ed in magic and step thru: feedback find." |
| 66 | puts "" |
| 67 | puts " NOTES: Without explicit tech-file option: the ./.magicrc or ./magic_setup and ~/.magicrc may load a default tech-file." |
| 68 | puts " Therefore the tech-file used CAN depend on whether your CWD is ~/design/<CURRENT_DESIGN>/mag when running this script." |
| 69 | puts " Since no *.mag are loaded by this script: the cell search path defined by any init files has no impact." |
| 70 | puts " Since about 8.3.68, magic may generate error-type \"See error definition in the subcell\". There typically are" |
| 71 | puts " redundancies of errors across the hierarchy anyway (but with tech-file err-strings), this seems another form." |
| 72 | puts "" |
| 73 | puts "example, just list all styles: by causing an error which provokes usage report:" |
| 74 | puts " magicGdrc -T /ef/tech/XFAB/EFXH035B/libs.tech/magic/current/EFXH035B.tech" |
| 75 | puts "example, same but run in a ~/design/*/mag/ dir, so techfile set by ./.magicrc (else magic's builtin minimum.tech):" |
| 76 | puts " magicGdrc" |
| 77 | puts "example, run GDS drc, explicit: tech, cif-istyle, drc-style:" |
| 78 | puts " magicGdrc -T /ef/tech/SW/EFS8A/libs.tech/magic/current/EFS8A.tech -I vendorimport -S 'drc(full)' /tmp/mytop.gds mytopcell" |
| 79 | puts "example, run GDS drc, default tech & styles, write klayout marker database, no per-cell *.drtcl feedback files:" |
| 80 | puts " magicGdrc -km /tmp/mytop.lyrdb -nf /tmp/mytop.gds mytopcell" |
| 81 | puts "example, same but make subcells for paths & polygons" |
| 82 | puts " magicGdrc -km /tmp/mytop.lyrdb -nf -pps /tmp/mytop.gds mytopcell" |
| 83 | puts "example, run GDS drc, no feedback (*.drtcl), only lumped/merged err-count for all cells" |
| 84 | puts " magicGdrc -tc /tmp/mytop.gds mytopcell" |
| 85 | puts "example, run GDS drc, no feedback (*.drtcl), lumped/merged err-count for subcells, detail errors for topcell" |
| 86 | puts " magicGdrc -nf -tt /tmp/mytop.gds mytopcell" |
| 87 | puts "" |
| 88 | |
| 89 | reportTechFile |
| 90 | reportAllStyles |
| 91 | puts "" |
| 92 | |
| 93 | if {[llength $args] > 0} { |
| 94 | puts "ERROR: ${::Prog}: [join $args]" |
| 95 | } |
| 96 | } |
| 97 | proc gdsChk {file} { |
| 98 | foreach suffix {"" ".gds" ".gds2" ".strm"} { |
| 99 | if {[file readable "${file}${suffix}"]} {return 1} |
| 100 | } |
| 101 | puts "ERROR: ${::Prog}: Cannot open (as-is or with .gds, .gds2, or .strm) to read GDS-II stream from: $file" |
| 102 | exit 1 |
| 103 | } |
| 104 | |
| 105 | proc reportTechFile {} { |
| 106 | puts "${::Prog}: tech-name: [tech name] -version: [tech version] -filename: [tech filename] -lambda [tech lambda]" |
| 107 | } |
| 108 | |
| 109 | # query currently loaded tech-file for styles the user might need for -I -S options |
| 110 | # Suggest a bad tech-file if none are found or errors thrown. |
| 111 | # Used after finding error in -I -S options, and probably should add it to the usage. |
| 112 | proc reportAllStyles {} { |
| 113 | set errs {} |
| 114 | if {[catch {set allstyle [cif listall istyle]} msg]} { |
| 115 | lappend errs "ERROR: ${::Prog}: bad tech-file? failed to 'cif listall istyle', $msg" |
| 116 | } elseif {$allstyle == {}} { |
| 117 | lappend errs "ERROR: ${::Prog}: bad tech-file? no cifinput styles found by 'cif listall istyle'" |
| 118 | } else { |
| 119 | puts "info: ${::Prog}: cifinput styles available: $allstyle" |
| 120 | } |
| 121 | if {[catch {set allstyle [drc listall style]} msg]} { |
| 122 | lappend errs "ERROR: ${::Prog}: bad tech-file? failed to 'drc listall style', $msg" |
| 123 | } elseif {$allstyle == {}} { |
| 124 | lappend errs "ERROR: ${::Prog}: bad tech-file? no drc styles found by 'drc listall style'" |
| 125 | } else { |
| 126 | puts "info: ${::Prog}: drc styles available: $allstyle" |
| 127 | } |
| 128 | if {$errs != {}} { |
| 129 | |
| 130 | } |
| 131 | return [llength $errs] |
| 132 | } |
| 133 | |
| 134 | # optionally hardcode library proc-s (part of site-wide extensions - always available - in context of efabless/open-galaxy) |
| 135 | # This is to make the script more standalone from efabless environment; but these capabilities should be native to magic. |
| 136 | |
| 137 | if {[info command unbounds] == {}} { |
| 138 | puts "${::Prog}: hardcoding library proc-s..." |
| 139 | # Replacement for 'cellname list exists CELLNAME', to fix ambiguity for cell "0". |
| 140 | # For cell "0" test for membership in 'cellname list allcells'. |
| 141 | # |
| 142 | # Instead of returning 0 for (non-existent) and cellname for exists, |
| 143 | # returns regular 0/1 instead for non-existent/exists. |
| 144 | # |
| 145 | # Therefore NOT direct replacement for uses of 'cellname list exists CELL'. |
| 146 | # Requires code changes. |
| 147 | proc cellnameExists {cell} { |
| 148 | expr {$cell ne "0" && [cellname list exists $cell] eq $cell || |
| 149 | $cell eq "0" && [lsearch -exact [cellname list allcells] $cell] > -1} |
| 150 | } |
| 151 | |
| 152 | # Walk allcells to get/return list of cellNames that are unbound. |
| 153 | # Only use this after: 'select top cell; expand' to expand whole hierarchy. |
| 154 | # |
| 155 | # foreach CELL in 'cellname list allcells': |
| 156 | # if flags says available : it's Bound, goto next cell. |
| 157 | # if filepath is "default", try to expand the cell. |
| 158 | # if still "default"**: cell made by "cellname create", never saved, goto next. |
| 159 | # if filepath is CELL.mag, check for "available" flags, if none: Unbound. |
| 160 | # else cell is bound. |
| 161 | # **: should never get there |
| 162 | proc unbounds {} { |
| 163 | set allcells [cellname list allcells] |
| 164 | # filter (UNNAMED) |
| 165 | set allcells [lsearch -exact -not -all -inline $allcells "(UNNAMED)"] |
| 166 | # set nbrAllCells [llength $allcells] |
| 167 | set ercell {} |
| 168 | foreach cell $allcells { |
| 169 | # filter (without recording as skipped) non-existent cells. |
| 170 | if {![cellnameExists $cell]} { continue } |
| 171 | |
| 172 | # filepath = "default": unexpanded (not loaded from disk), |
| 173 | # or created in-mem and never saved (is writable already |
| 174 | # though flags won't say so): skip both. |
| 175 | # TODO: use a combo of filepath & flags likely can detect created in-mem |
| 176 | set tmppath [cellname list filepath $cell] |
| 177 | if {$tmppath eq "default"} { |
| 178 | lappend skipped $cell |
| 179 | continue |
| 180 | } |
| 181 | |
| 182 | # flags not meaningful, until expanded or expand attempted. |
| 183 | # After expand attempt (filepath != "default"), and flags |
| 184 | # can now be used to determine cell unbound: not available. |
| 185 | set flags [cellname list flags $cell] |
| 186 | if {[lsearch -exact $flags available] < 0} { |
| 187 | lappend ercell $cell |
| 188 | continue |
| 189 | } |
| 190 | } |
| 191 | set ercell ;# return list of unbound cells, if any |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | # without top-level proc around bulk of script, intermediate error statements don't abort script. |
| 196 | proc main {argv} { |
| 197 | |
| 198 | set mlen [llength $argv] |
| 199 | |
| 200 | # process name-value pair options, if any |
| 201 | set nbrErr 0 |
| 202 | set ndx 0 |
| 203 | set max [llength $argv] |
| 204 | set extTechOpt {} ;# -T ... but not used here |
| 205 | set enumFilel {} ;# -l ... enum output file |
| 206 | set enumFileL {} ;# -L ... enum output file |
| 207 | set enumFileKm {} ;# -km ... enum output file |
| 208 | set variant {} ;# -S ... non-default drc style |
| 209 | set istyle {} ;# -I ... non-default cifinput style |
| 210 | set doFeedback 1 ;# -nf sets to 0: Do not write *.drtcl per-cell feedback files. |
| 211 | set pathSub 0 ;# -path-sub ... do 'gds path subcell yes' |
| 212 | set polySub 0 ;# -poly-sub ... do 'gds polygon subcell yes' |
| 213 | set subcellTab 1 ;# -tt, -tc both turn OFF subcell count-by-error report |
| 214 | set topcellTab 1 ;# -tc turns OFF topcell count-by-error report |
| 215 | set flatten 0 |
| 216 | while {$ndx < $max && [string match "-*" [lindex $argv $ndx]]} { |
| 217 | set opt [lindex $argv $ndx] |
| 218 | incr ndx |
| 219 | switch -exact -- $opt { |
| 220 | -T { |
| 221 | if {$ndx != 1} { |
| 222 | usage "-T option must very 1st (here was #$ndx)" |
| 223 | exit 1 |
| 224 | } |
| 225 | if {$ndx == $max} { |
| 226 | usage "missing tech-file argument for -T option" |
| 227 | exit 1 |
| 228 | } |
| 229 | set extTechOpt [lindex $argv $ndx] ;# unused |
| 230 | incr ndx |
| 231 | } |
| 232 | -S { |
| 233 | if {$ndx == $max} { |
| 234 | usage "missing drcStyle argument for -S option" |
| 235 | exit 1 |
| 236 | } |
| 237 | set variant [lindex $argv $ndx] |
| 238 | incr ndx |
| 239 | } |
| 240 | -I { |
| 241 | if {$ndx == $max} { |
| 242 | usage "missing cifinput-style argument for -I option" |
| 243 | exit 1 |
| 244 | } |
| 245 | set istyle [lindex $argv $ndx] |
| 246 | incr ndx |
| 247 | } |
| 248 | -F { set flatten 1} |
| 249 | -nf { set doFeedback 0 } |
| 250 | -path-sub { set pathSub 1} |
| 251 | -poly-sub { set polySub 1} |
| 252 | -pps { set pathSub 1; set polySub 1} |
| 253 | -tt { set subcellTab 0 ; set topcellTab 1} |
| 254 | -tc { set subcellTab 0 ; set topcellTab 0 } |
| 255 | -km { |
| 256 | if {$ndx == $max} { |
| 257 | usage "missing outputFile argument for -km option" |
| 258 | exit 1 |
| 259 | } |
| 260 | set enumFileKm [lindex $argv $ndx] |
| 261 | incr ndx |
| 262 | } |
| 263 | -l { |
| 264 | if {$ndx == $max} { |
| 265 | usage "missing outputFile argument for -l option" |
| 266 | exit 1 |
| 267 | } |
| 268 | set enumFilel [lindex $argv $ndx] |
| 269 | incr ndx |
| 270 | if {[catch {set enumOut [open $enumFilel w]} msg]} { |
| 271 | error "ERROR: ${::Prog}: failed to open-for-write '$enumFilel' threw error, $msg" |
| 272 | } |
| 273 | puts "${::Prog}: enumerating each error bbox to: $enumFilel" |
| 274 | } |
| 275 | -L { |
| 276 | if {$ndx == $max} { |
| 277 | usage "missing outputFile argument for -L option" |
| 278 | exit 1 |
| 279 | } |
| 280 | set enumFileL [lindex $argv $ndx] |
| 281 | incr ndx |
| 282 | if {[catch {set enumOutL [open $enumFileL w]} msg]} { |
| 283 | error "ERROR: ${::Prog}: failed to open-for-write '$enumFileL' threw error, $msg" |
| 284 | } |
| 285 | puts "${::Prog}: enumerating each error bbox to: $enumFileL" |
| 286 | } |
| 287 | default { |
| 288 | usage "unknown option: $opt" |
| 289 | exit 1 |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if {$ndx == $max} { |
| 295 | usage {Insufficient number of arguments, need gdsFileName [topCellName]} |
| 296 | exit 1 |
| 297 | } |
| 298 | |
| 299 | set gdsf [lindex $argv $ndx] ; incr ndx |
| 300 | set topc {} |
| 301 | set topcStr "(AUTO)" |
| 302 | if {$ndx < $max} { |
| 303 | set topc [lindex $argv $ndx] ; incr ndx |
| 304 | set topcStr $topc |
| 305 | } |
| 306 | # error if extra options (not understood, something is wrong): |
| 307 | if {$ndx < $max} { |
| 308 | error "ERROR: ${::Prog}: after gdsFile=\"$gdsf\", topcell=\"$topc\" found unsupported extra arguments: [lrange $argv $ndx end]" |
| 309 | } |
| 310 | # ndx no longer used for argv position from here |
| 311 | |
| 312 | gdsChk $gdsf |
| 313 | |
| 314 | # warning on combo of -tc & -km. If -km ok, open its output file. |
| 315 | if {$enumFileKm ne {}} { |
| 316 | if {! $topcellTab} { |
| 317 | puts "WARNING: ${::Prog}: with -tc cannot (-km) write klayout-marker-db" |
| 318 | } else { |
| 319 | if {[catch {set enumOutKm [open $enumFileKm w]} msg]} { |
| 320 | error "ERROR: ${::Prog}: failed to open-for-write '$enumFileKm' threw error, $msg" |
| 321 | } |
| 322 | puts "${::Prog}: enumerating each error bbox to: $enumFileKm" |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | # write a line with timestamp and all arguments to stdout (log) |
| 327 | # (magic renames the TCL clock command) |
| 328 | set clockp clock |
| 329 | if {[info command $clockp] == {} && [info command orig_clock] != {}} { |
| 330 | set clockp orig_clock |
| 331 | } |
| 332 | set nowSec [$clockp seconds] |
| 333 | set timestamp [$clockp format $nowSec -format "%Y-%m-%d.%T.%Z"] |
| 334 | # TODO: quote logged argv here as needed so it's machine readable for replay purposes. |
| 335 | puts "${::Prog}: timestamp: $timestamp, arguments: $argv" |
| 336 | |
| 337 | # just Manhattan is default, turn on euclidean, and log new mode |
| 338 | drc euclidean on |
| 339 | drc euclidean |
| 340 | |
| 341 | # 8.1.83 this worked: |
| 342 | # drc off; gds drccheck no; gds read ... ; load topcell; select top cell; expand; drc check; drc update; drc listall count |
| 343 | # By 8.2.64, that fails, the 'drc listall count' reports errors only in the top-cell, no subcells. |
| 344 | # 8.1.83 & 8.2.193 this works (gds drccheck defaults to on anyway): |
| 345 | # drc off; gds drccheck yes; gds read ... ; load topcell; select top cell; expand; drc check; drc update; drc listall count |
| 346 | # |
| 347 | # But are we properly avoiding redundant drc runs? |
| 348 | # |
| 349 | # turn off background checker. We'll invoke checks explicitly. |
| 350 | drc off |
| 351 | gds drccheck yes |
| 352 | puts "drc status (whether background checking enabled) is: [drc status]" |
| 353 | puts "gds drccheck (whether gds-read marks new cells as need-drc) is: [gds drccheck]" |
| 354 | |
| 355 | # set user's drc style; set user's cifinput istyle |
| 356 | # These are back-to-back without intervening status messages. |
| 357 | # If both wrong their errors are back-to-back. |
| 358 | set res {} |
| 359 | set res [drc list style] |
| 360 | if {$variant != {}} { |
| 361 | set allstyle [drc listall style] |
| 362 | set ndx [lsearch -exact $allstyle $variant] |
| 363 | if {$ndx < 0} { |
| 364 | puts "ERROR: ${::Prog}: drc style '$variant' not one of those available: $allstyle" |
| 365 | incr nbrErr |
| 366 | } else { |
| 367 | set res [drc list style $variant] |
| 368 | } |
| 369 | } |
| 370 | set res2 [cif list istyle] |
| 371 | if {$istyle != {}} { |
| 372 | set allstyle [cif listall istyle] |
| 373 | set ndx [lsearch -exact $allstyle $istyle] |
| 374 | if {$ndx < 0} { |
| 375 | puts "ERROR: ${::Prog}: istyle '$istyle' not one of those available: $allstyle" |
| 376 | incr nbrErr |
| 377 | } else { |
| 378 | set res2 [cif istyle $istyle] |
| 379 | } |
| 380 | } |
| 381 | if {$res != {}} { |
| 382 | puts "drc style reports:\n$res" |
| 383 | } |
| 384 | if {$res2 != {}} { |
| 385 | puts "cif istyle reports:\n$res2" |
| 386 | } |
| 387 | |
| 388 | # gds {path,polygon} subcell yes |
| 389 | if {$pathSub != 0} { gds path subcells yes } |
| 390 | puts "gds path subcells: [gds path subcells]" |
| 391 | if {$polySub != 0} { gds polygon subcells yes } |
| 392 | puts "gds polygon subcells: [gds polygon subcells]" |
| 393 | |
| 394 | # todo: this catch never happens. Need nicer error check of 'gds read' somehow. Can check for zero-sized file? |
| 395 | # if use /dev/null for example, it prints its own error message, but no throw, no useful return value. |
| 396 | puts "doing: gds read $gdsf ..." |
| 397 | if {[catch {set res [gds read $gdsf]} msg]} { |
| 398 | puts "ERROR: ${::Prog}: 'gds read $gdsf' threw error, $msg" |
| 399 | incr nbrErr |
| 400 | } |
| 401 | # nothing useful: |
| 402 | # puts "gds-read res: $res" |
| 403 | |
| 404 | set topcells [cellname list top] |
| 405 | set allcells [cellname list allcells] |
| 406 | # puts "cellname-list-top from GDS is: $topcells" |
| 407 | # puts "cellname-list-allcells from GDS are: $allcells" |
| 408 | # filter (UNNAMED) |
| 409 | set topcells [lsearch -exact -not -all -inline $topcells "(UNNAMED)"] |
| 410 | set allcells [lsearch -exact -not -all -inline $allcells "(UNNAMED)"] |
| 411 | set nbrAllCells [llength $allcells] |
| 412 | |
| 413 | if {$topcells == {}} { |
| 414 | puts "ERROR: ${::Prog}: GDS-read did not report any useful cell name(s) found." |
| 415 | incr nbrErr |
| 416 | } |
| 417 | |
| 418 | if {$nbrErr > 0} { |
| 419 | return $nbrErr ;# outside of main, we print termination with errors message |
| 420 | } |
| 421 | |
| 422 | if {$topc == {}} { |
| 423 | # try and infer topcell from cellname-list-top. |
| 424 | # presume its list of cells not placed anywhere else. |
| 425 | # todo: test with "library" GDS having more than one topcell |
| 426 | # here we just take the last entry |
| 427 | set topc [lindex $topcells end] |
| 428 | set topcStr $topc |
| 429 | puts "WARNING: auto-picked top-cell \"$topc\"; the topcells inferred from GDS are: $topcells" |
| 430 | } else { |
| 431 | # verify input topc argument exists in GDS read result |
| 432 | set ndx [lsearch -exact $allcells $topc] |
| 433 | if {$ndx < 0} { |
| 434 | puts "ERROR: ${::Prog}: top-cell name: $topc, not found in GDS" |
| 435 | puts "info: top cells inferred from GDS are: $topcells" |
| 436 | puts "info: all cells inferred from GDS are: $allcells" |
| 437 | return [incr nbrErr] ;# outside of main, we print termination with errors message |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | puts "${::Prog}: running drc on -gds: $gdsf -topcell: $topcStr" |
| 442 | reportTechFile |
| 443 | |
| 444 | # todo: need to error check load command somehow (no useful return value). |
| 445 | # it can fail with error message (in log) like: |
| 446 | # File dne.mag couldn't be found |
| 447 | # Creating new cell |
| 448 | if {[catch {set res [load $topc]} msg]} { |
| 449 | puts "ERROR: ${::Prog}: 'load $topc' threw error (maybe cellName not found in GDS?), $msg" |
| 450 | return [incr nbrErr] ;# outside of main, we print termination with errors message |
| 451 | } |
| 452 | # nothing useful: |
| 453 | # puts "load $topc res: $res" |
| 454 | |
| 455 | if {$flatten} { |
| 456 | # delete (UNNAMED) if any. |
| 457 | set trg "(UNNAMED)" |
| 458 | if {[cellnameExists $trg]} {cellname delete $trg} |
| 459 | |
| 460 | # rename top cell to (UNNAMED) |
| 461 | cellname rename $topc $trg |
| 462 | |
| 463 | # now Edit Cell contents are original top cell, but under name (UNNAMED) |
| 464 | # flatten Edit-Cell into original top cell name |
| 465 | puts "${::Prog}: flattening..." |
| 466 | flatten $topc |
| 467 | |
| 468 | # load and edit new version of top cell |
| 469 | load $topc |
| 470 | |
| 471 | # crude way even in batch to determine the "current" cell; perhaps not yet the "Edit" cell |
| 472 | # WARNING, if topcell locked elsewhere or not writable, it can't become the "Edit" cell. |
| 473 | set topcw [cellname list window] |
| 474 | if {$topcw ne $topc} { |
| 475 | puts "ERROR: ${::Prog}: assertion failed, post-flatten, $topc, is not the current cell, 'cellname list window'=$topcw" |
| 476 | return [incr nbrErr] ;# outside of main, we print termination with errors message |
| 477 | } |
| 478 | |
| 479 | # should not be necessary: |
| 480 | select top cell |
| 481 | edit |
| 482 | |
| 483 | # crude way even in batch to determine the "current" cell; perhaps not yet the "Edit" cell |
| 484 | # WARNING, if topcell locked elsewhere or not writable, it can't become the "Edit" cell. |
| 485 | set topcw [cellname list window] |
| 486 | if {$topcw ne $topc} { |
| 487 | puts "ERROR: ${::Prog}: assertion-2 failed, post-flatten, $topc, is not the current cell, 'cellname list window'=$topcw" |
| 488 | return [incr nbrErr] ;# outside of main, we print termination with errors message |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | # Erase all preexisting *.drtcl first. Else when cell transitions from |
| 493 | # dirty in previous run (leaving *.drtcl), to clean, the old *.drtcl |
| 494 | # remains. |
| 495 | # TODO: only delete *.drtcl of cells in 'cellname list allcells'? |
| 496 | if {$doFeedback} { |
| 497 | set files [glob -nocomplain -types {f} -- ./*.drtcl] |
| 498 | if {$flatten} { |
| 499 | # only delete topcell's .drtcl in flatten mode, if there is one |
| 500 | set files [lsearch -all -inline -exact $files ./$topc.drtcl] |
| 501 | } |
| 502 | if {$files != {}} { |
| 503 | # TODO: detect/report failure details better here? |
| 504 | puts "${::Prog}: deleting preexisting *.drtcl" |
| 505 | set msg {} |
| 506 | set delfail [catch {eval {file delete} $files} msg] |
| 507 | set files [glob -nocomplain -types {f} -- ./*.drtcl] |
| 508 | if {$delfail || $files != {}} { |
| 509 | puts "ERROR: ${::Prog}: failed to clean old ./*.drtcl files. $msg" |
| 510 | incr nbrErr |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | # 1st "select top cell": without it drc-list-count is blank, and error count reduced. |
| 516 | select top cell |
| 517 | |
| 518 | set bbox0 [view bbox] |
| 519 | set outScale [cif scale out] |
| 520 | |
| 521 | # set bbox1 [view bbox] |
| 522 | |
| 523 | # "select top cell" and box [view bbox] should be equivalent in |
| 524 | # placing a box around whole cell extent. |
| 525 | # The box cmd ALSO prints lambda and micron user-friendly box data, |
| 526 | # but it prints microns with not enough resolution, |
| 527 | # (and no option to disable that flawed print out). |
| 528 | # |
| 529 | # todo: emulate box output in full, except for higher resolution, |
| 530 | # here we only scale/print the overall bbox in microns. |
| 531 | set bbs {} |
| 532 | foreach oord $bbox0 { |
| 533 | lappend bbs [format "%.3f" [expr {$outScale * $oord}]] |
| 534 | } |
| 535 | puts "info: outScale: [format "%.6f" $outScale], view-bbox: $bbox0" |
| 536 | puts "info: Root cell box: ([lindex $bbs 0] [lindex $bbs 1]), ([lindex $bbs 2] [lindex $bbs 3])" |
| 537 | |
| 538 | drc check |
| 539 | drc catchup |
| 540 | drc statistics |
| 541 | drc rulestats |
| 542 | # puts "doing plain: drc count" |
| 543 | drc count |
| 544 | |
| 545 | # 2nd select top cell needed else error count may be reduced (why? bbox does not change due to DRC) |
| 546 | select top cell |
| 547 | |
| 548 | set celllist [drc listall count] |
| 549 | set drcListCountTot [drc list count total] |
| 550 | # puts stdout "(drc listall count) is << " nonewline; puts stdout [list $celllist] nonewline; puts " >>" |
| 551 | # puts stdout "(drc list count) is << " nonewline; puts stdout [list [drc list count]] nonewline; puts " >>" |
| 552 | # puts stdout "(drc list count total) is << " nonewline; puts stdout [list $drcListCountTot] nonewline; puts " >>" |
| 553 | # puts stdout "(drc listall count total) is << " nonewline; puts stdout [list [drc listall count total]] nonewline; puts " >>" |
| 554 | # puts stdout "(drc list why) is << " nonewline; puts stdout [list [drc list why]] nonewline; puts " >>" |
| 555 | # puts stdout "(drc listall why) is << " nonewline; puts stdout [list [drc listall why]] nonewline; puts " >>" |
| 556 | |
| 557 | set bbox2 [view bbox] |
| 558 | if {$bbox2 != $bbox0} { |
| 559 | set bbs {} |
| 560 | foreach oord $bbox2 { |
| 561 | lappend bbs [format "%.3f" [expr {$outScale * $oord}]] |
| 562 | } |
| 563 | puts "info: outScale: [format "%.6f" $outScale], view-bbox: $bbox2" |
| 564 | puts "info: Root cell box2: ([lindex $bbs 0] [lindex $bbs 1]), ([lindex $bbs 2] [lindex $bbs 3])" |
| 565 | } |
| 566 | |
| 567 | |
| 568 | # canonicalize order of celllist, move topc to last (if present whatsoever). |
| 569 | # force our own artificial entry for topc (zero errors) if not present (was clean) |
| 570 | # puts "celllist before: $celllist" |
| 571 | set nbrErrCells [llength $celllist] |
| 572 | set topcPair [lsearch -inline -index 0 -exact $celllist $topc] |
| 573 | set celllist [lsearch -not -all -inline -index 0 -exact $celllist $topc] |
| 574 | set celllist [lsort -index 0 -dictionary $celllist] |
| 575 | if {$topcPair == {}} { |
| 576 | # puts "info: ${::Prog}: $topc clean, forcing celllist entry for it" |
| 577 | set topcPair [list $topc 0] |
| 578 | } |
| 579 | lappend celllist $topcPair |
| 580 | # puts stdout "adjusted celllist(drc list count) is << " nonewline; puts stdout $celllist nonewline; puts " >>" |
| 581 | |
| 582 | array set kmErr2catNm {} |
| 583 | array set kmErr2catDesc {} |
| 584 | array set kmCell2item {} |
| 585 | if {$celllist != {} && [info exists enumOutKm]} { |
| 586 | # Header example of .lyrdb klayout Marker format |
| 587 | # <?xml version="1.0" encoding="utf-8"?> |
| 588 | # <report-database> |
| 589 | # <description>Diff of 'x.gds, Cell RINGO' vs. 'x.gds[1], Cell INV2'</description> |
| 590 | # <original-file/> |
| 591 | # <generator/> |
| 592 | # <top-cell>RINGO</top-cell> |
| 593 | # <tags> |
| 594 | # <tag> |
| 595 | # <name>red</name> |
| 596 | # <description>Red flag</description> |
| 597 | # </tag> |
| 598 | # ... |
| 599 | # </tags> |
| 600 | |
| 601 | puts $enumOutKm {<?xml version="1.0" encoding="utf-8"?><report-database>} |
| 602 | puts $enumOutKm "<description>$topc DRC timestamp: $timestamp, arguments: $argv</description>" |
| 603 | puts $enumOutKm {<original-file/><generator/>} |
| 604 | puts $enumOutKm "<top-cell>$topc</top-cell>" |
| 605 | puts $enumOutKm {<tags/>} |
| 606 | puts $enumOutKm {<cells>} |
| 607 | |
| 608 | # multiple <cells>...</cells> sections do accumulate, but cells and categories need |
| 609 | # to be defined before use in an item (specific error), and we know cell names here, |
| 610 | # so declare all cells to klayout here. |
| 611 | # |
| 612 | # Cell-specific header of klayout marker file |
| 613 | # <cell> |
| 614 | # <name>CELLNAME1</name> |
| 615 | # <variant>1</variant> (don't need) |
| 616 | # </cell> |
| 617 | # |
| 618 | foreach pair $celllist { |
| 619 | set acell [lindex $pair 0] |
| 620 | |
| 621 | # for -tt, no subcell error-detail: don't write subcells in <cells>...</cells> section. |
| 622 | if {$acell ne $topc && ! $subcellTab} { continue } |
| 623 | |
| 624 | puts $enumOutKm " <cell><name>$acell</name></cell>" |
| 625 | set kmCell2item($acell) {} |
| 626 | } |
| 627 | puts $enumOutKm {</cells>} |
| 628 | } |
| 629 | |
| 630 | # loop over celllist |
| 631 | set gtotal 0 |
| 632 | set gcells 0 |
| 633 | set lumpedHeader 0 |
| 634 | foreach pair $celllist { |
| 635 | set acell [lindex $pair 0] |
| 636 | set acount [lindex $pair 1] |
| 637 | |
| 638 | if {$acell ne $topc && ! $subcellTab} { |
| 639 | if {! $lumpedHeader} { |
| 640 | puts "--- #err|cell, lumped total counts" |
| 641 | set lumpedHeader 1 |
| 642 | } |
| 643 | puts "[format {%8d} $acount] $acell" |
| 644 | incr gcells |
| 645 | incr gtotal $acount |
| 646 | continue |
| 647 | } |
| 648 | if {$acell eq $topc && ! $topcellTab} { |
| 649 | if {! $lumpedHeader} { |
| 650 | puts "--- #err|cell, lumped total counts" |
| 651 | set lumpedHeader 1 |
| 652 | } |
| 653 | puts "[format {%8d} $acount] $acell" |
| 654 | incr gcells |
| 655 | incr gtotal $acount |
| 656 | continue |
| 657 | } |
| 658 | puts "" |
| 659 | |
| 660 | # todo: need useful error check of load command |
| 661 | if {[catch {set res [load $acell]} msg]} { |
| 662 | puts "ERROR: ${::Prog}: 'load $acell' threw error, $msg" |
| 663 | return [incr nbrErr] ;# outside of main, we print termination with errors message |
| 664 | } |
| 665 | |
| 666 | # instead use quiet version for per-cell selects |
| 667 | select top cell |
| 668 | |
| 669 | set drcListCountTot [drc listall count total] |
| 670 | |
| 671 | # enumerate errors under box, plain "drc why" only reports unique types, no quantities |
| 672 | # as-yet-undocumented "drc listall why" will give: {errStr1 {errBox1 ...} errStr2 {errBox1 ...} ... } |
| 673 | set pareto {} |
| 674 | set total 0 |
| 675 | set enumTotal 0 |
| 676 | set types 0 |
| 677 | set typeDup 0 |
| 678 | set dups 0 |
| 679 | |
| 680 | set fbOut {} |
| 681 | if {$acount != 0} { |
| 682 | # file path for feedback, keep in CWD |
| 683 | if {$doFeedback && $fbOut == {}} { |
| 684 | set fbOut "./$acell.drtcl" |
| 685 | if {![file writable $fbOut] && |
| 686 | ([file exists $fbOut] || ![file writable [file dir $fbOut]])} { |
| 687 | puts stderr "ERROR: ${::Prog}: feedback output not writable, $fbOut" |
| 688 | incr nbrErr |
| 689 | set fbOut {} |
| 690 | } elseif {[catch {set outfb [open $fbOut w]} msg]} { |
| 691 | puts stderr "ERROR: ${::Prog}: failed to truncate previous feedback output, $fbOut : $msg" |
| 692 | incr nbrErr |
| 693 | set fbOut {} |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | foreach {str boxes} [drc listall why] { |
| 698 | # sort errors |
| 699 | set boxes [lsort -dictionary $boxes] |
| 700 | # for our pareto, gather data |
| 701 | set this [llength $boxes] |
| 702 | incr total $this |
| 703 | incr types |
| 704 | lappend pareto [list $this $str] |
| 705 | |
| 706 | # for enumOut, emulate formatting of $CAD_ROOT/magic/tcl/drc.tcl, which is |
| 707 | # not tk pure: fails with complaint about winfo |
| 708 | # note: we walk these errors also in order to count/report stats on duplicates, even if not outputing enumerations |
| 709 | if {[info exists enumOut]} { |
| 710 | if {$types == 1} { |
| 711 | puts $enumOut "[join $pair]\n----------------------------------------" |
| 712 | } |
| 713 | puts $enumOut "${str}\n----------------------------------------" |
| 714 | } |
| 715 | if {[info exists enumOutL]} { |
| 716 | if {$types == 1} { |
| 717 | puts $enumOutL "[join $pair]\n----------------------------------------" |
| 718 | } |
| 719 | puts $enumOutL "${str}\n----------------------------------------" |
| 720 | } |
| 721 | if {[info exists enumOutKm]} { |
| 722 | # category names must be declared all together up front before use in items |
| 723 | # so we only store their names (error strings) and error detail (items) |
| 724 | # to dump after all cells and errors are processed. |
| 725 | # TODO: Only quote catName in item if embeds dot, instead of full-time |
| 726 | # TODO: test klayout handles literal (non-entity) single-quote in double-quoted name |
| 727 | set strKmNm $str |
| 728 | set strKmDesc $str |
| 729 | regsub -all -- {&} $strKmDesc {\&} strKmDesc ;# perhaps not needed; just in case |
| 730 | regsub -all -- {<} $strKmDesc {\<} strKmDesc ;# description does not have such bug, so use correct entity |
| 731 | regsub -all -- {>} $strKmDesc {\>} strKmDesc ;# perhaps not needed; just in case |
| 732 | regsub -all -- {&} $strKmNm {-and-} strKmNm ;# perhaps not needed; just in case |
| 733 | regsub -all -- {>} $strKmNm {-gt-} strKmNm ;# perhaps not needed; just in case |
| 734 | regsub -all -- {<} $strKmNm {-lt-} strKmNm ;# catName klayout bug: info win truncates at '<' as < entity |
| 735 | regsub -all -- "\"" $strKmNm {'} strKmNm ;# we dqoute each catNm in item, so change embedded double to single |
| 736 | set kmErr2catNm($str) $strKmNm |
| 737 | set kmErr2catDesc($str) $strKmDesc |
| 738 | # |
| 739 | # example klayout Marker format, header of one item (one error instance) |
| 740 | # <item> |
| 741 | # <tags/> (don't need?) |
| 742 | # <image/> (don't need?) |
| 743 | # <category>'DRC-MSG-STR'</category> (cat1.cat2 path delimit by dot: names with dot need single|double quotes) |
| 744 | # <cell>RINGO:1</cell> (don't need :N variant suffix) |
| 745 | # <visited>false</visited> (optional? start with false?) |
| 746 | # <multiplicity>1</multiplicity> (not boolean, if error "represents" more that are NOT enumerated) |
| 747 | # <values> ... </values> |
| 748 | # </item> |
| 749 | |
| 750 | set itemStr "<item><category>\"$strKmNm\"</category><cell>$acell</cell><values>" |
| 751 | } |
| 752 | set lastq {} |
| 753 | set thisDup 0 |
| 754 | foreach quad $boxes { |
| 755 | set quadUM {} |
| 756 | set kmBoxUM {} |
| 757 | foreach coord $quad { |
| 758 | set valum [expr {$coord * $outScale}] |
| 759 | set valumf [format "%.3f" $valum] |
| 760 | lappend quadUM "${valumf}um" |
| 761 | lappend kmBoxUM ${valumf} |
| 762 | } |
| 763 | set dup [expr {$quad == $lastq}] |
| 764 | incr thisDup $dup |
| 765 | set line $quadUM |
| 766 | if {[info exists enumOut]} { |
| 767 | if {$dup} { |
| 768 | puts $enumOut "[join $line] #dup" |
| 769 | } else { |
| 770 | puts $enumOut [join $line] |
| 771 | } |
| 772 | } |
| 773 | if {[info exists enumOutL]} { |
| 774 | if {$dup} { |
| 775 | puts $enumOutL "$quad #dup" |
| 776 | } else { |
| 777 | puts $enumOutL $quad |
| 778 | } |
| 779 | } |
| 780 | if {[info exists enumOutKm]} { |
| 781 | # <value>text: 'item: polygon'</value> (text is optional? Repeat the box coordinates here in um?) |
| 782 | # <value>polygon: (1.4,1.8;-1.4,1.8;-1.4,3.8;1.4,3.8)</value> |
| 783 | # <value>box: (1.4,1.8;-1.4,3.8)</value> |
| 784 | # </values> |
| 785 | set kmItem $itemStr |
| 786 | append kmItem " <value>box: ([lindex $kmBoxUM 0],[lindex $kmBoxUM 1];[lindex $kmBoxUM 2],[lindex $kmBoxUM 3])</value>" |
| 787 | if {$dup} { |
| 788 | append kmItem " <value>text: 'dup'</value>" |
| 789 | } |
| 790 | append kmItem " </values></item>" |
| 791 | lappend kmCell2item($acell) $kmItem |
| 792 | } |
| 793 | if {$fbOut != {}} { |
| 794 | set line [join $quadUM] |
| 795 | regsub -all -- "(\[\[\"\$\\\\])" $str {\\\1} strdq |
| 796 | puts $outfb "[concat box $line]" nonewline |
| 797 | puts $outfb " ; feedback add \"$strdq\" medium" nonewline |
| 798 | if {$dup} { |
| 799 | puts $outfb " ;#dup" |
| 800 | } else { |
| 801 | puts $outfb "" |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | incr enumTotal |
| 806 | set lastq $quad |
| 807 | } |
| 808 | if {$thisDup} { |
| 809 | incr typeDup |
| 810 | incr dups $thisDup |
| 811 | } |
| 812 | if {[info exists enumOut]} { |
| 813 | puts $enumOut "----------------------------------------\n" |
| 814 | } |
| 815 | if {[info exists enumOutL]} { |
| 816 | puts $enumOutL "----------------------------------------\n" |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | if {$fbOut != {}} { |
| 822 | close $outfb |
| 823 | set outfb {} |
| 824 | } |
| 825 | |
| 826 | set pareto [lsort -integer -decreasing -index 0 $pareto] |
| 827 | if {$total > 0} { |
| 828 | puts "--- #err|description, table for cell: $acell" |
| 829 | } |
| 830 | foreach pair $pareto { |
| 831 | puts "[format {%8d} [lindex $pair 0]] [lindex $pair 1]" |
| 832 | } |
| 833 | if {$typeDup} { |
| 834 | puts "[format {%8d} $dups] total duplicate error(s) among $typeDup error type(s), cell: $acell" |
| 835 | } |
| 836 | puts "[format {%8d} $total] total error(s) among $types error type(s), cell: $acell" |
| 837 | # add to grand-totals |
| 838 | incr gcells |
| 839 | incr gtotal $total |
| 840 | |
| 841 | # always compare the total from the enum to the pareto as error check |
| 842 | if {$total != $enumTotal} { |
| 843 | puts "ERROR: ${::Prog}: cell: $acell, internal error, pareto vs enum count mismatch: $total != $enumTotal" |
| 844 | incr nbrErr |
| 845 | } |
| 846 | # wish to compare the drc-list-count-total to the pareto total. |
| 847 | # Per te 2014-08-27 : it is not an error. |
| 848 | if {$total != $drcListCountTot} { |
| 849 | # puts "info: ${::Prog}: cell: $acell, drc-list-count-total vs drc-listall-why mismatch {drc list count total} gave $drcListCountTot, but {drc listall why} gave $total" |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | # grand totals |
| 854 | puts "[format {%8d} $nbrErrCells] of $nbrAllCells cell(s) report error(s)" |
| 855 | puts "[format {%8d} $gtotal] grand-total error(s) across $gcells cell(s)" |
| 856 | |
| 857 | if {[info exists enumOut]} { |
| 858 | close $enumOut |
| 859 | } |
| 860 | if {[info exists enumOutL]} { |
| 861 | close $enumOutL |
| 862 | } |
| 863 | if {[info exists enumOutKm]} { |
| 864 | # declare all category names and descriptions, note '<' in name vs description are represented differently |
| 865 | # |
| 866 | # <categories><category><name>layerN width -lt- 1.0um</name> |
| 867 | # <description>layerN width < 1.0um</description></category> |
| 868 | # <category> ... </category></categories> |
| 869 | # |
| 870 | puts $enumOutKm "<categories>" |
| 871 | foreach errStr [array names kmErr2catNm] { |
| 872 | set nm $kmErr2catNm($errStr) |
| 873 | set desc $kmErr2catDesc($errStr) |
| 874 | puts $enumOutKm " <category><name>$nm</name><description>$desc</description></category>" |
| 875 | } |
| 876 | puts $enumOutKm "</categories>" |
| 877 | |
| 878 | # dump all items (after all cells and all categories have been defined up front) |
| 879 | puts $enumOutKm "<items>" |
| 880 | foreach {acell items} [array get kmCell2item] { |
| 881 | foreach item $items { |
| 882 | puts $enumOutKm $item |
| 883 | } |
| 884 | } |
| 885 | puts $enumOutKm "</items>" |
| 886 | |
| 887 | # footer example .lyrdb klayout Marker file |
| 888 | # </report-database> |
| 889 | puts $enumOutKm {</report-database>} |
| 890 | close $enumOutKm |
| 891 | } |
| 892 | # todo: implement super-pareto, ranked table of SUM of all DRC errs/counts from ALL cells. |
| 893 | # (It still would not reflect as-if-flat hierarchical expansion due to repetition of instances). |
| 894 | |
| 895 | set nbrErr ;# return value |
| 896 | } ;# end main |
| 897 | |
| 898 | # non-zero exit-status on errors, either if thrown by main, or counted and returned by main |
| 899 | set nbrErr 0 |
| 900 | if {[catch {set nbrErr [main $argv]} msg]} { |
| 901 | puts stderr $msg |
| 902 | set nbrErr 1 |
| 903 | } elseif {$nbrErr > 0} { |
| 904 | puts "ERROR: ${::Prog}: script terminated with errors reported above." |
| 905 | } |
| 906 | exit $nbrErr |
| 907 | |
| 908 | # for emacs syntax-mode: |
| 909 | # Local Variables: |
| 910 | # mode:tcl |
| 911 | # End: |