UVM使用 factory 的概念,所有object都向 factory 註冊(register),以便在需要時返回所需類型的object。用utility macros方便將每個object註冊到 factory 中。
UVM還導入了很多自動化機制,用來實現 print 、 copy 和 compare object,並定義在macro裡面。
Object Utility
所有直接從 uvm_object 或 uvm_transaction 衍生的類別都需要使用 uvm_object_utils macro進行註冊。並且每個class都必須定義 new fucntion,並將class實例(instance)的名稱當參數。
1 | class mydata extends uvm_object; |
Component Utility
所有直接或間接從 uvm_component 衍生的類別都需要使用 uvm_component_utils macro進行註冊。並且每個直接或間接從 uvm_component 衍生的class,都必須定義 new fucntion,並將class實例(instance)的名稱和該object被實例化(instantiated)的parent class的當參數。
1 | class my_comp extends uvm_component; |
Macro Expansion: detail
如果詳細去trace UVM code的話,可以看到 uvm_object_utils 會被展開為其 *_begin 和 *_end 形式,開始和結束中間沒有任何內容。 *_begin 實做了 UVM factory所需的其他macro。
1 | // copy from uvm-1.2\docs\html\src\macros\uvm_object_defines.svh |
再詳細進去看uvm_object_utils_begin展開的這幾個macro可以看到register/create/get type name這些function的實作內容
1 | // copy from uvm-1.2\docs\html\src\macros\uvm_object_defines.svh |
uvm_component_utils 也是一樣的道理,就不詳細作筆記了。
Creation of class object
建議所有class object都透過呼叫 ``m_uvm_object_create_func 定義的 type_id::create()` 方法來建立。這樣可以讓任何child class物件透過factory機制create和return,增加testbench的彈性和重複使用性。
Example:
1 | class mydata extends uvm_object; |
Field Macros
``uvm_field_*` 是用來操作class屬性並提供自動實作像是(copy、compare和print)method的macro。讓使用者節省實作每個class自定義 do_copy、do_compare 和 do_print function的時間。
Example:
1 | class mydata extends uvm_object; |
不同的變數,要使用與他data type相對應的 ``uvm_field_*macro。例如變量類型為int、bit、byte的變數要用uvm_field_int,如果變數類型為 string的變數則要使用uvm_field_string`。這種macro至少要 ARG 和 FLAG 這兩個參數。
ARG要輸入變數名稱
FLAG根據不同使用狀況有以下幾種FLAG
| Flag | DescriptionPrice |
|---|---|
| UVM_ALL_ON | Set all operations on. |
| UVM_DEFAULT | This is the recommended set of flags to pass to the field macros. Currently, it enables all of the operations, making it functionally identical to UVM_ALL_ON. In the future however, additional flags could be added with a recommended default value of off. |
| UVM_NOCOPY | Do not copy this field. |
| UVM_NOCOMPARE | Do not compare this field. |
| UVM_NOPRINT | Do not print this field. |
| UVM_NOPACK | Do not pack or unpack this field. |
| UVM_REFERENCE | For object types, operate only on the handle (e.g. no deep copy) |
| UVM_PHYSICAL | Treat as a physical field. Use physical setting in policy class for this field. |
| UVM_ABSTRACT | Treat as an abstract field. Use the abstract setting in the policy class for this field. |
| UVM_READONLY | Do not allow setting of this field from the set_*_local methods or during uvm_component::apply_config_settings operation. |
除了對操作的控制,``uvm_field_*` macro還可以控制變數的基數,其可以取以下值。此值可以與上表中列出的操作標誌進行 OR 運算。如果沒有指定,則 UVM_HEX 是default value。
| Radix | Description |
|---|---|
| UVM_BIN | Print / record the field in binary (base-2). |
| UVM_DEC | Print / record the field in decimal (base-10). |
| UVM_UNSIGNED | Print / record the field in unsigned decimal (base-10). |
| UVM_OCT | Print / record the field in octal (base-8). |
| UVM_HEX | Print / record the field in hexadecimal (base-16). |
| UVM_STRING | Print / record the field in string format. |
| UVM_TIME | Print / record the field in time format. |