2013-04-30 144 views
3

我想定義一個返回大小列表的方法。 例如Specman方法返回大小列表

my_method(): list of my_struct is { ... }; 

顯然會返回一個未知大小的列表。聯機文檔沒有大小列表的語法定義作爲返回值。

回答

2

列表大小等確定:

my_list : list of int; 
keep my_list.size() == 4; 

你可以在模板結構包裝器這樣的列表,並限制該結構內部列表中的一些這樣的:

<' 

struct my_struct { 
    data : int; 
}; 

template struct FourElemWrpr of (<first'type>) { 
    d : list of <first'type>; 
    keep d.size() == 4; 
}; 

extend sys { 
    foo() : FourElemWrpr of int is { 
     gen result; 
     print result.d; 
    }; 
    run() is also { 
     var wrpr := foo(); 
     print wrpr.d; 
    }; 
}; 

'> 

當運行Specman 10,這產生:

Welcome to Specman Elite 
[...] 

Generating the test with Pgen using seed 1... 

Starting the test ... 
Running the test ... 
    result.d = 
0.  -208970122 
1.  -1768025704 
2.  -65377588 
3.  -723567746 
    wrpr.d = 
0.  -208970122 
1.  -1768025704 
2.  -65377588 
3.  -723567746 
No actual running requested. 
Checking the test ... 
Checking is complete - 0 DUT errors, 0 DUT warnings. 
0

當你定義一個列表類型的struct字段時,你可以使用al所以如下specifiy其大小:

struct list_wrapper { 
    my_list[4]: list of int; 
}; 

其可被用來代替:

struct list_wrapper { 
    my_list: list of int; 
    keep my_list.size() == 4; 
}; 

此語法僅適用於各個領域。不適用於局部變量,方法返回類型等。

此外,請注意,它不是一個「固定大小」列表,因爲它看起來似乎。聲明的大小(在上例中爲4)僅意味着初始大小。創建完成後,可以像添加其他列表一樣添加,刪除元素等。

[大小]表示法和使用約束之間有一個重要區別。當產生包含結構時的約束僅花費產生場效果,[大小]符號生效也爲創建的結構的字段由,或用於非generateable字段。