cpp_transpiler should emit DSLX constants
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
### What's hard to do? (limit 100 words)
Currently the cpp_transpiler only converts type definitions for use in C++: https://github.com/google/xls/blob/fe11876713d1710ae0e7aab974dbc1197221475b/xls/dslx/cpp_transpiler/cpp_transpiler.cc#L107-L108
It would be useful to also convert constants so that the C++ is aware of the parametrization of DSLX types.
### Current best alternative workaround (limit 100 words)
In some cases, you could make fake types in the DSLX library that would generate what you want as a side effect. For example:
```
const FOO = u32:32; // constant I care about
type FooBits = bits[FOO];
```
would generate something like
```
using FooBits = uint32_t;
constexpr int64_t kFooBitsWidth = 32; // hurray!
```
Alternatively, the constants can be redefined in the consumer C++ library, but this creates multiples sources of truth.
### Your view of the "best case XLS enhancement" (limit 100 words)
Emit DSLX `const` definitions in the C++ generated library.
Contributor guide
Assessment
This issue has not been assessed yet.