0

I have some parameterized Verilog and I need to dynamically generate instance module names, but I don't know how, within the confines of Verilog itself(i.e. without creating a script or similar to generate flat Verilog).

A bit of background, I have a large number of memory modules in a memory library. These are all named, approximately, MemModuleDepth_Width in a wide range of depths and widths. I have parameterized module that would like to use the memories from this library. However, to do this, I need to dynamically generate the module names, as shown below.

module fifo(in, out)
parameter width;
parameter depth;
...fifo stuff...
MemModule"depth"_"width" (read_address, read_data, etc.) <== where depth and width sweep in values
endmodule

This is not the typical use of something like a generate statement, and, as I have tried, also outside the scope of define macros, since the macros are expanded before the code body is parsed. This doesn't work:

`define DATAMEM(depth, width) MemModule``depth``_``width``
...
generate
    genvar i;
    for(i = 1; i <= depth; i = i++) begin : depth
        genvar j;
        for(j = 1; j <= width 0; j = j++) begin : width
            `DATAMEM(i, j) dpRam
        end
    end
endgenerate

This code simply tries to instantiate "MemModulei_j" rather than substituting the actual numerical values for i and j.

Any hints as to how one might do this?

1
  • 2
    actually it should generate module names as this depth[0].width[0].MemModuleI_j, depth[0].width[1]..... See if this is sufficient for you or not. Commented May 10, 2019 at 1:18

1 Answer 1

3

You cannot build an identifier name except through the use of macros. As you pointed out, that will not work for parameter values.

If you had a manageable number of actual depth/width combinations you expect to use, you could create a generate-case/if construct tree

module MemModuleGeneric #(int depth, width) (...);
case (width)
  16: case (depth)
        16: MemModule16_16 M(read_address, read_data, etc.);
        24: MemModule16_24 M(read_address, read_data, etc.);
      endcase
  32: case (depth)
        16: MemModule32_16 M(read_address, read_data, etc.);
        24: MemModule32_24 M(read_address, read_data, etc.);
      endcase
endcase
endmodule
Sign up to request clarification or add additional context in comments.

3 Comments

You can easily use another scripting language to generate these combinations, and put it in a file that's included here. That way if you need to add a new memory module, simply update the script (or configuration file that the script will consume).
The OP did not want a script so they could take advantage of parameterization
I meant to generate the case statements that you provided. They can still parameterize the wrapper module.

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.