1

我希望来自 SystemVerilog 的数据数组具有来自 C/C++ 端数组的完整数据副本:

C/C++ 代码:

void myCfunc(svOpenArrayHandle results) {
    int randomsize;
    ...
    uint32_t myArray[randomsize];
    ...
    svPutBitArrElemVecVal(results, myArray, 1); // copies only the first element
    //svPutBitArrElemVecVal(results, myArray, 1, 2, 3); // still only copies the first element for some reason
    // svCopyArr(results, myArray); // this isn't a DPI function, but I would like do to something like this.
    // Copy the whole array, not just the an element
}

SV 代码:

module tb_top;
    int results[100];
    import "DPI-C" function myCfunc(output int results[]);
    ...
    initial begin
        myCfunc(results);
    end
endmodule : tb_top

我的问题是我每次都不知道源数组的确切大小。此外,即使每次都是固定大小,我会想象对于大型数组来说,拥有一长串索引参数将是多余的。其他 SV-DPI 处理程序函数似乎不适用于我的案例,或者我一定误解了它们的使用方式。

4

1 回答 1

1

您的构造称为“开放数组”。标准定义了一些可用于确定数组参数的函数。

/*
* Open array querying functions
* These functions are modeled upon the SystemVerilog array
* querying functions and use the same semantics.
*
* If the dimension is 0, then the query refers to the
* packed part of an array (which is one-dimensional).
* Dimensions > 0 refer to the unpacked part of an array.
*/
/* h= handle to open array, d=dimension */
XXTERN int svLeft(const svOpenArrayHandle h, int d);
XXTERN int svRight(const svOpenArrayHandle h, int d);
XXTERN int svLow(const svOpenArrayHandle h, int d);
XXTERN int svHigh(const svOpenArrayHandle h, int d);
XXTERN int svIncrement(const svOpenArrayHandle h, int d);
XXTERN int svSize(const svOpenArrayHandle h, int d);
XXTERN int svDimensions(const svOpenArrayHandle h);

作为替代方法,您可以将数组大小作为单独的参数传递给您的函数。

于 2021-06-20T14:54:53.660 回答