From d9e4582558b84f0cacb64b3e4a1e5d67854ddbd2 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Wed, 28 Jun 2023 11:51:15 +1000 Subject: [PATCH] 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}`. --- kernel/fmt.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/fmt.cc b/kernel/fmt.cc index 68725c136..41de49392 100644 --- a/kernel/fmt.cc +++ b/kernel/fmt.cc @@ -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;