diff --git a/amaranth/build/plat.py b/amaranth/build/plat.py index 293a6f122..2c09dca82 100644 --- a/amaranth/build/plat.py +++ b/amaranth/build/plat.py @@ -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 @@ -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 diff --git a/amaranth/vendor/_lattice_ecp5.py b/amaranth/vendor/_lattice_ecp5.py index 10c8e589b..3c197b4b7 100644 --- a/amaranth/vendor/_lattice_ecp5.py +++ b/amaranth/vendor/_lattice_ecp5.py @@ -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)")}} diff --git a/amaranth/vendor/_lattice_machxo_2_3l.py b/amaranth/vendor/_lattice_machxo_2_3l.py index ef219bdb3..677dcf337 100644 --- a/amaranth/vendor/_lattice_machxo_2_3l.py +++ b/amaranth/vendor/_lattice_machxo_2_3l.py @@ -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)")}}