From f34dd70fcd8d2fd219b021c25a2f52ac5b377d97 Mon Sep 17 00:00:00 2001 From: Daniel Lim Wee Soong Date: Wed, 5 Aug 2020 23:28:49 +0800 Subject: [PATCH 1/3] Use yowasp_yosys instead of yosys from conda Signed-off-by: Daniel Lim Wee Soong --- environment.yml | 1 - requirements.txt | 2 ++ sphinxcontrib_verilog_diagrams/__init__.py | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/environment.yml b/environment.yml index 30e7597..f7c4f2b 100644 --- a/environment.yml +++ b/environment.yml @@ -11,7 +11,6 @@ dependencies: - pip - python=3.7 - sphinx -- yosys - pip: # Packages installed from PyPI - -r file:requirements.txt - -r file:docs/requirements.txt diff --git a/requirements.txt b/requirements.txt index 15df521..2626b19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,7 @@ setuptools docutils sphinx +yowasp-yosys>=0.9.post4547.dev9 + # Needed to upload to PyPi twine diff --git a/sphinxcontrib_verilog_diagrams/__init__.py b/sphinxcontrib_verilog_diagrams/__init__.py index 7330284..1f92109 100644 --- a/sphinxcontrib_verilog_diagrams/__init__.py +++ b/sphinxcontrib_verilog_diagrams/__init__.py @@ -43,6 +43,8 @@ from sphinx.util.i18n import search_image_for_language from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL +import yowasp_yosys + if False: # For type annotation from typing import Any, Dict, List, Tuple # NOQA @@ -208,9 +210,9 @@ def run(self): def run_yosys(src, cmd): - ycmd = "yosys -p '{cmd}' {src}".format(src=src, cmd=cmd) - print("Running yosys:", ycmd) - subprocess.check_output(ycmd, shell=True) + ycmd = ["-q", "-p", cmd, src] + print("Running yosys: yosys -q -p", "'{}'".format(cmd), src) + yowasp_yosys.run_yosys(ycmd) def diagram_yosys(ipath, opath, module='top', flatten=False): @@ -231,6 +233,10 @@ def diagram_yosys(ipath, opath, module='top', flatten=False): prep -top {top} {flatten}; cd {top}; show -format {fmt} -prefix {oprefix} """.format(top=module, flatten=flatten, fmt=oext, oprefix=oprefix).strip(), ) + # somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg, + # perhaps a limitation with wasm + svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)]) + open("{}.svg".format(oprefix), "wb").write(svgdata) assert path.exists(opath), 'Output file {} was not created!'.format(oopath) print('Output file created: {}'.format(opath)) @@ -268,7 +274,7 @@ def diagram_netlistsvg(ipath, opath, module='top', flatten=False): run_yosys( src=ipath, cmd = """\ -prep -top {top} {flatten}; cd {top}; write_json {ojson} +prep -top {top} {flatten}; cd {top}; write_json -compat-int {ojson} """.format(top=module, flatten=flatten, ojson=ojson).strip()) assert path.exists(ojson), 'Output file {} was not created!'.format(ojson) From 2ea10f004edbd0545411ff40e3c440189d577355 Mon Sep 17 00:00:00 2001 From: Daniel Lim Wee Soong Date: Sun, 9 Aug 2020 13:54:57 +0800 Subject: [PATCH 2/3] Allow user to choose between yowasp and system-installed yosys Signed-off-by: Daniel Lim Wee Soong --- README.rst | 10 ++++++++++ docs/conf.py | 5 +++++ sphinxcontrib_verilog_diagrams/__init__.py | 23 ++++++++++++++-------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index cda6a66..a84f92a 100644 --- a/README.rst +++ b/README.rst @@ -82,6 +82,16 @@ Required .. |yosys| replace:: ``yosys`` .. _yosys: https://github.com/YosysHQ/yosys +By default, `verilog-diagram` uses the `yowasp-yosys` package provided in PyPI. It can be installed by running `pip install -r requirements.txt`. +However, you could also use the `yosys` that is installed on your system, by adding the following line in `setup(app)` inside conf.py. + +.. code-block:: py + def setup(app): + ... + VerilogDiagram.use_yowasp = False + ... + + Optional ~~~~~~~~ diff --git a/docs/conf.py b/docs/conf.py index f4f2e2f..e728d9a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,6 +37,7 @@ # import os import sys +from sphinxcontrib_verilog_diagrams import VerilogDiagram sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ @@ -251,3 +252,7 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'https://docs.python.org/': None} + +def setup(app): + # VerilogDiagram.use_yowasp = False + pass diff --git a/sphinxcontrib_verilog_diagrams/__init__.py b/sphinxcontrib_verilog_diagrams/__init__.py index 1f92109..21ccae1 100644 --- a/sphinxcontrib_verilog_diagrams/__init__.py +++ b/sphinxcontrib_verilog_diagrams/__init__.py @@ -43,8 +43,6 @@ from sphinx.util.i18n import search_image_for_language from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL -import yowasp_yosys - if False: # For type annotation from typing import Any, Dict, List, Tuple # NOQA @@ -150,6 +148,8 @@ class VerilogDiagram(Directive): final_argument_whitespace = False + use_yowasp = True + option_spec = { 'type': str, 'module': str, @@ -210,9 +210,14 @@ def run(self): def run_yosys(src, cmd): - ycmd = ["-q", "-p", cmd, src] print("Running yosys: yosys -q -p", "'{}'".format(cmd), src) - yowasp_yosys.run_yosys(ycmd) + if VerilogDiagram.use_yowasp: + import yowasp_yosys + ycmd = ["-q", "-p", "{}".format(cmd), src] + yowasp_yosys.run_yosys(ycmd) + else: + ycmd = "yosys -p '{cmd}' {src}".format(src=src, cmd=cmd) + subprocess.check_output(ycmd, shell=True) def diagram_yosys(ipath, opath, module='top', flatten=False): @@ -233,10 +238,12 @@ def diagram_yosys(ipath, opath, module='top', flatten=False): prep -top {top} {flatten}; cd {top}; show -format {fmt} -prefix {oprefix} """.format(top=module, flatten=flatten, fmt=oext, oprefix=oprefix).strip(), ) - # somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg, - # perhaps a limitation with wasm - svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)]) - open("{}.svg".format(oprefix), "wb").write(svgdata) + + if VerilogDiagram.use_yowasp: + # somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg, + # which works on native yosys, perhaps a limitation with wasm + svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)]) + open("{}.svg".format(oprefix), "wb").write(svgdata) assert path.exists(opath), 'Output file {} was not created!'.format(oopath) print('Output file created: {}'.format(opath)) From a870d49bed192856386cca21c158f4fe911361c2 Mon Sep 17 00:00:00 2001 From: Daniel Lim Wee Soong Date: Sun, 9 Aug 2020 14:24:46 +0800 Subject: [PATCH 3/3] Fix rst syntax error Signed-off-by: Daniel Lim Wee Soong --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index a84f92a..c3d4ad3 100644 --- a/README.rst +++ b/README.rst @@ -86,6 +86,7 @@ By default, `verilog-diagram` uses the `yowasp-yosys` package provided in PyPI. However, you could also use the `yosys` that is installed on your system, by adding the following line in `setup(app)` inside conf.py. .. code-block:: py + def setup(app): ... VerilogDiagram.use_yowasp = False