传递模块名称作为参数

igo*_*gon 4 hardware verilog register-transfer-level system-verilog

我想为我正在编写的模块创建通用包装。包装程序应具有将这些模块连接到不同类型的NoC的能力,而不必更改内部模块的行为。

我认为实现此目标的一种方法如下。考虑一个非常简单的模块来包装:

module add #(                                                                                                                       
             parameter COLUMN_WIDTH     = 32                                                                                        
             )

   (
    //data in                                                                                                                       
    input logic [COLUMN_WIDTH-1:0]  col_1,
    input logic [COLUMN_WIDTH-1:0]  col_2,
    //data out                                                                                                                      
    output logic [COLUMN_WIDTH-1:0] col_o

    );

   assign col_o = col_1 + col_2;

endmodule
Run Code Online (Sandbox Code Playgroud)

包装器应为以下内容:

module wrapper #(                                                                                                                   
                 parameter COLUMN_WIDTH     = 32,                                                                                   
                 parameter WRAPPED_MODULE   = add                                                                                   
             )
   (
    //data in                                                                                                                       
    input logic [COLUMN_WIDTH-1:0]  col_1,
    input logic [COLUMN_WIDTH-1:0]  col_2,
    //data out                                                                                                                      
    output logic [COLUMN_WIDTH-1:0] col_o,
    /* std signals */
    input logic                     clk,
    input logic                     reset_i // reset everything                                                                     
    );

   logic [COLUMN_WIDTH-1:0]         max_result;

   WRAPPED_MODULE #(.COLUMN_WDITH(COLUMN_WIDTH),
                    ) a(
                        .*
                        );

   always @(posedge clk) begin
      if (reset_i)
        max_result <= 0;
      else
        max_result <= (col_o > max_result) ? col_o : max_result;
   end

endmodule
Run Code Online (Sandbox Code Playgroud)

我得到的错误如下:

Error-[IND] Identifier not declared
wrapper.sv, 4
  Identifier 'add' has not been declared yet. If this error is not expected, 
  please check if you have set `default_nettype to none.
Run Code Online (Sandbox Code Playgroud)

这是有道理的,因为参数与宏不同。完整的设计可能应实例化一堆包装模块,并且我不想通过为每个内部模块创建包装器来重复代码。我怎样才能做到这一点?

Gre*_*reg 5

参数不能是模块名称。它可以是data_type,隐式data_type或type

IEEE标准2000至12年 §A.2.1.1 模块参数声明

parameter_declaration :: =
    参数data_type_or_implicit list_of_param_assignments
  | 参数类型list_of_type_assignments

一种解决方法是使用generate块并比较参数的值。

module wrapper #(
    parameter        COLUMN_WIDTH     = 32,
    parameter string WRAPPED_MODULE   = "add"
  )
  (
    // ...
  );
  // ...
  generate
    if (WRAPPED_MODULE=="add") begin
      add #(.COLUMN_WDITH(COLUMN_WIDTH) ) a( .* );
    end
    else begin
     // ...
    end
  endgenerate
  // ...
endmodule
Run Code Online (Sandbox Code Playgroud)