From 35199ce0e1c5879513f37672335a14ff59d6169d Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 00:04:08 +0100 Subject: [PATCH 01/10] Added script for generating Symbolator diagrams Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbolator_plots.py | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py new file mode 100644 index 000000000..c879d8bb4 --- /dev/null +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py @@ -0,0 +1,95 @@ +import sys +import symbolator +import argparse +from pathlib import Path +import errno +import contextlib +import traceback + + +@contextlib.contextmanager +def redirect_argv(args): + sys._argv = sys.argv + sys.argv = args + yield + sys.argv = sys._argv + + +def main(argv): + parser = argparse.ArgumentParser(prog=argv[0]) + parser.add_argument( + 'libraries_dir', + help='Path to the libraries directory of skywater-pdk', + type=Path + ) + parser.add_argument( + 'output_dir', + help='Path to the output directory', + type=Path + ) + parser.add_argument( + '--libname', + help='Library name to generate the Symbolator diagrams for', + type=str + ) + parser.add_argument( + '--version', + help='Version for which the Symbolator diagrams should be generated', + type=str + ) + parser.add_argument( + '--create-dirs', + help='Create directories for output when not present', + action='store_true' + ) + + args = parser.parse_args(argv[1:]) + + libraries_dir = args.libraries_dir + + symbol_v_files = libraries_dir.rglob('*.symbol.v') + + for symbol_v_file in symbol_v_files: + if args.libname and args.libname != symbol_v_file.parts[1]: + continue + if args.version and args.version != symbol_v_file.parts[2]: + continue + + print(f'===> {str(symbol_v_file)}') + libname = symbol_v_file.parts[1] + out_filename = (args.output_dir / + symbol_v_file.resolve() + .relative_to(libraries_dir.resolve())) + out_filename = out_filename.with_suffix('.svg') + out_dir = out_filename.parent + + if not out_dir.exists(): + if args.create_dirs: + out_dir.mkdir(parents=True) + else: + print(f'The output directory {str(out_dir)} is missing') + print('Run the script with --create-dirs to make directories') + return errno.ENOENT + + if out_filename.exists(): + print(f'The {out_filename} already exists') + return errno.EEXIST + + arguments = (f'--libname {libname} --title -t -o {out_filename}' + + f' --output-as-filename -i {str(symbol_v_file)}' + + ' --format svg') + with redirect_argv(arguments.split(' ')): + try: + symbolator.main() + except Exception: + print( + f'Failed to run: symbolator {arguments}', + file=sys.stderr + ) + print('Error message:\n', file=sys.stderr) + traceback.print_exc() + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) From 60e4b4811029cb8e995fc2e9e88f41fc773b3376 Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 00:26:20 +0100 Subject: [PATCH 02/10] Added possibility to log files where Symbolator failed to generate plots Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbolator_plots.py | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py index c879d8bb4..1295e39ec 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py @@ -42,6 +42,11 @@ def main(argv): help='Create directories for output when not present', action='store_true' ) + parser.add_argument( + '--failed-inputs', + help='Path to files for which Symbolator failed to generate diagram', + type=Path + ) args = parser.parse_args(argv[1:]) @@ -49,45 +54,49 @@ def main(argv): symbol_v_files = libraries_dir.rglob('*.symbol.v') - for symbol_v_file in symbol_v_files: - if args.libname and args.libname != symbol_v_file.parts[1]: - continue - if args.version and args.version != symbol_v_file.parts[2]: - continue + nc = contextlib.nullcontext() + + with open(args.failed_inputs, 'w') if args.failed_inputs else nc as err: + for symbol_v_file in symbol_v_files: + if args.libname and args.libname != symbol_v_file.parts[1]: + continue + if args.version and args.version != symbol_v_file.parts[2]: + continue - print(f'===> {str(symbol_v_file)}') - libname = symbol_v_file.parts[1] - out_filename = (args.output_dir / - symbol_v_file.resolve() - .relative_to(libraries_dir.resolve())) - out_filename = out_filename.with_suffix('.svg') - out_dir = out_filename.parent + print(f'===> {str(symbol_v_file)}') + libname = symbol_v_file.parts[1] + out_filename = (args.output_dir / + symbol_v_file.resolve() + .relative_to(libraries_dir.resolve())) + out_filename = out_filename.with_suffix('.svg') + out_dir = out_filename.parent - if not out_dir.exists(): - if args.create_dirs: - out_dir.mkdir(parents=True) - else: - print(f'The output directory {str(out_dir)} is missing') - print('Run the script with --create-dirs to make directories') - return errno.ENOENT + if not out_dir.exists(): + if args.create_dirs: + out_dir.mkdir(parents=True) + else: + print(f'The output directory {str(out_dir)} is missing') + print('Run the script with --create-dirs') + return errno.ENOENT - if out_filename.exists(): - print(f'The {out_filename} already exists') - return errno.EEXIST + if out_filename.exists(): + print(f'The {out_filename} already exists') + return errno.EEXIST - arguments = (f'--libname {libname} --title -t -o {out_filename}' + - f' --output-as-filename -i {str(symbol_v_file)}' + - ' --format svg') - with redirect_argv(arguments.split(' ')): - try: - symbolator.main() - except Exception: - print( - f'Failed to run: symbolator {arguments}', - file=sys.stderr - ) - print('Error message:\n', file=sys.stderr) - traceback.print_exc() + arguments = (f'--libname {libname} --title -t -o {out_filename}' + + f' --output-as-filename -i {str(symbol_v_file)}' + + ' --format svg') + with redirect_argv(arguments.split(' ')): + try: + symbolator.main() + except Exception: + print( + f'Failed to run: symbolator {arguments}', + file=sys.stderr + ) + print('Error message:\n', file=sys.stderr) + traceback.print_exc() + err.write(f'{symbol_v_file}\n') return 0 From 6d5ae7c272d0c0f57872b1735e9677f8b7d7ffd1 Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 10:13:32 +0100 Subject: [PATCH 03/10] Added possibility to overwrite existing symbol.svg files Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbolator_plots.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py index 1295e39ec..8d615b461 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py @@ -47,6 +47,11 @@ def main(argv): help='Path to files for which Symbolator failed to generate diagram', type=Path ) + parser.add_argument( + '--overwrite-existing', + help='If present, the script will overwrite existing symbol.svg files', + action='store_true' + ) args = parser.parse_args(argv[1:]) @@ -79,7 +84,7 @@ def main(argv): print('Run the script with --create-dirs') return errno.ENOENT - if out_filename.exists(): + if out_filename.exists() and not args.overwrite_existing: print(f'The {out_filename} already exists') return errno.EEXIST From 4282990ba3b95253844815f50874db6ca8d1e9d8 Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 10:15:01 +0100 Subject: [PATCH 04/10] Added SymbiFlow/symbolator to requirements.txt Signed-off-by: Grzegorz Latosinski --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index fe8a2c1b2..b06aea9a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ flake8 # rst_include tool as GitHub doesn't support `.. include::` when rendering # previews. rst_include +git+git://github.com/SymbiFlow/symbolator.git@master#egg=symbolator # The Python API for the SkyWater PDK. -e scripts/python-skywater-pdk From aa630223297e6a68ad3672d2db32156044746b1b Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 13:21:52 +0100 Subject: [PATCH 05/10] Added header for generate_symbolator_plots.py Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbolator_plots.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py index 8d615b461..23baab29c 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright 2020 SkyWater PDK Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + + import sys import symbolator import argparse From 2b90c3e2a64ce715d651af5f1ade776da5d0c16b Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Wed, 18 Nov 2020 16:39:36 +0100 Subject: [PATCH 06/10] Renamed generate_symbolator_plots.py to generate_symbols.py Signed-off-by: Grzegorz Latosinski --- .../{generate_symbolator_plots.py => generate_symbols.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/python-skywater-pdk/skywater_pdk/{generate_symbolator_plots.py => generate_symbols.py} (100%) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py similarity index 100% rename from scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py rename to scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py From 35b26faa05764c501e9cab100fc3064c0a727ede Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Wed, 18 Nov 2020 17:19:44 +0100 Subject: [PATCH 07/10] generate_symbols.py: switched from contextlib to subprocess Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbols.py | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py index 23baab29c..975746537 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py @@ -19,20 +19,12 @@ import sys -import symbolator import argparse from pathlib import Path import errno import contextlib import traceback - - -@contextlib.contextmanager -def redirect_argv(args): - sys._argv = sys.argv - sys.argv = args - yield - sys.argv = sys._argv +import subprocess def main(argv): @@ -108,20 +100,23 @@ def main(argv): print(f'The {out_filename} already exists') return errno.EEXIST - arguments = (f'--libname {libname} --title -t -o {out_filename}' + - f' --output-as-filename -i {str(symbol_v_file)}' + - ' --format svg') - with redirect_argv(arguments.split(' ')): - try: - symbolator.main() - except Exception: - print( - f'Failed to run: symbolator {arguments}', - file=sys.stderr - ) - print('Error message:\n', file=sys.stderr) - traceback.print_exc() - err.write(f'{symbol_v_file}\n') + program = ('symbolator' + + f' --libname {libname} --title -t -o {out_filename}' + + f' --output-as-filename -i {str(symbol_v_file)}' + + ' --format svg') + res = subprocess.run( + program.split(' '), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + if res.returncode != 0: + print( + f'Failed to run: {program}', + file=sys.stderr + ) + print('STDOUT:\n', file=sys.stderr) + print(res.stdout.decode()) + err.write(f'{symbol_v_file}\n') return 0 From b59aafbc02d01acb19a9a316533ca92ef773008f Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Wed, 25 Nov 2020 09:45:52 +0100 Subject: [PATCH 08/10] symbolator-generator: improved help for --failed-inputs Signed-off-by: Grzegorz Latosinski --- scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py index 975746537..1f6e185ac 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py @@ -56,7 +56,9 @@ def main(argv): ) parser.add_argument( '--failed-inputs', - help='Path to files for which Symbolator failed to generate diagram', + help=('Path to an output file that will store list of files for ' + + 'which the symbolator failed to create symbols' + ), type=Path ) parser.add_argument( From 49771a3c62aac3def0ecf83c016855a9fbc06499 Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Wed, 25 Nov 2020 09:47:23 +0100 Subject: [PATCH 09/10] symbolator-generator: cleaned up the script Signed-off-by: Grzegorz Latosinski --- scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py index 1f6e185ac..513782ce7 100644 --- a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py @@ -23,7 +23,6 @@ from pathlib import Path import errno import contextlib -import traceback import subprocess @@ -58,7 +57,7 @@ def main(argv): '--failed-inputs', help=('Path to an output file that will store list of files for ' + 'which the symbolator failed to create symbols' - ), + ), type=Path ) parser.add_argument( From 14a4884732eaf0f32ca9616ab7385d873910499b Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Wed, 25 Nov 2020 10:34:07 +0100 Subject: [PATCH 10/10] symbolator-generator: moved generate_symbols.py to cell/generate/symbol.py Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/{generate_symbols.py => cell/generate/symbol.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/python-skywater-pdk/skywater_pdk/{generate_symbols.py => cell/generate/symbol.py} (100%) diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py b/scripts/python-skywater-pdk/skywater_pdk/cell/generate/symbol.py similarity index 100% rename from scripts/python-skywater-pdk/skywater_pdk/generate_symbols.py rename to scripts/python-skywater-pdk/skywater_pdk/cell/generate/symbol.py