vlsiexpert
Newbie
Need help on a simple system verilog code
1. class packet has dynamic array data[] and it's size is constrained between 1 to 250
2. Extending the packet class to small_packet and constraining size to be less than 10
3. casting small_packet to packet class's object
I would expect the size should be always less than 10, but it is not obeying the constraint in extended class
Any help?code link
[ MODERATOR ACTION ] Upload original code here
EDA Playground
Edit, save, simulate, synthesize SystemVerilog, Verilog, VHDL and other HDLs from your web browser.
www.edaplayground.com
1. class packet has dynamic array data[] and it's size is constrained between 1 to 250
2. Extending the packet class to small_packet and constraining size to be less than 10
3. casting small_packet to packet class's object
I would expect the size should be always less than 10, but it is not obeying the constraint in extended class
Any help?code link
[ MODERATOR ACTION ] Upload original code here
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 // Code your testbench here // or browse Examples class packet; rand byte data[]; rand bit [7:0] length; constraint payload_size_c { data.size inside { [1 : 250]};} endclass class gen; rand packet pkt; function exec(); pkt = new(); if ( !pkt.randomize()) $fatal("Gen: trans randomization failed"); endfunction: exec endclass class small_packet extends packet; constraint small_c { data.size < 10 ; } endclass program test; small_packet spkt; gen sgen; initial begin spkt = new(); sgen = new(); sgen.pkt = spkt; sgen.exec(); $display("Size = %d, length = %d",sgen.pkt.data.size,sgen.pkt.length); end endprogram
Last edited by a moderator: