您可以直接使用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