来自本土记录器的 $psprintf 功能?
$psprintf functionality from home-grown logger?
有没有人想出一个聪明的方法来支持 $psprinf
(或 $sformat
)类似您自己的记录器的功能?
即我想更改我的台词:
log.info($psprintf(" The burst took %0d cycles as expected", cycle_count));
至:
log.info(" The burst took %0d cycles as expected", cycle_count);
这主要是为了美观,但在每行打印中添加 10 个字符会很乏味。
欢迎提出聪明的想法!
更新:注意!主要问题是模仿 $psprintf
接受多个(不是确切数量的)参数的能力。我认为该语言不支持它,但我已经离开几年了,所以也许突然出现了一些聪明的东西?
SystemVerilog 不支持具有可变数量参数的函数或任务,但您可以使用具有您期望的最大参数数量的宏
// must have between 1 and 5 arguments
`define LOG(a1,a2="",a3="",a4="",a5="") log.info($psprintf(a1,a2,a3,a4,a5))
`LOG(" The burst took %0d cycles as expected", cycle_count);
如果您不知道预期有多少参数,则必须将括号作为参数的一部分传递。
`define LOG(arg) log.info($psprintf arg )
`LOG((" The burst took %0d cycles as expected", cycle_count));
有没有人想出一个聪明的方法来支持 $psprinf
(或 $sformat
)类似您自己的记录器的功能?
即我想更改我的台词:
log.info($psprintf(" The burst took %0d cycles as expected", cycle_count));
至:
log.info(" The burst took %0d cycles as expected", cycle_count);
这主要是为了美观,但在每行打印中添加 10 个字符会很乏味。
欢迎提出聪明的想法!
更新:注意!主要问题是模仿 $psprintf
接受多个(不是确切数量的)参数的能力。我认为该语言不支持它,但我已经离开几年了,所以也许突然出现了一些聪明的东西?
SystemVerilog 不支持具有可变数量参数的函数或任务,但您可以使用具有您期望的最大参数数量的宏
// must have between 1 and 5 arguments
`define LOG(a1,a2="",a3="",a4="",a5="") log.info($psprintf(a1,a2,a3,a4,a5))
`LOG(" The burst took %0d cycles as expected", cycle_count);
如果您不知道预期有多少参数,则必须将括号作为参数的一部分传递。
`define LOG(arg) log.info($psprintf arg )
`LOG((" The burst took %0d cycles as expected", cycle_count));