There is a difference in the elaboration of generate blocks between VCS and Slang. VCS can elaborate the following code snippet without issues, but Slang cannot. The code has been simplified, so it may not seem practical, but this is to illustrate the issue.
The critical part is the conditional generate block. Due to certain constraints, I need to use the parameter assignment .T_RGB(T) / .T_CMYK(T) because the RGB definition might need to be changed in reality, such as changing each field to 10 bits while keeping the field names the same.
In VCS, this code can be elaborated without errors. However, Slang reports:
test.sv:22:19: error: no member named 'r' in 'T_RGB' (aka 'CMYK')
return (color.r * 3 + color.g * 6 + color.b * 1) / 10;
~~~~~~^
It seems that regardless of the generate block condition, both ColorFunctions are elaborated, causing the type T with CMYK fields to be provided to the T_RGB parameter. I would expect Slang not to elaborate ColorFunctions in the false condition branch.
There are some ways to fix this issue in RTL. For example, in GrayScaleModule, provide two types, one for RGB and one for CMYK, but it would complicate the I/O. Alternatively, we can split the virtual class into two to avoid mixing different type parameters. However, I want to bring up this issue as it seems to be a major difference in different tools.
On a higher level, I believe this syntax oddity is due to the lack of OOP support in SystemVerilog. Because we cannot implement functions for structs like in C, we need to use this virtual class with static functions, as recommended in LRM. The LRM does not specify whether to always elaborate 'static' functions regardless of the generate block condition, leaving the decision to the tools, but I might be missing something.
Additional context
I've run the code with Synopsys VCS, Cadence Xcelium, and Siemens Questa. All tools can elaborate the code snippet I provided.
Describe the bug
There is a difference in the elaboration of generate blocks between VCS and Slang. VCS can elaborate the following code snippet without issues, but Slang cannot. The code has been simplified, so it may not seem practical, but this is to illustrate the issue.
To Reproduce
Consider the following code snippet:
The critical part is the conditional generate block. Due to certain constraints, I need to use the parameter assignment
.T_RGB(T)
/.T_CMYK(T)
because the RGB definition might need to be changed in reality, such as changing each field to 10 bits while keeping the field names the same.In VCS, this code can be elaborated without errors. However, Slang reports:
It seems that regardless of the generate block condition, both ColorFunctions are elaborated, causing the type
T
with CMYK fields to be provided to theT_RGB
parameter. I would expect Slang not to elaborate ColorFunctions in the false condition branch.There are some ways to fix this issue in RTL. For example, in GrayScaleModule, provide two types, one for RGB and one for CMYK, but it would complicate the I/O. Alternatively, we can split the virtual class into two to avoid mixing different type parameters. However, I want to bring up this issue as it seems to be a major difference in different tools.
On a higher level, I believe this syntax oddity is due to the lack of OOP support in SystemVerilog. Because we cannot implement functions for structs like in C, we need to use this virtual class with static functions, as recommended in LRM. The LRM does not specify whether to always elaborate 'static' functions regardless of the generate block condition, leaving the decision to the tools, but I might be missing something.
Additional context
I've run the code with Synopsys VCS, Cadence Xcelium, and Siemens Questa. All tools can elaborate the code snippet I provided.