所以我在公共(public)模块中使用参数化类型。
有没有一种说法: if( type == TYPE1 ) 以一种方式分配结构 else if( type == TYPE2 ) 以另一种方式分配
我在生成 block 中想象了这一点。
最佳答案
是的,您可以使用类型运算符执行生成 if/case 或过程 if/case,例如:
real r;
if ( type(r) == type(real) ) ...
但不幸的是,无论条件如何,所有分支中的代码仍然必须成功编译。您将无法引用不存在的结构成员。
typedef struct {int a;} s1_t;
typedef struct {int a;int b;} s2_t;
s1_t s;
initial
#1 // procedural-if
if (type(s) == type(s1_t))
$display("%m s.a = %0d",s.a);
else if (type(s) == type(s2_t))
$display("%m s.b ==%0d",s.b); // this will not compile
关于system-verilog - 在 systemverilog 中,有没有办法以类型为条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40496074/