Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions amaranth/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ def tcl_escape(string):
def tcl_quote(string):
return '"' + re.sub(r"([$[\\])", r"\\\1", string) + '"'

def sdc_quote(string):
# synplify used in lattice diamond requires different quoting
# than standard tcl quoting: wrapped in curly braces but escaped
# as if wrapped in quotation marks.
return "{" + re.sub(r"([${}\\])", r"\\\1", string) + "}"

def verbose(arg):
if get_override_flag("verbose"):
return arg
Expand All @@ -448,6 +454,7 @@ def render(source, origin, syntax=None):
compiled.environment.filters["ascii_escape"] = ascii_escape
compiled.environment.filters["tcl_escape"] = tcl_escape
compiled.environment.filters["tcl_quote"] = tcl_quote
compiled.environment.filters["sdc_quote"] = sdc_quote
except jinja2.TemplateSyntaxError as e:
e.args = (f"{e.message} (at {origin}:{e.lineno})",)
raise
Expand Down
5 changes: 3 additions & 2 deletions amaranth/vendor/_lattice_ecp5.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ class LatticeECP5Platform(TemplatedPlatform):
{{get_override("add_preferences")|default("# (add_preferences placeholder)")}}
""",
"{{name}}.sdc": r"""
set_hierarchy_separator {/}
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
{% if port_signal is not none -%}
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
{% else -%}
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
{% endif %}
{% endfor %}
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}
Expand Down
5 changes: 3 additions & 2 deletions amaranth/vendor/_lattice_machxo_2_3l.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ class LatticeMachXO2Or3LPlatform(TemplatedPlatform):
{{get_override("add_preferences")|default("# (add_preferences placeholder)")}}
""",
"{{name}}.sdc": r"""
set_hierarchy_separator {/}
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
{% if port_signal is not none -%}
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
{% else -%}
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
{% endif %}
{% endfor %}
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}
Expand Down