Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macros Systemverilog:是否可以将宏视为可以索引的数组?_Macros_System Verilog - Fatal编程技术网

Macros Systemverilog:是否可以将宏视为可以索引的数组?

Macros Systemverilog:是否可以将宏视为可以索引的数组?,macros,system-verilog,Macros,System Verilog,在SystemVerilog中,是否可以为宏编制索引以进行长层次引用?i、 e `define CONDENSED top.DUT.mod.sub_module.register_map 然后做一些类似的事情: `CONDENSED.reg1[0] 宏只是简单的文本替换。执行子位置的文本预处理器对SystemVerilog语法一无所知,只知道令牌是什么(字符串、数字文本、标识符、注释)。只要生成的文本是legal SystemVerilog文本,就可以使用任何宏。(请注意有关分割组成标记的文

在SystemVerilog中,是否可以为宏编制索引以进行长层次引用?i、 e

`define CONDENSED top.DUT.mod.sub_module.register_map
然后做一些类似的事情:

`CONDENSED.reg1[0]

宏只是简单的文本替换。执行子位置的文本预处理器对SystemVerilog语法一无所知,只知道令牌是什么(字符串、数字文本、标识符、注释)。只要生成的文本是legal SystemVerilog文本,就可以使用任何宏。(请注意有关分割组成标记的文本的规则)。

您甚至可以在宏中包含索引:

`define MY_SELECTION(index0, index1) c0_a[index0].c1_a[index1].a

class c1;
  int a;
endclass

class c0;
  c1 c1_a[10];

  function new();
    foreach(c1_a[idx]) begin
      c1_a[idx] = new();
    end
  endfunction
endclass

module top;
  initial begin
    automatic c0 c0_a[10];

    foreach(c0_a[idx]) begin
      c0_a[idx] = new();
    end

    `MY_SELECTION(5, 6) = 8;
    $display("my_value: %0d", `MY_SELECTION(5, 6));

    `MY_SELECTION(5, 6)[0] = 1;
    $display("my_value: %0d", `MY_SELECTION(5, 6));
  end
endmodule
此代码的输出如下所示:

my_value: 8
my_value: 9
您可以在EDA操场上运行此示例-