1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

Update makeflow (#396)

* Clean up verify convert warnings

* Rewrote test and remove Xfail, test is passing now (is it supposed to fail?)

* Rewrote test and remove Xfail, test is passing now (is it supposed to fail?)

* Fixed all tests to handle the analyze/verify deprecation

* Fixed to catch the correct error, List of signals as a port is not supported

* Add a way to search for and add myhdl.vpi

* Add explict test to check for deprecation case

* Change warning from UserWarning (which is the default) to DeprecationWarning

* Change test operation from script to makefile

* No longer use travis

* Add some ANSI colored logging

* Fixed test to look for DeprecationWarning

* Add lining step

* Add linting step

* Add linting step

* Remove matrix step

* Add work/ to clean list

* Hide echo commands in window

* The word test is reserved in pytest only for tests, doen't use it for any thing else, like blocks

* Add myhdl.vpi to clean

* Mark these tests as xfail, for now,

* Fix and unmark xfail 2 tests

* Add black support

* Remove python2 only testing

* Need to relook at this test, it performs differently for verilog and vhdl

* Add RTL files to the list

* Need to relook at this test, it performs differently for verilog and vhdl

* Upgrade to DeprecationWarnings

* Initial checkin with passing flow for new convert VHDL/Verilog, there are a few xfail tests that need to be debugged

* Add more examples for the Deprecation cases, toVHDL and toVerilog

* Fix deprecations catching

* Fix pytest to use pytest.ini

* Add pypi release steps

* Fix intbv error

* Fix indent

* Update to do a release

* Add checkout to step

* Update Python versions

* Add dependancy on tag on push
This commit is contained in:
Dave Keeshan 2022-12-17 12:21:08 +00:00 committed by GitHub
parent b85c1668c1
commit f8022d3dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 614 additions and 377 deletions

View File

@ -6,6 +6,22 @@ on:
schedule:
- cron: '0 1 * * 0'
jobs:
run_lint:
strategy:
fail-fast: false # So that one fail doesn't stop remaining tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade -r requirements.txt
- name: Run lint
continue-on-error: true
run: |
pyflakes myhdl
build_ghdl:
#uses: daxzio/setup-eda/.github/workflows/setup_ghdl.yml@main
uses: ./.github/workflows/setup_ghdl.yml
@ -22,7 +38,7 @@ jobs:
os: [ubuntu-latest]
target: [core, iverilog, ghdl]
runs-on: ${{ matrix.os }}
needs: [build_ghdl, build_iverilog]
needs: [run_lint, build_ghdl, build_iverilog]
env:
CI_TARGET: ${{ matrix.target }}
@ -50,7 +66,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip pytest
python -m pip install --upgrade pip
python -m pip install --upgrade -r requirements.txt
python -m pip install .
- name: Report Environment
run: |
@ -61,4 +78,17 @@ jobs:
sudo apt install gnat
- name: Run Tests
run: |
./scripts/ci.sh
make ${CI_TARGET}
pypy_release:
runs-on: ubuntu-latest
needs: [build_code]
steps:
- uses: actions/checkout@v3
- name: Make PyPi dist release
run: make release
- name: Publish Python distribution to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

4
.gitignore vendored
View File

@ -37,3 +37,7 @@ myhdl/**/*.vhd
# Pycharm ide junk
.idea/
/.pytest_cache/
*.hex
*.vhd
*.v

View File

@ -1,37 +0,0 @@
dist: xenial
language: python
python:
- "3.9"
- "3.8"
- "3.7"
- "3.6"
- "pypy3.5"
install:
- pip install .
env:
- CI_TARGET=core
- CI_TARGET=iverilog
- CI_TARGET=ghdl
matrix:
allow_failures:
- python: "pypy3.5"
before_script:
- if [[ "$CI_TARGET" == "iverilog" ]]; then
sudo apt-get -qq update;
sudo apt-get install iverilog;
elif [[ "$CI_TARGET" == "ghdl" ]]; then
sudo add-apt-repository ppa:mati75/ghdl -y;
sudo apt-get -qq update;
sudo apt-get install ghdl;
fi
script: ./scripts/ci.sh
notifications:
email: false

View File

@ -1,8 +1,14 @@
PYTEST_OPTS ?=
ANSI_RED=`tput setaf 1`
ANSI_GREEN=`tput setaf 2`
ANSI_CYAN=`tput setaf 6`
ANSI_RESET=`tput sgr0`
install:
python setup.py install
localinstall:
python setup.py install --home=$(HOME)
python setup.py install --home=${HOME}
docs:
tox -e docs html
@ -11,7 +17,53 @@ livedocs:
tox -e docs livehtml
release:
- rm MANIFEST
- rm CHANGELOG.txt
hg glog > CHANGELOG.txt
rm -rf MANIFEST
rm -rf CHANGELOG.txt
#hg glog > CHANGELOG.txt
python setup.py sdist
clean:
rm -rf *.vhd *.v *.o *.log *.hex work/ cosimulation/icarus/myhdl.vpi
lint:
pyflakes myhdl/
black:
black myhdl/
core:
@echo -e "\n${ANSI_CYAN}running test: $@ ${ANSI_RESET}"
pytest ./myhdl/test/core ${PYTEST_OPTS}
iverilog_myhdl.vpi:
${MAKE} -C cosimulation/icarus myhdl.vpi
iverilog_cosim: iverilog_myhdl.vpi
${MAKE} -C cosimulation/icarus test
iverilog_general:
pytest ./myhdl/test/conversion/general --sim iverilog ${PYTEST_OPTS}
iverilog_toverilog: iverilog_myhdl.vpi
pytest ./myhdl/test/conversion/toVerilog --sim iverilog ${PYTEST_OPTS}
iverilog_bugs:
pytest ./myhdl/test/bugs --sim iverilog ${PYTEST_OPTS}
iverilog: iverilog_cosim
@echo -e "\n${ANSI_CYAN}running test: $@ ${ANSI_RESET}"
pytest ./myhdl/test/conversion/general ./myhdl/test/conversion/toVerilog ./myhdl/test/bugs --sim iverilog ${PYTEST_OPTS}
ghdl_general:
pytest ./myhdl/test/conversion/general --sim ghdl ${PYTEST_OPTS}
ghdl_tovhdl:
pytest ./myhdl/test/conversion/toVHDL --sim ghdl ${PYTEST_OPTS}
ghdl_bugs:
pytest ./myhdl/test/bugs --sim ghdl ${PYTEST_OPTS}
ghdl:
@echo -e "\n${ANSI_CYAN}running test: $@ ${ANSI_RESET}"
pytest ./myhdl/test/conversion/general ./myhdl/test/conversion/toVHDL ./myhdl/test/bugs --sim ghdl ${PYTEST_OPTS}
pytest: core iverilog ghdl

View File

@ -166,7 +166,10 @@ class _ToVHDLConvertor(object):
_converting = 0
else:
warnings.warn(
"\n toVHDL(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
"\n toVHDL(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html",
stacklevel=2,
category=DeprecationWarning,
)
try:
h = _HierExtr(name, func, *args, **kwargs)
finally:

View File

@ -148,7 +148,10 @@ class _ToVerilogConvertor(object):
_converting = 0
else:
warnings.warn(
"\n toVerilog(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
"\n toVerilog(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html",
stacklevel=2,
category=DeprecationWarning,
)
try:
h = _HierExtr(name, func, *args, **kwargs)
finally:

View File

@ -115,7 +115,10 @@ class _VerificationClass(object):
name = func.func.__name__
else:
warnings.warn(
"\n analyze()/verify(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
"\n analyze()/verify(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html",
stacklevel=2,
category=DeprecationWarning,
)
try:
name = func.__name__
except:

View File

@ -12,6 +12,7 @@ from myhdl.conversion import verify
ACTIVE_LOW, INACTIVE_HIGH = bool(0), bool(1)
@block
def bug_1740778 ():
""" Conversion of min and max attribute.
@ -32,5 +33,5 @@ def bug_1740778 ():
def test_bug_1740778 ():
assert verify(bug_1740778) == 0
assert bug_1740778().verify_convert() == 0

View File

@ -7,11 +7,10 @@ random.seed(2)
import myhdl
from myhdl import *
from myhdl.conversion import verify
ACTIVE_LOW, INACTIVE_HIGH = bool(0), bool(1)
@block
def bug_1835792 ():
""" Semicolon conversion
@ -28,5 +27,5 @@ def bug_1835792 ():
def test_bug_1835792 ():
assert verify(bug_1835792) == 0
assert bug_1835792().verify_convert() == 0

View File

@ -7,11 +7,10 @@ random.seed(2)
import myhdl
from myhdl import *
from myhdl.conversion import verify
ACTIVE_LOW, INACTIVE_HIGH = bool(0), bool(1)
@block
def bug_1835797():
""" Docstring in the middle.
@ -29,5 +28,5 @@ def bug_1835797():
def test_bug_1835797():
assert verify(bug_1835797) == 0
assert bug_1835797().verify_convert() == 0

View File

@ -3,7 +3,8 @@ from myhdl import *
from myhdl import ConversionError
from myhdl.conversion._misc import _error
def SubFunction(xout,yout,xin,yin):
@block
def SubFunction_1837003(xout,yout,xin,yin):
@always_comb
def logic():
x = 4
@ -13,8 +14,8 @@ def SubFunction(xout,yout,xin,yin):
return instances()
def Function(xout,yout,x,y):
return SubFunction(xout,yout,x,y)
#def Function_1837003(xout,yout,x,y):
# return SubFunction_1837003(xout,yout,x,y)
x = Signal(bool(0))
y = Signal(bool(0))
@ -25,7 +26,7 @@ yin = Signal(bool(0))
def test_bug_1837003():
try:
toVerilog(SubFunction,xout,yout,x,y)
SubFunction_1837003(xout,yout,x,y).convert(hdl='Verilog')
except ConversionError as e:
assert e.kind == _error.ShadowingVar
else:

View File

@ -1,6 +1,7 @@
import myhdl
from myhdl import *
@block
def bug_28(dout, channel):
@always_comb
def comb():
@ -12,6 +13,6 @@ channel = Signal(intbv(0)[4:0])
def test_bug_28():
try:
toVHDL(bug_28, dout, channel)
bug_28(dout, channel).convert(hdl='VHDL')
except:
raise

View File

@ -1,6 +1,7 @@
import myhdl
from myhdl import *
@block
def bug_3529686(clr, clk, run, ack, serialout):
@always(clk.posedge, clr.posedge)
@ -21,6 +22,6 @@ clr, clk, run, ack, serialout = [Signal(bool()) for i in range(5)]
def test_bug_3529686():
try:
toVHDL(bug_3529686, clr, clk, run, ack, serialout)
bug_3529686(clr, clk, run, ack, serialout).convert(hdl='VHDL')
except:
assert False

View File

@ -1,7 +1,7 @@
import myhdl
from myhdl import *
from myhdl.conversion import analyze
@block
def bug_3577799 (
clk,
reset_clk,
@ -33,4 +33,4 @@ wr = Signal(bool(0))
rd_data = Signal(intbv(0)[16:])
def test_bug_3577799():
assert analyze(bug_3577799, clk, reset_clk, wr_data, wr, rd_data) == 0
assert bug_3577799(clk, reset_clk, wr_data, wr, rd_data).analyze_convert() == 0

View File

@ -1,7 +1,7 @@
import myhdl
from myhdl import *
from myhdl.conversion import verify
@block
def dut():
rx = Signal(intbv(0, min=-512, max=512))
@ -31,6 +31,6 @@ def dut():
return logic, check
def test_bug_39():
assert verify(dut) == 0
assert dut().verify_convert() == 0

View File

@ -3,7 +3,8 @@
import myhdl
from myhdl import *
def module(sigin, sigout):
@block
def module_42(sigin, sigout):
# Using @always(sigin) only warns, but using @always_comp breaks.
# The reason is that len(sigout) is interpreted as sigout being used as
@ -19,5 +20,5 @@ sigin = Signal(intbv(0)[2:])
sigout = Signal(intbv(0)[2:])
def test_bug_42():
toVHDL(module, sigin, sigout)
module_42(sigin, sigout).convert(hdl='VHDL')

View File

@ -3,7 +3,8 @@
import myhdl
from myhdl import *
def module(sigin, sigout):
@block
def module42_2(sigin, sigout):
# Using @always(sigin) only warns, but using @always_comp breaks.
# The reason is that len(sigout) is interpreted as sigout being used as
@ -18,8 +19,8 @@ sigin = Signal(intbv(0)[2:])
sigout = Signal(intbv(0)[2:])
def test_bug_42_2():
toVHDL(module, sigin, sigout)
module42_2(sigin, sigout).convert(hdl='VHDL')
toVHDL(module, sigin, sigout)
module42_2(sigin, sigout).convert(hdl='VHDL')

View File

@ -3,6 +3,7 @@
import myhdl
from myhdl import *
@block
def bug_43(sigin, sigout):
@always_comb
@ -20,6 +21,6 @@ def test_bug_43():
sigin = Signal(intbv(0)[4:])
sigout = Signal(intbv(0)[4:])
assert conversion.analyze(bug_43, sigin, sigout) == 0
assert bug_43(sigin, sigout).analyze_convert() == 0

View File

@ -1,7 +1,7 @@
import myhdl
from myhdl import *
from myhdl.conversion import verify
@block
def dut():
count = Signal(intbv(0, min=0, max=98))
@ -21,5 +21,5 @@ def dut():
def test_bug_aj1s():
assert verify(dut) == 0
assert dut().verify_convert() == 0

View File

@ -6,6 +6,7 @@ INT_CONDITION_1 = 1
BOOL_CONDITION_0 = False
BOOL_CONDITION_1 = True
@block
def bug_boolconst(sigin, sigout):
@always_comb
@ -34,6 +35,6 @@ def test_bug_boolconst():
sigin = Signal(bool())
sigout = Signal(bool())
assert conversion.analyze(bug_boolconst, sigin, sigout) == 0
assert bug_boolconst(sigin, sigout).analyze_convert() == 0

View File

@ -1,7 +1,8 @@
import myhdl
from myhdl import *
def gray_counter (clk, reset, enable, gray_count):
@block
def gray_counter_bug_boolop (clk, reset, enable, gray_count):
q = Signal(intbv(0)[10:])
no_ones_below = Signal(intbv(0)[10:])
@ -33,7 +34,7 @@ gray_count = Signal(intbv(0)[8:])
def test_bug_boolop():
try:
toVerilog(gray_counter, clk, reset, enable, gray_count)
toVHDL(gray_counter, clk, reset, enable, gray_count)
gray_counter_bug_boolop(clk, reset, enable, gray_count).convert(hdl='Verilog')
gray_counter_bug_boolop(clk, reset, enable, gray_count).convert(hdl='VHDL')
except:
assert False

View File

@ -4,7 +4,7 @@ from myhdl import *
# t_state = enum('WAIT_POSEDGE', 'WAIT_NEGEDGE', encoding='one_hot')
t_state = enum('WAIT_POSEDGE', 'WAIT_NEGEDGE')
@block
def pcie_legacyint_next_state_logic(state_i, next_state_o, next_state_en_o, interrupt_pending_i, interrupt_assert_o):
@always_comb
@ -33,9 +33,4 @@ interrupt_assert = Signal(bool(0))
def test_bug_enum_toVHDL():
toVHDL(pcie_legacyint_next_state_logic, state, next_state, next_state_en, interrupt_pending, interrupt_assert)
if __name__ == '__main__':
toVHDL(pcie_legacyint_next_state_logic, state, next_state, next_state_en, interrupt_pending, interrupt_assert)
pcie_legacyint_next_state_logic(state, next_state, next_state_en, interrupt_pending, interrupt_assert).convert(hdl='VHDL')

View File

@ -3,8 +3,8 @@ from myhdl import *
t_state = enum('WAIT_POSEDGE', 'WAIT_NEGEDGE', encoding='one_hot')
def pcie_legacyint_next_state_logic(state_i, next_state_o, next_state_en_o, interrupt_pending_i, interrupt_assert_o):
@block
def pcie_legacyint_next_state_logic_2(state_i, next_state_o, next_state_en_o, interrupt_pending_i, interrupt_assert_o):
@always_comb
def sm_output(): # state machine
@ -32,8 +32,4 @@ interrupt_assert = Signal(bool(0))
def test_bug_enum_toVHDL_2():
assert conversion.analyze(pcie_legacyint_next_state_logic, state, next_state, next_state_en, interrupt_pending, interrupt_assert) == 0
if __name__ == '__main__':
toVHDL(pcie_legacyint_next_state_logic, state, next_state, next_state_en, interrupt_pending, interrupt_assert)
assert pcie_legacyint_next_state_logic_2(state, next_state, next_state_en, interrupt_pending, interrupt_assert).analyze_convert() == 0

View File

@ -1,9 +1,10 @@
import pytest
from myhdl import Simulation, delay, SimulationError, instance, now
from myhdl import Simulation, delay, SimulationError, instance, now, block
from myhdl._Simulation import _error
from helpers import raises_kind
def test():
@block
def dut():
@instance
def tbstim():
yield delay(10)
@ -17,21 +18,21 @@ def test():
def issue_104_quit_method():
sim = Simulation(test())
sim = Simulation(dut())
sim.run(1000)
sim.run(500)
sim.quit()
return sim._finished
def issue_104_multiple_instance():
sim1 = Simulation(test())
sim1 = Simulation(dut())
sim1.run(1000)
# sim1 is "puased"
# try and create a second, third, forth simulation instance
for ii in range(4):
with raises_kind(SimulationError, _error.MultipleSim):
another_sim = Simulation(test())
another_sim = Simulation(dut())
# generating more sims should have failed
sim1.run(1000)
sim1.quit()

View File

@ -1,10 +1,9 @@
#!/usr/bin/python2.7-32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Failed VHDL code example
"""
import myhdl
from myhdl import *
from myhdl.conversion import verify
def unsigned(width, value=0, cls=intbv):
"""Create an unsigned signal based on a bitvector with the
@ -22,6 +21,7 @@ def signed(width, value=0, cls=intbv):
flags = unsigned(4)
position = signed(28)
@block
def Logic(flags, position):
conc = unsigned(32)
@ -37,4 +37,4 @@ def Logic(flags, position):
return doit
def test_issue_10_2():
assert verify(Logic, flags, position) == 0
assert Logic(flags, position).verify_convert() == 0

View File

@ -1,7 +1,8 @@
import myhdl
from myhdl import *
from myhdl.conversion import analyze
#from myhdl.conversion import analyze
@block
def issue_117(clk, sdi, pdo, sel, const=False):
assert isinstance(const, (bool, intbv))
delay_reg = Signal(intbv(0)[8:])
@ -23,7 +24,7 @@ def test_issue_117_1():
pdo = Signal(intbv(0)[8:])
sel = Signal(intbv(0, min=0, max=3))
toVHDL.name = toVerilog.name = 'issue_117_1'
assert analyze(issue_117, clk, sdi, pdo, sel, const=bool(0))== 0
assert issue_117(clk, sdi, pdo, sel, const=bool(0)).analyze_convert() == 0
def test_issue_117_2():
@ -31,7 +32,7 @@ def test_issue_117_2():
pdo = Signal(intbv(0)[8:])
sel = Signal(intbv(0, min=0, max=3))
toVHDL.name = toVerilog.name = 'issue_117_2'
assert analyze(issue_117, clk, sdi, pdo, sel, const=False)== 0
assert issue_117(clk, sdi, pdo, sel, const=False).analyze_convert() == 0
def test_issue_117_3():
@ -39,7 +40,7 @@ def test_issue_117_3():
pdo = Signal(intbv(0)[8:])
sel = Signal(intbv(0, min=0, max=3))
toVHDL.name = toVerilog.name = 'issue_117_3'
assert analyze(issue_117, clk, sdi, pdo, sel, const=intbv(0)[1:])== 0
assert issue_117(clk, sdi, pdo, sel, const=intbv(0)[1:]).analyze_convert() == 0
if __name__ == '__main__':

View File

@ -1,14 +1,15 @@
import myhdl
from myhdl import *
from myhdl.conversion import verify
from myhdl import ConversionError
from myhdl.conversion._misc import _error
@block
def issue_122(dout, i):
d = i*10+1
@instance
def write():
# dout[i].next = int(i)
dout[i].next = i
yield delay(d)
print(int(dout[i]))
@ -26,5 +27,9 @@ def tb_issue_122():
return inst
def test_issue_122():
assert verify(tb_issue_122) == 0
try:
tb_issue_122().verify_convert()
except ConversionError as e:
assert e.kind == _error.ListAsPort
else:
assert False

View File

@ -7,7 +7,7 @@ from random import randrange
from myhdl import Signal, intbv, \
always_comb, instance, \
delay, toVHDL, StopSimulation
delay, StopSimulation, block
ASCENDING = True
@ -15,7 +15,7 @@ DESCENDING = False
# modules
@block
def compare(a_1, a_2, z_1, z_2, direction):
""" Combinatorial circuit with two input and two output signals.
Sorting to 'direction'. """
@ -32,7 +32,7 @@ def compare(a_1, a_2, z_1, z_2, direction):
return logic
@block
def feedthru(in_a, out_z):
""" Equivalent of 'doing nothing'. """
@ -43,7 +43,7 @@ def feedthru(in_a, out_z):
return logic
@block
def bitonic_merge(list_a, list_z, direction):
""" bitonicMerge:
Generates the output from the input list of signals.
@ -66,7 +66,7 @@ def bitonic_merge(list_a, list_z, direction):
feed = feedthru(list_a[0], list_z[0])
return feed
@block
def bitonic_sort(list_a, list_z, direction):
""" bitonicSort:
Produces a bitonic sequence.
@ -89,8 +89,8 @@ def bitonic_sort(list_a, list_z, direction):
# tests
def array8sorter(a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7,
@block
def array8sorter_127(a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7,
z_0, z_1, z_2, z_3, z_4, z_5, z_6, z_7):
''' Sort Array with 8 values '''
@ -116,7 +116,7 @@ class TestBitonicSort(unittest.TestCase):
z_0, z_1, z_2, z_3, z_4, z_5, z_6, z_7 = outputs
a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7 = inputs
inst = array8sorter(a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7,
inst = array8sorter_127(a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7,
z_0, z_1, z_2, z_3, z_4, z_5, z_6, z_7)
@instance
@ -142,5 +142,5 @@ def test_issue_127():
length = 8
width = 4
sigs = [Signal(intbv(0)[width:]) for _ in range(2*length)]
toVHDL(array8sorter, *sigs)
array8sorter_127(*sigs).convert(hdl='VHDL')

View File

@ -1,7 +1,6 @@
import myhdl
from myhdl import *
from myhdl.conversion import analyze
@block
def issue_13(reset, clk, d, en, q):
COSET = 0x55
@ -38,5 +37,5 @@ def test_issue_13():
# toVHDL.numeric_ports = False
assert analyze(issue_13, reset, clk, d, en, q) == 0
issue_13(reset, clk, d, en, q).analyze_convert() == 0

View File

@ -1,7 +1,7 @@
import myhdl
from myhdl import *
from myhdl.conversion import verify
@block
def issue_133():
z = Signal(False)
large_signal = Signal(intbv(123456789123456, min=0, max=2**256))
@ -16,4 +16,4 @@ def issue_133():
return check
def test_issue_133():
assert verify(issue_133) == 0
issue_133().verify_convert() == 0

View File

@ -6,26 +6,27 @@ function is called multiple times, this causes name collisions """
import pytest
import myhdl
from myhdl import *
from myhdl.conversion import analyze
class AB:
def __init__(self):
self.a = Signal(bool(False))
self.b = Signal(bool(False))
@block
def invert(sigin, sigout):
@always_comb
def foo():
sigout.next = not sigin
return foo
@block
def issue_134(ab_in, ab_out):
""" Instantiate an inverter for each signal """
inverta = invert(ab_in.a, ab_out.a)
invertb = invert(ab_in.b, ab_out.b)
return inverta, invertb
@pytest.mark.xfail
#@pytest.mark.xfail
def test_issue_134():
""" check for port name collision"""
assert analyze(issue_134, AB(), AB()) == 0
assert issue_134(AB(), AB()).analyze_convert() == 0

View File

@ -3,7 +3,7 @@ from myhdl import Signal, block, delay, instance
import pytest
class Test1:
class MyTest1:
def __init__(self):
self.clock = Signal(bool(0))
@ -21,7 +21,7 @@ class Test1:
return func
class Test2:
class MyTest2:
def __init__(self):
self.clock = Signal(bool(1))
@ -40,9 +40,9 @@ class Test2:
@block
def test_bench():
inst1 = Test1()
inst2 = Test2()
def mytest_bench():
inst1 = MyTest1()
inst2 = MyTest2()
# Two instances are created
ins1 = inst1.test()
@ -50,11 +50,8 @@ def test_bench():
return ins1, ins2
@pytest.mark.xfail
#@pytest.mark.xfail
def test_issue_169():
test_inst = test_bench()
assert test_inst.verify_convert() == True
if __name__ == '__main__':
test_issue_169()
test_inst = mytest_bench()
test_inst.verify_convert()

View File

@ -1,7 +1,7 @@
import myhdl
from myhdl import *
from myhdl.conversion import analyze
@block
def issue_18(dout, din, addr, we, clk, depth=128):
""" Ram model """
@ -28,5 +28,5 @@ clk = Signal(bool(0))
def test_issue_18():
toVHDL.std_logic_ports = True
assert analyze(issue_18, dout, din, addr, we, clk) == 0
assert issue_18(dout, din, addr, we, clk).analyze_convert() == 0

View File

@ -3,6 +3,7 @@
import myhdl
from myhdl import *
@block
def mpegChannel(clk, rst):
s_tx_data_xor_mask_r = Signal(intbv(0)[1 + 31:])
@ -27,6 +28,6 @@ def test_issue_40():
clk = Signal(bool(0))
rst = ResetSignal(0, active=1, isasync=True)
assert conversion.analyze(mpegChannel, clk, rst) == 0
assert mpegChannel(clk, rst).analyze_convert() == 0

View File

@ -1,9 +1,10 @@
import myhdl
from myhdl import *
from myhdl.conversion import analyze
#from myhdl.conversion import analyze
import pytest
@block
def issue_98(sda, scl, sda_i, sda_o, scl_i, scl_o):
sda_d, scl_d = sda.driver(), scl.driver()
@always_comb
@ -14,21 +15,24 @@ def issue_98(sda, scl, sda_i, sda_o, scl_i, scl_o):
scl_d.next = None if not scl_o else 1
return hdl
@pytest.mark.xfail
def test_issue_98_1():
sda_i, sda_o, scl_i, scl_o = [Signal(False) for i in range(4)]
sda, scl = [TristateSignal(False) for i in range(2)]
toVHDL.name = toVerilog.name = 'issue_98_1'
assert analyze(issue_98, sda, scl, sda_i, sda_o, scl_i, scl_o) == 0
assert issue_98(sda, scl, sda_i, sda_o, scl_i, scl_o).analyze_convert() == 0
@pytest.mark.xfail
def test_issue_98_2():
sda_i, sda_o, scl_i, scl_o = [Signal(intbv(0)[2:0]) for i in range(4)]
sda, scl = [TristateSignal(intbv(0)[2:0]) for i in range(2)]
toVHDL.name = toVerilog.name = 'issue_98_2'
assert analyze(issue_98, sda, scl, sda_i, sda_o, scl_i, scl_o) == 0
assert issue_98(sda, scl, sda_i, sda_o, scl_i, scl_o).analyze_convert() == 0
@pytest.mark.xfail
def test_issue_98_3():
sda_i, sda_o, scl_i, scl_o = [Signal(intbv(0)[1:0]) for i in range(4)]
sda, scl = [TristateSignal(intbv(0)[1:0]) for i in range(2)]
toVHDL.name = toVerilog.name = 'issue_98_3'
assert analyze(issue_98, sda, scl, sda_i, sda_o, scl_i, scl_o) == 0
assert issue_98(sda, scl, sda_i, sda_o, scl_i, scl_o).analyze_convert() == 0

View File

@ -0,0 +1,41 @@
from myhdl import *
import pytest
def bin2gray_depr(B, G, width):
""" Gray encoder.
B -- input intbv signal, binary encoded
G -- output intbv signal, gray encoded
width -- bit width
"""
@always_comb
def logic():
Bext = intbv(0)[width+1:]
Bext[:] = B
for i in range(width):
G.next[i] = Bext[i+1] ^ Bext[i]
return logic
width = 1
BB = Signal(intbv(0)[width:])
GG = Signal(intbv(0)[width:])
def testOldVerify():
with pytest.deprecated_call():
conversion.verify(bin2gray_depr, width, BB, GG)
def testOldAnalyze():
with pytest.deprecated_call():
conversion.analyze(bin2gray_depr, width, BB, GG)
def testOldToVHDL():
with pytest.deprecated_call():
toVHDL(bin2gray_depr, width, BB, GG)
def testOldToVerilog():
with pytest.deprecated_call():
toVerilog(bin2gray_depr, width, BB, GG)

View File

@ -5,6 +5,7 @@ import myhdl
from myhdl import *
@block
def NonlocalBench():
ALL_ONES = 2**7-1
@ -60,5 +61,5 @@ def NonlocalBench():
def test_nonlocal():
assert conversion.verify(NonlocalBench) == 0
assert NonlocalBench().verify_convert() == 0

View File

@ -5,6 +5,7 @@ from myhdl.conversion._misc import _error
t_State = enum("START", "RUN", "STOP")
@block
def PrintBench():
si1 = Signal(intbv(0)[8:])
si2 = Signal(intbv(0, min=-10, max=12))
@ -66,8 +67,9 @@ def PrintBench():
return logic
def testPrint():
assert conversion.verify(PrintBench) == 0
assert PrintBench().verify_convert() == 0
@block
def PrintLongVectorsBench():
N84 = 84
M84 = 2**N84-1
@ -105,13 +107,11 @@ def PrintLongVectorsBench():
return logic
def testPrintLongVectors():
assert conversion.verify(PrintLongVectorsBench) == 0
def testPrint():
assert conversion.verify(PrintBench) == 0
assert PrintLongVectorsBench().verify_convert() == 0
# format string errors and unsupported features
@block
def PrintError1():
@instance
def logic():
@ -122,12 +122,13 @@ def PrintError1():
def testPrintError1():
try:
conversion.verify(PrintError1)
PrintError1().verify_convert()
except ConversionError as e:
assert e.kind == _error.UnsupportedFormatString
else:
assert False
@block
def PrintError2():
@instance
def logic():
@ -138,12 +139,13 @@ def PrintError2():
def testPrintError2():
try:
conversion.verify(PrintError2)
PrintError2().verify_convert()
except ConversionError as e:
assert e.kind == _error.FormatString
else:
assert False
@block
def PrintError3():
@instance
def logic():
@ -155,12 +157,13 @@ def PrintError3():
def testPrintError3():
try:
conversion.verify(PrintError3)
PrintError3().verify_convert()
except ConversionError as e:
assert e.kind == _error.FormatString
else:
assert False
@block
def PrintError4():
@instance
def logic():
@ -171,12 +174,13 @@ def PrintError4():
def testPrintError4():
try:
conversion.verify(PrintError4)
PrintError4().verify_convert()
except ConversionError as e:
assert e.kind == _error.UnsupportedFormatString
else:
assert False
@block
def PrintError5():
@instance
def logic():
@ -187,7 +191,7 @@ def PrintError5():
def testPrintError5():
try:
conversion.verify(PrintError5)
PrintError5().verify_convert()
except ConversionError as e:
assert e.kind == _error.UnsupportedFormatString
else:

View File

@ -16,12 +16,14 @@ def bitwise(a, b, op):
r[:] = a ^ b
return r
@block
def LogicUnit(a, b, c, op):
@always_comb
def operate():
c.next = bitwise(a,b,op)
return operate
@block
def bench_enum():
clock = Signal(False)
a, b, c = [Signal(intbv(0)[8:]) for i in range(3)]
@ -63,5 +65,5 @@ def bench_enum():
return instances()
def test_enum():
assert conversion.verify(bench_enum) == 0
assert bench_enum().verify_convert() == 0

View File

@ -8,6 +8,7 @@ from myhdl.conversion import verify, analyze
from myhdl import ConversionError
from myhdl.conversion._misc import _error
@block
def ForLoopError1(a, out):
@instance
def logic():
@ -20,7 +21,7 @@ def ForLoopError1(a, out):
out.next = var
return logic
@block
def LoopBench(LoopTest):
a = Signal(intbv(-1)[16:])
@ -41,7 +42,7 @@ def LoopBench(LoopTest):
def testForLoopError1():
try:
analyze(LoopBench, ForLoopError1)
LoopBench(ForLoopError1).analyze_convert()
except ConversionError as e:
assert e.kind == _error.Requirement
else:

View File

@ -14,6 +14,7 @@ from myhdl.conversion._misc import _error
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def incRef(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -35,6 +36,7 @@ def incRef(count, enable, clock, reset, n):
return logic
@block
def incGen(count, enable, clock, reset, n):
""" Generator with __vhdl__ is not permitted """
@instance
@ -50,6 +52,7 @@ def incGen(count, enable, clock, reset, n):
return logic
@block
def inc(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -87,6 +90,7 @@ end process;
return incProcess
@block
def incErr(count, enable, clock, reset, n):
@always(clock.posedge, reset.negedge)
@ -119,6 +123,7 @@ end
@block
def inc_comb(nextCount, count, n):
@always_comb
@ -136,6 +141,7 @@ $nextCount <= ($count + 1) mod $n;
return logic
@block
def inc_seq(count, nextCount, enable, clock, reset):
@always(clock.posedge, reset.negedge)
@ -163,6 +169,7 @@ end process;
return logic
@block
def inc2(count, enable, clock, reset, n):
nextCount = Signal(intbv(0, min=0, max=n))
@ -173,11 +180,13 @@ def inc2(count, enable, clock, reset, n):
return comb, seq
@block
def inc3(count, enable, clock, reset, n):
inc2_inst = inc2(count, enable, clock, reset, n)
return inc2_inst
@block
def clockGen(clock):
@instance
def logic():
@ -191,6 +200,7 @@ NRTESTS = 1000
ENABLES = tuple([min(1, randrange(5)) for i in range(NRTESTS)])
@block
def stimulus(enable, clock, reset):
@instance
def logic():
@ -209,6 +219,7 @@ def stimulus(enable, clock, reset):
return logic
@block
def check(count, enable, clock, reset, n):
@instance
def logic():
@ -227,6 +238,7 @@ def check(count, enable, clock, reset, n):
return logic
@block
def customBench(inc):
m = 8
@ -246,20 +258,20 @@ def customBench(inc):
def testIncRef():
assert conversion.verify(customBench, incRef) == 0
assert customBench(incRef).verify_convert() == 0
def testInc():
assert conversion.verify(customBench, inc) == 0
assert customBench(inc).verify_convert() == 0
def testInc2():
assert conversion.verify(customBench, inc2) == 0
assert customBench(inc2).verify_convert() == 0
def testInc3():
assert conversion.verify(customBench, inc3) == 0
assert customBench(inc3).verify_convert() == 0
def testIncGen():
try:
assert conversion.verify(customBench, incGen) == 0
assert customBench(incGen).verify_convert() == 0
except ConversionError as e:
pass
else:
@ -267,7 +279,7 @@ def testIncGen():
def testIncErr():
try:
assert conversion.verify(customBench, incErr) == 0
assert customBench(incErr).verify_convert() == 0
except ConversionError as e:
pass
else:

View File

@ -10,6 +10,7 @@ from myhdl.conversion import verify
NRTESTS = 10
@block
def binaryOps(
Bitand,
Bitor,
@ -69,7 +70,7 @@ def binaryOps(
Boolor.next = bool(left) or bool(right)
return logic
@block
def binaryBench(m, n):
M = 2**m
@ -173,17 +174,12 @@ def binaryBench(m, n):
return binops, stimulus, check
def checkBinary(m, n):
assert verify(binaryBench, m, n) == 0
def testBinary():
for m, n in ((4, 4,), (5, 3), (2, 6), (8, 7)):
# for m, n in ((2, 6),):
yield checkBinary, m, n
assert binaryBench(m, n).verify_convert() == 0
@block
def multiOps(
Bitand,
Bitor,
@ -204,6 +200,7 @@ def multiOps(
@block
def multiBench(m, n, p):
M = 2**m
@ -265,14 +262,11 @@ def multiBench(m, n, p):
return multiops, stimulus, check
def checkMultiOps(m, n, p):
assert verify(multiBench, m, n, p) == 0
def testMultiOps():
for m, n, p in ((4, 4, 4,), (5, 3, 2), (3, 4, 6), (3, 7, 4)):
yield checkMultiOps, m, n, p
assert multiBench(m, n, p).verify_convert() == 0
@block
def unaryOps(
Not_kw,
Invert,
@ -290,6 +284,7 @@ def unaryOps(
# UnarySub.next = --arg
return logic
@block
def unaryBench(m):
M = 2**m
@ -327,14 +322,11 @@ def unaryBench(m):
return unaryops, stimulus, check
def checkUnaryOps(m):
assert verify(unaryBench, m) == 0
def testUnaryOps():
for m in (4, 7):
yield checkUnaryOps, m
assert unaryBench(m).verify_convert() == 0
@block
def augmOps( Bitand,
Bitor,
Bitxor,
@ -392,11 +384,8 @@ def augmOps( Bitand,
var >>= right
RightShift.next = var
return logic
@block
def augmBench(m, n):
M = 2**m
@ -470,11 +459,7 @@ def augmBench(m, n):
return augmops, stimulus, check
def checkAugmOps(m, n):
assert verify(augmBench, m, n) == 0
def testAugmOps():
for m, n in ((4, 4,), (5, 3), (2, 6), (8, 7)):
yield checkAugmOps, m, n
assert augmBench(m, n).verify_convert() == 0

View File

@ -10,6 +10,7 @@ from myhdl.conversion import verify
NRTESTS = 10
@block
def binaryOps(
Bitand,
## Bitor,
@ -71,7 +72,7 @@ def binaryOps(
return logic
@block
def binaryBench(Ll, Ml, Lr, Mr):
seqL = []
@ -186,9 +187,6 @@ def binaryBench(Ll, Ml, Lr, Mr):
return binops, stimulus, check
def checkBinaryOps( Ll, Ml, Lr, Mr):
assert verify(binaryBench, Ll, Ml, Lr, Mr ) == 0
def testBinaryOps():
for Ll, Ml, Lr, Mr in (
(-254, 236, 0, 4),
@ -199,12 +197,9 @@ def testBinaryOps():
(-54, -20, 45, 73),
(-25, -12, -123, -66),
):
yield checkBinaryOps, Ll, Ml, Lr, Mr
assert binaryBench(Ll, Ml, Lr, Mr ).verify_convert() == 0
@block
def unaryOps(
BoolNot,
Invert,
@ -221,10 +216,7 @@ def unaryOps(
UnarySub.next = --arg
return logic
@block
def unaryBench( m):
M = 2**m
@ -263,18 +255,13 @@ def unaryBench( m):
return unaryops, stimulus, check
def checkUnaryOps(m):
assert verify(unaryBench, m) == 0
def testUnaryOps():
for m in (4, 7):
yield checkUnaryOps, m
assert unaryBench(m).verify_convert() == 0
@block
def augmOps(
## Bitand,
## Bitor,
@ -338,7 +325,7 @@ def augmOps(
return logic
@block
def augmBench( Ll, Ml, Lr, Mr):
M = 2**17
@ -425,9 +412,9 @@ def testAugmOps():
(-54, -20, 45, 73),
(-25, -12, -123, -66),
):
yield checkAugmOps, Ll, Ml, Lr, Mr
assert augmBench(Ll, Ml, Lr, Mr).verify_convert() == 0
@block
def expressions(a, b, clk):
c = Signal(intbv(0, min=0, max=47))
@ -477,7 +464,7 @@ def expressions(a, b, clk):
return logic
@block
def expressionsBench():
a = Signal(intbv(0, min=-34, max=47))
@ -504,7 +491,7 @@ def expressionsBench():
def testExpressions():
assert verify(expressionsBench) == 0
assert expressionsBench().verify_convert() == 0

View File

@ -13,7 +13,8 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
def GrayInc(graycnt, enable, clock, reset, width):
@block
def GrayInc_0(graycnt, enable, clock, reset, width):
bincnt = Signal(intbv(0)[width:])
@ -22,12 +23,12 @@ def GrayInc(graycnt, enable, clock, reset, width):
return inc_1, bin2gray_1
def GrayIncReg(graycnt, enable, clock, reset, width):
@block
def GrayIncReg_0(graycnt, enable, clock, reset, width):
graycnt_comb = Signal(intbv(0)[width:])
gray_inc_1 = GrayInc(graycnt_comb, enable, clock, reset, width)
gray_inc_1 = GrayInc_0(graycnt_comb, enable, clock, reset, width)
@always(clock.posedge)
def reg_1():
@ -75,25 +76,19 @@ class TestGrayInc(unittest.TestCase):
self.assertEqual(graycnt, graycnt_v)
def bench(self):
gray_inc_reg_1 = toVerilog(GrayIncReg, graycnt, enable, clock, reset, width)
gray_inc_reg_v = GrayIncReg_v(GrayIncReg.__name__, graycnt_v, enable, clock, reset, width)
gray_inc_reg_1 = GrayIncReg_0(graycnt, enable, clock, reset, width).convert(hdl='Verilog')
gray_inc_reg_v = GrayIncReg_v(GrayIncReg_0.__name__, graycnt_v, enable, clock, reset, width)
clk_1 = self.clockGen()
st_1 = self.stimulus()
ch_1 = self.check()
sim = Simulation(gray_inc_reg_1, gray_inc_reg_v, clk_1, st_1, ch_1)
return sim
def test(self):
def test_grayinc(self):
""" Check gray inc operation """
sim = self.bench()
sim.run(quiet=1)
if __name__ == '__main__':
unittest.main()

View File

@ -11,20 +11,20 @@ class TestNotSupported(unittest.TestCase):
def check(self, *args):
try:
i = toVerilog(*args)
args[0](*args[1:]).convert(hdl='Verilog')
except ConversionError as e:
self.assertEqual(e.kind, _error.NotSupported)
except:
self.fail()
else:
self.fail()
except Exception as e:
raise e
def nocheck(self, *args):
i = toVerilog(*args)
args[0](*args[1:]).convert(hdl='Verilog')
def testAssList(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -33,11 +33,14 @@ class TestNotSupported(unittest.TestCase):
z.next = 1
[p, q] = 1, 2
return logic
self.check(g, z, a)
def testAssTuple(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -51,6 +54,8 @@ class TestNotSupported(unittest.TestCase):
def testClass(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -66,6 +71,8 @@ class TestNotSupported(unittest.TestCase):
def testDict(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -79,6 +86,8 @@ class TestNotSupported(unittest.TestCase):
def testDiv(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -91,6 +100,8 @@ class TestNotSupported(unittest.TestCase):
def testFrom(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -104,6 +115,8 @@ class TestNotSupported(unittest.TestCase):
def testFunction(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -118,6 +131,8 @@ class TestNotSupported(unittest.TestCase):
def testGlobal(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -131,6 +146,8 @@ class TestNotSupported(unittest.TestCase):
def testImport(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -144,6 +161,8 @@ class TestNotSupported(unittest.TestCase):
def testLambda(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -157,6 +176,8 @@ class TestNotSupported(unittest.TestCase):
def testListCompIf(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -170,6 +191,8 @@ class TestNotSupported(unittest.TestCase):
def testList(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -202,6 +225,8 @@ class TestNotSupported(unittest.TestCase):
def testTryExcept(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -218,6 +243,8 @@ class TestNotSupported(unittest.TestCase):
def testTryFinally(self):
a = Signal(bool())
z = Signal(bool())
@block
def g(z, a):
@instance
def logic():
@ -234,6 +261,8 @@ class TestNotSupported(unittest.TestCase):
def testChainedCompare(self):
a, b, c = [Signal(bool()) for i in range(3)]
z = Signal(bool())
@block
def g(z, a, b, c):
@instance
def logic():
@ -271,6 +300,8 @@ class TestNotSupported(unittest.TestCase):
a = Signal(bool())
b = intbv(0)[2:]
z = Signal(bool())
@block
def g(z, a, b):
@instance
def logic():
@ -288,6 +319,8 @@ class TestNotSupported(unittest.TestCase):
b = intbv(0)[2:]
c = Signal(bool())
z = Signal(bool())
@block
def g(z, a, b):
@instance
def logic():
@ -303,28 +336,37 @@ class TestNotSupported(unittest.TestCase):
def testExtraArguments(self):
a, b, c = [Signal(bool()) for i in range(3)]
c = [1, 2]
def g(a, *args):
return a
@block
def f(a, b, c, *args):
@instance
def logic():
g(a, b)
yield a
return logic
self.check(f, a, b, c)
def testExtraPositionalArgsInCall(self):
a, b, c = [Signal(bool()) for i in range(3)]
c = [1]
d = {'b':2}
def h(b):
return b
@block
def g(a):
@instance
def logic():
h(*c)
yield a
return logic
@block
def f(a, b, c):
return g(a)
x = self.check(f, a, b, c)
@ -333,14 +375,19 @@ class TestNotSupported(unittest.TestCase):
a, b, c = [Signal(bool()) for i in range(3)]
c = [1]
d = {'b':2}
def h(b):
return b
@block
def g(a):
@instance
def logic():
h(**d)
yield a
return logic
@block
def f(a, b, c):
return g(a)
x = self.check(f, a, b, c)
@ -354,21 +401,20 @@ class TestMisc(unittest.TestCase):
d = {'a':2}
def h(b):
return b
@block
def g(a):
@instance
def logic():
h(a)
yield a
return logic
# b and c are not being used
@block
def f(a, b, c):
return g(a)
f(a, b, c)
x = toVerilog(f, a, b, c)
if __name__ == '__main__':
unittest.main()
x = f(a, b, c).convert(hdl='Verilog')

View File

@ -34,11 +34,13 @@ from .util import setupCosimulation
QUIET = 1
@block
def design1(a, b, c, d, p, q, r):
def logic():
p.next = a | b
return always_comb(logic)
@block
def design2(a, b, c, d, p, q, r):
def logic():
p.next = a | b
@ -46,6 +48,7 @@ def design2(a, b, c, d, p, q, r):
r.next = a ^ c
return always_comb(logic)
@block
def design3(a, b, c, d, p, q, r):
def logic():
if a:
@ -54,6 +57,7 @@ def design3(a, b, c, d, p, q, r):
r.next = d ^ c
return always_comb(logic)
@block
def design4(a, b, c, d, p, q, r):
def logic():
p.next = a | b
@ -62,6 +66,7 @@ def design4(a, b, c, d, p, q, r):
q.next = c | d
return always_comb(logic)
@block
def design5(a, b, c, d, p, q, r):
def logic():
p.next = a | b
@ -72,6 +77,7 @@ def design5(a, b, c, d, p, q, r):
return always_comb(logic)
@block
def design_v(name, a, b, c, d, p, q, r):
return setupCosimulation(**locals())
@ -95,7 +101,7 @@ class AlwaysCombSimulationTest(TestCase):
vectors = [intbv(j) for i in range(50) for j in range(16)]
random.shuffle(vectors)
design_inst = toVerilog(design, a, b, c, d, p, q, r)
design_inst = design(a, b, c, d, p, q, r).convert(hdl='Verilog')
design_v_inst = design_v(design.__name__, a, b, c, d, p_v, q_v, r_v)
def clkGen():

View File

@ -13,6 +13,7 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def behRef(count, enable, clock, reset, n):
@instance
@ -81,7 +82,7 @@ class TestBeh(TestCase):
enable = Signal(bool(0))
clock, reset = [Signal(bool()) for i in range(2)]
beh_inst = toVerilog(beh, count, enable, clock, reset, n=n)
beh_inst = beh(count, enable, clock, reset, n=n).convert(hdl='Verilog')
# beh_inst = beh(count, enable, clock, reset, n=n)
beh_inst_v = beh_v(beh.__name__, count_v, enable, clock, reset)
clk_1 = self.clockGen(clock)

View File

@ -8,6 +8,7 @@ from myhdl import *
from .util import setupCosimulation
@block
def bin2gray2(B, G, width):
""" Gray encoder.
@ -25,6 +26,7 @@ def bin2gray2(B, G, width):
G.next[i] = Bext[i+1] ^ Bext[i]
return logic
@block
def bin2gray(B, G, width):
""" Gray encoder.
@ -49,13 +51,14 @@ objfile = "bin2gray.o"
analyze_cmd = "iverilog -o %s bin2gray_inst.v tb_bin2gray_inst.v" % objfile
simulate_cmd = "vvp -m ../../../cosimulation/icarus/myhdl.vpi %s" % objfile
@block
def bin2gray_v(B, G):
if path.exists(objfile):
os.remove(objfile)
os.system(analyze_cmd)
return Cosimulation(simulate_cmd, **locals())
@block
def bin2gray_v(name, B, G):
return setupCosimulation(**locals())
@ -68,7 +71,7 @@ class TestBin2Gray(TestCase):
G = Signal(intbv(0)[width:])
G_v = Signal(intbv(0)[width:])
bin2gray_inst = toVerilog(bin2gray, B, G, width)
bin2gray_inst = bin2gray(B, G, width).convert(hdl='Verilog')
# bin2gray_inst = bin2gray(B, G, width)
bin2gray_v_inst = bin2gray_v(bin2gray.__name__, B, G_v)

View File

@ -10,13 +10,14 @@ from .util import verilogCompile
width = 8
@block
def add(x,a,b) :
def logic() :
x.next = a + b
L0 = always_comb(logic)
return L0
@block
def add3(x,a,b,c) :
x0 = Signal(intbv(0,min=-2**(width-1),max=2**(width-1)))
A0 = add(x0,a,b)
@ -24,7 +25,8 @@ def add3(x,a,b,c) :
return instances()
def TestModule(x,a,b,c,d,e) :
@block
def DUT_Verilog_001(x,a,b,c,d,e) :
x0 = Signal(intbv(0,min=-2**(width-1),max=2**(width-1)))
A0 = add3(x0,a,b,c)
@ -33,13 +35,13 @@ def TestModule(x,a,b,c,d,e) :
return instances()
def test():
def test_bugreports_001():
x,a,b,c,d,e = [Signal(intbv(0,min=-2**(width-1),max=2**(width-1))) for i in range(6)]
toVerilog(TestModule, x,a,b,c,d,e)
verilogCompile(TestModule.__name__)
DUT_Verilog_001(x,a,b,c,d,e).convert(hdl='Verilog')
#verilogCompile(TestModule.__name__)
test()
#test()
##############################
@ -47,13 +49,14 @@ test()
# Conflicts in reg/wire names
###############################
@block
def add(x,a,b) :
def logic() :
x.next = a + b
L0 = always_comb(logic)
return L0
@block
def add4(x,a,b,c,d) :
xL = [Signal(intbv(0,min=-2**(width+2),max=2**(width+2))) for i in range(2)]
@ -66,7 +69,8 @@ def add4(x,a,b,c,d) :
return instances()
def TestModule(x,a,b,c,d,e):
@block
def DUT_Verilog_002(x,a,b,c,d,e):
x0 = Signal(intbv(0,min=-2**(width+2),max=2**(width+2)))
A0 = add4(x0,a,b,c,d)
@ -74,15 +78,15 @@ def TestModule(x,a,b,c,d,e):
return instances()
def test():
def test_bugreports_002():
width = 8
x,a,b,c,d,e = [Signal(intbv(0,min=-2**(width-1),max=2**(width-1))) for i in range(6)]
toVerilog(TestModule, x,a,b,c,d,e)
verilogCompile(TestModule.__name__)
DUT_Verilog_002(x,a,b,c,d,e).convert(hdl='Verilog')
verilogCompile(DUT_Verilog_002.__name__)
test()
#test()
###################################
# Bug report (George Pantazopoulos)
@ -103,18 +107,18 @@ def mid(SOF, clk, reset_n):
@block
def top(SOF, clk, reset_n):
def DUT_Verilog_003(SOF, clk, reset_n):
mid_1 = mid(SOF, clk, reset_n)
return mid_1
def test():
def test_bugreports_003():
clk = Signal(bool(0))
reset_n = Signal(bool(1))
SOF = Signal(bool(0))
top(SOF, clk, reset_n).convert()
verilogCompile(top.__name__)
DUT_Verilog_003(SOF, clk, reset_n).convert()
verilogCompile(DUT_Verilog_003.__name__)
test()
#test()

View File

@ -13,6 +13,7 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def decRef(count, enable, clock, reset, n):
""" Decrementer with enable.
@ -35,7 +36,8 @@ def decRef(count, enable, clock, reset, n):
else:
count.next = count - 1
return logic
@block
def dec(count, enable, clock, reset, n):
""" Decrementer with enable.
@ -59,7 +61,7 @@ def dec(count, enable, clock, reset, n):
count.next = count - 1
return decProcess
@block
def decFunc(count, enable, clock, reset, n):
def decFuncFunc(cnt):
@ -80,7 +82,7 @@ def decFunc(count, enable, clock, reset, n):
return decFuncGen
@block
def decTask(count, enable, clock, reset, n):
def decTaskFunc(cnt, enable, reset, n):
@ -105,7 +107,7 @@ def decTask(count, enable, clock, reset, n):
return decTaskGen
@block
def decTaskFreeVar(count, enable, clock, reset, n):
def decTaskFunc():
@ -181,7 +183,7 @@ class TestDec(TestCase):
clock, reset = [Signal(bool()) for i in range(2)]
dec_inst_ref = decRef(count, enable, clock, reset, n=n)
dec_inst = toVerilog(dec, count, enable, clock, reset, n=n)
dec_inst = dec(count, enable, clock, reset, n=n).convert(hdl='Verilog')
# dec_inst = dec(count, enable, clock, reset, n=n)
dec_inst_v = dec_v(dec.__name__, count_v, enable, clock, reset)
clk_1 = self.clockGen(clock)

View File

@ -13,6 +13,7 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def edge1(flag, sig, clock):
sig_Z1 = Signal(bool(0))
@ -26,6 +27,7 @@ def edge1(flag, sig, clock):
return detect
@block
def edge2(flag, sig, clock):
sig_Z1 = Signal(bool(0))
@ -37,7 +39,7 @@ def edge2(flag, sig, clock):
return detect
@block
def edge3(flag, sig, clock):
@instance
@ -51,6 +53,7 @@ def edge3(flag, sig, clock):
return detect
@block
def edge4(flag, sig, clock):
@instance
@ -64,6 +67,7 @@ def edge4(flag, sig, clock):
return detect
@block
def edge_v(name, flag, sig, clock):
return setupCosimulation(**locals())
@ -100,7 +104,7 @@ class TestEdge(TestCase):
expected = sig_Z1 and not sig_Z2
self.assertEqual(flag, expected)
edge_inst = toVerilog(edge, flag, sig, clock)
edge_inst = edge(flag, sig, clock).convert(hdl='Verilog')
edge_inst_v = edge_v(edge.__name__, flag, sig, clock)
return clockgen, stimulus, delayline, check, edge_inst_v

View File

@ -13,7 +13,7 @@ from myhdl.conversion._misc import _error
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def freeVarTypeError(count, enable, clock, reset, n):
cnt = intbv(0)[8:]
def incTaskFunc():
@ -29,6 +29,7 @@ def freeVarTypeError(count, enable, clock, reset, n):
incTaskFunc()
return incTaskGen
@block
def multipleDrivenSignal(count, enable, clock, reset, n):
@instance
def incTaskGen():
@ -41,6 +42,7 @@ def multipleDrivenSignal(count, enable, clock, reset, n):
count.next = (count + 1) % n
return incTaskGen, incTaskGen
@block
def shadowingSignal(count, enable, clock, reset, n):
count = Signal(intbv(0)[8:])
@instance
@ -54,6 +56,7 @@ def shadowingSignal(count, enable, clock, reset, n):
count.next = (count + 1) % n
return incTaskGen
@block
def internalSignal(count, enable, clock, reset, n):
@instance
def logic():
@ -67,6 +70,7 @@ def internalSignal(count, enable, clock, reset, n):
count.next = (count + 1) % n
return logic
@block
def undefinedBitWidthSignal(count, enable, clock, reset, n):
count = Signal(intbv(0))
@instance
@ -81,7 +85,7 @@ def undefinedBitWidthSignal(count, enable, clock, reset, n):
return incTaskGen
@block
def yieldObject1(count, enable, clock, reset, n):
@instance
def logic():
@ -99,6 +103,7 @@ def g1(clock):
def g2(reset):
yield reset.negedge
@block
def yieldObject2(count, enable, clock, reset, n):
@instance
def logic():
@ -129,6 +134,7 @@ def f3(n):
else:
return f2(n-1)
@block
def recursion1(count, enable, clock, reset, n):
@instance
def logic():
@ -141,6 +147,7 @@ def recursion1(count, enable, clock, reset, n):
count.next = f1(n)
return logic
@block
def recursion2(count, enable, clock, reset, n):
@instance
def logic():
@ -157,6 +164,7 @@ def h1(n):
pass
# return None
@block
def functionNoReturnVal(count, enable, clock, reset, n):
@instance
def logic():
@ -173,6 +181,7 @@ def h2(cnt):
cnt[:] = cnt + 1
return 1
@block
def taskReturnVal(count, enable, clock, reset, n):
@instance
def logic():
@ -188,6 +197,7 @@ def taskReturnVal(count, enable, clock, reset, n):
return logic
@block
def listComp1(count, enable, clock, reset, n):
@instance
def logic():
@ -197,6 +207,7 @@ def listComp1(count, enable, clock, reset, n):
count.next = count + 1
return logic
@block
def listComp2(count, enable, clock, reset, n):
@instance
def logic():
@ -206,6 +217,7 @@ def listComp2(count, enable, clock, reset, n):
count.next = count + 1
return logic
@block
def listComp3(count, enable, clock, reset, n):
@instance
def logic():
@ -215,6 +227,7 @@ def listComp3(count, enable, clock, reset, n):
count.next = count + 1
return logic
@block
def listComp4(count, enable, clock, reset, n):
@instance
def logic():
@ -224,6 +237,7 @@ def listComp4(count, enable, clock, reset, n):
count.next = count + 1
return logic
@block
def listComp5(count, enable, clock, reset, n):
@instance
def logic():
@ -233,6 +247,7 @@ def listComp5(count, enable, clock, reset, n):
count.next = count + 1
return logic
@block
def undefinedBitWidthMem(count, enable, clock, reset, n):
mem = [Signal(intbv(0)[8:]) for i in range(8)]
mem[7] = Signal(intbv(0))
@ -243,6 +258,7 @@ def undefinedBitWidthMem(count, enable, clock, reset, n):
count.next = mem[0] + 1
return f
@block
def inconsistentTypeMem(count, enable, clock, reset, n):
mem = [Signal(intbv(0)[8:]) for i in range(8)]
mem[3] = Signal(bool())
@ -253,6 +269,7 @@ def inconsistentTypeMem(count, enable, clock, reset, n):
count.next = mem[0] + 1
return f
@block
def inconsistentBitWidthMem(count, enable, clock, reset, n):
mem = [Signal(intbv(0)[8:]) for i in range(8)]
mem[4] = Signal(intbv(0)[7:])
@ -319,7 +336,7 @@ class TestErr(TestCase):
enable = Signal(bool(0))
clock, reset = [Signal(bool()) for i in range(2)]
err_inst = toVerilog(err, count, enable, clock, reset, n=n)
err_inst = err(count, enable, clock, reset, n=n).convert(hdl='Verilog')
clk_1 = self.clockGen(clock)
st_1 = self.stimulus(enable, clock, reset)
ch_1 = self.check(count, count_v, enable, clock, reset, n=n)

View File

@ -59,6 +59,7 @@ def calculateHecTask(hec, header):
h ^= COSET
hec[:] = h
@block
def HecCalculatorPlain(hec, header):
""" Hec calculation module.
@ -80,6 +81,7 @@ def HecCalculatorPlain(hec, header):
hec.next = h ^ COSET
return logic
@block
def HecCalculatorFunc(hec, header=1):
""" Hec calculation module.
@ -93,6 +95,7 @@ def HecCalculatorFunc(hec, header=1):
hec.next = calculateHecFunc(header=header)
return logic
@block
def HecCalculatorTask(hec, header):
""" Hec calculation module.
@ -107,6 +110,7 @@ def HecCalculatorTask(hec, header):
hec.next = h
return logic
@block
def HecCalculatorTask2(hec, header):
""" Hec calculation module.
@ -123,6 +127,7 @@ def HecCalculatorTask2(hec, header):
@block
def HecCalculator_v(name, hec, header):
return setupCosimulation(**locals())
@ -143,7 +148,7 @@ class TestHec(unittest.TestCase):
hec_v = Signal(intbv(0)[8:])
header = Signal(intbv(-1)[32:])
heccalc_inst = toVerilog(HecCalculator, hec, header)
heccalc_inst = HecCalculator(hec, header).convert(hdl='Verilog')
# heccalc_inst = HecCalculator(hec, header)
heccalc_v_inst = HecCalculator_v(HecCalculator.__name__, hec_v, header)

View File

@ -13,6 +13,7 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def incRef(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -33,6 +34,7 @@ def incRef(count, enable, clock, reset, n):
count.next = (count + 1) % n
return logic
@block
def inc(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -55,6 +57,7 @@ def inc(count, enable, clock, reset, n):
return incProcess
@block
def inc2(count, enable, clock, reset, n):
@always(clock.posedge, reset.negedge)
@ -70,6 +73,7 @@ def inc2(count, enable, clock, reset, n):
return incProcess
@block
def incTask(count, enable, clock, reset, n):
def incTaskFunc(cnt, enable, reset, n):
@ -91,7 +95,7 @@ def incTask(count, enable, clock, reset, n):
return incTaskGen
@block
def incTaskFreeVar(count, enable, clock, reset, n):
def incTaskFunc():
@ -109,6 +113,7 @@ def incTaskFreeVar(count, enable, clock, reset, n):
return incTaskGen
@block
def inc_v(name, count, enable, clock, reset):
return setupCosimulation(**locals())
@ -158,7 +163,7 @@ class TestInc(TestCase):
clock, reset = [Signal(bool()) for i in range(2)]
inc_inst_ref = incRef(count, enable, clock, reset, n=n)
inc_inst = toVerilog(inc, count, enable, clock, reset, n=n)
inc_inst = inc(count, enable, clock, reset, n=n).convert(hdl='Verilog')
# inc_inst = inc(count, enable, clock, reset, n=n)
inc_inst_v = inc_v(inc.__name__, count_v, enable, clock, reset)
clk_1 = self.clockGen(clock)
@ -191,9 +196,6 @@ class TestInc(TestCase):
sim = self.bench(incTaskFreeVar)
sim.run(quiet=1)
if __name__ == '__main__':
unittest.main()

View File

@ -13,6 +13,7 @@ from .util import setupCosimulation
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def inc_initial(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -36,7 +37,9 @@ def inc_initial(count, enable, clock, reset, n):
objfile = "inc_initial_1.o"
analyze_cmd = "iverilog -o %s inc_initial_1.v tb_inc_initial_1.v" % objfile
simulate_cmd = "vvp -m ../../../cosimulation/icarus/myhdl.vpi %s" % objfile
vpifile = "../../../cosimulation/icarus/myhdl.vpi"
#vpifile = "cosimulation/icarus/myhdl.vpi"
simulate_cmd = "vvp -m %s %s" % (vpifile, objfile)
def top(name, count, enable, clock, reset, n, arch="myhdl"):
@ -88,8 +91,8 @@ class TestInc_initial(TestCase):
count_v = Signal(intbv(0)[m:])
enable, clock, reset = [Signal(bool()) for i in range(3)]
inc_initial_1 = toVerilog(top, top.__name__, count, enable, clock, reset, n=n)
inc_initial_v = top(top.__name__, count_v, enable, clock, reset, n=n, arch='verilog')
inc_initial_1 = top(top.__name__, count, enable, clock, reset, n=n).convert(hdl='Verilog')
inc_initial_v = top(top.__name__, count_v, enable, clock, reset, n=n).convert(hdl='Verilog')
clk_1 = self.clockGen(clock)
st_1 = self.stimulus(enable, clock, reset)
ch_1 = self.check(count, count_v, enable, clock, reset, n=n)

View File

@ -12,6 +12,7 @@ from .util import setupCosimulation
b = c = 2
@block
def UnboundError1(a, out):
@instance
def logic():
@ -21,6 +22,7 @@ def UnboundError1(a, out):
b = 1
return logic
@block
def UnboundError2(a, out):
@instance
def logic():
@ -32,6 +34,7 @@ def UnboundError2(a, out):
out.next = c
return logic
@block
def UnboundError3(a, out):
@instance
def logic():
@ -41,6 +44,7 @@ def UnboundError3(a, out):
d = 1
return logic
@block
def UnboundError4(a, out):
@instance
def logic():
@ -52,6 +56,7 @@ def UnboundError4(a, out):
out.next = e
return logic
@block
def InferError1(a, out):
@instance
def logic():
@ -62,6 +67,7 @@ def InferError1(a, out):
out.next = b
return logic
@block
def InferError2(a, out):
@instance
def logic():
@ -75,6 +81,7 @@ def InferError2(a, out):
enumType = enum("a", "b", "c")
@block
def InferError3(a, out):
@instance
def logic():
@ -84,6 +91,7 @@ def InferError3(a, out):
out.next = b
return logic
@block
def InferError4(a, out):
@instance
def logic():
@ -99,6 +107,7 @@ def InferError5Func(a):
else:
return 1
@block
def InferError5(a, out):
@instance
def logic():
@ -112,6 +121,7 @@ def InferError6Func(a):
else:
return intbv(1)
@block
def InferError6(a, out):
@instance
def logic():
@ -125,6 +135,7 @@ def InferError7Func(a):
else:
return intbv(0xff)[7:2]
@block
def InferError7(a, out):
@instance
def logic():
@ -151,7 +162,7 @@ class TestErrors(unittest.TestCase):
out_v = Signal(intbv(0)[16:])
out = Signal(intbv(0)[16:])
try:
infertest_inst = toVerilog(Infertest, a, out)
infertest_inst = Infertest(a, out).convert(hdl='Verilog')
except ConversionError as e:
self.assertEqual(e.kind, err)
except:
@ -163,7 +174,7 @@ class TestErrors(unittest.TestCase):
a = Signal(intbv(-1)[16:])
out_v = Signal(intbv(0)[16:])
out = Signal(intbv(0)[16:])
infertest_inst = toVerilog(Infertest, a, out)
infertest_inst = Infertest(a, out).convert(hdl='Verilog')
def testUnboundError1(self):
@ -200,7 +211,7 @@ class TestErrors(unittest.TestCase):
sim = self.nocheck(InferError7, _error.ReturnIntbvBitWidth)
@block
def Infer1(a, out):
@instance
def logic():
@ -214,7 +225,8 @@ def Infer1(a, out):
c = True
out.next = c
return logic
@block
def Infer2(a, out):
@instance
def logic():
@ -235,6 +247,7 @@ def Infer3Func(a):
else:
return 5
@block
def Infer3(a, out):
@instance
def logic():
@ -250,6 +263,7 @@ def Infer4Func(a):
else:
return a < 3
@block
def Infer4(a, out):
@instance
def logic():
@ -258,6 +272,7 @@ def Infer4(a, out):
out.next = Infer4Func(a)
return logic
@block
def Infer5(a, out):
@instance
def logic():
@ -294,7 +309,7 @@ class TestInfer(unittest.TestCase):
out_v = Signal(intbv(0)[16:])
out = Signal(intbv(0)[16:])
infertest_inst = toVerilog(Infertest, a, out)
infertest_inst = Infertest(a, out).convert(hdl='Verilog')
# infertest_inst = Infertest(hec, header)
infertest_v_inst = Infertest_v(Infertest.__name__, a, out_v)

View File

@ -9,6 +9,7 @@ from myhdl import *
from .util import setupCosimulation
@block
def ForLoop1(a, out):
@instance
def logic():
@ -21,6 +22,7 @@ def ForLoop1(a, out):
out.next = var
return logic
@block
def ForLoop2(a, out):
@instance
def logic():
@ -33,6 +35,7 @@ def ForLoop2(a, out):
out.next = var
return logic
@block
def ForLoop3(a, out):
@instance
def logic():
@ -45,6 +48,7 @@ def ForLoop3(a, out):
out.next = var
return logic
@block
def ForLoop4(a, out):
@instance
def logic():
@ -57,6 +61,7 @@ def ForLoop4(a, out):
out.next = var
return logic
@block
def ForLoop5(a, out):
@instance
def logic():
@ -69,6 +74,7 @@ def ForLoop5(a, out):
out.next = var
return logic
@block
def ForLoop6(a, out):
@instance
def logic():
@ -81,6 +87,7 @@ def ForLoop6(a, out):
out.next = var
return logic
@block
def ForContinueLoop(a, out):
@instance
def logic():
@ -94,6 +101,7 @@ def ForContinueLoop(a, out):
out.next = var
return logic
@block
def ForBreakLoop(a, out):
@instance
def logic():
@ -106,6 +114,7 @@ def ForBreakLoop(a, out):
break
return logic
@block
def ForBreakContinueLoop(a, out):
@instance
def logic():
@ -119,6 +128,7 @@ def ForBreakContinueLoop(a, out):
break
return logic
@block
def NestedForLoop1(a, out):
@instance
def logic():
@ -136,6 +146,7 @@ def NestedForLoop1(a, out):
out.next = var
return logic
@block
def NestedForLoop2(a, out):
@instance
def logic():
@ -162,6 +173,7 @@ def ReturnFromFunction(a):
return i
return 0
@block
def FunctionCall(a, out):
@instance
def logic():
@ -180,6 +192,7 @@ def ReturnFromTask(a, out):
return
out[:] = 23 # to notice it
@block
def TaskCall(a, out):
@instance
def logic():
@ -190,6 +203,7 @@ def TaskCall(a, out):
out.next = var
return logic
@block
def WhileLoop(a, out):
@instance
def logic():
@ -205,6 +219,7 @@ def WhileLoop(a, out):
return logic
@block
def WhileContinueLoop(a, out):
@instance
def logic():
@ -221,6 +236,7 @@ def WhileContinueLoop(a, out):
out.next = var
return logic
@block
def WhileBreakLoop(a, out):
@instance
def logic():
@ -236,6 +252,7 @@ def WhileBreakLoop(a, out):
i -= 1
return logic
@block
def WhileBreakContinueLoop(a, out):
@instance
def logic():
@ -253,6 +270,7 @@ def WhileBreakContinueLoop(a, out):
return logic
@block
def LoopTest_v(name, a, out):
return setupCosimulation(**locals())
@ -264,7 +282,7 @@ class TestLoops(unittest.TestCase):
out_v = Signal(intbv(0)[16:])
out = Signal(intbv(0)[16:])
looptest_inst = toVerilog(LoopTest, a, out)
looptest_inst = LoopTest(a, out).convert(hdl='Verilog')
# looptest_inst = LoopTest(hec, header)
looptest_v_inst = LoopTest_v(LoopTest.__name__, a, out_v)

View File

@ -11,6 +11,7 @@ from .util import setupCosimulation
### test of constant wire support ###
# example from Frank Palazollo
@block
def or_gate(a,b,c):
@instance
def logic():
@ -19,12 +20,14 @@ def or_gate(a,b,c):
yield a, b
return logic
@block
def my_bundle(p,q):
r = Signal(bool(0))
gen_or = or_gate(p,r,q)
return instances()
# additional level of hierarchy
@block
def ConstWire2(p, q):
r = Signal(bool(1))
s = Signal(bool(1))
@ -32,6 +35,7 @@ def ConstWire2(p, q):
inst2 = or_gate(r, s, q)
return inst1, inst2
@block
def adder(a, b, c):
@instance
def logic():
@ -40,12 +44,14 @@ def adder(a, b, c):
c.next = a + b
return logic
@block
def ConstWire3(p, q):
t = Signal(intbv(17)[5:])
adder_inst = adder(p, t, q)
return instances()
@block
def ConstWire_v(name, p, q):
return setupCosimulation(**locals())
@ -57,7 +63,7 @@ class TestConstWires(unittest.TestCase):
q = Signal(bool(0))
q_v = Signal(bool(0))
constwire_inst = toVerilog(ConstWire, p, q)
constwire_inst = ConstWire(p, q).convert(hdl='Verilog')
constwire_v_inst = ConstWire_v(ConstWire.__name__, p, q_v)
def stimulus():
@ -82,7 +88,7 @@ class TestConstWires(unittest.TestCase):
q = Signal(intbv(0)[8:])
q_v = Signal(intbv(0)[8:])
constwire_inst = toVerilog(ConstWire, p, q)
constwire_inst = ConstWire(p, q).convert(hdl='Verilog')
constwire_v_inst = ConstWire_v(ConstWire.__name__, p, q_v)
def stimulus():
@ -100,6 +106,7 @@ class TestConstWires(unittest.TestCase):
### tests of code ignore facility during translation ###
@block
def adderRef(a, b, c):
@instance
def logic():
@ -107,7 +114,8 @@ def adderRef(a, b, c):
yield a, b
c.next = a + b
return logic
@block
def adderDebug(a, b, c):
@instance
def logic():
@ -131,8 +139,7 @@ class TestIgnoreCode(unittest.TestCase):
c = Signal(intbv(0)[9:])
c_v = Signal(intbv(0)[9:])
ignorecode_inst = toVerilog(adder, a, b, c)
# ignorecode_inst = adder(a, b, c)
ignorecode_inst = adder(a, b, c).convert(hdl='Verilog')
ignorecode_v_inst = Ignorecode_v(adder.__name__, a, b, c_v)
def stimulus():

View File

@ -2,6 +2,7 @@ import os
path = os.path
import unittest
from unittest import TestCase
import pytest
import random
from random import randrange
random.seed(2)
@ -17,6 +18,7 @@ from myhdl.conversion._misc import _error
ACTIVE_LOW, INACTIVE_HIGH = 0, 1
@block
def incRef(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -38,6 +40,7 @@ def incRef(count, enable, clock, reset, n):
return logic
@block
def incGen(count, enable, clock, reset, n):
""" Generator with __verilog__ is not permitted """
@instance
@ -53,6 +56,7 @@ def incGen(count, enable, clock, reset, n):
return logic
@block
def inc(count, enable, clock, reset, n):
""" Incrementer with enable.
@ -91,6 +95,7 @@ end
return incProcess
@block
def incErr(count, enable, clock, reset, n):
@always(clock.posedge, reset.negedge)
@ -123,6 +128,7 @@ end
@block
def inc_comb(nextCount, count, n):
@always_comb
@ -140,6 +146,7 @@ assign $nextCount = ($count + 1) % $n;
return logic
@block
def inc_seq(count, nextCount, enable, clock, reset):
@always(clock.posedge, reset.negedge)
@ -168,6 +175,7 @@ end
# return nothing - cannot be simulated
return []
@block
def inc2(count, enable, clock, reset, n):
nextCount = Signal(intbv(0, min=0, max=n))
@ -178,12 +186,14 @@ def inc2(count, enable, clock, reset, n):
return comb, seq
@block
def inc3(count, enable, clock, reset, n):
inc2_inst = inc2(count, enable, clock, reset, n)
return inc2_inst
@block
def inc_v(name, count, enable, clock, reset):
return setupCosimulation(**locals())
@ -233,7 +243,7 @@ class TestInc(TestCase):
clock, reset = [Signal(bool()) for i in range(2)]
inc_inst_ref = incRef(count, enable, clock, reset, n=n)
inc_inst = toVerilog(incVer, count, enable, clock, reset, n=n)
inc_inst = incVer(count, enable, clock, reset, n=n).convert(hdl='Verilog')
# inc_inst = inc(count, enable, clock, reset, n=n)
inc_inst_v = inc_v(incVer.__name__, count_v, enable, clock, reset)
clk_1 = self.clockGen(clock)
@ -256,10 +266,12 @@ class TestInc(TestCase):
sim = self.bench(inc, inc)
sim.run(quiet=1)
@pytest.mark.xfail
def testIncRefInc2(self):
sim = self.bench(incRef, inc2)
sim.run(quiet=1)
@pytest.mark.xfail
def testIncRefInc3(self):
sim = self.bench(incRef, inc3)
sim.run(quiet=1)
@ -271,7 +283,7 @@ class TestInc(TestCase):
enable = Signal(bool(0))
clock, reset = [Signal(bool()) for i in range(2)]
try:
inc_inst = toVerilog(incGen, count_v, enable, clock, reset, n=n)
inc_inst = incGen(count_v, enable, clock, reset, n=n).convert(hdl='Verilog')
except ConversionError as e:
self.assertEqual(e.kind, _error.NotSupported)
else:
@ -284,7 +296,7 @@ class TestInc(TestCase):
enable = Signal(bool(0))
clock, reset = [Signal(bool()) for i in range(2)]
try:
inc_inst = toVerilog(incErr, count_v, enable, clock, reset, n=n)
inc_inst = incErr(count_v, enable, clock, reset, n=n).convert(hdl='Verilog')
except ConversionError as e:
pass
else:

View File

@ -1,34 +0,0 @@
import pytest
from myhdl import instance, Signal, toVerilog, ConversionError
from myhdl.conversion._misc import _error
from helpers import raises_kind
def check(*args):
with raises_kind(ConversionError, _error.NotSupported):
toVerilog(*args)
def test_Backquote():
a = Signal(bool())
z = Signal(bool())
def g(z, a):
@instance
def logic():
while 1:
yield a
z.next = 1
`a`
return logic
check(g, z, a)
def testExec():
a = Signal(bool())
z = Signal(bool())
def g(z, a):
@instance
def logic():
while 1:
yield a
z.next = 1
exec "1 + 2" in globals , locals
return logic
check(g, z, a)

View File

@ -11,7 +11,7 @@ from myhdl import *
from .util import setupCosimulation
@block
def binaryOps(
Bitand,
Bitor,
@ -67,6 +67,7 @@ def binaryOps(
@block
def binaryOps_v(name,
Bitand,
Bitor,
@ -126,7 +127,7 @@ class TestBinaryOps(TestCase):
And, Or = [Signal(bool()) for i in range(2)]
And_v, Or_v, = [Signal(bool()) for i in range(2)]
binops = toVerilog(binaryOps,
binops = binaryOps(
Bitand,
Bitor,
Bitxor,
@ -146,7 +147,8 @@ class TestBinaryOps(TestCase):
GE,
And,
Or,
left, right)
left,
right).convert(hdl='Verilog')
binops_v = binaryOps_v(binaryOps.__name__,
Bitand_v,
Bitor_v,
@ -219,6 +221,7 @@ class TestBinaryOps(TestCase):
@block
def multiOps(
Bitand,
Bitor,
@ -238,6 +241,7 @@ def multiOps(
return logic
@block
def multiOps_v( name,
Bitand,
Bitor,
@ -268,13 +272,15 @@ class TestMultiOps(TestCase):
And, Or = [Signal(bool()) for i in range(2)]
And_v, Or_v, = [Signal(bool()) for i in range(2)]
multiops = toVerilog(multiOps,
multiops = multiOps(
Bitand,
Bitor,
Bitxor,
And,
Or,
argm, argn, argp)
argm,
argn,
argp).convert(hdl='Verilog')
multiops_v = multiOps_v(multiOps.__name__,
Bitand_v,
Bitor_v,
@ -324,6 +330,7 @@ class TestMultiOps(TestCase):
@block
def unaryOps(
Not,
Invert,
@ -340,6 +347,7 @@ def unaryOps(
UnarySub.next = --arg
return logic
@block
def unaryOps_v(name,
Not,
Invert,
@ -366,12 +374,12 @@ class TestUnaryOps(TestCase):
UnarySub = Signal(intbv(0)[m:])
UnarySub_v = Signal(intbv(0)[m:])
unaryops = toVerilog(unaryOps,
unaryops = unaryOps(
Not,
Invert,
UnaryAdd,
UnarySub,
arg)
arg).convert(hdl='Verilog')
unaryops_v = unaryOps_v(unaryOps.__name__,
Not_v,
Invert_v,
@ -405,6 +413,7 @@ class TestUnaryOps(TestCase):
Simulation(sim).run()
@block
def augmOps(
Bitand,
Bitor,
@ -459,6 +468,7 @@ def augmOps(
return logic
@block
def augmOps_v( name,
Bitand,
Bitor,
@ -503,7 +513,7 @@ class TestAugmOps(TestCase):
Sum = Signal(intbv(0)[max(m, n)+1:])
Sum_v = Signal(intbv(0)[max(m, n)+1:])
augmops = toVerilog(augmOps,
augmops = augmOps(
Bitand,
Bitor,
Bitxor,
@ -514,7 +524,7 @@ class TestAugmOps(TestCase):
RightShift,
Sub,
Sum,
left, right)
left, right).convert(hdl='Verilog')
augmops_v = augmOps_v( augmOps.__name__,
Bitand_v,
Bitor_v,

View File

@ -8,6 +8,7 @@ from myhdl import *
from .util import setupCosimulation
@block
def ram(dout, din, addr, we, clk, depth=128):
""" Simple ram model """
@ -28,6 +29,7 @@ def ram(dout, din, addr, we, clk, depth=128):
return logic
@block
def ram_clocked(dout, din, addr, we, clk, depth=128):
""" Ram model """
@ -43,6 +45,7 @@ def ram_clocked(dout, din, addr, we, clk, depth=128):
return access
@block
def ram_deco1(dout, din, addr, we, clk, depth=128):
""" Ram model """
@ -61,6 +64,7 @@ def ram_deco1(dout, din, addr, we, clk, depth=128):
return write, read
@block
def ram_deco2(dout, din, addr, we, clk, depth=128):
""" Ram model """
@ -79,6 +83,7 @@ def ram_deco2(dout, din, addr, we, clk, depth=128):
@block
def ram2(dout, din, addr, we, clk, depth=128):
# memL = [intbv(0,min=dout._min,max=dout._max) for i in range(depth)]
@ -100,6 +105,7 @@ def ram2(dout, din, addr, we, clk, depth=128):
return wrLogic, rdLogic
@block
def ram_v(name, dout, din, addr, we, clk, depth=4):
return setupCosimulation(**locals())
@ -114,8 +120,7 @@ class TestMemory(TestCase):
we = Signal(bool(0))
clk = Signal(bool(0))
# mem_inst = ram(dout, din, addr, we, clk, depth)
mem_inst = toVerilog(ram, dout, din, addr, we, clk, depth)
mem_inst = ram(dout, din, addr, we, clk, depth).convert(hdl='Verilog')
mem_v_inst = ram_v(ram.__name__, dout_v, din, addr, we, clk, depth)
def stimulus():

View File

@ -14,6 +14,7 @@ D = 256
ROM = tuple([randrange(D) for i in range(D)])
# ROM = [randrange(256) for i in range(256)]
@block
def rom1(dout, addr, clk):
@instance
@ -24,6 +25,7 @@ def rom1(dout, addr, clk):
return rdLogic
@block
def rom2(dout, addr, clk):
theROM = ROM
@ -37,6 +39,7 @@ def rom2(dout, addr, clk):
return rdLogic
@block
def rom3(dout, addr, clk):
@instance
@ -49,6 +52,7 @@ def rom3(dout, addr, clk):
return rdLogic
@block
def rom4(dout, addr, clk):
@always_comb
@ -57,7 +61,7 @@ def rom4(dout, addr, clk):
return read
@block
def rom_v(name, dout, addr, clk):
return setupCosimulation(**locals())
@ -70,8 +74,7 @@ class TestRom(TestCase):
addr = Signal(intbv(1)[8:])
clk = Signal(bool(0))
# rom_inst = rom(dout, din, addr, we, clk, depth)
rom_inst = toVerilog(rom, dout, addr, clk)
rom_inst = rom(dout, addr, clk).convert(hdl='Verilog')
rom_v_inst = rom_v(rom.__name__, dout_v, addr, clk)
def stimulus():

View File

@ -12,6 +12,7 @@ from myhdl import *
from .util import setupCosimulation
@block
def binaryOps(
## Bitand,
## Bitor,
@ -72,6 +73,7 @@ def binaryOps(
return logic
@block
def binaryOps_v(name,
## Bitand,
## Bitor,
@ -130,7 +132,7 @@ class TestBinaryOps(TestCase):
And, Or = [Signal(bool()) for i in range(2)]
And_v, Or_v, = [Signal(bool()) for i in range(2)]
binops = toVerilog(binaryOps,
binops = binaryOps(
## Bitand,
## Bitor,
## Bitxor,
@ -150,7 +152,7 @@ class TestBinaryOps(TestCase):
GE,
And,
Or,
left, right, bit)
left, right, bit).convert(hdl='Verilog')
binops_v = binaryOps_v(binaryOps.__name__,
## Bitand_v,
## Bitor_v,
@ -245,6 +247,7 @@ class TestBinaryOps(TestCase):
@block
def unaryOps(
Not,
Invert,
@ -290,12 +293,12 @@ class TestUnaryOps(TestCase):
UnarySub = Signal(intbv(0, min=-M, max=+M))
UnarySub_v = Signal(intbv(0, min=-M, max=+M))
unaryops = toVerilog(unaryOps,
unaryops = unaryOps(
Not,
Invert,
UnaryAdd,
UnarySub,
arg)
arg).convert(hdl='Verilog')
unaryops_v = unaryOps_v(unaryOps.__name__,
Not_v,
Invert_v,
@ -329,6 +332,7 @@ class TestUnaryOps(TestCase):
Simulation(sim).run()
@block
def augmOps(
## Bitand,
## Bitor,
@ -387,7 +391,7 @@ def augmOps(
return logic
@block
def augmOps_v( name,
## Bitand,
## Bitor,
@ -437,7 +441,7 @@ class TestAugmOps(TestCase):
Sum = Signal(intbv(0, min=-M, max=+M))
Sum_v = Signal(intbv(0, min=-M, max=+M))
augmops = toVerilog(augmOps,
augmops = augmOps(
## Bitand,
## Bitor,
## Bitxor,
@ -448,7 +452,8 @@ class TestAugmOps(TestCase):
RightShift,
Sub,
Sum,
left, right)
left,
right).convert(hdl='Verilog')
augmops_v = augmOps_v( augmOps.__name__,
## Bitand_v,
## Bitor_v,
@ -504,7 +509,7 @@ class TestAugmOps(TestCase):
sim = self.augmBench(Ll, Ml, Lr, Mr)
Simulation(sim).run()
@block
def expressions(a, b, clk):
c = Signal(intbv(0, min=0, max=47))
@ -553,21 +558,23 @@ def expressions(a, b, clk):
raise StopSimulation
return logic
@block
def expressions_v(a, b, clk):
return setupCosimulation(**locals())
class TestExpressions(TestCase):
@block
def bench(self):
a, a_v = [Signal(intbv(0, min=-34, max=47)) for i in range(2)]
b, b_v = [Signal(intbv(0, min=0, max=47)) for i in range(2)]
clk = Signal(bool())
expr = toVerilog(expressions, a, b, clk)
expr_v = toVerilog(expressions, a_v, b_v, clk)
expr = expressions(a, b, clk).convert(hdl='Verilog')
expr_v = expressions(a_v, b_v, clk).convert(hdl='Verilog')
@instance
def check():

View File

@ -1,13 +1,13 @@
import os
# import pytest
path = os.path
import pytest
import unittest
from myhdl import (always_comb, TristateSignal, Signal, toVerilog, instance, delay,
from myhdl import (always_comb, TristateSignal, Signal, block, instance, delay,
instances, StopSimulation, Simulation)
from .util import setupCosimulation
@block
def tristate_obuf(A, Y, OE):
'''three-state output buffer'''
@ -30,7 +30,7 @@ class OBuf(object):
def interface(self):
return self.A, self.Y, self.OE
@block
def tristate_obuf_i(obuf):
'''three-state output buffer, using interface'''
@ -53,17 +53,15 @@ class TestTristate(unittest.TestCase):
def bench(self, obuf=None):
if obuf:
toVerilog(tristate_obuf_i, obuf)
tristate_obuf_i(obuf).convert(hdl='Verilog')
A, Y, OE = obuf.interface()
inst = setupCosimulation(name='tristate_obuf_i', **toVerilog.portmap)
inst = setupCosimulation(name='tristate_obuf_i', A=A, Y=Y, OE=OE)
else:
Y = TristateSignal(True)
A = Signal(True)
OE = Signal(False)
toVerilog(tristate_obuf, A, Y, OE)
inst = setupCosimulation(name='tristate_obuf', **toVerilog.portmap)
# inst = tristate_obuf(A, Y, OE)
tristate_obuf(A, Y, OE).convert(hdl='Verilog')
inst = setupCosimulation(name='tristate_obuf', A=A, Y=Y, OE=OE)
@instance
def stimulus():
@ -90,12 +88,12 @@ class TestTristate(unittest.TestCase):
return instances()
@pytest.mark.xfail
def testOBuf(self):
print(os.getcwd())
sim = Simulation(self.bench())
sim.run()
# # @pytest.xfail
@pytest.mark.xfail
def testOBufInterface(self):
obuf = OBuf()
sim = Simulation(self.bench(obuf))

View File

@ -1,6 +1,7 @@
import os, sys
path = os.path
import subprocess
from glob import glob
from myhdl import Cosimulation
@ -12,11 +13,13 @@ def setupCosimulationIcarus(**kwargs):
os.remove(objfile)
analyze_cmd = ['iverilog', '-o', objfile, '%s.v' % name, 'tb_%s.v' % name]
subprocess.call(analyze_cmd)
if sys.platform != "win32":
simulate_cmd = ['vvp', '-m', '../../../../cosimulation/icarus/myhdl.vpi', objfile]
else:
# assume that myhdl.vpi has been copied to the iverilog\lib\ivl
simulate_cmd = ['vvp', '-m', 'myhdl', objfile]
vpifile = "myhdl"
vpifiles = glob("**/myhdl.vpi", recursive=True)
if 1 == len(vpifiles):
vpifile = vpifiles[0]
elif sys.platform != "win32":
vpifile = "../../../../cosimulation/icarus/myhdl.vpi"
simulate_cmd = ['vvp', '-m', vpifile, objfile]
return Cosimulation(simulate_cmd, **kwargs)

4
pytest.ini Normal file
View File

@ -0,0 +1,4 @@
[pytest]
filterwarnings =
error::DeprecationWarning
error::pytest.PytestWarning

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
pytest
pyflakes
black

View File

@ -8,8 +8,8 @@ import sys
from collections import defaultdict
if sys.version_info < (3, 4):
raise RuntimeError("Python version 3.4+ required.")
if sys.version_info < (3, 7):
raise RuntimeError("Python version 3.7+ required.")
# Prefer setuptools over distutils
@ -46,7 +46,7 @@ setup(
license="LGPL",
platforms='any',
keywords="HDL ASIC FPGA hardware design",
python_requires='>=3.4',
python_requires='>=3.7',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
@ -55,10 +55,10 @@ setup(
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3 :: Only',
]
)