2016-11-08 87 views

回答

2

是的,你可以使用类型的操作做一个产生中频/箱,或程序如果/箱,如:

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 
1

IEEE1800-2012 §中有type()运营商6.23。从LRM实例:

bit[12:0] A_bus, B_bus; 
parameter typebus_t = type(A_bus); 
generate 
    case(type(bus_t)) 
    type(bit[12:0]): addfixed_int #(bus_t) (A_bus,B_bus); 
    type(real): add_float #(type(A_bus)) (A_bus,B_bus); 
    endcase 
endgenerate

还有一个在IEEE1800-2012 § 20.6.1描述$typename()$typename()返回该类型的字符串。用法示例从LRM:

// source code   // $typename would return 
typedef bitnode;   // "bit" 
node [2:0] X;    // "bit [2:0]" 
int signedY;    // "int" 
packageA; 
enum{A,B,C=99} X;   // "enum{A=32'sd0,B=32'sd1,C=32'sd99}A::e$1" 
typedef bit[9:1'b1] word; // "A::bit[9:1]" 
endpackage: A 
importA::*; 
moduletop; 
typedef struct{node A,B;} AB_t; 
AB_t AB[10];    // "struct{bit A;bit B;}top.AB_t$[0:9]" 
... 
endmodule
相关问题