build.plat, vendor.*: don't join strings passed as _opts overrides.
authorwhitequark <whitequark@whitequark.org>
Sat, 6 Jul 2019 23:09:46 +0000 (23:09 +0000)
committerwhitequark <whitequark@whitequark.org>
Sat, 6 Jul 2019 23:09:46 +0000 (23:09 +0000)
Right now an array is expected in any _opts overrides, and if it is
actually a string (because it is passed via an environment variable,
usually), awkwardness results as each character is joined with ` `.

Fixes #130.

nmigen/build/plat.py
nmigen/vendor/lattice_ecp5.py
nmigen/vendor/lattice_ice40.py
nmigen/vendor/xilinx_7series.py
nmigen/vendor/xilinx_spartan6.py

index 3de59f5bd8688f6fe664116db0672cf164f8be78..da193081f0a116af8c3435065214f112d70285e5 100644 (file)
@@ -243,6 +243,12 @@ class TemplatedPlatform(Platform):
             else:
                 return jinja2.Undefined(name=var)
 
+        def options(opts):
+            if isinstance(opts, str):
+                return opts
+            else:
+                return " ".join(opts)
+
         def verbose(arg):
             if "NMIGEN_verbose" in os.environ:
                 return arg
@@ -259,6 +265,7 @@ class TemplatedPlatform(Platform):
             try:
                 source   = textwrap.dedent(source).strip()
                 compiled = jinja2.Template(source, trim_blocks=True, lstrip_blocks=True)
+                compiled.environment.filters["options"] = options
             except jinja2.TemplateSyntaxError as e:
                 e.args = ("{} (at {}:{})".format(e.message, origin, e.lineno),)
                 raise
index ee2cc115060ee719271d32b24a4744f5def3bbe4..2993dd1b936f75793f269991403e71df46e512fd 100644 (file)
@@ -68,14 +68,14 @@ class LatticeECP5Platform(TemplatedPlatform):
         "{{name}}.ys": r"""
             # {{autogenerated}}
             {% for file in platform.iter_extra_files(".v") -%}
-                read_verilog {{get_override("read_opts")|join(" ")}} {{file}}
+                read_verilog {{get_override("read_opts")|options}} {{file}}
             {% endfor %}
             {% for file in platform.iter_extra_files(".sv") -%}
-                read_verilog -sv {{get_override("read_opts")|join(" ")}} {{file}}
+                read_verilog -sv {{get_override("read_opts")|options}} {{file}}
             {% endfor %}
             read_ilang {{name}}.il
             {{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
-            synth_ecp5 {{get_override("synth_opts")|join(" ")}} -top {{name}}
+            synth_ecp5 {{get_override("synth_opts")|options}} -top {{name}}
             {{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}}
             write_json {{name}}.json
         """,
@@ -97,14 +97,14 @@ class LatticeECP5Platform(TemplatedPlatform):
         r"""
         {{get_tool("yosys")}}
             {{quiet("-q")}}
-            {{get_override("yosys_opts")|join(" ")}}
+            {{get_override("yosys_opts")|options}}
             -l {{name}}.rpt
             {{name}}.ys
         """,
         r"""
         {{get_tool("nextpnr-ecp5")}}
             {{quiet("--quiet")}}
-            {{get_override("nextpnr_opts")|join(" ")}}
+            {{get_override("nextpnr_opts")|options}}
             --log {{name}}.tim
             {{platform._nextpnr_device_options[platform.device]}}
             --package {{platform._nextpnr_package_options[platform.package]|upper}}
index 340a03aa6b40cc2758e4a296712cd413c2b2fd50..e296ce696b61b0ac4a61a924f3033b0da1823872 100644 (file)
@@ -60,14 +60,14 @@ class LatticeICE40Platform(TemplatedPlatform):
         "{{name}}.ys": r"""
             # {{autogenerated}}
             {% for file in platform.iter_extra_files(".v") -%}
-                read_verilog {{get_override("read_opts")|join(" ")}} {{file}}
+                read_verilog {{get_override("read_opts")|options}} {{file}}
             {% endfor %}
             {% for file in platform.iter_extra_files(".sv") -%}
-                read_verilog -sv {{get_override("read_opts")|join(" ")}} {{file}}
+                read_verilog -sv {{get_override("read_opts")|options}} {{file}}
             {% endfor %}
             read_ilang {{name}}.il
             {{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
-            synth_ice40 {{get_override("synth_opts")|join(" ")}} -top {{name}}
+            synth_ice40 {{get_override("synth_opts")|options}} -top {{name}}
             {{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}}
             write_json {{name}}.json
         """,
@@ -89,14 +89,14 @@ class LatticeICE40Platform(TemplatedPlatform):
         r"""
         {{get_tool("yosys")}}
             {{quiet("-q")}}
-            {{get_override("yosys_opts")|join(" ")}}
+            {{get_override("yosys_opts")|options}}
             -l {{name}}.rpt
             {{name}}.ys
         """,
         r"""
         {{get_tool("nextpnr-ice40")}}
             {{quiet("--quiet")}}
-            {{get_override("nextpnr_opts")|default(["--placer","heap"])|join(" ")}}
+            {{get_override("nextpnr_opts")|default(["--placer","heap"])|options}}
             --log {{name}}.tim
             {{platform._nextpnr_device_options[platform.device]}}
             --package
index 7b06cdb9ec7f29bea027791e60f07e70f3b26873..4749ed67f6123e10450df3ac0e108fc70b878237 100644 (file)
@@ -109,7 +109,7 @@ class Xilinx7SeriesPlatform(TemplatedPlatform):
         r"""
         {{get_tool("vivado")}}
             {{verbose("-verbose")}}
-            {{get_override("vivado_opts")|join(" ")}}
+            {{get_override("vivado_opts")|options}}
             -mode batch
             -log {{name}}.log
             -source {{name}}.tcl
index 7ac360a46c84efedb037d3a188b6a7c6373da2e6..fe4c77548a825638515bc405d1911eea681d9298 100644 (file)
@@ -93,35 +93,35 @@ class XilinxSpartan6Platform(TemplatedPlatform):
     command_templates = [
         r"""
         {{get_tool("xst")}}
-            {{get_override("xst_opts")|join(" ")}}
+            {{get_override("xst_opts")|options}}
             -ifn {{name}}.xst
         """,
         r"""
         {{get_tool("ngdbuild")}}
             {{quiet("-quiet")}}
             {{verbose("-verbose")}}
-            {{get_override("ngdbuild_opts")|join(" ")}}
+            {{get_override("ngdbuild_opts")|options}}
             -uc {{name}}.ucf
             {{name}}.ngc
         """,
         r"""
         {{get_tool("map")}}
             {{verbose("-detail")}}
-            {{get_override("map_opts")|default(["-w"])|join(" ")}}
+            {{get_override("map_opts")|default(["-w"])|options}}
             -o {{name}}_map.ncd
             {{name}}.ngd
             {{name}}.pcf
         """,
         r"""
         {{get_tool("par")}}
-            {{get_override("par_opts")|default(["-w"])|join(" ")}}
+            {{get_override("par_opts")|default(["-w"])|options}}
             {{name}}_map.ncd
             {{name}}_par.ncd
             {{name}}.pcf
         """,
         r"""
         {{get_tool("bitgen")}}
-            {{get_override("bitgen_opts")|default(["-w"])|join(" ")}}
+            {{get_override("bitgen_opts")|default(["-w"])|options}}
             {{name}}_par.ncd
             {{name}}.bit
         """