Search code examples
uvm

hooking up uvm_analysis_export and write function


I've learned two design patterns of writing a subscriber:

1) Derive from uvm_subscriber, override the write function, which is then called over the built-in analysis port

2) derive from uvm_component, install an uvm_analysis_export and uvm_tlm_analysis_fifo, connect them and process in the run_phase

I'm wondering about the following. If I do not derive from uvm_subscriber, but from uvm_component, install an uvm_analysis_export and write a write function, which is to be called over the uvm_analysis_export by the corresponding port, how do I do hook up the uvm_analysis_export to the write? Is it possible at all?


Solution

  • It is not possible to "hook up the uvm_analysis_export to the write". Instead, you need to derive from uvm_component, install a uvm_analysis_imp (an imp not an export) and write a write function.

    An imp is the endpoint; (with the subscriber pattern) it is this that calls the write method. An export is a waypoint; it can only be connected to another export or imp.

    If we look at the source code for the uvm_subscriber class, we can see how to do it:

    virtual class uvm_subscriber #(type T=int) extends uvm_component;
    
      typedef uvm_subscriber #(T) this_type;
    
      // Port: analysis_export
      //
      // This export provides access to the write method, which derived subscribers
      // must implement.
    
      uvm_analysis_imp #(T, this_type) analysis_export;
    
      // Function: new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
    
      function new (string name, uvm_component parent);
        super.new(name, parent);
        analysis_export = new("analysis_imp", this);
      endfunction
    
      // Function: write
      //
      // A pure virtual method that must be defined in each subclass. Access
      // to this method by outside components should be done via the
      // analysis_export.
    
      pure virtual function void write(T t);
    
    endclass
    

    I am not quite sure why you'd want to do this, because as you can see, you'd be pretty much just rewriting what's already done for you in uvm_subscriber. I guess by asking the question you've learnt something and I've refreshed some knowledge in answering it.