2013-05-09 162 views
3

我在写SystemVerilog代码,我发现$ sformat是一个系统任务,而不是一个函数。 有没有相当于$ sformat的函数?

我想要做一个函数内的以下内容:

assert(my_dto_h.a == 10) else begin 
    `ovm_error("component", $sformat("my_dto_h.a should be 10, not %0d", my_dto_h.a)) 
end 

不幸的是,我从QuestaSim 10.2获得以下运行时错误:

** Error: (vsim-PLI-3029) component.sv(105): Expected a system function, not system task '$sformat'.

回答

9

是,$sformatf

从LRM:

系统函数$sformatf行为就像$sformat除了字符串结果传递回作为函数结果值$sformatf,没有放置在第一个参数作为$sformat。因此$sformatf可用于字符串值有效的地方。

variable_format_string_output_function ::= 
    $sformatf (format_string [ , list_of_arguments ]) 

例子:

string s; 
s = $sformatf("Value = %0d", value); 
1

您可以使用$psprintf。它不是标准的一部分,但许多模拟器,如QuestaSim和VCS都支持它。

assert(my_dto_h.a == 10) else begin 
    `ovm_error("component", $psprintf("my_dto_h.a should be 10, not %0d", my_dto_h.a)) 
end 
相关问题