是否可以通过VPI c函数迭代非int索引类型的systemverilog关联数组?

问题描述 投票:0回答:1

例如

// test.sv

class cls;
    int b;
endclass

module m
    cls testObj;
    int map[cls];
    initial begin
      inst = new;
      inst.b = 10;
      map[cls] = 12;
      $VPIcall;
    end
endmoudle

// 伪代码 vpi c

vpiHandle mapHandle = vpi_handle_by_name("m.map", 0); // return valid handle
vpiHandle valueHandle = vpi_handle_by_name("map[testObj]", mapHandle); // return zero

好像我们无法像这样获取valueHandle,我想知道是否可以通过VPI迭代或获取存储在关联数组中的值?

system-verilog associative-array vpi
1个回答
0
投票

注意事项:

  1. VPI能力通过不同的工具实现不同。您的第一行应该可以工作,具体取决于工具和编译时使用的限定符。例如,为了使其与“vcs”一起使用,我使用了 -debug_all (应该有更好的选择)。
  2. 第二行永远不会起作用,但是您可以使用一些扫描技术来获取数组的元素。我使用了vpi_handle_by_index
  3. 您的代码示例无法编译。

这是一个适用于我的 vcs 示例:

verilog:

class cls;
   int b;
endclass

module m;
   
   cls testObj, obj1;
   
   int map[cls];
   initial begin
      testObj = new;
      testObj.b = 10;
      map[testObj] = 12;
      obj1 = new;
      obj1.b = 20;
      map[obj1] = 13;
      $testme;
   end
endmodule

vpi:

#include <stdio.h>
#include <vpi_user.h>

void testme() {
    vpiHandle mapHandle = vpi_handle_by_name("m.map", 0); // return valid handle
    vpi_printf("map: %p\n", mapHandle);

vpiHandle el;
    s_vpi_value val = {vpiIntVal};

    vpiHandle iterator = vpi_iterate(vpiReg, mapHandle);
    while ((el = vpi_scan(iterator))) {
        vpi_get_value(el, &val); 
        vpi_printf("%s: %d\n", vpi_get_str(vpiType, el),  val.value.integer); 
    }
    
}
    
© www.soinside.com 2019 - 2024. All rights reserved.