Extern types don't codegen correctly when array-typed
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
Extern types (e.g. `#[sv_type(...)]`) don't codegen correctly for array types.
**To Reproduce**
Given an sv type like `typedef logic[7:0][3] u8_3_t;`:
```
#[sv_type("u8_3_t")]
type u8_3_t = u8[3];
fn muladd(abc: u8_3_t) -> u8 {
abc[0] * abc[1] + abc[2]
}
```
and run:
```
$BINPATH/xls/dslx/ir_convert/ir_converter_main test.x --top=muladd --interface_proto_file=test.proto | $BINPATH/xls/tools/codegen_main - --delay_model=asap7 --pipeline_stages=1 --ir_interface_proto=test.proto
```
**Expected behavior**
Codegen should use `abc[0]`, `abc[1]`, `abc[2]`, etc., but in reality you get
```
wire [7:0] abc_unflattened[3];
assign abc_unflattened[0] = abc[7:0];
assign abc_unflattened[1] = abc[15:8];
assign abc_unflattened[2] = abc[23:16];
```
**Additional context**
The problem is that our codegen expects array ports to be packed into a bitvector and then internally unpacks the array, but using extern types violates this expectation.
A workaround is to wrap extern sv types in a struct.
Contributor guide
Assessment
This issue has not been assessed yet.