Associative Array of Events

Hi,

Been trying to create an associative array of events and Modelsim doesn’t seem to be happy about it.

  
module event_associative_array;
  // String-indexed
  event e_str[string];
  initial forever begin
    wait(e_str.exists("a"));
    @(e_str["a"]);
    $display("Triggered");
  end

  // Stimulus
  initial begin
    #10;
    ->e_str["a"];
    #10 $finish;
  end
endmodule

Running that gives:


# ** Warning: (vsim-3829) ../../../resources/sv_examples/event_associative_array.sv(13): Non-existent associative array entry. Returning default value.
# ** Note: $finish    : ../../../resources/sv_examples/event_associative_array.sv(14)
#    Time: 20 ns  Iteration: 0  Instance: /event_associative_array

Line 13 is

->e_str["a_str"];

I’ve been looking around to find out if this is legal. It certainly compiles. Seems like an associative array entry is not created unless it’s the LHS of an expression.

Anyone have an idea of a workaround (aside from using uvm_event)?

An associative array of events is legal, but you are correct that it takes an assignment to an array element to construct it. Both an event trigger → and event control @ are just references.

Unfortunately, there is no such thing as a built-in event constructor, so you have to make your own.

module event_associative_array;
  // String-indexed
   event e_str[string];
   
   function automatic event new_event();
      event e;
      return e;
   endfunction    
   initial begin
      e_str["a"]=new_event();
      forever begin
	 @(e_str["a"]);
	 $display("Triggered");
      end
   end
   
   // Stimulus
   initial begin
      #10;
      ->e_str["a"];
      #10 $finish;
   end   
endmodule

Note that uvm_event_pool accomplishes the same thing.

In reply to dave_59:

That is brilliant, thanks very much indeed!