Tim Edwards | 55f4d0e | 2020-07-05 15:41:02 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # compare_dirs.py <path> |
| 4 | # |
| 5 | # |
| 6 | # Compare the format subdirectories of <path> and report on which files do not appear |
| 7 | # in all of them. If a directory has no files in it, then it is ignored. |
| 8 | # |
| 9 | # NOTE: This script was not designed for files in the "ef_format" file structure. |
| 10 | |
| 11 | import os |
| 12 | import sys |
| 13 | |
| 14 | def compare_dirs(path, styles, formats, debug): |
| 15 | do_cdl = True if 'cdl' in formats else False |
| 16 | do_gds = True if 'gds' in formats else False |
| 17 | do_lef = True if 'lef' in formats else False |
| 18 | do_mag = True if 'mag' in formats else False |
| 19 | do_maglef = True if 'maglef' in formats else False |
| 20 | do_verilog = True if 'verilog' in formats else False |
| 21 | |
| 22 | try: |
| 23 | d1 = os.listdir(path + '/cdl') |
| 24 | except: |
| 25 | d1 = [] |
| 26 | d1e = list(item for item in d1 if os.path.splitext(item)[1] == '.cdl') |
| 27 | d1r = list(os.path.splitext(item)[0] for item in d1e) |
| 28 | try: |
| 29 | d2 = os.listdir(path + '/gds') |
| 30 | except: |
| 31 | d2 = [] |
| 32 | d2e = list(item for item in d2 if os.path.splitext(item)[1] == '.gds') |
| 33 | d2r = list(os.path.splitext(item)[0] for item in d2e) |
| 34 | try: |
| 35 | d3 = os.listdir(path + '/lef') |
| 36 | except: |
| 37 | d3 = [] |
| 38 | d3e = list(item for item in d3 if os.path.splitext(item)[1] == '.lef') |
| 39 | d3r = list(os.path.splitext(item)[0] for item in d3e) |
| 40 | try: |
| 41 | d4 = os.listdir(path + '/mag') |
| 42 | except: |
| 43 | d4 = [] |
| 44 | d4e = list(item for item in d4 if os.path.splitext(item)[1] == '.mag') |
| 45 | d4r = list(os.path.splitext(item)[0] for item in d4e) |
| 46 | try: |
| 47 | d5 = os.listdir(path + '/maglef') |
| 48 | except: |
| 49 | d5 = [] |
| 50 | d5e = list(item for item in d5 if os.path.splitext(item)[1] == '.mag') |
| 51 | d5r = list(os.path.splitext(item)[0] for item in d5e) |
| 52 | try: |
| 53 | d6 = os.listdir(path + '/verilog') |
| 54 | except: |
| 55 | d6 = [] |
| 56 | d6e = list(item for item in d6 if os.path.splitext(item)[1] == '.v') |
| 57 | d6r = list(os.path.splitext(os.path.splitext(item)[0])[0] for item in d6e) |
| 58 | |
| 59 | d1r.sort() |
| 60 | d2r.sort() |
| 61 | d3r.sort() |
| 62 | d4r.sort() |
| 63 | d5r.sort() |
| 64 | d6r.sort() |
| 65 | |
| 66 | d1_2 = list(item for item in d1r if item not in d2r) |
| 67 | d1_3 = list(item for item in d1r if item not in d3r) |
| 68 | d1_4 = list(item for item in d1r if item not in d4r) |
| 69 | d1_5 = list(item for item in d1r if item not in d5r) |
| 70 | d1_6 = list(item for item in d1r if item not in d6r) |
| 71 | |
| 72 | d2_1 = list(item for item in d2r if item not in d1r) |
| 73 | d2_3 = list(item for item in d2r if item not in d3r) |
| 74 | d2_4 = list(item for item in d2r if item not in d4r) |
| 75 | d2_5 = list(item for item in d2r if item not in d5r) |
| 76 | d2_6 = list(item for item in d2r if item not in d6r) |
| 77 | |
| 78 | d3_1 = list(item for item in d3r if item not in d1r) |
| 79 | d3_2 = list(item for item in d3r if item not in d2r) |
| 80 | d3_4 = list(item for item in d3r if item not in d4r) |
| 81 | d3_5 = list(item for item in d3r if item not in d5r) |
| 82 | d3_6 = list(item for item in d3r if item not in d6r) |
| 83 | |
| 84 | d4_1 = list(item for item in d4r if item not in d1r) |
| 85 | d4_2 = list(item for item in d4r if item not in d2r) |
| 86 | d4_3 = list(item for item in d4r if item not in d3r) |
| 87 | d4_5 = list(item for item in d4r if item not in d5r) |
| 88 | d4_6 = list(item for item in d4r if item not in d6r) |
| 89 | |
| 90 | d5_1 = list(item for item in d5r if item not in d1r) |
| 91 | d5_2 = list(item for item in d5r if item not in d2r) |
| 92 | d5_3 = list(item for item in d5r if item not in d3r) |
| 93 | d5_4 = list(item for item in d5r if item not in d4r) |
| 94 | d5_6 = list(item for item in d5r if item not in d6r) |
| 95 | |
| 96 | d6_1 = list(item for item in d6r if item not in d1r) |
| 97 | d6_2 = list(item for item in d6r if item not in d2r) |
| 98 | d6_3 = list(item for item in d6r if item not in d3r) |
| 99 | d6_4 = list(item for item in d6r if item not in d4r) |
| 100 | d6_5 = list(item for item in d6r if item not in d5r) |
| 101 | |
| 102 | d_complete = [] |
| 103 | if do_cdl: |
| 104 | d_complete.extend(list(item for item in d1r if item not in d_complete)) |
| 105 | if do_gds: |
| 106 | d_complete.extend(list(item for item in d2r if item not in d_complete)) |
| 107 | if do_lef: |
| 108 | d_complete.extend(list(item for item in d3r if item not in d_complete)) |
| 109 | if do_mag: |
| 110 | d_complete.extend(list(item for item in d4r if item not in d_complete)) |
| 111 | if do_maglef: |
| 112 | d_complete.extend(list(item for item in d5r if item not in d_complete)) |
| 113 | if do_verilog: |
| 114 | d_complete.extend(list(item for item in d6r if item not in d_complete)) |
| 115 | |
| 116 | d_all = d_complete |
| 117 | if do_cdl: |
| 118 | d_all = list(item for item in d_all if item in d1r) |
| 119 | if do_gds: |
| 120 | d_all = list(item for item in d_all if item in d2r) |
| 121 | if do_lef: |
| 122 | d_all = list(item for item in d_all if item in d3r) |
| 123 | if do_mag: |
| 124 | d_all = list(item for item in d_all if item in d4r) |
| 125 | if do_maglef: |
| 126 | d_all = list(item for item in d_all if item in d5r) |
| 127 | if do_verilog: |
| 128 | d_all = list(item for item in d_all if item in d6r) |
| 129 | |
| 130 | d_notall = list(item for item in d_complete if item not in d_all) |
| 131 | |
| 132 | d_all.sort() |
| 133 | d_complete.sort() |
| 134 | d_notall.sort() |
| 135 | |
| 136 | if debug: |
| 137 | print('Selected styles option: ' + ','.join(styles)) |
| 138 | print('Selected formats option: ' + ','.join(formats)) |
| 139 | print('\nd_complete = ' + ','.join(d_complete)) |
| 140 | print('\nd_notall = ' + ','.join(d_notall) + '\n') |
| 141 | |
| 142 | print('Library file type cross-correlation:' + '\n') |
| 143 | |
| 144 | if 'allgood' in styles: |
| 145 | print('Cells appearing in all libraries:') |
| 146 | for cell in d_all.sort(): |
| 147 | print(cell) |
| 148 | |
| 149 | if 'cross' in styles: |
| 150 | # Print which cells appear in one format but not in another, for all format pairs |
| 151 | if do_cdl: |
| 152 | print('') |
| 153 | if do_gds and len(d1_2) > 0: |
| 154 | print('Cells appearing in cdl/ but not in gds/:') |
| 155 | for cell in d1_2: |
| 156 | print(cell) |
| 157 | if do_lef and len(d1_3) > 0: |
| 158 | print('Cells appearing in cdl/ but not in lef/:') |
| 159 | for cell in d1_3: |
| 160 | print(cell) |
| 161 | if do_mag and len(d1_4) > 0: |
| 162 | print('Cells appearing in cdl/ but not in mag/:') |
| 163 | for cell in d1_4: |
| 164 | print(cell) |
| 165 | if do_maglef and len(d1_5) > 0: |
| 166 | print('Cells appearing in cdl/ but not in maglef/:') |
| 167 | for cell in d1_5: |
| 168 | print(cell) |
| 169 | if do_verilog and len(d1_6) > 0: |
| 170 | print('Cells appearing in cdl/ but not in verilog/:') |
| 171 | for cell in d1_6: |
| 172 | print(cell) |
| 173 | |
| 174 | if do_gds: |
| 175 | print('') |
| 176 | if do_cdl and len(d2_1) > 0: |
| 177 | print('Cells appearing in gds/ but not in cdl/:') |
| 178 | for cell in d2_1: |
| 179 | print(cell) |
| 180 | if do_lef and len(d2_3) > 0: |
| 181 | print('Cells appearing in gds/ but not in lef/:') |
| 182 | for cell in d2_3: |
| 183 | print(cell) |
| 184 | if do_mag and len(d2_4) > 0: |
| 185 | print('Cells appearing in gds/ but not in mag/:') |
| 186 | for cell in d2_4: |
| 187 | print(cell) |
| 188 | if do_maglef and len(d2_5) > 0: |
| 189 | print('Cells appearing in gds/ but not in maglef/:') |
| 190 | for cell in d2_5: |
| 191 | print(cell) |
| 192 | if do_verilog and len(d2_6) > 0: |
| 193 | print('Cells appearing in gds/ but not in verilog/:') |
| 194 | for cell in d2_6: |
| 195 | print(cell) |
| 196 | |
| 197 | if do_lef: |
| 198 | print('') |
| 199 | if do_cdl and len(d3_1) > 0: |
| 200 | print('Cells appearing in lef/ but not in cdl/:') |
| 201 | for cell in d3_1: |
| 202 | print(cell) |
| 203 | if do_gds and len(d3_2) > 0: |
| 204 | print('Cells appearing in lef/ but not in gds/:') |
| 205 | for cell in d3_2: |
| 206 | print(cell) |
| 207 | if do_mag and len(d3_4) > 0: |
| 208 | print('Cells appearing in lef/ but not in mag/:') |
| 209 | for cell in d3_4: |
| 210 | print(cell) |
| 211 | if do_maglef and len(d3_5) > 0: |
| 212 | print('Cells appearing in lef/ but not in maglef/:') |
| 213 | for cell in d3_5: |
| 214 | print(cell) |
| 215 | if do_verilog and len(d3_6) > 0: |
| 216 | print('Cells appearing in lef/ but not in verilog/:') |
| 217 | for cell in d3_6: |
| 218 | print(cell) |
| 219 | |
| 220 | if do_mag: |
| 221 | print('') |
| 222 | if do_cdl and len(d4_1) > 0: |
| 223 | print('Cells appearing in mag/ but not in cdl/:') |
| 224 | for cell in d4_1: |
| 225 | print(cell) |
| 226 | if do_gds and len(d4_2) > 0: |
| 227 | print('Cells appearing in mag/ but not in gds/:') |
| 228 | for cell in d4_2: |
| 229 | print(cell) |
| 230 | if do_lef and len(d4_3) > 0: |
| 231 | print('Cells appearing in mag/ but not in lef/:') |
| 232 | for cell in d4_3: |
| 233 | print(cell) |
| 234 | if do_maglef and len(d4_5) > 0: |
| 235 | print('Cells appearing in mag/ but not in maglef/:') |
| 236 | for cell in d4_5: |
| 237 | print(cell) |
| 238 | if do_verilog and len(d4_6) > 0: |
| 239 | print('Cells appearing in mag/ but not in verilog/:') |
| 240 | for cell in d4_6: |
| 241 | print(cell) |
| 242 | |
| 243 | if do_maglef: |
| 244 | print('') |
| 245 | if do_cdl and len(d5_1) > 0: |
| 246 | print('Cells appearing in maglef/ but not in cdl/:') |
| 247 | for cell in d5_1: |
| 248 | print(cell) |
| 249 | if do_gds and len(d5_2) > 0: |
| 250 | print('Cells appearing in maglef/ but not in gds/:') |
| 251 | for cell in d5_2: |
| 252 | print(cell) |
| 253 | if do_lef and len(d5_3) > 0: |
| 254 | print('Cells appearing in maglef/ but not in lef/:') |
| 255 | for cell in d5_3: |
| 256 | print(cell) |
| 257 | if do_mag and len(d5_4) > 0: |
| 258 | print('Cells appearing in maglef/ but not in mag/:') |
| 259 | for cell in d5_4: |
| 260 | print(cell) |
| 261 | if do_verilog and len(d5_6) > 0: |
| 262 | print('Cells appearing in maglef/ but not in verilog/:') |
| 263 | for cell in d5_6: |
| 264 | print(cell) |
| 265 | |
| 266 | if do_verilog: |
| 267 | print('') |
| 268 | if do_cdl and len(d6_1) > 0: |
| 269 | print('Cells appearing in verilog/ but not in cdl/:') |
| 270 | for cell in d6_1: |
| 271 | print(cell) |
| 272 | if do_gds and len(d6_2) > 0: |
| 273 | print('Cells appearing in verilog/ but not in gds/:') |
| 274 | for cell in d6_2: |
| 275 | print(cell) |
| 276 | if do_lef and len(d6_3) > 0: |
| 277 | print('Cells appearing in verilog/ but not in lef/:') |
| 278 | for cell in d6_3: |
| 279 | print(cell) |
| 280 | if do_mag and len(d6_4) > 0: |
| 281 | print('Cells appearing in verilog/ but not in mag/:') |
| 282 | for cell in d6_4: |
| 283 | print(cell) |
| 284 | if do_maglef and len(d6_5) > 0: |
| 285 | print('Cells appearing in verilog/ but not in maglef/:') |
| 286 | for cell in d6_5: |
| 287 | print(cell) |
| 288 | |
| 289 | if 'cell' in styles: |
| 290 | # Print one cell per row, with list of formats per cell |
| 291 | for cell in d_complete: |
| 292 | informats = [] |
| 293 | if do_cdl and cell in d1r: |
| 294 | informats.append('CDL') |
| 295 | if do_gds and cell in d2r: |
| 296 | informats.append('GDS') |
| 297 | if do_lef and cell in d3r: |
| 298 | informats.append('LEF') |
| 299 | if do_mag and cell in d4r: |
| 300 | informats.append('mag') |
| 301 | if do_maglef and cell in d5r: |
| 302 | informats.append('maglef') |
| 303 | if do_verilog and cell in d6r: |
| 304 | informats.append('verilog') |
| 305 | print(cell + ': ' + ','.join(informats)) |
| 306 | |
| 307 | if 'notcell' in styles: |
| 308 | # Print one cell per row, with list of missing formats per cell |
| 309 | for cell in d_complete: |
| 310 | informats = [] |
| 311 | if do_cdl and cell not in d1r: |
| 312 | informats.append('CDL') |
| 313 | if do_gds and cell not in d2r: |
| 314 | informats.append('GDS') |
| 315 | if do_lef and cell not in d3r: |
| 316 | informats.append('LEF') |
| 317 | if do_mag and cell not in d4r: |
| 318 | informats.append('mag') |
| 319 | if do_maglef and cell not in d5r: |
| 320 | informats.append('maglef') |
| 321 | if do_verilog and cell not in d6r: |
| 322 | informats.append('verilog') |
| 323 | print(cell + ': ' + ','.join(informats)) |
| 324 | |
| 325 | if 'table' in styles: |
| 326 | cellnamelen = 0 |
| 327 | for cell in d_complete: |
| 328 | if len(cell) > cellnamelen: |
| 329 | cellnamelen = len(cell) |
| 330 | |
| 331 | # Print one cell per row, with list of formats per cell in tabular form |
| 332 | outline = 'cell' |
| 333 | outline += ' ' * (cellnamelen - 5) |
| 334 | fmtspc = 0 |
| 335 | if do_cdl: |
| 336 | outline += ' CDL' |
| 337 | fmtspc += 4 |
| 338 | if do_gds: |
| 339 | outline += ' GDS' |
| 340 | fmtspc += 4 |
| 341 | if do_lef: |
| 342 | outline += ' LEF' |
| 343 | fmtspc += 4 |
| 344 | if do_mag: |
| 345 | outline += ' mag' |
| 346 | fmtspc += 4 |
| 347 | if do_maglef: |
| 348 | outline += ' maglef' |
| 349 | fmtspc += 7 |
| 350 | if do_verilog: |
| 351 | outline += ' verilog' |
| 352 | fmtspc += 8 |
| 353 | print(outline) |
| 354 | print('-' * (cellnamelen + fmtspc)) |
| 355 | for cell in d_complete: |
| 356 | informats = [] |
| 357 | outline = cell |
| 358 | outline += ' ' * (cellnamelen - len(cell)) |
| 359 | if do_cdl: |
| 360 | if cell in d1r: |
| 361 | outline += ' X ' |
| 362 | else: |
| 363 | outline += ' ' |
| 364 | if do_gds: |
| 365 | if cell in d2r: |
| 366 | outline += ' X ' |
| 367 | else: |
| 368 | outline += ' ' |
| 369 | if do_lef: |
| 370 | if cell in d3r: |
| 371 | outline += ' X ' |
| 372 | else: |
| 373 | outline += ' ' |
| 374 | if do_mag: |
| 375 | if cell in d4r: |
| 376 | outline += ' X ' |
| 377 | else: |
| 378 | outline += ' ' |
| 379 | if do_maglef: |
| 380 | if cell in d5r: |
| 381 | outline += ' X ' |
| 382 | else: |
| 383 | outline += ' ' |
| 384 | if do_verilog: |
| 385 | if cell in d6r: |
| 386 | outline += ' X' |
| 387 | else: |
| 388 | outline += ' ' |
| 389 | print(outline) |
| 390 | print('-' * (cellnamelen + fmtspc)) |
| 391 | |
| 392 | def usage(): |
| 393 | print('compare_dirs.py <path_to_dir> [-styles=<style_list>] [-debug] [-formats=<format_list>|"all"]') |
| 394 | print(' <format_list>: Comma-separated list of one or more of the following formats:') |
| 395 | print(' cdl, gds, lef, verilog, mag, maglef') |
| 396 | print(' <style_list>: Comma-separated list of one or more of the following styles:') |
| 397 | print(' allgood, cross, cell, notcell, table') |
| 398 | return 0 |
| 399 | |
| 400 | if __name__ == '__main__': |
| 401 | |
| 402 | options = [] |
| 403 | arguments = [] |
| 404 | for item in sys.argv[1:]: |
| 405 | if item.find('-', 0) == 0: |
| 406 | options.append(item) |
| 407 | else: |
| 408 | arguments.append(item) |
| 409 | |
| 410 | if len(arguments) < 1: |
| 411 | print("Not enough options given to compare_dirs.py.") |
| 412 | usage() |
| 413 | sys.exit(0) |
| 414 | |
| 415 | debug = True if '-debug' in options else False |
| 416 | |
| 417 | allformats = ['cdl', 'gds', 'lef', 'mag', 'maglef', 'verilog'] |
| 418 | allstyles = ['allgood', 'cross', 'cell', 'notcell', 'table'] |
| 419 | |
| 420 | formats = allformats |
| 421 | styles = ['table'] |
| 422 | |
| 423 | for option in options: |
| 424 | if '=' in option: |
| 425 | optpair = option.split('=') |
| 426 | if optpair[0] == '-styles' or optpair[0] == '-style': |
| 427 | if optpair[1] == 'all': |
| 428 | styles = allstyles |
| 429 | else: |
| 430 | styles = optpair[1].split(',') |
| 431 | elif optpair[0] == '-formats' or optpair[0] == '-format': |
| 432 | if optpair[1] == 'all': |
| 433 | formats = allformats |
| 434 | else: |
| 435 | formats = optpair[1].split(',') |
| 436 | |
| 437 | path = arguments[0] |
| 438 | compare_dirs(path, styles, formats, debug) |
| 439 | sys.exit(0) |