Skip to content

Commit 8da5529

Browse files
committed
build.plat,vendor._lattice: add Diamond escaping quirk.
Partially addresses amaranth-lang#546.
1 parent f0dd01e commit 8da5529

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

amaranth/build/plat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,15 @@ def escape_one(match):
330330
return f"_{ord(match.group(1)[0]):02x}_"
331331
return "".join(escape_one(m) for m in re.finditer(r"([^A-Za-z0-9_])|(.)", string))
332332

333-
def tcl_quote(string):
334-
return '"' + re.sub(r"([$[\\])", r"\\\1", string) + '"'
333+
def tcl_quote(string, quirk=None):
334+
escaped = '"' + re.sub(r"([$[\\])", r"\\\1", string) + '"'
335+
if quirk == "Diamond":
336+
# Diamond seems to assign `clk\$2` as a name for the Verilog net `\clk$2 `, and
337+
# `clk\\\$2` as a name for the Verilog net `\clk\$2 `.
338+
return escaped.replace("\\", "\\\\")
339+
else:
340+
assert quirk is None
341+
return escaped
335342

336343
def verbose(arg):
337344
if get_override_flag("verbose"):

amaranth/vendor/_lattice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ class LatticePlatform(TemplatedPlatform):
686686
set_hierarchy_separator {/}
687687
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
688688
{% if port_signal is not none -%}
689-
create_clock -name {{port_signal.name|tcl_quote}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_quote}}]
689+
create_clock -name {{port_signal.name|tcl_quote("Diamond")}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_quote("Diamond")}}]
690690
{% else -%}
691-
create_clock -name {{net_signal.name|tcl_quote}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_quote}}]
691+
create_clock -name {{net_signal.name|tcl_quote("Diamond")}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_quote("Diamond")}}]
692692
{% endif %}
693693
{% endfor %}
694694
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}

0 commit comments

Comments
 (0)