3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-24 01:25:33 +00:00

fmt,cxxrtl: support {,PLUS_,SPACE_}MINUS integer formats.

The first two were already supported with the `plus` boolean flag.
The third one is a new specifier, which is allocated the ` ` character.
In addition, `MINUS` is now allocated the `-` character, but old format
where there is no `+`, `-`, or `-` in the respective position is also
accepted for compatibility.
This commit is contained in:
Catherine 2024-03-28 06:59:23 +00:00 committed by Marcelina Kościelnicka
parent 8388846e3a
commit 6d6b138607
3 changed files with 50 additions and 16 deletions

View file

@ -1033,7 +1033,11 @@ struct fmt_part {
// INTEGER type
unsigned base; // = 10;
bool signed_; // = false;
bool plus; // = false;
enum {
MINUS = 0,
PLUS_MINUS = 1,
SPACE_MINUS = 2,
} sign; // = MINUS;
bool hex_upper; // = false;
// VLOG_TIME type
@ -1105,8 +1109,11 @@ struct fmt_part {
buf += '0' + remainder.template trunc<4>().template get<uint8_t>();
xval = quotient;
}
if (negative || plus)
buf += negative ? '-' : '+';
switch (sign) {
case MINUS: buf += negative ? "-" : ""; break;
case PLUS_MINUS: buf += negative ? "-" : "+"; break;
case SPACE_MINUS: buf += negative ? "-" : " "; break;
}
std::reverse(buf.begin(), buf.end());
} else assert(false && "Unsupported base for fmt_part");
break;