Commit 988cbd3d authored by Sebastien Bourdeauducq's avatar Sebastien Bourdeauducq
Browse files

Merge branch 'master' of github.com:m-labs/migen

parents ca5ee584 73c607aa
...@@ -16,8 +16,10 @@ requirements: ...@@ -16,8 +16,10 @@ requirements:
- python 3.5.* - python 3.5.*
- sphinx - sphinx
- sphinx_rtd_theme - sphinx_rtd_theme
- colorama
run: run:
- python 3.5.* - python 3.5.*
- colorama
test: test:
imports: imports:
......
...@@ -74,6 +74,13 @@ Replications ...@@ -74,6 +74,13 @@ Replications
============ ============
The ``Replicate`` object represents the equivalent of {count{expression}} in Verilog. The ``Replicate`` object represents the equivalent of {count{expression}} in Verilog.
For example, the expression: ::
Replicate(0, 4)
is equivalent to::
Cat(0, 0, 0, 0)
Statements Statements
********** **********
......
...@@ -10,7 +10,10 @@ Migen lets you write testbenches using Python's generator functions. Such testbe ...@@ -10,7 +10,10 @@ Migen lets you write testbenches using Python's generator functions. Such testbe
#. Clocking: simulation can be advanced by one clock cycle using ``yield``; #. Clocking: simulation can be advanced by one clock cycle using ``yield``;
#. Composition: control can be transferred to another testbench function using ``yield from run_other()``. #. Composition: control can be transferred to another testbench function using ``yield from run_other()``.
A testbench can be run using the ``run_simulation`` function from ``migen.sim``; ``run_simulation(mod, bench)`` runs the generator function ``bench`` against the logic defined in an FHDL module ``mod``. A testbench can be run using the ``run_simulation`` function from ``migen.sim``; ``run_simulation(dut, bench)`` runs the generator function ``bench`` against the logic defined in an FHDL module ``dut``.
Passing the ``vcd_name="file.vcd"`` argument to ``run_simulation`` will cause it to write a VCD
dump of the signals inside ``dut`` to ``file.vcd``.
Examples Examples
******** ********
......
import os import os
import struct import struct
from distutils.version import StrictVersion from distutils.version import StrictVersion
import re
import subprocess
import sys
def mkdir_noerror(d): def mkdir_noerror(d):
...@@ -40,3 +43,25 @@ def versions(path): ...@@ -40,3 +43,25 @@ def versions(path):
yield StrictVersion(n) yield StrictVersion(n)
except ValueError: except ValueError:
continue continue
def sub_rules(lines, rules, max_matches=1):
for line in lines:
n = max_matches
for pattern, color in rules:
line, m = re.subn(pattern, color, line, n)
n -= m
if not n:
break
yield line
def subprocess_call_filtered(command, rules, *, max_matches=1, **kwargs):
proc = subprocess.Popen(command, stdout=subprocess.PIPE,
universal_newlines=True, bufsize=1,
**kwargs)
with proc:
for line in sub_rules(iter(proc.stdout.readline, ""),
rules, max_matches):
sys.stdout.write(line)
return proc.returncode
import os import os
import sys import sys
try:
import colorama
colorama.init() # install escape sequence translation on Windows
_have_colorama = True
except ImportError:
_have_colorama = False
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.fhdl.specials import Instance from migen.fhdl.specials import Instance
...@@ -12,6 +18,20 @@ from migen.genlib.io import * ...@@ -12,6 +18,20 @@ from migen.genlib.io import *
from migen.build import tools from migen.build import tools
colors = []
if _have_colorama:
colors += [
("^ERROR:.*$", colorama.Fore.RED + colorama.Style.BRIGHT +
r"\g<0>" + colorama.Style.RESET_ALL),
("^CRITICAL WARNING:.*$", colorama.Fore.RED +
r"\g<0>" + colorama.Style.RESET_ALL),
("^WARNING:.*$", colorama.Fore.YELLOW +
r"\g<0>" + colorama.Style.RESET_ALL),
("^INFO:.*$", colorama.Fore.GREEN +
r"\g<0>" + colorama.Style.RESET_ALL),
]
def settings(path, ver=None, sub=None): def settings(path, ver=None, sub=None):
if ver is None: if ver is None:
vers = list(tools.versions(path)) vers = list(tools.versions(path))
......
...@@ -119,7 +119,7 @@ bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit{fail_stmt} ...@@ -119,7 +119,7 @@ bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit{fail_stmt}
build_script_file = "build_" + build_name + script_ext build_script_file = "build_" + build_name + script_ext
tools.write_to_file(build_script_file, build_script_contents, force_unix=False) tools.write_to_file(build_script_file, build_script_contents, force_unix=False)
command = shell + [build_script_file] command = shell + [build_script_file]
r = subprocess.call(command) r = tools.subprocess_call_filtered(command, common.colors)
if r != 0: if r != 0:
raise OSError("Subprocess failed") raise OSError("Subprocess failed")
......
...@@ -57,7 +57,7 @@ def _run_vivado(build_name, vivado_path, source, ver=None): ...@@ -57,7 +57,7 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n" build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
build_script_file = "build_" + build_name + ".bat" build_script_file = "build_" + build_name + ".bat"
tools.write_to_file(build_script_file, build_script_contents) tools.write_to_file(build_script_file, build_script_contents)
r = subprocess.call([build_script_file]) command = build_script_file
else: else:
build_script_contents = "# Autogenerated by Migen\nset -e\n" build_script_contents = "# Autogenerated by Migen\nset -e\n"
settings = common.settings(vivado_path, ver) settings = common.settings(vivado_path, ver)
...@@ -65,8 +65,8 @@ def _run_vivado(build_name, vivado_path, source, ver=None): ...@@ -65,8 +65,8 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n" build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
build_script_file = "build_" + build_name + ".sh" build_script_file = "build_" + build_name + ".sh"
tools.write_to_file(build_script_file, build_script_contents) tools.write_to_file(build_script_file, build_script_contents)
r = subprocess.call(["bash", build_script_file]) command = ["bash", build_script_file]
r = tools.subprocess_call_filtered(command, common.colors)
if r != 0: if r != 0:
raise OSError("Subprocess failed") raise OSError("Subprocess failed")
......
...@@ -86,9 +86,11 @@ class FSM(Module): ...@@ -86,9 +86,11 @@ class FSM(Module):
""" """
Finite state machine Finite state machine
Any Python objects can be used as states, e.g. strings.
Parameters Parameters
---------- ----------
reset_state : str reset_state
Reset state. Defaults to the first added state. Reset state. Defaults to the first added state.
Examples Examples
...@@ -139,7 +141,7 @@ class FSM(Module): ...@@ -139,7 +141,7 @@ class FSM(Module):
`self.comb += a.eq(b)` when the FSM is in the given `state`; `self.comb += a.eq(b)` when the FSM is in the given `state`;
* synchronous statements of form `NextValue(a, b)`, equivalent to * synchronous statements of form `NextValue(a, b)`, equivalent to
`self.sync += a.eq(b)` when the FSM is in the given `state`; `self.sync += a.eq(b)` when the FSM is in the given `state`;
* a statement of form `NextState("STATE")`, selecting the next state; * a statement of form `NextState(new_state)`, selecting the next state;
* `If`, `Case`, etc. * `If`, `Case`, etc.
""" """
if self.finalized: if self.finalized:
......
...@@ -10,7 +10,7 @@ if sys.version_info[:3] < (3, 3): ...@@ -10,7 +10,7 @@ if sys.version_info[:3] < (3, 3):
requirements = [ requirements = [
"sphinx", "sphinx_rtd_theme" "sphinx", "sphinx_rtd_theme", "colorama"
] ]
setup( setup(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment