else:
self.extra_files[filename] = content
+ def iter_files(self, *suffixes):
+ for filename in self.extra_files:
+ if filename.endswith(suffixes):
+ yield filename
+
@property
def _toolchain_env_var(self):
return f"NMIGEN_ENV_{self.toolchain}"
for filename, content in self.extra_files.items():
plan.add_file(filename, content)
return plan
-
- def iter_extra_files(self, *endswith):
- return (f for f in self.extra_files if f.endswith(endswith))
set_global_assignment -name NUM_PARALLEL_PROCESSORS {{get_override("nproc")}}
{% endif %}
- {% for file in platform.iter_extra_files(".v") -%}
+ {% for file in platform.iter_files(".v") -%}
set_global_assignment -name VERILOG_FILE {{file|tcl_quote}}
{% endfor %}
- {% for file in platform.iter_extra_files(".sv") -%}
+ {% for file in platform.iter_files(".sv") -%}
set_global_assignment -name SYSTEMVERILOG_FILE {{file|tcl_quote}}
{% endfor %}
- {% for file in platform.iter_extra_files(".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".vhd", ".vhdl") -%}
set_global_assignment -name VHDL_FILE {{file|tcl_quote}}
{% endfor %}
set_global_assignment -name VERILOG_FILE {{name}}.v
""",
"{{name}}.ys": r"""
# {{autogenerated}}
- {% for file in platform.iter_extra_files(".v") -%}
+ {% for file in platform.iter_files(".v") -%}
read_verilog {{get_override("read_verilog_opts")|options}} {{file}}
{% endfor %}
- {% for file in platform.iter_extra_files(".sv") -%}
+ {% for file in platform.iter_files(".sv") -%}
read_verilog -sv {{get_override("read_verilog_opts")|options}} {{file}}
{% endfor %}
- {% for file in platform.iter_extra_files(".il") -%}
+ {% for file in platform.iter_files(".il") -%}
read_ilang {{file}}
{% endfor %}
read_ilang {{name}}.il
-dev {{platform.device}}-{{platform.speed}}{{platform.package}}{{platform.grade}} \
-lpf {{name}}.lpf \
-synthesis synplify
- {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
prj_src add {{file|tcl_escape}}
{% endfor %}
prj_src add {{name}}.v
""",
"{{name}}.ys": r"""
# {{autogenerated}}
- {% for file in platform.iter_extra_files(".v") -%}
+ {% for file in platform.iter_files(".v") -%}
read_verilog {{get_override("read_verilog_opts")|options}} {{file}}
{% endfor %}
- {% for file in platform.iter_extra_files(".sv") -%}
+ {% for file in platform.iter_files(".sv") -%}
read_verilog -sv {{get_override("read_verilog_opts")|options}} {{file}}
{% endfor %}
- {% for file in platform.iter_extra_files(".il") -%}
+ {% for file in platform.iter_files(".il") -%}
read_ilang {{file}}
{% endfor %}
read_ilang {{name}}.il
-d {{platform.device}}
-t {{platform.package}}
{{get_override("lse_opts")|options|default("# (lse_opts placeholder)")}}
- {% for file in platform.iter_extra_files(".v") -%}
+ {% for file in platform.iter_files(".v") -%}
-ver {{file}}
{% endfor %}
-ver {{name}}.v
""",
"{{name}}_syn.prj": r"""
# {{autogenerated}}
- {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
add_file -verilog {{file|tcl_escape}}
{% endfor %}
add_file -verilog {{name}}.v
-dev {{platform.device}}-{{platform.speed}}{{platform.package}}{{platform.grade}} \
-lpf {{name}}.lpf \
-synthesis synplify
- {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
prj_src add {{file|tcl_escape}}
{% endfor %}
prj_src add {{name}}.v
r"""
{{invoke_tool("symbiflow_synth")}}
-t {{name}}
- -v {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%} {{file}} {% endfor %} {{name}}.v
+ -v {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%} {{file}} {% endfor %} {{name}}.v
-d {{platform.device}}
-p {{name}}.pcf
-P {{platform.package}}
"{{name}}.tcl": r"""
# {{autogenerated}}
create_project -force -name {{name}} -part {{platform._part}}
- {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
add_files {{file|tcl_escape}}
{% endfor %}
add_files {{name}}.v
read_xdc {{name}}.xdc
- {% for file in platform.iter_extra_files(".xdc") -%}
+ {% for file in platform.iter_files(".xdc") -%}
read_xdc {{file|tcl_escape}}
{% endfor %}
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
r"""
{{invoke_tool("synth")}}
-t {{name}}
- -v {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%} {{file}} {% endfor %} {{name}}.v
+ -v {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%} {{file}} {% endfor %} {{name}}.v
-p {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
-x {{name}}.xdc
""",
""",
"{{name}}.prj": r"""
# {{autogenerated}}
- {% for file in platform.iter_extra_files(".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".vhd", ".vhdl") -%}
vhdl work {{file}}
{% endfor %}
- {% for file in platform.iter_extra_files(".v") -%}
+ {% for file in platform.iter_files(".v") -%}
verilog work {{file}}
{% endfor %}
verilog work {{name}}.v
"{{name}}.tcl": r"""
# {{autogenerated}}
create_project -force -name {{name}} -part {{platform.device}}-{{platform.package}}-{{platform.speed}}
- {% for file in platform.iter_extra_files(".v", ".sv", ".vhd", ".vhdl") -%}
+ {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
add_files {{file|tcl_escape}}
{% endfor %}
add_files {{name}}.v
read_xdc {{name}}.xdc
- {% for file in platform.iter_extra_files(".xdc") -%}
+ {% for file in platform.iter_files(".xdc") -%}
read_xdc {{file|tcl_escape}}
{% endfor %}
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
with self.assertRaisesRegex(ValueError,
r"^File 'foo' already exists$"):
self.platform.add_file("foo", "bar")
+
+ def test_iter_files(self):
+ self.platform.add_file("foo.v", "")
+ self.platform.add_file("bar.v", "")
+ self.platform.add_file("baz.vhd", "")
+ self.assertEqual(list(self.platform.iter_files(".v")),
+ ["foo.v", "bar.v"])
+ self.assertEqual(list(self.platform.iter_files(".vhd")),
+ ["baz.vhd"])
+ self.assertEqual(list(self.platform.iter_files(".v", ".vhd")),
+ ["foo.v", "bar.v", "baz.vhd"])