Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

back.rtlil: espace { and } in format string #1519

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amaranth/back/rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ def emit_print(self, cell_idx, cell):
if cell.format is not None:
for chunk in cell.format.chunks:
if isinstance(chunk, str):
format.append(chunk)
format.append(chunk.replace("{", "{{").replace("}", "}}"))
else:
spec = _ast.Format._parse_format_spec(chunk.format_desc, _ast.Shape(len(chunk.value), chunk.signed))
type = spec["type"]
Expand Down
45 changes: 45 additions & 0 deletions tests/test_back_rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,51 @@ def test_print_align(self):
end
""")

def test_escape_curly(self):
m = Module()
m.d.comb += [
Print("{"),
Print("}"),
]
self.assertRTLIL(m, [], R"""
attribute \generator "Amaranth"
attribute \top 1
module \top
wire width 1 $1
wire width 1 $2
process $3
assign $1 [0] 1'0
assign $1 [0] 1'1
end
cell $print $4
parameter \FORMAT "{{\n"
parameter \ARGS_WIDTH 0
parameter signed \PRIORITY 32'11111111111111111111111111111110
parameter \TRG_ENABLE 0
parameter \TRG_WIDTH 0
parameter \TRG_POLARITY 0
connect \EN $1 [0]
connect \ARGS { }
connect \TRG { }
end
process $5
assign $2 [0] 1'0
assign $2 [0] 1'1
end
cell $print $6
parameter \FORMAT "}}\n"
parameter \ARGS_WIDTH 0
parameter signed \PRIORITY 32'11111111111111111111111111111100
parameter \TRG_ENABLE 0
parameter \TRG_WIDTH 0
parameter \TRG_POLARITY 0
connect \EN $2 [0]
connect \ARGS { }
connect \TRG { }
end
end
""")


class DetailTestCase(RTLILTestCase):
def test_enum(self):
Expand Down
Loading