Skip to content

Commit

Permalink
build.plat: add iter_extra_files method.
Browse files Browse the repository at this point in the history
* vendor.xilinx_7series: employ iter_extra_files.
  • Loading branch information
peteut committed Jul 2, 2019
1 parent f2cc64f commit 4c61207
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 4 additions & 0 deletions nmigen/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,7 @@ def render(source, origin):
for filename, content in self.extra_files.items():
plan.add_file(filename, content)
return plan

def iter_extra_files(self, *endswith):
for file in [f for f in self.extra_files if f.endswith(endswith)]:
yield file

This comment has been minimized.

Copy link
@whitequark

whitequark Jul 2, 2019

Contributor

This isn't important at all, but Python allows doing this a bit more elegantly if you want a generator anyway:

def iter_extra_files(self, *endswith):
    return (f for f in self.extra_files if f.endswith(endswith))
12 changes: 4 additions & 8 deletions nmigen/vendor/xilinx_7series.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ class Xilinx7SeriesPlatform(TemplatedPlatform):
"{{name}}.tcl": r"""
# {{autogenerated}}
create_project -force -name {{name}} -part {{platform.device}}{{platform.package}}-{{platform.speed}}
{% for file in platform.extra_files %}
{% if file.endswith((".v", ".sv")) -%}
add_files {{file}}
{% endif %}
{% for file in platform.iter_extra_files(".v", ".sv") %}
add_files {{file}}

This comment has been minimized.

Copy link
@whitequark

whitequark Jul 2, 2019

Contributor

I prefer to keep the script templates nicely formatted by indenting the inside of for loops and replacing the preceding %} with -%}.

{% endfor %}
add_files {{name}}.v
read_xdc {{name}}.xdc
{% for file in platform.extra_files %}
{% if file.endswith("xdc") -%}
read_xdc {{file}}
{% endif %}
{% for file in platform.iter_extra_files(".xdc") %}
read_xdc {{file}}
{% endfor %}
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
synth_design -top {{name}} -part {{platform.device}}{{platform.package}}-{{platform.speed}}
Expand Down

0 comments on commit 4c61207

Please sign in to comment.