声明枚举类型的数组

Declaring an array of enumerated types

我想执行以下操作:

typedef enum {a, b, c} my_type_e;
typedef enum {receive, transmit} dir_e;

class my_class #(type my_type_e);
  my_type_e variable_name;
endclass

但我想使用 dir_e 作为索引使 "variable_name" 成为一个数组。例如

my_class class_h;
class_h.variable_name[rx] = a;

my_class class_h;
class_h.variable_name[tx] = c;

这有意义吗?

您想声明一个关联数组。

class my_class #(type my_type_e);
  my_type_e variable_name[dir_e];
endclass

my_class class_h;
class_h.variable_name[receive] = a;

假设您想使用参数,我不会让类型参数与现有类型相匹配。另外,一些模拟器仍然不支持没有默认值。

typedef enum {a, b, c} my_type_e;
typedef enum {receive, transmit} dir_e;

class my_class #(type T=my_type_e, type K=dir_e);
  T variable_name[K];
endclass

my_class class_h;
class_h.variable_name[receive] = a;