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