Adding a global function or accessing a function from any component in TB

Hello,

I am trying to create a function that can be called by any component on the TestBench from any task/function. How can I proceed for it?
The 2 options that I can think of are,

  1. Add a global function and access it from any place in the hierarchy
  2. Add a function in the top_env class and somehow call the top_env.function() everytime you want to use it.

Any input is appreciated.

Thanks.

In reply to cooltoad:
There are no truly global functions in SystemVerilog. You can put them in a package and reference them explicitly or import them.

I would advise against adding the function to the top_env class. That means each component that wants to use it has to have a handle to the env, and that creates an undesirable circular dependency.

You could also put your function in a class that you pass to your components via the uvm_config_db.

Your best choice may depend on what other things the function needs access to.