System Verilog 枚举类型分配
System Verilog Enum Type Assignment
我的库中有一个通用模块,它在设计的不同地方多次使用。
module generic #(
parameter WIDTH = 1
) (
input logic [WIDTH-1:0] a,
output logic [WIDTH-1:0] z
);
some function...
endmodule
这在设计中是这样使用的,其中 my_type_t 是在别处定义的 typedef enum logic
类型:
my_type_t ope, res;
generic #(
.WIDTH ($bits(ope))
) ope_res (
.a (ope),
.z (res)
);
编译时,我在 VCS 中收到 lint 警告:
Warning-[ENUMASSIGN] Illegal assignment to enum variable
...
Only expressions of the enum type can be assigned to an enum variable.
The type logic [WIDTH-1:0] is incompatible with the enum 'my_type_t'
Expression: z
Use the static cast operator to convert the expression to enum type.
有没有简单的方法可以解决这个问题? generic
模块用于不同的 type
,因此它必须是非 type
模块。
你最好有充分的理由从枚举类型中强制转换。您可以使用流式解包运算符
解决该错误
generic #(
.WIDTH ($bits(ope))
) ope_res (
.a (ope),
.z ({>>{res}})
);
解决此问题的正确方法是 generic
使用参数化类型。
module generic #(
parameter WIDTH = 1, type T = logic [WIDTH-1:0]
) (
input logic T a,
output logic T z
);
// some function...
endmodule
module ...
my_type_t ope, res;
generic #(
.T (my_type_t)
) ope_res (
.a (ope),
.z (res)
);
endmodule
我的库中有一个通用模块,它在设计的不同地方多次使用。
module generic #(
parameter WIDTH = 1
) (
input logic [WIDTH-1:0] a,
output logic [WIDTH-1:0] z
);
some function...
endmodule
这在设计中是这样使用的,其中 my_type_t 是在别处定义的 typedef enum logic
类型:
my_type_t ope, res;
generic #(
.WIDTH ($bits(ope))
) ope_res (
.a (ope),
.z (res)
);
编译时,我在 VCS 中收到 lint 警告:
Warning-[ENUMASSIGN] Illegal assignment to enum variable
...
Only expressions of the enum type can be assigned to an enum variable.
The type logic [WIDTH-1:0] is incompatible with the enum 'my_type_t'
Expression: z
Use the static cast operator to convert the expression to enum type.
有没有简单的方法可以解决这个问题? generic
模块用于不同的 type
,因此它必须是非 type
模块。
你最好有充分的理由从枚举类型中强制转换。您可以使用流式解包运算符
解决该错误generic #(
.WIDTH ($bits(ope))
) ope_res (
.a (ope),
.z ({>>{res}})
);
解决此问题的正确方法是 generic
使用参数化类型。
module generic #(
parameter WIDTH = 1, type T = logic [WIDTH-1:0]
) (
input logic T a,
output logic T z
);
// some function...
endmodule
module ...
my_type_t ope, res;
generic #(
.T (my_type_t)
) ope_res (
.a (ope),
.z (res)
);
endmodule