fmt: handle part with unspecified padding in `emit_rtlil`

e.g. `$displayh(8'ha)` won't have a padding set, because it just gets
`lzero` set instead by `compute_required_decimal_places`.

It also doesn't have a width.  In this case, we can just fill in a dummy
(unused) padding.  Either space or zero would work, but space is a bit
more distinct given the width field follows.

Also omit writing the width if it's zero.  This makes the emitted ilang
a little cleaner in places; `{8:> h0u}` is the output for this example,
now.  The other possible extreme would be `{8:>00h0u}`.
This commit is contained in:
Charlotte 2023-06-28 11:51:15 +10:00 committed by Marcelina Kościelnicka
parent 1a222cb163
commit d9e4582558
1 changed files with 4 additions and 3 deletions

View File

@ -183,9 +183,10 @@ void Fmt::emit_rtlil(RTLIL::Cell *cell) const {
else if (part.justify == FmtPart::LEFT)
fmt += '<';
else log_abort();
log_assert(part.padding == '0' || part.padding == ' ');
fmt += part.padding;
fmt += std::to_string(part.width);
log_assert(part.width == 0 || part.padding != '\0');
fmt += part.padding != '\0' ? part.padding : ' ';
if (part.width > 0)
fmt += std::to_string(part.width);
if (part.type == FmtPart::INTEGER) {
switch (part.base) {
case 2: fmt += 'b'; break;