lonely
lonely

Reputation: 681

Element not found for associative array index in constraint

I'm trying to randomize the contents of an associative array, and I ran into an error:

element not found for associative array index in constraint

How do I initialize these indices and then randomize their values?

module top;

class TFoo;

typedef struct {
                rand byte element_id;
                rand byte length;
                rand byte body_val[int];
               } mgmt_info_ele;

rand mgmt_info_ele   tspec; 

constraint tspec_1                                //Constraints for tspec
   {
      tspec.element_id == 8'd13;
      tspec.length == 'd55;
      //tspec.body_val.num() == tspec.length;      
      {tspec.body_val[1][0],tspec.body_val[0][7]} inside {[1:3]};
      tspec.body_val[1][7:6] inside {0, 1, 3};
      tspec.body_val[2][7:1] == 7'b0;
   }
endclass

TFoo f = new;
int status;

initial begin
    for(int i = 0; i < 1000; i++) begin
        $display("i=%0d: %s", i, f.get_randstate());
                $display("NUM Return value = %0d", f.tspec.body_val.num());      
        status = f.randomize();
        $display(status);
        assert(status) else $fatal;
    end
end

endmodule

Upvotes: 0

Views: 571

Answers (1)

dave_59
dave_59

Reputation: 42698

Calling randomize cannot modify the size of an associative array or any of its index keys. The indexes of an associative array are not necessarily consecutive. That is why people sometimes call them sparse arrays. Perhaps you should use a dynamic array instead.

Upvotes: 2

Related Questions