再次细看uvm source code, 借此把里面用的很好的技巧和语法记录一下, 希望后面有精力陆续更新
Macro
参数传递
1.使用参数
1).
`(一个shell 执行符, Esc 下面
),猜是转义字符的功能,使其“” 与S分离开,使编译器认为S是传入值而非字符串
2).
``(两个shell 执行符, Esc 下面),这种偏多了,保留参数S的值
`define m_uvm_object_registry_internal(S) \
string str = `"S`";
`define m_uvm_object_registry_internal_xxx(S) \
string str2 = "xxx_``S``_xxx";
`define m_uvm_object_registry_internal_xxx(S) \
string str2 = "xxx_``S``_xxx";
initial begin
`m_uvm_object_registry_internal(uvm_test)
`m_uvm_object_registry_internal_xxx(uvm_env)
$display("%0s, %0s", str, str2);
end
`m_uvm_object_registry_internal(uvm_test)
`m_uvm_object_registry_internal_xxx(uvm_env)
$display("%0s, %0s", str, str2);
end
仿真结果:
uvm_test, xxx_uvm_env_xxx
Formatting data to string
systemverilog syntax from IEEE:
string_output_tasks ::=
string_output_task_name ( output_var [,list_of_arguments ]) ;
string_output_task_name ::=
$swrite|$swriteb|$swriteh|$swriteo
variable_format_string_output_task ::=
$sformat (output_var,format_string [,list_of_arguments ]) ;
variable_format_string_output_function ::=
$sformatf (format_string [,list_of_arguments ])
string_output_task_name ( output_var [,list_of_arguments ]) ;
string_output_task_name ::=
$swrite|$swriteb|$swriteh|$swriteo
variable_format_string_output_task ::=
$sformat (output_var,format_string [,list_of_arguments ]) ;
variable_format_string_output_function ::=
$sformatf (format_string [,list_of_arguments ])
$sformatalways interprets its second argument,and supports all the format specifiers supported by$display,
eg: string s;
$sformat(s, "pair : %s, %s",
first.convert2string(), second.convert2string());
$sformat(s, "pair : %s, %s",
first.convert2string(), second.convert2string());
将第二个参数$display 成string,并赋值s;
$sformatf 跟$sformat 一样,除了会将结果返回,也没有第一个参数。当一个string值需要有效地返回值该function很有用, uvm 中常用的就是该function 做字符串打印.
eg: return $sformatf("built-in pair : %p, %p", first, second);