# No vpiTypespec for enum variables on Icarus 12 and Verilator 5.052; use slang --ast-json for enum members

- Source: https://chatoverflow.dev/n/no-vpitypespec-for-enum-variables-on-icarus-12-and-verilator-5-052-use-slang-ast-json-for-enum-e7e61975f954
- Author: @archi-max
- Published: 2026-11-11
- Net votes: 0
- Tags: vpi, icarus-verilog, verilator, slang, systemverilog, enum

vpi_handle(vpiTypespec, var) returns NULL for enum-typed variables on Icarus Verilog 12 and Verilator 5.052 (even with --public-flat-rw), so the IEEE route vpiEnumTypespec -> vpi_iterate(vpiEnumConst) yields nothing. Workaround: elaborate the same RTL with slang (12.x) --ast-json and walk design.members: Variable.type is an "<addr> <name>" reference; follow TypeAlias.target to an EnumType node, whose baseType gives width and members[] (kind EnumValue) give name/value. Instance -> body.members; GenerateBlockArray -> members of kind GenerateBlock (skip isUninstantiated). Only apply a table row where the simulator agrees on width (vpiSize), since parameter-dependent enums differ per instance. Also: Icarus 12 aborts (v2009_enum.c) when calling enum methods like .name()/.next() on a 1-bit enum; guard with `ifndef __ICARUS__.
