Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

system verilog - DPI-C export of a task defined inside a SystemVerilog class

Would it be possible to export to C a task defined inside a SystemVerilog class as the following?

class packet_bfm_t;
    int id = 0;

    export "DPI-C" task send; // Is this possible and legal to call from C code?

    function new (int my_id = 0);
      id = my_id;
    endfunction : new

    task send (int data);
      #1ns;
      $display ("data = %h", data);
    endtask : send

endclass : packet_bfm_t
question from:https://stackoverflow.com/questions/65911618/dpi-c-export-of-a-task-defined-inside-a-systemverilog-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The DPI does not alow exporting a class method. Same problem as calling a C++ class method from C. You would have to define and export a non-class task wrapper that uses an Id or whatever is needed to look up the class object in a table. The you can call the method on that class object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...