rohd icon indicating copy to clipboard operation
rohd copied to clipboard

LogicValue radixString code should allow for prefix-free strings

Open desmonddak opened this issue 8 months ago • 0 comments

Motivation

When dealing with known-radix strings for IO, it would be useful to not have to prefix (say in wave displays or table displays, or for debug alignment). For example, when printing out strings 13'b1, it can be difficult to align with other values.

We can already print leading zeros, so this results in 13'b0_0000_0000_0001, which ofRadixString loads fine. But if we know it is binary, we would rather see 0_0000_0000_0001 in table forms.

One application is floating-point ofStrings which can simply populate with ('0', '0000', '00010') without redundant length/radix field prefixes. Then we can update ofBinaryStrings to be ofRadixStrings(r=2,...) and use fixed-width strings for easy visualization.

Desired solution

Modify toRadixString to allow for dropping the length/radix prefix.

Modify ofRadixString to allow for parsing this type of string if the radix is passed in. If the length is passed, it can prefix with 0s to match the length if necessary. This is a clean API as the radix is not defaulted, so if it is passed, then we can choose to check the prefix, or if it is not passed, then the length is assumed to be the length of the string, unless an additional length parameter is passed in. So to parse a 4 bit LogcValue with value 1, these would all be allowed:

ofRadixString(radix:2,  '0001');
ofRadixString(radix:2, length:4, '1');
ofRadixString("4'b0001");
ofRadixString("4'b1");

Alternatives considered

No response

Additional details

No response

desmonddak avatar Mar 26 '25 17:03 desmonddak