0

I am trying to export several tasks to a C program via DPI-C. The tasks are defined in the module "my_subm" as:

module my_subm;
    task mytask1(...);
    ...
    endtask
    task mytask2(...);
    ...
    endtask
endmodule

And in my main module "main_mod", where "my_subm" is instantiated:

module main_mod;
    my_subm my_subm_i ();
    `include "dpic_exports.svh"

    initial begin
        ...
    end
endmodule

Where "dpic_exports.svh" is:

`ifndef DPIC_EXPORTS
`define DPIC_EXPORTS

export "DPI-C" task my_subm_i.mytask1;
export "DPI-C" task my_subm_i.mytask2;

`endif

When trying to compile it I get an error saying that in "dpic_exports.svh" my_subm_i is an illegal location for a hierarchical name.

What am I doing wrong?

What I need is these tasks to be available from the scope of "main_mod", as the C tasks that will access them are called from that module.

DogTag
  • 3
  • 1
  • 4

2 Answers2

1

The export statement has to be in the same location as the task/function being exported. Two suggestions: You can create wrapper tasks in your main_mod and export those

task mytask1;
  my_subm_i.mytask1;
endtask
task mytask2;
  my_subm_i.mytask2;
endtask
export "DPI-C" task mytask1;
export "DPI-C" task mytask2;

The other option is to put the export statements inside my_subn_i and use svSetScope(svGetScopeFromName("main_mod.my_subm_i"); in your C code.

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • Saw the answer too late, but exactly how I ended up solving it (export statements inside submodule and using svSetScope in the C code). Accepting your answer now so that it may help someone else. Thank you! – DogTag Nov 27 '17 at 12:48
0

It does seem that a hierarchical reference is not allowed in an export statement.

Here's workaround. Apologies if I'm teaching you to suck eggs:

module my_subm;

    task mytask1(...);
    ...
    endtask
    task mytask2(...);
    ...
    endtask
endmodule

module main_mod;
    my_subm my_subm_i ();

    export "DPI-C" task mytask1;
    export "DPI-C" task mytask2;

    task mytask1(...);
        my_subm_i.mytask1(...);
    endtask

    task mytask2(...);
        my_subm_i.mytask2(...);
    endtask

    initial begin
        ...
    end

endmodule
Matthew Taylor
  • 13,365
  • 3
  • 17
  • 44
  • Is that any different from what I said an hour earlier :) – dave_59 Nov 09 '17 at 18:59
  • No. But your answer wasn't there when I posted mine. It only appeared after posting mine (complete with "1 hour ago" tag). Hey - you got 10 points for it, I wouldn't complain! :) – Matthew Taylor Nov 10 '17 at 09:04