1

In the code fragment below I'm getting this error:

Source info:

x.data[theword][thebyteH : thebyteL] = $urandom_range(0,255) ; 'this' is not an elaboration-time constant. To correct the error you may convert this const variable to a parameter or a localparam.

The geometry of the data record, just a memory, is declared in the definition_pkg. A data record object is created in the Base_txn and I can access it directly like so:

x.data[0][7:0]  = x.frameID ;   

I don't know why am I getting an elaboration time error since all that is happening (I think) in for loop is that I'm indexing an already existing object.

Any suggestions, explanation, or solutions appreciated.

definition_pkg.svh

`define REC_DATAWIDTH 32  
`define REC_ROWS 16

typedef bit[`REC_DATAWIDTH-1:0] DataRec [`REC_ROWS]  ;

sequences.sv

class Base_txn extends uvm_sequence_item;  

    rand DataRec data;  
    ...


class sequencethingy extends uvm_sequence#(Base_txn);  
    ...  
    int byte4val ;  
    int theword ;  
    int thebyteH ;  
    int thebyteL ;  

// -----------------------------------------------------------------------  
function void build_S (ref Base_txn x);  
   ...  
   x.data[0][7:0]  = x.frameID ;  
   ...  
   for (int i = 8 ; i <= (byte4val+8) ; i++)  // byte8 is the location of S[0]  
   begin  
   theword =  i/4 ;  
   thebyteL =  8*(i%4) ;  
   thebyteH =  thebyteL + 7  ;
   x.data[theword][thebyteH : thebyteL] = $urandom_range(0,255) ;  
   end  
 endfunction  

...  

task body();  
    Base_txn wd_tx;  
    ...  
    build_S(wd_tx) ; // give the processor some data  
Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37
DHD
  • 27
  • 6

1 Answers1

2

Write this as

x.data[theword][thebyteL +:8] = $urandom_range(0,255) ;  

See Indexing vectors and arrays with +:

Community
  • 1
  • 1
dave_59
  • 39,096
  • 3
  • 24
  • 63