首页|资源下载
登录|注册

您现在的位置是:首页 > 技术阅读 >  SystemVerilog中的struct

SystemVerilog中的struct

时间:2024-07-17

SystemVerilog“struct”表示相同或不同数据类型的集合。


struct可以作为一个整体使用,也可以单独通过名称引用组成这个struct的元素。由于这些元素的数据类型可能不相同,所以不能够使用数组。

如果需要在多个module或者类中使用相同的struct,则应该将struct定义(`typedef)放到SystemVerilog package中,然后将其导入到每个module或者class。

默认情况下,struct都是unpacked的,我们也可以显式地加上关键字。下面是一个简单的示例,展示了array和struct的区别。

// Normal arrays -> a collection of variables of same data type
int array [10]; // all elements are of type ‘int’
bit [7:0] mem [256]; // all elements are of type ‘bit’

// Structures -> a collection of variables of same or different data types
struct
{
byte val1;
int val2;
string val3; } DataValue;

当然,我们也可以定义一个数组,其中数组中的每一个数据项都是一个struct.

DataValue v1[20]; //array of structures

struct
{
byte val1;
int val2[10]; //array within a structure
string val3; } DataValue;