-
Notifications
You must be signed in to change notification settings - Fork 432
Added netlistsvg wrapper/generator #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wgryncewicz
wants to merge
4
commits into
google:main
Choose a base branch
from
antmicro:netlistsvg-generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3a9fef6
Added netlistsvg wrapper/generator
wgryncewicz 17c37e1
Moved to argparse, pathlib, subprocess
wgryncewicz da5a537
Netlistsvg wrapper moved and renamed
wgryncewicz 35187a3
Added json patching option for minor netlistsvg incompatibilities
wgryncewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
scripts/python-skywater-pdk/skywater_pdk/netlistsvg-generate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2020 The SkyWater PDK Authors. | ||
| # | ||
| # Use of this source code is governed by the Apache 2.0 | ||
| # license that can be found in the LICENSE file or at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| import csv | ||
| import json | ||
| import os | ||
| import sys | ||
| import argparse | ||
| import pathlib | ||
| import glob | ||
| import subprocess | ||
|
|
||
| def outfile(cellpath, define_data, ftype='', extra='', exists=False): | ||
| ''' Determines output file path and name. | ||
|
|
||
| Args: | ||
| cellpath - path to a cell [str of pathlib.Path] | ||
| define_data - cell definition data [dic] | ||
| ftype - file type suffix [str] | ||
| extra - extra suffix [str] | ||
| exist - optional check if file exists [bool or None] | ||
|
|
||
| Returns: | ||
| outpath - output file namepath [str] | ||
| ''' | ||
|
|
||
| fname = define_data['name'].lower().replace('$', '_') | ||
| if ftype: | ||
| ftype = '.'+ftype | ||
| outpath = os.path.join(cellpath, f'{define_data["file_prefix"]}{extra}{ftype}.svg') | ||
| if exists is None: | ||
| pass | ||
| elif not exists: | ||
| #assert not os.path.exists(outpath), "Refusing to overwrite existing file:"+outpath | ||
| print("Creating", outpath) | ||
| elif exists: | ||
| assert os.path.exists(outpath), "Missing required:"+outpath | ||
| return outpath | ||
|
|
||
|
|
||
| def write_netlistsvg(cellpath, define_data): | ||
| ''' Generates netlistsvg for a given cell. | ||
|
|
||
| Args: | ||
| cellpath - path to a cell [str of pathlib.Path] | ||
| define_data - cell definition data [dic] | ||
| ''' | ||
|
|
||
| netlist_json = os.path.join(cellpath, define_data['file_prefix']+'.json') | ||
| if not os.path.exists(netlist_json): | ||
| print("No netlist in", cellpath) | ||
| assert os.path.exists(netlist_json), netlist_json | ||
| outpath = outfile(cellpath, define_data, 'schematic') | ||
| if subprocess.call(['netlistsvg', netlist_json, '-o', outpath]): | ||
| raise ChildProcessError("netlistsvg execution failed") | ||
|
|
||
| def process(cellpath): | ||
| ''' Processes cell indicated by path. | ||
| Opens cell definiton and calls further processing | ||
|
|
||
| Args: | ||
| cellpath - path to a cell [str of pathlib.Path] | ||
| ''' | ||
|
|
||
| print() | ||
| print(cellpath) | ||
| define_json = os.path.join(cellpath, 'definition.json') | ||
| if not os.path.exists(define_json): | ||
| print("No definition.json in", cellpath) | ||
| assert os.path.exists(define_json), define_json | ||
| define_data = json.load(open(define_json)) | ||
|
|
||
| if define_data['type'] == 'cell': | ||
| write_netlistsvg(cellpath, define_data) | ||
|
|
||
| return | ||
|
|
||
|
|
||
| def main(): | ||
| ''' Generates netlistsvg schematic from cell netlist.''' | ||
|
|
||
| prereq_txt = 'prerequisities:\n netlistsvg' | ||
| output_txt = 'output:\n generates [cell_prefix].schematic.svg' | ||
| allcellpath = '../../../libraries/*/latest/cells/*' | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description = main.__doc__, | ||
| epilog = prereq_txt +'\n\n'+ output_txt, | ||
| formatter_class=argparse.RawDescriptionHelpFormatter) | ||
| parser.add_argument( | ||
| "--all_libs", | ||
| help="process all cells in "+allcellpath, | ||
| action="store_true") | ||
| parser.add_argument( | ||
| "cell_dir", | ||
| help="path to the cell directory", | ||
| type=pathlib.Path, | ||
| nargs="*") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| if args.all_libs: | ||
| path = pathlib.Path(allcellpath).expanduser() | ||
| parts = path.parts[1:] if path.is_absolute() else path.parts | ||
| paths = pathlib.Path(path.root).glob(str(pathlib.Path("").joinpath(*parts))) | ||
| args.cell_dir = list(paths) | ||
|
|
||
| cell_dirs = [d.resolve() for d in args.cell_dir if d.is_dir()] | ||
|
|
||
| errors = 0 | ||
| for d in cell_dirs: | ||
| try: | ||
| process(d) | ||
| except KeyboardInterrupt: | ||
| sys.exit(1) | ||
| except (AssertionError, FileNotFoundError, ChildProcessError) as ex: | ||
| print (f'Error: {type(ex).__name__}') | ||
| print (f'{ex.args}') | ||
| errors +=1 | ||
| print (f'\n{len(cell_dirs)} files processed, {errors} errors.') | ||
| return 0 if errors else 1 | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.