0

We can use vpi_scan in the following way:

vpiHandle iter = vpi_iterate(property, handle);
if (iter)
  while ( entry = vpi_scan(iter) )
    /*code*/;

iter will be freed when vpi_scan() returns NULL. But what if I need to scan through the loop several times? Is there a way to tell vpi_scan not to free the iterator, so that I could vpi_free_object when I'm done? I think I can solve the problem using an additional container (to collect and keep all entries), but is it really needed?

EDIT: 1. I would not like to call vpi_iterate more than once, since it can be expensive. 2. Suppose I go with an additional container solution. Is there a way to find out the number of entries in the vpi_scan loop without actual scanning through the loop? This could make implementation simpler.

TT_ stands with Russia
  • 1,785
  • 3
  • 21
  • 33
  • Can you not call vpi_iterate again? – user253751 Nov 19 '18 at 23:22
  • @immibis Not sure about performance. The property can be "expensive" to recognize. – TT_ stands with Russia Nov 19 '18 at 23:26
  • 1
    1) to re-run your loop again, call vpi_iterate again, it will return a new handle.; 2) there is no way to tell iterator to not free the objects. 3) keeping entries in a separate container might be a good solution performance-wise.4) there is no way to know the number of elements in the iteration before scanning. Use lists. – Serge Nov 20 '18 at 02:29
  • @Serge If you want to post as an answer, I'll accept it. Just in case - any references for #2,4? – TT_ stands with Russia Nov 20 '18 at 14:05

1 Answers1

2
  1. ut what if I need to scan through the loop several times? vpi_iterate returns an initialized pointer to the iterator. Every vpi_scan removes an element from the list and frees it. If vpi_scan did not run till the end, you'd better use vpi_free_object to clean the rest of the iterator list. If you need to rescan the same object again, you can call vpi_iterate again and it will return a new iterator object which you can re-scan.

  2. s there a way to tell vpi_scan not to free the iterator, so that I could vpi_free_object when I'm done? No, (1) is the only mechanism which can be used to access and free iterator elements. There is no other exist in the standard.

  3. I think I can solve the problem using an additional container (to collect and keep all entries), but is it really needed? -- this is a good idea if you want to re-scan your data structs. It could be much better from the performance point of view. Verilog simulator usually has a separately generated vpi database which it needs to consult, probably multiple times to provide you with vpi access information.

  4. Is there a way to find out the number of entries in the vpi_scan loop without actual scanning through the loop? not really. there are no defined way to query this information from the iterator. There might be a work-around with using vpi_handle(vpiUse, iterator) but it depends on the underlying data and the type of iteration. It is much easier to use linked lists created by the first scanning loop.

you can get all additional information for LRM or a verilog pli handbook.

Serge
  • 11,616
  • 3
  • 18
  • 28