2010-02-17 26 views
3

海蘭分配多個結構構件,的Specman:一個表達

我擴大現有的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, ... }; 

回答

4

我現在想不出設置你想要的所有成員的一個直接途徑,但有一種方法來初始化變量(我不知道這是否適用於結構成員以及) 。反正像下面這樣可能適合你:

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

你可以找到更多信息有關newhelp new struct從的Specman提示。

希望它有幫助!

1

您可以直接使用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 = [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*方法。

+0

OMG!解壓! :)始終將unpack()視爲非類型安全的構造函數或API。忘記這些任務非常容易,並且沒有驗證代碼可以讓您(或您的代碼的客戶端)保持警覺。 – Asaf 2010-03-15 14:31:48

2

按名稱分配字段的簡單功能是我一直髮現的有用的代碼和可讀的語言功能。

這是我怎麼會去一下吧:

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()是完全正確的(請參閱ross的答案),但是容易出錯的IMO。我建議驗證(實際運行的代碼)你選擇使用unpack()的每個地方。 OMG!