Skip to content

Commit 135dc83

Browse files
daniellimwsrw1nkler
authored andcommitted
Allow user to choose between yowasp and system-installed yosys
Signed-off-by: Daniel Lim Wee Soong <weesoong.lim@gmail.com>
1 parent 4e93e76 commit 135dc83

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ Required
8282
.. |yosys| replace:: ``yosys``
8383
.. _yosys: https://github.com/YosysHQ/yosys
8484

85+
By default, `verilog-diagram` uses the `yowasp-yosys` package provided in PyPI. It can be installed by running `pip install -r requirements.txt`.
86+
However, you could also use the `yosys` that is installed on your system, by adding the following line in `setup(app)` inside conf.py.
87+
88+
.. code-block:: py
89+
def setup(app):
90+
...
91+
VerilogDiagram.use_yowasp = False
92+
...
93+
94+
8595
Optional
8696
~~~~~~~~
8797

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#
3838
import os
3939
import sys
40+
from sphinxcontrib_verilog_diagrams import VerilogDiagram
4041
sys.path.insert(0, os.path.abspath('..'))
4142

4243
# -- General configuration ------------------------------------------------
@@ -251,3 +252,7 @@
251252

252253
# Example configuration for intersphinx: refer to the Python standard library.
253254
intersphinx_mapping = {'https://docs.python.org/': None}
255+
256+
def setup(app):
257+
# VerilogDiagram.use_yowasp = False
258+
pass

sphinxcontrib_verilog_diagrams/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
from sphinx.util.i18n import search_image_for_language
4444
from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL
4545

46-
import yowasp_yosys
47-
4846
if False:
4947
# For type annotation
5048
from typing import Any, Dict, List, Tuple # NOQA
@@ -150,6 +148,8 @@ class VerilogDiagram(Directive):
150148

151149
final_argument_whitespace = False
152150

151+
use_yowasp = True
152+
153153
option_spec = {
154154
'type': str,
155155
'module': str,
@@ -232,9 +232,14 @@ def run(self):
232232

233233

234234
def run_yosys(src, cmd):
235-
ycmd = ["-q", "-p", cmd, src]
236235
print("Running yosys: yosys -q -p", "'{}'".format(cmd), src)
237-
yowasp_yosys.run_yosys(ycmd)
236+
if VerilogDiagram.use_yowasp:
237+
import yowasp_yosys
238+
ycmd = ["-q", "-p", "{}".format(cmd), src]
239+
yowasp_yosys.run_yosys(ycmd)
240+
else:
241+
ycmd = "yosys -p '{cmd}' {src}".format(src=src, cmd=cmd)
242+
subprocess.check_output(ycmd, shell=True)
238243

239244

240245
def diagram_yosys(ipath, opath, module='top', flatten=False, yosys_script='default'):
@@ -262,10 +267,12 @@ def diagram_yosys(ipath, opath, module='top', flatten=False, yosys_script='defau
262267
prep -top {top} {flatten}; cd {top}; {script}; show -format {fmt} -prefix {oprefix}
263268
""".format(top=module, flatten=flatten, fmt=oext, oprefix=oprefix, script=yosys_script_cmd).strip(),
264269
)
265-
# somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg,
266-
# perhaps a limitation with wasm
267-
svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)])
268-
open("{}.svg".format(oprefix), "wb").write(svgdata)
270+
271+
if VerilogDiagram.use_yowasp:
272+
# somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg,
273+
# which works on native yosys, perhaps a limitation with wasm
274+
svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)])
275+
open("{}.svg".format(oprefix), "wb").write(svgdata)
269276

270277
assert path.exists(opath), 'Output file {} was not created!'.format(oopath)
271278
print('Output file created: {}'.format(opath))

0 commit comments

Comments
 (0)