为什么 typedef 不能在 systemveriliog 的本地使用?

Why is typedef can not be used in local in systemveriliog?

为什么typedef不能在systemveriliog中本地使用?

我引用自 http://www.asic-world.com/systemverilog/data_types7.html

我在使用 struct 而不是 typedef struct 时遇到问题。为什么不使用?

第一个问题"why typedef cannot be used locally?" Typedef 可以在任何 SystemVerilog 模块中使用,并且可以根据我们的需要 accessed/initialized。参考第 6.18 节用户自定义类型的 SV LRM IEEE 1800 - 2012

这是一个在模块中使用 typedef 的例子

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 的情况下使用 struct,我已经在上面的示例中展示了。

以上代码的输出

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