blob: 31f4ac718770fd65a45670ed4d0ed6098d131b1a [file] [log] [blame]
Tim Edwards9d3debb2020-10-20 20:52:18 -04001#!/usr/bin/env python3
Tim Edwards7f052a62020-07-28 11:07:26 -04002#
3# split_gds.py --
4#
Tim Edwards55f4d0e2020-07-05 15:41:02 -04005# Script to read a GDS library and write into individual GDS files, one per cell
6
7import os
8import sys
9import subprocess
10
11def usage():
12 print('split_gds.py <path_to_gds_library> <magic_techfile> [<file_with_list_of_cells>]')
13
14if __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 Edwardsd14571f2021-01-06 14:49:27 -050048 print('#!/usr/bin/env wish', file=ofile)
Tim Edwards55f4d0e2020-07-05 15:41:02 -040049 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)