Specman:在一个表达式中分配多个结构成员

发布于 2024-08-22 02:03:43 字数 362 浏览 4 评论 0原文

嘿,

我扩展了一个现有的 specman 测试,其中出现了一些类似这样的代码:

struct dataset {
  !register : int (bits:16);
  ... other members
}

...

data : list of dataset;
foo : dataset;
gen foo;

foo.register = 0xfe;
... assign other foo members ...
data.push(foo.copy());

有没有一种方法可以在一行中分配给结构体的成员?喜欢:

foo = { 0xff, ... };

Hy,

I expanding an existing specman test where some code like this appears:

struct dataset {
  !register : int (bits:16);
  ... other members
}

...

data : list of dataset;
foo : dataset;
gen foo;

foo.register = 0xfe;
... assign other foo members ...
data.push(foo.copy());

is there a way to assign to the members of the struct in one line? like:

foo = { 0xff, ... };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慕巷 2024-08-29 02:03:43

我目前无法想出一种根据需要设置所有成员的直接方法,但是有一种方法可以初始化变量(我不确定它是否也适用于结构成员)。无论如何,类似下面的内容可能适合您:

myfunc() is {
    var foo : dataset = new dataset with {
        .register = 0xff;
        .bar = 0xfa;
    }
    data.push(foo.copy());
}

您可以从specman提示符中使用help new struct找到有关new的更多信息。

希望有帮助!

I currently can't think of a direct way of setting all members as you want, but there is a way to initialize variables (I'm not sure if it works on struct members as well). Anyway something like the following may fit for you:

myfunc() is {
    var foo : dataset = new dataset with {
        .register = 0xff;
        .bar = 0xfa;
    }
    data.push(foo.copy());
}

You can find more information about new with help new struct from the specman prompt.

Hope it helps!

缱绻入梦 2024-08-29 02:03:43

按名称分配字段的简单优点是我一直认为有用、编码安全且可读的一种语言功能。

这就是我的做法:

struct s {
  a : int;
  b : string;
  c : bit;
};

extend sys {
  ex() is {
    var s := new s with {.a = 0x0; .b = "zero"; .c = 0;};
  };
  run() is also {
    var s;
    gen s keeping {.a == 0x0; .b == "zero"; .c == 0;};
  };
};

我什至会这样做 data.push(new dataset with {.reg = 0xff; bar = 0x0;}); 但如果您愿意,您可以提高可读性标志。

警告:使用 unpack() 是完全正确的(参见罗斯的答案),但在我看来很容易出错。我建议验证(使用实际运行的代码)您选择使用 unpack() 的每个地方。

the simple beuty of assigning fields by name is one language feature i've always found usefull , safe to code and readable.

this is how i'd go about it:

struct s {
  a : int;
  b : string;
  c : bit;
};

extend sys {
  ex() is {
    var s := new s with {.a = 0x0; .b = "zero"; .c = 0;};
  };
  run() is also {
    var s;
    gen s keeping {.a == 0x0; .b == "zero"; .c == 0;};
  };
};

i even do data.push(new dataset with {.reg = 0xff; bar = 0x0;}); but you may raise the readablity flag if you want.

warning: using unpack() is perfectly correct (see ross's answer), however error prone IMO. i recommend to verify (with code that actually runs) every place you opt to use unpack().

花开柳相依 2024-08-29 02:03:43

您可以直接使用 Specman 的 packunpack 功能以及“物理字段”(这些实例成员以修饰符 % 为前缀)。

示例:

define FLOODLES_WIDTH 47;
type floodles_t : uint(bits:FLOODLES_WIDTH);

define FLABNICKERS_WIDTH 28;
type flabnickers_t : uint(bits:FLABNICKERS_WIDTH);

struct foo_s {
   %!floodle : floodles_t;
   %!flabnicker : flabnickers_t;
};

extend sys {
   run() is also {
      var f : foo_s = new;
      unpack(packing.low,64'hdeadbeefdeadbeef,f);
      print f;

      unpack(packing.low,64'hacedacedacedaced,f);
      print f;

   };
   setup() is also {
      set_config(print,radix,hex);
   };
};

运行此命令时,它会打印:

Loading /nfs/pdx/home/rbroger1/tmp.e ...
read...parse...update...patch...h code...code...clean...
Doing setup ...
Generating the test using seed 1...

Starting the test ...
Running the test ...
  f = foo_s-@0: foo_s   of unit: sys
        ----------------------------------------------  @tmp
0       !%floodle:                      0x3eefdeadbeef
1       !%flabnicker:                   0x001bd5b
  f = foo_s-@0: foo_s   of unit: sys
        ----------------------------------------------  @tmp
0       !%floodle:                      0x2cedacedaced
1       !%flabnicker:                   0x00159db

在您的 Specman 文档中查找 packing, unpacking,Physical fields, Packing.low, Packing.high

即使结构未映射到 DUT,您仍然可以使用物理字段。如果您的结构已经将物理字段用于其他目的,那么您需要为该结构寻求某种 set* 方法。

You can directly use the pack and unpack facility of Specman with "physical fields" ( those instance members prefixed with the modifier %).

Example:

define FLOODLES_WIDTH 47;
type floodles_t : uint(bits:FLOODLES_WIDTH);

define FLABNICKERS_WIDTH 28;
type flabnickers_t : uint(bits:FLABNICKERS_WIDTH);

struct foo_s {
   %!floodle : floodles_t;
   %!flabnicker : flabnickers_t;
};

extend sys {
   run() is also {
      var f : foo_s = new;
      unpack(packing.low,64'hdeadbeefdeadbeef,f);
      print f;

      unpack(packing.low,64'hacedacedacedaced,f);
      print f;

   };
   setup() is also {
      set_config(print,radix,hex);
   };
};

When this run, it prints:

Loading /nfs/pdx/home/rbroger1/tmp.e ...
read...parse...update...patch...h code...code...clean...
Doing setup ...
Generating the test using seed 1...

Starting the test ...
Running the test ...
  f = foo_s-@0: foo_s   of unit: sys
        ----------------------------------------------  @tmp
0       !%floodle:                      0x3eefdeadbeef
1       !%flabnicker:                   0x001bd5b
  f = foo_s-@0: foo_s   of unit: sys
        ----------------------------------------------  @tmp
0       !%floodle:                      0x2cedacedaced
1       !%flabnicker:                   0x00159db

Look up packing, unpacking, physical fields, packing.low, packing.high in your Specman docs.

You can still use physical fields even if the struct doesn't map to the DUT. If your struct is already using physical fields for some other purpose then you'll need to pursue some sort of set* method for that struct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文