Skip to content

Commit a4f79fe

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 a55b0b2 commit a4f79fe

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

nmigen/build/plat.py

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

398+
def sdc_quote(string):
399+
# synplify used in lattice diamond requires different quoting
400+
# than standard tcl quoting: wrapped in curly braces but escaped
401+
# as if wrapped in quotation marks.
402+
return "{" + re.sub(r"([${}\\])", r"\\\1", string) + "}"
403+
398404
def verbose(arg):
399405
if "NMIGEN_verbose" in os.environ:
400406
return arg
@@ -417,6 +423,7 @@ def render(source, origin, syntax=None):
417423
compiled.environment.filters["ascii_escape"] = ascii_escape
418424
compiled.environment.filters["tcl_escape"] = tcl_escape
419425
compiled.environment.filters["tcl_quote"] = tcl_quote
426+
compiled.environment.filters["sdc_quote"] = sdc_quote
420427
except jinja2.TemplateSyntaxError as e:
421428
e.args = ("{} (at {}:{})".format(e.message, origin, e.lineno),)
422429
raise

nmigen/vendor/lattice_ecp5.py

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

nmigen/vendor/lattice_machxo_2_3l.py

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

0 commit comments

Comments
 (0)