blob: 0a84a4849048db6609b3daf56b76e3508a8b2604 [file] [log] [blame]
Tim Edwardsafa7a412020-12-07 16:10:02 -05001#!/bin/env python3
2#
3# generate_fill.py ---
4#
5# Run the fill generation on the caravel top level.
6#
7
8import sys
9import os
10import re
11import subprocess
12
13def usage():
14 print("generate_fill.py [layout_name] [-keep]")
15 return 0
16
17if __name__ == '__main__':
18
19 if len(sys.argv) == 1:
20 usage()
21 sys.exit(0)
22
23 optionlist = []
24 arguments = []
25
26 debugmode = False
27 keepmode = False
28
29 for option in sys.argv[1:]:
30 if option.find('-', 0) == 0:
31 optionlist.append(option)
32 else:
33 arguments.append(option)
34
35 if len(arguments) > 1:
36 print("Wrong number of arguments given to generate_fill.py.")
37 usage()
38 sys.exit(0)
39
40 if len(arguments) == 1:
41 project = arguments[0]
42 else:
43 project = 'caravel'
44
45 if '-debug' in optionlist:
46 debugmode = True
47 if '-keep' in optionlist:
48 keepmode = True
49
50 magdir = '../mag'
51 rcfile = magdir + '/.magicrc'
52
53 with open(magdir + '/generate_fill.tcl', 'w') as ofile:
54 print('#!/bin/env wish', file=ofile)
55 print('drc off', file=ofile)
56 print('load ' + project + ' -dereference', file=ofile)
57 print('select top cell', file=ofile)
58 print('expand', file=ofile)
59
60 # Flatten into a cell with a new name
61 print('puts stdout "Flattening layout. . . "', file=ofile)
62 print('flatten -nolabels ' + project + '_fill_pattern', file=ofile)
63 print('load ' + project + '_fill_pattern', file=ofile)
64
65 # Remove any GDS_FILE reference
66 print('property GDS_FILE ""', file=ofile)
67 print('cif ostyle wafflefill', file=ofile)
68 print('puts stdout "Writing GDS. . . "', file=ofile)
69 print('gds write ../gds/' + project + '_fill_pattern.gds', file=ofile)
70 print('quit -noprompt', file=ofile)
71
72 myenv = os.environ.copy()
73 myenv['MAGTYPE'] = 'mag'
74
75 mproc = subprocess.run(['magic', '-dnull', '-noconsole',
76 '-rcfile', rcfile, magdir + '/generate_fill.tcl'],
77 stdin = subprocess.DEVNULL,
78 stdout = subprocess.PIPE,
79 stderr = subprocess.PIPE,
80 cwd = magdir,
81 env = myenv,
82 universal_newlines = True)
83 if mproc.stdout:
84 for line in mproc.stdout.splitlines():
85 print(line)
86 if mproc.stderr:
87 print('Error message output from magic:')
88 for line in mproc.stderr.splitlines():
89 print(line)
90 if mproc.returncode != 0:
91 print('ERROR: Magic exited with status ' + str(mproc.returncode))
92
93 if not keepmode:
94 os.remove(magdir + '/generate_fill.tcl')
95
96 exit(0)