Skip to content

Commit 97bf602

Browse files
committed
vendor.lattice_{ecp5,machxo_2_3l}: special case quoting in sdc files
synplify used in lattice diamond requires different quoting than standard tcl quoting: wrapped in curly braces but escaped as if wrapped in quotation marks.
1 parent 6cd1ec2 commit 97bf602

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

amaranth/build/plat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ def tcl_escape(string):
439439
def tcl_quote(string):
440440
return '"' + re.sub(r"([$[\\])", r"\\\1", string) + '"'
441441

442+
def sdc_quote(string):
443+
# synplify used in lattice diamond requires different quoting
444+
# than standard tcl quoting: wrapped in curly braces but escaped
445+
# as if wrapped in quotation marks.
446+
return "{" + re.sub(r"([${}\\])", r"\\\1", string) + "}"
447+
442448
def verbose(arg):
443449
if get_override_flag("verbose"):
444450
return arg
@@ -461,6 +467,7 @@ def render(source, origin, syntax=None):
461467
compiled.environment.filters["ascii_escape"] = ascii_escape
462468
compiled.environment.filters["tcl_escape"] = tcl_escape
463469
compiled.environment.filters["tcl_quote"] = tcl_quote
470+
compiled.environment.filters["sdc_quote"] = sdc_quote
464471
except jinja2.TemplateSyntaxError as e:
465472
e.args = (f"{e.message} (at {origin}:{e.lineno})",)
466473
raise

amaranth/vendor/_lattice_ecp5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ class LatticeECP5Platform(TemplatedPlatform):
239239
set_hierarchy_separator {/}
240240
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
241241
{% if port_signal is not none -%}
242-
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
242+
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
243243
{% else -%}
244-
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
244+
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
245245
{% endif %}
246246
{% endfor %}
247247
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}

amaranth/vendor/_lattice_machxo_2_3l.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class LatticeMachXO2Or3LPlatform(TemplatedPlatform):
106106
set_hierarchy_separator {/}
107107
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
108108
{% if port_signal is not none -%}
109-
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
109+
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
110110
{% else -%}
111-
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
111+
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
112112
{% endif %}
113113
{% endfor %}
114114
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}

0 commit comments

Comments
 (0)