在verilog中声明的导线问题会生成块

use*_*672 3 verilog declaration

在一个generate区块内,我有多个if陈述.当我在第一个if语句中声明一个连线时 - 我不能在其他if语句中使用它

请参阅我的模块的以下精简示例:

module my_module 
#(parameter integer NUM_X_PORTS = 1,
  parameter integer NUM_Y_PORTS = 1)
 (
  // port declarations
 );

generate 

  if (NUM_X_PORTS > 0) begin
    wire [NUM_X_PORTS-1:0] x1;
    // logic filled in here
  end

  if (NUM_Y_PORTS > 0) begin
    wire [NUM_Y_PORTS-1:0] y1;
    // logic filled in here
  end

  if ((NUM_X_PORTS > 0) && (NUM_Y_PORTS > 0)) begin
    for (i=0; i<NUM_Y_PORTS; i=i+1) begin
      assign z[i] = y1[i] & |x1; // I can't use x1 and y1 here
    end

endgenerate
Run Code Online (Sandbox Code Playgroud)

来自VCS和nLint的错误消息是尚未声明标识符x1和y1.

但它们已在之前生成的if语句中声明 - 这里的问题是什么?

Gre*_*reg 7

导线x1y1定义超出了分配范围.一种解决方案是添加和引用范围标签:

if (NUM_X_PORTS > 0) begin : scope_x1
  wire [NUM_X_PORTS-1:0] x1;
  // logic filled in here
end

if (NUM_Y_PORTS > 0) begin : scope_y1
  wire [NUM_Y_PORTS-1:0] y1;
  // logic filled in here
end

if ((NUM_X_PORTS > 0) && (NUM_Y_PORTS > 0)) begin : scope_z
  for (i=0; i<NUM_Y_PORTS; i=i+1) begin : scopes_z_i_ // loop has unique scope
    // x1 & y1 accessed by scope label found by its parent
    assign z[i] = scope_y1.y1[i] & |scope_x1.x1; 
  end
end
Run Code Online (Sandbox Code Playgroud)

对于工作分配,声明x1y1必须存在scope_2于其范围或其父级.

if ((NUM_X_PORTS > 0) && (NUM_Y_PORTS > 0)) begin  : scope_z
  wire [NUM_X_PORTS-1:0] x1;
  wire [NUM_Y_PORTS-1:0] y1;
  // logic filled in here
  for (i=0; i<NUM_Y_PORTS; i=i+1) begin : scopes_z_i_ // loop has unique scope
    assign z[i] = y1[i] & |x1; // everything is withing scope_z
  end
end
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,这x1y1范围有限.如果你不希望电线在其被尊重NUM_*_PORTS > 0为假时存在,那么你必须遵循第一个例子.

请参阅IEEE Std1800-2012§27.生成有关更多内容的构造