Skip to content

Commit

Permalink
fmt: allow padding characters other than '0' and ' '.
Browse files Browse the repository at this point in the history
When converted to Verilog, padding characters are replaced with one of
these two. Otherwise padding is performed with exactly that character.
  • Loading branch information
whitequark authored and mwkmwkmwk committed Apr 2, 2024
1 parent ddf7b46 commit 27cb4c5
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions kernel/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ void Fmt::parse_rtlil(const RTLIL::Cell *cell) {
if (++i == fmt.size())
log_assert(false && "Unexpected end in format substitution");

if (fmt[i] == '0' || fmt[i] == ' ')
part.padding = fmt[i];
else
log_assert(false && "Unexpected padding in format substitution");
part.padding = fmt[i];
if (++i == fmt.size())
log_assert(false && "Unexpected end in format substitution");

Expand Down Expand Up @@ -550,7 +547,6 @@ std::vector<VerilogFmtArg> Fmt::emit_verilog() const
if (part.width == 0) {
fmt.str += '0';
} else if (part.width > 0) {
log_assert(part.padding == ' ' || part.padding == '0');
if (part.base != 10 || part.padding == '0')
fmt.str += '0';
fmt.str += std::to_string(part.width);
Expand All @@ -576,7 +572,6 @@ std::vector<VerilogFmtArg> Fmt::emit_verilog() const
fmt.str += '-';
if (part.sig.size() == 8) {
if (part.width > 0) {
log_assert(part.padding == '0' || part.padding == ' ');
if (part.padding == '0')
fmt.str += part.padding;
fmt.str += std::to_string(part.width);
Expand All @@ -585,7 +580,6 @@ std::vector<VerilogFmtArg> Fmt::emit_verilog() const
} else {
log_assert(part.sig.size() % 8 == 0);
if (part.width > 0) {
log_assert(part.padding == ' '); // no zero padding
fmt.str += std::to_string(part.width);
}
fmt.str += 's';
Expand Down Expand Up @@ -616,7 +610,6 @@ std::vector<VerilogFmtArg> Fmt::emit_verilog() const
fmt.str += '+';
if (part.justify == FmtPart::LEFT)
fmt.str += '-';
log_assert(part.padding == ' ' || part.padding == '0');
if (part.padding == '0' && part.width > 0)
fmt.str += '0';
fmt.str += std::to_string(part.width);
Expand Down

0 comments on commit 27cb4c5

Please sign in to comment.