Tim Edwards | 9d3debb | 2020-10-20 20:52:18 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tim Edwards | 7f052a6 | 2020-07-28 11:07:26 -0400 | [diff] [blame] | 2 | # |
| 3 | # split_gds.py -- |
| 4 | # |
Tim Edwards | 55f4d0e | 2020-07-05 15:41:02 -0400 | [diff] [blame] | 5 | # Script to read a GDS library and write into individual GDS files, one per cell |
| 6 | |
| 7 | import os |
| 8 | import sys |
| 9 | import subprocess |
| 10 | |
| 11 | def usage(): |
| 12 | print('split_gds.py <path_to_gds_library> <magic_techfile> [<file_with_list_of_cells>]') |
| 13 | |
| 14 | if __name__ == '__main__': |
| 15 | |
| 16 | if len(sys.argv) == 1: |
| 17 | print("No options given to split_gds.py.") |
| 18 | usage() |
| 19 | sys.exit(0) |
| 20 | |
| 21 | optionlist = [] |
| 22 | arguments = [] |
| 23 | |
| 24 | for option in sys.argv[1:]: |
| 25 | if option.find('-', 0) == 0: |
| 26 | optionlist.append(option) |
| 27 | else: |
| 28 | arguments.append(option) |
| 29 | |
| 30 | if len(arguments) != 3: |
| 31 | print("Wrong number of arguments given to split_gds.py.") |
| 32 | usage() |
| 33 | sys.exit(0) |
| 34 | |
| 35 | source = arguments[0] |
| 36 | |
| 37 | techfile = arguments[1] |
| 38 | |
| 39 | celllist = arguments[2] |
| 40 | if os.path.isfile(celllist): |
| 41 | with open(celllist, 'r') as ifile: |
| 42 | celllist = ifile.read().splitlines() |
| 43 | |
| 44 | destdir = os.path.split(source)[0] |
| 45 | gdsfile = os.path.split(source)[1] |
| 46 | |
| 47 | with open(destdir + '/split_gds.tcl', 'w') as ofile: |
Tim Edwards | d14571f | 2021-01-06 14:49:27 -0500 | [diff] [blame] | 48 | print('#!/usr/bin/env wish', file=ofile) |
Tim Edwards | 55f4d0e | 2020-07-05 15:41:02 -0400 | [diff] [blame] | 49 | print('drc off', file=ofile) |
| 50 | print('gds readonly true', file=ofile) |
| 51 | print('gds rescale false', file=ofile) |
| 52 | print('tech unlock *', file=ofile) |
| 53 | print('gds read ' + gdsfile, file=ofile) |
| 54 | |
| 55 | for cell in celllist: |
| 56 | print('load ' + cell, file=ofile) |
| 57 | print('gds write ' + cell, file=ofile) |
| 58 | |
| 59 | print('quit -noprompt', file=ofile) |
| 60 | |
| 61 | mproc = subprocess.run(['magic', '-dnull', '-noconsole', |
| 62 | '-T', techfile, |
| 63 | destdir + '/split_gds.tcl'], |
| 64 | stdin = subprocess.DEVNULL, |
| 65 | stdout = subprocess.PIPE, |
| 66 | stderr = subprocess.PIPE, cwd = destdir, |
| 67 | universal_newlines = True) |
| 68 | if mproc.stdout: |
| 69 | for line in mproc.stdout.splitlines(): |
| 70 | print(line) |
| 71 | if mproc.stderr: |
| 72 | print('Error message output from magic:') |
| 73 | for line in mproc.stderr.splitlines(): |
| 74 | print(line) |
| 75 | if mproc.returncode != 0: |
| 76 | print('ERROR: Magic exited with status ' + str(mproc.returncode)) |
| 77 | |
| 78 | os.remove(destdir + '/split_gds.tcl') |
| 79 | exit(0) |