diff --git a/README.rst b/README.rst index cda6a66..c3d4ad3 100644 --- a/README.rst +++ b/README.rst @@ -82,6 +82,17 @@ 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/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..21ccae1 100644 --- a/sphinxcontrib_verilog_diagrams/__init__.py +++ b/sphinxcontrib_verilog_diagrams/__init__.py @@ -148,6 +148,8 @@ class VerilogDiagram(Directive): final_argument_whitespace = False + use_yowasp = True + option_spec = { 'type': str, 'module': str, @@ -208,9 +210,14 @@ 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) + print("Running yosys: yosys -q -p", "'{}'".format(cmd), src) + 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): @@ -232,6 +239,12 @@ def diagram_yosys(ipath, opath, module='top', flatten=False): """.format(top=module, flatten=flatten, fmt=oext, oprefix=oprefix).strip(), ) + 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)) @@ -268,7 +281,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)