2015-06-22 47 views

回答

0

您的第一個問題「爲什麼typedef不能在本地使用?」 Typedef可以用在任何SystemVerilog模塊中,可以根據我們的需要進行訪問/初始化。請參閱SV LRM的第6.18節用戶定義類型IEEE 1800 - 2012

下面是使用類型定義模塊

struct { //using struct without typedef 
    byte a; 
    reg b; 
    shortint unsigned c; 
} myStruct; 

module struct_data(); 

struct { 
    byte a; 
    reg b; 
    shortint unsigned c; 
} myLocalStruct = '{11,1,101}; 

typedef struct { //using typedef inside the module 
real r0, r1; 
int i0, i1; 
logic [ 7:0] opcode; 
logic [23:0] address; 
} instruction_word_t; 

instruction_word_t IW; 
assign IW = '{ real:1.0,default:0}; 

assign myStruct = '{10,0,100}; 

initial begin 
    #1; 
    $display ("a = %b b = %b c = %h", myStruct.a, myStruct.b, myStruct.c); 
    $display ("a = %b b = %b c = %h", myLocalStruct.a, myLocalStruct.b, myLocalStruct.c); 
    $display ("r0 = %b r1 = %d opcode = %h ,address = %h ",IW.r0, IW.r1, IW.opcode,IW.address); 
    #1 $finish; 
end 

endmodule 

內部關於第二個問題一個例子,我們也可以用結構不使用的typedef,我已經出上面的例子。上面的代碼

a = 00001010 b = 0 c = 0064 
a = 00001011 b = 1 c = 0065 
r0 = 00000000000000000000000000000001 r1 =   1 opcode = 00 ,address = 000000 
相關問題