Distributing task calls between SV implementations in "generate" blocks

In reply to dave_59:

Thanks Dave, that was helpful. The contrast of “generate-if” vs “procedural-if” is what I was missing.

As an aside, while waiting for the response I was playing around and found that (at least on one tool) the following works:

module ram #(parameter Vendor = 0) ();
  generate
    if (Vendor) begin : impl
      vendor_ram uINST ();
    end
    else begin : impl
      behavioral_ram uINST ();
    end
    task RamWrite (input a, output b);
      begin
        if (Vendor) impl.uINST.RamWrite(a, b);
        else impl.uINST.RamWrite(a, b);
      end
    endtask // RamWrite
  endgenerate
endmodule

module vendor_ram;
  task RamWrite (input a, output b);
    begin $display("vendor ram write"); end
  endtask // VendorRamWrite
endmodule

module behavioral_ram;
  task RamWrite (input a, output b);
    begin $display("behav ram write"); end
  endtask // BehavioralRamWrite
endmodule

Basically, name the two generate blocks the same, name the tasks the same, and ensure tasks have the same arguments. This probably doesn’t solve my original problem because I need to be able to call different subtasks.

I’m asking this followup because I’m not sure if this is expected to work (cross-vendor etc). It feels a bit like I’m “fooling” the tool. I did run it and verified that it calls the right sub-module’s task when I change the top level parameter.

If this is legal, I could imagine building an additional layer of “distributor” tasks (within vendor_ram and behavioral_ram) which have the same name/arguments (RamWrite), which then call the local versions (VendorRamWrite & BehavioralRamWrite). If that is somehow valid it’s another way to get this to work.

I’ll still look into the config files. AFAIK those are the only way to swap in a really different implementation (behavioral, gate level, etc) so it’s a powerful technique. It’s not ideal for the problem I was trying to solve as I’m trying to make a very reusable library and I don’t want the “integration” person to be in the loop for these RAM mappings. If the config file can be setup hierarchically that could work…