我想编写一个Verilog模块,以便它可以实例化其参数中命名的模块。
module parent();
parameter MODULE = "missing_module";
initial $display("I want to instantiate %s", MODULE);
endmodule
module top();
parent #(.MODULE("child_1")) p();
endmodule
除了不是那个$display
,一个模块实例化child_1
因为这是通过MODULE
参数传入的名称。
这在Verilog中无法完成。如果您知道 MODULE 的所有可能选择,您可以做一个generate-case
module parent();
parameter MODULE = "missing_module";
case(MODULE)
"child_1": child_1 inst_name(ports);
"child_2": child_2 inst_name(ports);
"child_3": child_3 inst_name(ports);
endcase
endmodule
其他选项包括使用 Verilogconfig
或文本宏。但我必须更详细地了解你的情况。
您无法在带有参数的 verilog 中执行此操作。 如果你真的需要任意的模块名称,你可以使用宏来完成,如下所示:
`define PARENT_MODULE(CHILD_MODULE)
module parent();
CHILD_MODULE child();
endmodule
`PARENT_MODULE(my_child)
module top;
parent p();
endmodule
....
`undef PARENT_MODULE