Skip to content

Commit 2f3b1b7

Browse files
authored
Merge pull request #56 from antmicro/nmigen
Continuation: Support nMigen and RTLIL inputs
2 parents ac79fa4 + 00294b7 commit 2f3b1b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1187
-543
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ venv.bak/
104104
.mypy_cache/
105105

106106
# version number
107-
sphinxcontrib_verilog_diagrams/version.py
107+
sphinxcontrib_hdl_diagrams/version.py

.readthedocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version: 2
88
# Build documentation in the docs/ directory with Sphinx
99
sphinx:
1010
configuration: docs/conf.py
11+
fail_on_warning: true
1112

1213
formats:
1314
- htmlzip

.travis.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: minimal
22

33
before_install:
44
- make env
5+
- source env/conda/bin/activate sphinxcontrib-hdl-diagrams
56

67
stages:
78
- name:
@@ -13,28 +14,41 @@ jobs:
1314
- stage: Tests
1415
name: "Test :skin: option"
1516
script:
16-
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
1717
- cd tests && python3 -m unittest test.TestSkins
1818

1919
- stage: Tests
2020
name: "Test :yosys_script: option"
2121
script:
22-
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
2322
- cd tests && python3 -m unittest test.TestYosysScript
2423

2524
- stage: Tests
2625
name: "Test verilog_diagram_yosys config variable"
2726
script:
28-
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
2927
- cd tests && python3 -m unittest test.TestYosysType
3028

29+
- stage: Tests
30+
name: "Test nMigen input format"
31+
script:
32+
- cd tests && python3 -m unittest test.TestNMigen
33+
34+
- stage: Tests
35+
name: "Test RTLIL input format"
36+
script:
37+
- cd tests && python3 -m unittest test.TestRTLIL
38+
39+
- stage: Tests
40+
name: "Test compatibility package"
41+
script:
42+
- cd tests && python3 -m unittest test.TestCompat
43+
3144
- stage: Build
3245
name: "Build"
3346
script:
3447
- make build
3548

3649
- stage: Deploy
3750
name: "PyPI"
51+
before_install: null
3852
before_deploy:
3953
- make clean
4054
- make sphinxcontrib_verilog_diagrams/version.py

Makefile

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ENVIRONMENT_FILE := environment.yml
2020
include third_party/make-env/conda.mk
2121

2222
# Create a version.py file
23-
VERSION_PY = sphinxcontrib_verilog_diagrams/version.py
23+
VERSION_PY = sphinxcontrib_hdl_diagrams/version.py
2424
$(VERSION_PY):
2525
echo "__version__ = '$$(git describe | sed -e's/v\([0-9]\+\)\.\([0-9]\+\)-\([0-9]\+\)-g[0-9a-f]\+/\1.\2.post\3/')'" > $@
2626

@@ -33,35 +33,57 @@ version-clean:
3333

3434
clean: version-clean
3535

36-
# Build and upload commands
36+
# Build and upload main package
37+
38+
#PYPI_TEST = --repository-url https://test.pypi.org/legacy/
39+
PYPI_TEST = --repository testpypi
40+
3741
build: $(VERSION_PY) | $(CONDA_ENV_PYTHON)
3842
$(IN_CONDA_ENV) python setup.py sdist bdist_wheel && twine check dist/*
3943

40-
.PHONY: build
41-
4244
build-clean:
4345
rm -rf env/downloads/conda-pkgs
4446
rm -rf build dist *.egg-info
4547
find -name *.pyc -delete
4648
find -name __pycache__ -delete
4749

48-
clean: build-clean
49-
50-
#PYPI_TEST = --repository-url https://test.pypi.org/legacy/
51-
#PYPI_TEST = --repository testpypi
52-
5350
upload-test: build | $(CONDA_ENV_PYTHON)
5451
$(IN_CONDA_ENV) twine upload ${PYPI_TEST} dist/*
5552

56-
.PHONY: upload-test
57-
5853
upload: build | $(CONDA_ENV_PYTHON)
5954
$(IN_CONDA_ENV) twine upload --verbose dist/*
6055

61-
.PHONY: upload
56+
.PHONY: build build-clean upload upload-test
57+
58+
# Build and upload compatibility package
59+
60+
COMPAT_PACKAGE_DIR = compat
61+
62+
build_compat: $(VERSION_PY) | $(CONDA_ENV_PYTHON)
63+
$(IN_CONDA_ENV) cd $(COMPAT_PACKAGE_DIR); python setup.py sdist bdist_wheel && twine check dist/*
64+
65+
build_compat-clean:
66+
cd $(COMPAT_PACKAGE_DIR); rm -rf env/downloads/conda-pkgs
67+
cd $(COMPAT_PACKAGE_DIR); rm -rf build dist *.egg-info
68+
cd $(COMPAT_PACKAGE_DIR); find -name *.pyc -delete
69+
cd $(COMPAT_PACKAGE_DIR); find -name __pycache__ -delete
70+
71+
upload_compat-test: build_compat | $(CONDA_ENV_PYTHON)
72+
$(IN_CONDA_ENV) cd $(COMPAT_PACKAGE_DIR); twine upload ${PYPI_TEST} dist/*
73+
74+
upload_compat: build_compat | $(CONDA_ENV_PYTHON)
75+
$(IN_CONDA_ENV) cd $(COMPAT_PACKAGE_DIR); twine upload --verbose dist/*
76+
77+
.PHONY: build_compat build_compat-clean upload_compat-test upload_compat
78+
79+
# Tests
6280

6381
test: $(VERSION_PY) | $(CONDA_ENV_PYTHON)
6482
$(IN_CONDA_ENV) cd docs; make html
6583
$(IN_CONDA_ENV) cd tests; make test
6684

6785
.PHONY: test
86+
87+
# Cleanup
88+
89+
clean: build-clean build_compat-clean

README.rst

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
sphinxcontrib-verilog-diagrams
1+
sphinxcontrib-hdl-diagrams
22
==============================
33

44

5-
.. image:: https://img.shields.io/pypi/v/sphinxcontrib-verilog-diagrams.svg
6-
:target: https://pypi.python.org/pypi/sphinxcontrib-verilog-diagrams
5+
.. image:: https://img.shields.io/pypi/v/sphinxcontrib-hdl-diagrams.svg
6+
:target: https://pypi.python.org/pypi/sphinxcontrib-hdl-diagrams
77
:alt: PyPI
88

99

10-
.. image:: https://img.shields.io/pypi/pyversions/sphinxcontrib-verilog-diagrams.svg
11-
:target: https://pypi.python.org/pypi/sphinxcontrib-verilog-diagrams
10+
.. image:: https://img.shields.io/pypi/pyversions/sphinxcontrib-hdl-diagrams.svg
11+
:target: https://pypi.python.org/pypi/sphinxcontrib-hdl-diagrams
1212
:alt: PyPI version
1313

1414

15-
.. image:: https://readthedocs.org/projects/sphinxcontrib-verilog-diagrams/badge
16-
:target: https://sphinxcontrib-verilog-diagrams.readthedocs.io/en/latest/
15+
.. image:: https://readthedocs.org/projects/sphinxcontrib-hdl-diagrams/badge
16+
:target: https://sphinxcontrib-hdl-diagrams.readthedocs.io/en/latest/
1717
:alt: Documentation
1818

1919

20-
.. image:: https://travis-ci.com/SymbiFlow/sphinxcontrib-verilog-diagrams.svg?branch=master
21-
:target: https://travis-ci.com/SymbiFlow/sphinxcontrib-verilog-diagrams
20+
.. image:: https://travis-ci.com/SymbiFlow/sphinxcontrib-hdl-diagrams.svg?branch=master
21+
:target: https://travis-ci.com/SymbiFlow/sphinxcontrib-hdl-diagrams
2222
:alt: Build Status
2323

2424

25-
.. image:: https://codecov.io/gh/SymbiFlow/sphinxcontrib-verilog-diagrams/branch/master/graph/badge.svg
26-
:target: https://codecov.io/gh/SymbiFlow/sphinxcontrib-verilog-diagrams
25+
.. image:: https://codecov.io/gh/SymbiFlow/sphinxcontrib-hdl-diagrams/branch/master/graph/badge.svg
26+
:target: https://codecov.io/gh/SymbiFlow/sphinxcontrib-hdl-diagrams
2727
:alt: codecov
2828

2929

3030
----
3131

32-
Sphinx Extension which generates various types of diagrams from Verilog code.
32+
Sphinx Extension which generates various types of diagrams from HDL code, supporting Verilog,
33+
nMigen and RTLIL.
3334

34-
`sphinxcontrib-verilog-diagrams <https://github.com/SymbiFlow/sphinxcontrib-verilog-diagrams>`_
35+
`sphinxcontrib-hdl-diagrams <https://github.com/SymbiFlow/sphinxcontrib-hdl-diagrams>`_
3536
is a Sphinx extension to make it easier to write nice documentation from
36-
Verilog files. It primarily uses `Yosys <https://github.com/YosysHQ/yosys>`_ to do the Verilog reading.
37+
HDL source files. It primarily uses `Yosys <https://github.com/YosysHQ/yosys>`_ to read the source files
38+
and generate the diagrams.
3739

38-
Check out the `documentation <https://sphinxcontrib-verilog-diagrams.readthedocs.io/en/latest>`_ for examples.
40+
Check out the `documentation <https://sphinxcontrib-hdl-diagrams.readthedocs.io/en/latest>`_ for examples.
3941

4042
Installation
4143
------------
@@ -44,13 +46,13 @@ Python 3.5+ is required.
4446

4547
.. code-block::
4648
47-
pip install sphinxcontrib-verilog-diagrams
49+
pip install sphinxcontrib-hdl-diagrams
4850
4951
Or,
5052

5153
.. code-block::
5254
53-
python3 -m pip install sphinxcontrib-verilog-diagrams
55+
python3 -m pip install sphinxcontrib-hdl-diagrams
5456
5557
Sphinx Integration
5658
^^^^^^^^^^^^^^^^^^
@@ -61,7 +63,7 @@ In your conf.py, add the following lines.
6163
6264
extensions = [
6365
...,
64-
'sphinxcontrib_verilog_diagrams',
66+
'sphinxcontrib_hdl_diagrams',
6567
]
6668
6769
Non-Python Dependencies
@@ -107,15 +109,15 @@ Optional
107109
Usage
108110
-----
109111

110-
``verilog-diagram``
112+
``hdl-diagram``
111113
^^^^^^^^^^^^^^^^^^^
112114

113-
The ``verilog-diagram`` RST directive can be used to generate a diagram from Verilog code and include it in your documentation.
114-
Check out the `examples <https://sphinxcontrib-verilog-diagrams.readthedocs.io/en/latest/>`_ to see how to use it.
115+
The ``hdl-diagram`` RST directive can be used to generate a diagram from Verilog code and include it in your documentation.
116+
Check out the `examples <https://sphinxcontrib-hdl-diagrams.readthedocs.io/en/latest/>`_ to see how to use it.
115117

116118
.. code-block:: rst
117119
118-
.. verilog-diagram:: file.v
120+
.. hdl-diagram:: file.v
119121
:type: XXXXX
120122
:module: XXXX
121123
:skin: XXXX
@@ -125,7 +127,7 @@ Check out the `examples <https://sphinxcontrib-verilog-diagrams.readthedocs.io/e
125127
Options
126128
~~~~~~~
127129

128-
``:type:`` - Verilog Diagram Types;
130+
``:type:`` - HDL Diagram Types;
129131

130132

131133
* ``yosys-blackbox`` - Netlist rendered by Yosys.

compat/setup.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (C) 2020 The SymbiFlow Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
20+
import sys
21+
from os import path
22+
23+
from setuptools import setup, find_packages
24+
25+
__dir__ = path.dirname(path.abspath(__file__))
26+
readme_file = path.join(__dir__, '../README.rst')
27+
try:
28+
with open(readme_file) as f:
29+
readme = f.read()
30+
except FileNotFoundError as e:
31+
import traceback
32+
traceback.print_exc()
33+
readme = ''
34+
__version__ = 'error'
35+
36+
install_requires = [
37+
'sphinxcontrib-hdl-diagrams'
38+
]
39+
40+
setup(
41+
name='sphinxcontrib-verilog-diagrams',
42+
version="0.1.0",
43+
description='Generate diagrams from Verilog in Sphinx.',
44+
long_description=readme,
45+
long_description_content_type="text/x-rst",
46+
author="The SymbiFlow Authors",
47+
author_email='symbiflow@lists.librecores.org',
48+
url='https://github.com/SymbiFlow/sphinxcontrib-hdl-diagrams',
49+
packages=find_packages(),
50+
license="Apache 2.0",
51+
keywords='Verilog sphinx sphinx-extension netlistsvg FPGA',
52+
classifiers=[
53+
'Development Status :: 4 - Beta',
54+
'Framework :: Sphinx :: Extension',
55+
'Intended Audience :: Developers',
56+
'License :: OSI Approved :: Apache Software License',
57+
'Natural Language :: English',
58+
'Programming Language :: Python :: 3.5',
59+
'Programming Language :: Python :: 3.6',
60+
'Topic :: Text Processing',
61+
],
62+
install_requires=install_requires,
63+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import warnings
2+
import sphinxcontrib_hdl_diagrams
3+
4+
def setup(app):
5+
deprecation_msg = """
6+
sphinxcontrib-verilog-diagram extension is depreciated!
7+
Please use sphinxcontrib-hdl-diagrams instead:
8+
https://github.com/SymbiFlow/sphinxcontrib-hdl-diagrams"""
9+
warnings.warn(deprecation_msg, DeprecationWarning)
10+
11+
return sphinxcontrib_hdl_diagrams.setup(app)

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MAKEDIR := $(dir $(lastword $(MAKEFILE_LIST)))
77
SPHINXOPTS =
88
SPHINXBUILD = [ -e env/bin/activate ] && source env/bin/activate; sphinx-build
99
SPHINXAUTOBUILD = [ -e env/bin/activate ] && source env/bin/activate; sphinx-autobuild
10-
SPHINXPROJ = SphinxVerilog
10+
SPHINXPROJ = SphinxContribHDLDiagramsDocs
1111
SOURCEDIR = .
1212
BUILDDIR = _build
1313

docs/code/nmigen/counter.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2020 The SymbiFlow Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
18+
from nmigen import *
19+
from nmigen.back import rtlil
20+
21+
22+
class Counter(Elaboratable):
23+
def __init__(self, width):
24+
self.v = Signal(width, reset=2**width-1)
25+
self.o = Signal()
26+
27+
def elaborate(self, platform):
28+
m = Module()
29+
m.d.sync += self.v.eq(self.v + 1)
30+
m.d.comb += self.o.eq(self.v[-1])
31+
return m
32+
33+
34+
ctr = Counter(width=16)
35+
print(rtlil.convert(ctr, ports=[ctr.o]))

0 commit comments

Comments
 (0)