Problems with wires declared inside verilog generate blocks

http://stackoverflow.com/questions/22200666/problems-with-wires-declared-inside-verilog-generate-blocks


Within a generate block, I have multiple if statements. When I declare a wire in the first if statement - I can't use it in other if statements

See the following stripped down example of my module:

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

The error message from both VCS and nLint is that indentifiers x1 and y1 have not been declared.

But they have been declared within previous generated if statements - what is the problem here?

=======================================================================================================

The wires x1 and y1 are defined outside of scope of the assignment. One solution is to add and reference scope lables:

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

For the assignment to work, the declaration of x1 and y1 must exist withing the scope of scope_2 or its parent.

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

In both this cases x1 and y1 are limited in scope. If you do not wish the wire to exist when its respected NUM_*_PORTS > 0 is false, then you must follow the first example.

See IEEE Std 1800-2012 § 27. Generate constructs for more on generate


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值