intel / intel/rohd

LogicValue radixString code should allow for prefix-free strings

Open
#591 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Dart
Stars
489
Forks
88
Avg merge
3d 23h
Merged PRs (30d)
10

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.