Skip to content

Commit 50de645

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 306eb7e commit 50de645

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
@@ -426,6 +426,12 @@ def tcl_escape(string):
426426
def tcl_quote(string):
427427
return '"' + re.sub(r"([$[\\])", r"\\\1", string) + '"'
428428

429+
def sdc_quote(string):
430+
# synplify used in lattice diamond requires different quoting
431+
# than standard tcl quoting: wrapped in curly braces but escaped
432+
# as if wrapped in quotation marks.
433+
return "{" + re.sub(r"([${}\\])", r"\\\1", string) + "}"
434+
429435
def verbose(arg):
430436
if get_override_flag("verbose"):
431437
return arg
@@ -448,6 +454,7 @@ def render(source, origin, syntax=None):
448454
compiled.environment.filters["ascii_escape"] = ascii_escape
449455
compiled.environment.filters["tcl_escape"] = tcl_escape
450456
compiled.environment.filters["tcl_quote"] = tcl_quote
457+
compiled.environment.filters["sdc_quote"] = sdc_quote
451458
except jinja2.TemplateSyntaxError as e:
452459
e.args = (f"{e.message} (at {origin}:{e.lineno})",)
453460
raise

amaranth/vendor/_lattice_ecp5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class LatticeECP5Platform(TemplatedPlatform):
237237
set_hierarchy_separator {/}
238238
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
239239
{% if port_signal is not none -%}
240-
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
240+
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
241241
{% else -%}
242-
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
242+
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
243243
{% endif %}
244244
{% endfor %}
245245
{{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
@@ -104,9 +104,9 @@ class LatticeMachXO2Or3LPlatform(TemplatedPlatform):
104104
set_hierarchy_separator {/}
105105
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
106106
{% if port_signal is not none -%}
107-
create_clock -name {{port_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
107+
create_clock -name {{port_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|sdc_quote}}]
108108
{% else -%}
109-
create_clock -name {{net_signal.name|tcl_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
109+
create_clock -name {{net_signal.name|sdc_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|sdc_quote}}]
110110
{% endif %}
111111
{% endfor %}
112112
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}

0 commit comments

Comments
 (0)