Major Tools
Other Tools
General Info

use enum from a sv module in c++ testbench using /*verilator_public*/

Added by toby matthews about 1 year ago

Hello all,

I would like to get some help to use typedef enums from a module. I found this: but there is no explanation on how to actually do it.

in my file i have these two lines:

    typedef enum logic [2:0] {load_W, load_H, load_HU, load_B, load_BU } ram_sel_load_t /*verilator public*/;
    typedef enum logic [1:0] {store_W,store_H, store_B } ram_sel_store_t /*verilator public*/;
after verilating, i get a file in the objdir that contains the enums - "Vram___024unit.h" of which the contents are
VL_MODULE(Vram___024unit) {

    // That were declared public
    enum ram_sel_load_t {
    load_W = 0U,
    load_H = 1U,
    load_HU = 2U,
    load_B = 3U,
    load_BU = 4U

    enum ram_sel_store_t {
    store_W = 0U,
    store_H = 1U,
    store_B = 2U
but the problem is that i have no idea how to use the enum values without including this "Vram___024unit.h" file to my testbench. I can do it like this:
#include "Vram___024unit.h" 
int main(int argc, char** argv, char** env) {
       printf("---->%d   \n", Vram___024unit::ram_sel_load_t::load_HU);

But the unit file has a header that says this file is design internal, so i am not sure if this is the correct way of using it.

I believe i should be able to access it from the Vram class (Vram.h) top module verilated header file which has this:
    // CELLS
    // Public to allow access to /*verilator_public*/ items;
    // otherwise the application code can consider these internals.
    Vram_ram*              ram;
    Vram___024unit*        __PVT____024unit;
I cant seem to figure out how to get the enum value from the Vram top module class. I have tried various sort of permutations like this one below

Vram *TOP;
TOP = new Vram;
printf("%d", TOP->__PVT____024unit::ram_sel_load_t::load_HU);
(this does not work of course)

could anyone please show me the correct way of using the enum values?

Replies (2)

RE: use enum from a sv module in c++ testbench using /*verilator_public*/ - Added by Wilson Snyder about 1 year ago

Yes, you need to include the internal header. Typically also include the main header:

#include "Vram.h" 
#include "Vram___024unit.h"

The comment about it being internal should be cleaned up as it does not apply when public is used, I'll think of how to properly word that.