声明一组枚举类型

时间:2016-12-19 17:47:41

标签: system-verilog

我想做以下事情:

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

但我想制作" variable_name"使用dir_e作为索引的数组。例如

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

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

这有意义吗?

2 个答案:

答案 0 :(得分:1)

您想要声明一个关联数组。

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;

答案 1 :(得分:0)

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

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;