Skip to content

Commit

Permalink
back.rtlil: espace { and } in format string
Browse files Browse the repository at this point in the history
Fixes #1518
  • Loading branch information
rroohhh authored and whitequark committed Sep 20, 2024
1 parent 1f4b2db commit dd36508
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
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

0 comments on commit dd36508

Please sign in to comment.