0

I would like to write a Verilog module such that it can instantiate the module named in its parameter.

module parent();
  parameter MODULE = "missing_module";

  initial $display("I want to instantiate %s", MODULE);
endmodule

module top();
  parent #(.MODULE("child_1")) p();
endmodule

Except that instead of that $display, a module instantiation of child_1 as that was the name passed in via the MODULE parameter.

2 Answers 2

3

This cannot be done in Verilog. If you know all the possible choices for MODULE, you could do agenerate-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

Other options are using Verilog configs or text macros. But I would have to have more details about your situation.

Sign up to request clarification or add additional context in comments.

Comments

2

You cannot do it in verilog with parameters. If you really need to have arbitrary module names, you can do it with macros, something like the following:

`define PARENT_MODULE(CHILD_MODULE) \
    module parent();\
        CHILD_MODULE child();\
    endmodule

`PARENT_MODULE(my_child)

module top;
  parent p();
endmodule

 ....

`undef PARENT_MODULE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.