[CU]factory机制2-factory机制之用于类注册的宏(factory机制-注册)

1. 用于factory注册的宏

注:宏实现类的注册;

1.1. `uvm_object_utils

1 `define uvm_object_utils(T) \
2   `uvm_object_utils_begin(T) \
3   `uvm_object_utils_end
1 `define uvm_object_utils_begin(T) \
2    `m_uvm_object_registry_internal(T,T)  \
3    `m_uvm_object_create_func(T) \
4    `m_uvm_get_type_name_func(T) \
5    `uvm_field_utils_begin(T) 
6 
7 `define uvm_object_utils_end \
8      end \
9    endfunction \
 1 `define m_uvm_object_registry_internal(T,S) \
 2    typedef uvm_object_registry#(T,`"S`") type_id; \
 3    static function type_id get_type(); \
 4      return type_id::get(); \
 5    endfunction \
 6    virtual function uvm_object_wrapper get_object_type(); \
 7      return type_id::get(); \
 8    endfunction 
 9 
10 `define m_uvm_object_create_func(T) \
11    `ifdef UVM_CREATE_OPT \
12         virtual function void call_new(); \
13         endfunction \
14    `else \
15     function uvm_object create (string name=""); \
16         T tmp; \
17        `ifdef UVM_OBJECT_MUST_HAVE_CONSTRUCTOR \
18           if (name=="") tmp = new(); \
19           else tmp = new(name); \
20        `else \
21           tmp = new(); \
22           if (name!="") \
23             tmp.set_name(name); \
24        `endif \
25        return tmp; \
26     endfunction \
27    `endif 
28 
29 `define m_uvm_get_type_name_func(T) \
30    const static string type_name = `"T`"; \
31    virtual function string get_type_name (); \
32      return type_name; \
33    endfunction 

1.2. `uvm_component_utils

 1 `define uvm_component_utils(T) \
 2    `m_uvm_component_registry_internal(T,T) \
 3    `m_uvm_get_type_name_func(T) \
 4 
 5 `define m_uvm_component_registry_internal(T,S) \
 6    typedef uvm_component_registry #(T,`"S`") type_id; \
 7    static function type_id get_type(); \
 8      return type_id::get(); \
 9    endfunction \
10    virtual function uvm_object_wrapper get_object_type(); \
11      return type_id::get(); \
12    endfunction
13 
14 `define m_uvm_get_type_name_func(T) \
15    const static string type_name = `"T`"; \
16    virtual function string get_type_name (); \
17      return type_name; \
18    endfunction 

1.3. `uvm_object_param_utils

 1 `define uvm_object_param_utils(T) \
 2   `uvm_object_param_utils_begin(T) \
 3   `uvm_object_utils_end
 4 
 5 `define uvm_object_param_utils_begin(T) \
 6    `m_uvm_object_registry_param(T)  \
 7    `m_uvm_object_create_func(T) \
 8    `uvm_field_utils_begin(T) 
 9        
10 `define uvm_object_utils_end \
11      end \
12    endfunction \
1 `define m_uvm_object_registry_param(T) \
2    typedef uvm_object_registry #(T) type_id; \
3    static function type_id get_type(); \
4      return type_id::get(); \
5    endfunction \
6    virtual function uvm_object_wrapper get_object_type(); \
7      return type_id::get(); \
8    endfunction 

(1) 从uvm_object派生一个普通类的时候,使用的是`uvm_object_utils;

(2)从uvm_object派生一个参数化的类的时候,使用的是`uvm_object_param_utils;

1 //示例
2 class para_class#(type T=int) extends uvm_object;
3     typedef para_class#(type T=int) my_type;
4     `uvm_object_param_utils(my_type)
5     ...
6 endclass
 1 //示例
 2 class transaction #(width=48) extends uvm_sequence_item;
 3     rand bit[width-1:0] data;
 4     `uvm_object_param_utils_begin(transaction #(width))
 5         `uvm_field_int(data,UVM_ALL_ON)
 6     `uvm_object_utils_end
 7 endclass
 8 
 9 class my_component extends uvm_component;
10     task run_phase(uvm_phase phase);
11         transaction tr=transaction #(60)::type_id::create("tr",this);
12     endtask
13 endclass

1.4. `uvm_component_param_utils

 1 `define uvm_component_param_utils(T) \
 2    `m_uvm_component_registry_param(T) \
 3 
 4 
 5 `define m_uvm_component_registry_param(T) \
 6    typedef uvm_component_registry #(T) type_id; \
 7    static function type_id get_type(); \
 8      return type_id::get(); \
 9    endfunction \
10    virtual function uvm_object_wrapper get_object_type(); \
11      return type_id::get(); \
12    endfunction

 

 

 

 

posted on 2021-10-31 15:31  知北游。。  阅读(161)  评论(0编辑  收藏  举报

导航