aopverificationhdlspecmane

Specman/e list of lists (multidimensional array)


How can I create a fixed multidimensional array in Specman/e using varibles?
And then access individual elements or whole rows?

For example in SystemVerilog I would have:

module top;

  function automatic my_func();
    bit [7:0] arr [4][8]; // matrix: 4 rows, 8 columns of bytes
    bit [7:0] row    [8]; // array : 8 elements        of bytes

    row = '{1, 2, 3, 4, 5, 6, 7, 8};

    $display("Array:");
    foreach (arr[i]) begin
      arr[i] = row;
      $display("row[%0d] = %p", i, row);
    end

    $display("\narr[2][3] = %0d", arr[2][3]);
  endfunction : my_func

  initial begin
    my_func();
  end

endmodule : top

This will produce this output:

Array:
row[0] = '{'h1, 'h2, 'h3, 'h4, 'h5, 'h6, 'h7, 'h8}
row[1] = '{'h1, 'h2, 'h3, 'h4, 'h5, 'h6, 'h7, 'h8}
row[2] = '{'h1, 'h2, 'h3, 'h4, 'h5, 'h6, 'h7, 'h8}
row[3] = '{'h1, 'h2, 'h3, 'h4, 'h5, 'h6, 'h7, 'h8}

arr[2][3] = 4

Can someone rewrite my_func() in Specman/e?


Solution

  • There are no fixed arrays in e. But you can define a variable of a list type, including a multi-dimensional list, such as:

    var my_md_list: list of list of my_type;
    

    It is not the same as a multi-dimensional array in other languages, in the sense that in general each inner list (being an element of the outer list) may be of a different size. But you still can achieve your purpose using it. For example, your code might be rewritten in e more or less like this:

    var arr: list of list of byte;
    var row: list of byte = {1;2;3;4;5;6;7;8};
    
    for i from 0 to 3 do {
        arr.add(row.copy());
        print arr[i];
    };
    
    print arr[2][3];
    

    Notice the usage of row.copy() - it ensures that each outer list element will be a copy of the original list. If we don't use copy(), we will get a list of many pointers to the same list. This may also be legitimate, depending on the purpose of your code.