您可以直接使用Specman的pack
和unpack
工具与“物理场”(这些实例成员的前缀为修饰符%
)。
例子:
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 = [email protected]: foo_s of unit: sys
---------------------------------------------- @tmp
0 !%floodle: 0x3eefdeadbeef
1 !%flabnicker: 0x001bd5b
f = [email protected]: foo_s of unit: sys
---------------------------------------------- @tmp
0 !%floodle: 0x2cedacedaced
1 !%flabnicker: 0x00159db
在你的Specman文档查找packing, unpacking, physical fields, packing.low, packing.high
。
即使结构没有映射到DUT,您仍然可以使用物理字段。如果你的结构体已经在使用物理字段来实现其他目的,那么你需要为这个结构体采用某种set*
方法。
OMG!解压! :)始终将unpack()视为非类型安全的构造函数或API。忘记这些任务非常容易,并且没有验证代码可以让您(或您的代码的客户端)保持警觉。 – Asaf 2010-03-15 14:31:48