tags:

views:

192

answers:

2

How do I return an array from a method call in Specman? E.g.

method a : list of uint is { 
   var data: list of uint;
   .....
   result = data;

};

extend sys {
 var data_sys: list of uint;
 run() is also {
  data_sys = a();
 };
};

My print out shows some elements are different from array data and data_sys. Can you tell me what I missed?

+1  A: 

The code you posted wont compile. Put in more print statements or set a break point in specview and step through the code. Do you know which test-phase you're doing your printout? If you want to procedurally set data_sys ( instead of having Specman generate it ), you should specify the do-not-generate modifier '!'.

[...]
!data_sys : list of uint;
[...]
Ross Rogers
+1  A: 

pls provide a sscce.

without that, this very basic example might do:

extend sys {
  m() : list of uint is {
    print result.size(); // result.size() = 0
  };

  run() is also {
    var m := m();
  };
};

methods can return an array, which is allocated for you by default. it's returned by pointer, so be aware.

as a thumb-rule, try to avoid list-returning methods when you calculate on them. try to pass the list as a parameter, to convey its dynamic nature, unless the method is a creation method or a getter:

collect_packets(packets : list of packet) is {...};
get_collected_packets() : list of packet is {...};
Asaf