Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1ce168beb9f2^
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 856a9f35a21e
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Aug 21, 2019

  1. build.plat: remove TemplatedPlatform.unix_interpreter.

    Vendor toolchains generally require far more workarounds than this,
    and we already have a perfectly fine way of overriding templates.
    whitequark committed Aug 21, 2019
    Copy the full SHA
    1ce168b View commit details
  2. vendor: style. NFC.

    whitequark committed Aug 21, 2019
    Copy the full SHA
    6c5938b View commit details
  3. vendor.lattice_ice40: remove --placer heap default option.

    It is not the place of nMigen to decide on this default, since both
    SA and HeAP have valid uses that are not covered by the other.
    whitequark committed Aug 21, 2019
    Copy the full SHA
    7d922a6 View commit details
  4. vendor.altera: add Quartus support. (WIP)

    whitequark committed Aug 21, 2019
    Copy the full SHA
    856a9f3 View commit details
Showing with 191 additions and 24 deletions.
  1. +0 −10 nmigen/build/plat.py
  2. +172 −0 nmigen/vendor/altera.py
  3. +3 −3 nmigen/vendor/lattice_ecp5.py
  4. +3 −4 nmigen/vendor/lattice_ice40.py
  5. +1 −1 nmigen/vendor/xilinx_7series.py
  6. +12 −6 nmigen/vendor/xilinx_spartan_3_6.py
10 changes: 0 additions & 10 deletions nmigen/build/plat.py
Original file line number Diff line number Diff line change
@@ -225,13 +225,11 @@ class TemplatedPlatform(Platform):
toolchain = abstractproperty()
file_templates = abstractproperty()
command_templates = abstractproperty()
unix_interpreter = "sh"

build_script_templates = {
"build_{{name}}.sh": """
# {{autogenerated}}
set -e{{verbose("x")}}
{{emit_unix_interpreter()}}
[ -n "$NMIGEN_{{platform.toolchain}}_env" ] && . "$NMIGEN_{{platform.toolchain}}_env"
{{emit_commands("sh")}}
""",
@@ -248,13 +246,6 @@ def toolchain_prepare(self, fragment, name, **kwargs):
# and to incorporate the nMigen version into generated code.
autogenerated = "Automatically generated by nMigen {}. Do not edit.".format(__version__)

def emit_unix_interpreter():
if self.unix_interpreter == "sh":
return "# runs on any POSIX sh"
if self.unix_interpreter == "bash":
return """if [ -z "$BASH" ] ; then exec /bin/bash "$0" "$@"; fi"""
assert False

def emit_design(backend):
backend_mod = {"rtlil": rtlil, "verilog": verilog}[backend]
return backend_mod.convert_fragment(fragment, name=name)
@@ -321,7 +312,6 @@ def render(source, origin):
return compiled.render({
"name": name,
"platform": self,
"emit_unix_interpreter": emit_unix_interpreter,
"emit_design": emit_design,
"emit_commands": emit_commands,
"get_tool": get_tool,
172 changes: 172 additions & 0 deletions nmigen/vendor/altera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
from abc import abstractproperty

from ..hdl import *
from ..build import *


__all__ = ["AlteraPlatform"]


class AlteraPlatform(TemplatedPlatform):
"""
Required tools:
* ``quartus_map``
* ``quartus_fit``
* ``quartus_asm``
* ``quartus_sta``
* ``quartus_cpf``
The environment is populated by running the script specified in the environment variable
``NMIGEN_Quartus_env``, if present.
Available overrides:
* ``nproc``: sets the number of cores used by all tools.
* ``quartus_map_opts``: adds extra options for ``quartus_map``.
* ``quartus_fit_opts``: adds extra options for ``quartus_fit``.
* ``quartus_asm_opts``: adds extra options for ``quartus_asm``.
* ``quartus_sta_opts``: adds extra options for ``quartus_sta``.
* ``quartus_cpf_opts_rbf``: adds extra options for ``quartus_cpf``,
when emitting an ``rbf`` file.
Build products:
* ``{{name}}_out/*.rpt``: toolchain reports.
* ``{{name}}.rbf``: raw binary bitstream.
"""

toolchain = "Quartus"

device = abstractproperty()
package = abstractproperty()
speed = abstractproperty()
suffix = ""

file_templates = {
**TemplatedPlatform.build_script_templates,
"build_{{name}}.sh": r"""
# {{autogenerated}}
if [ -n "$NMIGEN_{{platform.toolchain}}_env" ]; then
QUARTUS_ROOTDIR=$(dirname $(dirname "$NMIGEN_{{platform.toolchain}}_env"))
# Quartus' qenv.sh does not work with `set -e`.
. "$NMIGEN_{{platform.toolchain}}_env"
fi
set -e{{verbose("x")}}
{{emit_commands("sh")}}
""",
"{{name}}.v": r"""
/* {{autogenerated}} */
{{emit_design("verilog")}}
""",
"{{name}}.qsf": r"""
# {{autogenerated}}
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY "{{name}}_out"
{% if get_override("nproc") -%}
set_global_assignment -name NUM_PARALLEL_PROCESSORS {{get_override("nproc")}}
{% endif %}
{% for file in platform.iter_extra_files(".v") -%}
set_global_assignment -name VERILOG_FILE "{{file}}"
{% endfor %}
{% for file in platform.iter_extra_files(".sv") -%}
set_global_assignment -name SYSTEMVERILOG_FILE "{{file}}"
{% endfor %}
set_global_assignment -name VERILOG_FILE "{{name}}.v"
set_global_assignment -name TOP_LEVEL_ENTITY "{{name}}"
set_global_assignment -name DEVICE {{platform.device}}{{platform.package}}{{platform.speed}}{{platform.suffix}}
{% for port_name, pin_name, extras in platform.iter_port_constraints_bits() -%}
set_location_assignment -to "{{port_name}}" Pin_{{pin_name}}
{% for key, value in extras.items() -%}
set_instance_assignment -to "{{port_name}}" -name {{key}} "{{value}}"
{% endfor %}
{% endfor %}
""",
"{{name}}.sdc": r"""
{% for signal, frequency in platform.iter_clock_constraints() -%}
create_clock -period {{1000000000/frequency}} [get_ports {{signal.name}}]
{% endfor %}
""",
}
command_templates = [
r"""
{{get_tool("quartus_map")}}
{{get_override("quartus_map_opts")|options}}
--rev="{{name}}" "{{name}}"
""",
r"""
{{get_tool("quartus_fit")}}
{{get_override("quartus_fit_opts")|options}}
--rev="{{name}}" "{{name}}"
""",
r"""
{{get_tool("quartus_asm")}}
{{get_override("quartus_asm_opts")|options}}
--rev="{{name}}" "{{name}}"
""",
r"""
{{get_tool("quartus_sta")}}
{{get_override("quartus_sta_opts")|options}}
--rev="{{name}}" "{{name}}"
""",
r"""
{{get_tool("quartus_cpf")}}
{{get_override("quartus_cpf_opts_rbf")|options}}
-c "{{name}}_out/{{name}}.sof" "{{name}}.rbf"
""",
]

def create_missing_domain(self, name):
# TODO: investigate this
return super().create_missing_domain(name)

# TODO: fix all of the following
@staticmethod
def _invert_if(invert, value):
if invert:
return ~value
else:
return value

def get_input(self, pin, port, attrs, invert):
self._check_feature("single-ended input", pin, attrs,
valid_xdrs=(0,), valid_attrs=True)

m = Module()
m.d.comb += pin.i.eq(self._invert_if(invert, port))
return m

def get_output(self, pin, port, attrs, invert):
self._check_feature("single-ended output", pin, attrs,
valid_xdrs=(0,), valid_attrs=True)

m = Module()
m.d.comb += port.eq(self._invert_if(invert, pin.o))
return m

def get_tristate(self, pin, port, attrs, invert):
self._check_feature("single-ended tristate", pin, attrs,
valid_xdrs=(0,), valid_attrs=True)

m = Module()
m.submodules += Instance("$tribuf",
p_WIDTH=pin.width,
i_EN=pin.oe,
i_A=self._invert_if(invert, pin.o),
o_Y=port,
)
return m

def get_input_output(self, pin, port, attrs, invert):
self._check_feature("single-ended input/output", pin, attrs,
valid_xdrs=(0,), valid_attrs=True)

m = Module()
m.submodules += Instance("$tribuf",
p_WIDTH=pin.width,
i_EN=pin.oe,
i_A=self._invert_if(invert, pin.o),
o_Y=port,
)
m.d.comb += pin.i.eq(self._invert_if(invert, port))
return m

# TODO: support differential IO
6 changes: 3 additions & 3 deletions nmigen/vendor/lattice_ecp5.py
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ class LatticeECP5Platform(TemplatedPlatform):
* ``synth_opts``: adds options for ``synth_ecp5`` Yosys command.
* ``script_after_read``: inserts commands after ``read_ilang`` in Yosys script.
* ``script_after_synth``: inserts commands after ``synth_ecp5`` in Yosys script.
* ``yosys_opts``: adds extra options for Yosys.
* ``nextpnr_opts``: adds extra options for nextpnr.
* ``ecppack_opts``: adds extra options for ecppack.
* ``yosys_opts``: adds extra options for ``yosys``.
* ``nextpnr_opts``: adds extra options for ``nextpnr-ecp5``.
* ``ecppack_opts``: adds extra options for ``ecppack``.
Build products:
* ``{{name}}.rpt``: Yosys log.
7 changes: 3 additions & 4 deletions nmigen/vendor/lattice_ice40.py
Original file line number Diff line number Diff line change
@@ -23,9 +23,8 @@ class LatticeICE40Platform(TemplatedPlatform):
* ``synth_opts``: adds options for ``synth_ice40`` Yosys command.
* ``script_after_read``: inserts commands after ``read_ilang`` in Yosys script.
* ``script_after_synth``: inserts commands after ``synth_ice40`` in Yosys script.
* ``yosys_opts``: adds extra options for Yosys.
* ``nextpnr_opts``: adds extra and overrides default options for nextpnr;
default options: ``--placer heap``.
* ``yosys_opts``: adds extra options for ``yosys``.
* ``nextpnr_opts``: adds extra options for ``nextpnr-ice40``.
Build products:
* ``{{name}}.rpt``: Yosys log.
@@ -107,7 +106,7 @@ class LatticeICE40Platform(TemplatedPlatform):
r"""
{{get_tool("nextpnr-ice40")}}
{{quiet("--quiet")}}
{{get_override("nextpnr_opts")|default(["--placer","heap"])|options}}
{{get_override("nextpnr_opts")|options}}
--log {{name}}.tim
{{platform._nextpnr_device_options[platform.device]}}
--package
2 changes: 1 addition & 1 deletion nmigen/vendor/xilinx_7series.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ class Xilinx7SeriesPlatform(TemplatedPlatform):
* ``script_before_bitstream``: inserts commands before ``write_bitstream`` in Tcl script.
* ``script_after_bitstream``: inserts commands after ``write_bitstream`` in Tcl script.
* ``add_constraints``: inserts commands in XDC file.
* ``vivado_opts``: adds extra options for Vivado.
* ``vivado_opts``: adds extra options for ``vivado``.
Build products:
* ``{{name}}.log``: Vivado log.
18 changes: 12 additions & 6 deletions nmigen/vendor/xilinx_spartan_3_6.py
Original file line number Diff line number Diff line change
@@ -26,11 +26,11 @@ class XilinxSpartan3Or6Platform(TemplatedPlatform):
Available overrides:
* ``script_after_run``: inserts commands after ``run`` in XST script.
* ``add_constraints``: inserts commands in UCF file.
* ``xst_opts``: adds extra options for XST.
* ``ngdbuild_opts``: adds extra options for NGDBuild.
* ``map_opts``: adds extra options for MAP.
* ``par_opts``: adds extra options for PAR.
* ``bitgen_opts``: adds extra and overrides default options for BitGen;
* ``xst_opts``: adds extra options for ``xst``.
* ``ngdbuild_opts``: adds extra options for ``ngdbuild``.
* ``map_opts``: adds extra options for ``map``.
* ``par_opts``: adds extra options for ``par``.
* ``bitgen_opts``: adds extra and overrides default options for ``bitgen``;
default options: ``-g Compress``.
Build products:
@@ -76,6 +76,13 @@ def family(self):

file_templates = {
**TemplatedPlatform.build_script_templates,
"build_{{name}}.sh": r"""
# {{autogenerated}}
set -e{{verbose("x")}}
if [ -z "$BASH" ] ; then exec /bin/bash "$0" "$@"; fi
[ -n "$NMIGEN_{{platform.toolchain}}_env" ] && . "$NMIGEN_{{platform.toolchain}}_env"
{{emit_commands("sh")}}
""",
"{{name}}.v": r"""
/* {{autogenerated}} */
{{emit_design("verilog")}}
@@ -118,7 +125,6 @@ def family(self):
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}
"""
}
unix_interpreter = "bash"
command_templates = [
r"""
{{get_tool("xst")}}