如何在两个模块之间传递 class?

How to pass a class between two modules?

我有两个模块和一个 class,我想将 class 从一个模块移到另一个模块。像这样:

class foo;
   int x;
   int y;
endclass

module mod_A(output foo foo_inst, output event trig);
   initial begin
      foo my_foo = new;
      my_foo.x = 1;
      my_foo.y = 2;
      foo_inst = my_foo;
      ->trig;
   end
endmodule

module mod_B(input foo foo_inst, input event trig);
   always @(trig) begin
       $display("%d%d, is a funky number.", foo_inst.x, foo_inst.y);
   end
endmodule

module top();
   event trig;
   foo   foo_inst;
   mod_A mod_A(.trig, .foo_inst);
   mod_B mod_B(.trig, .foo_inst);
endmodule

当然还有一些函数定义在class中,每个模块都会用到。 此设置的问题是我看到 mod_B:

每个端口的错误
Error-[RIPLIP] Register in low conn of input port
Non-net variable 'foo_inst' cannot be an input or inout port.
Non-net variable   'trig'   cannot be an input or inout port.

EDAplayground 不支持 class 对象作为模块端口并且 1800-2012 仅在端口声明 (23.2.2) 中提及接口声明、事件、数组结构或联合,所以我的问题是:

任何类型的变量都可以是 inputoutput 端口。您可能需要为您的编译器编写

input var foo foo_inst,

但是当端口真的是句柄时,最好使用 ref

module mod_A(ref foo foo_inst, ref event trig);

请注意,您有 foo_ofoo_inst 的拼写错误以及触发器 ->trig 和事件控件 @(trig).[=19= 之间的竞争条件]