SystemVerilog $sformatf $psprintf系统函数,以及字符串的跨行
·
$sformatf和$psprintf常用来对字符串进行格式化,可以返回一个整理好的字符串。其中$sformatf为system verilog标准中的系统函数,而$psprintf则为VCS对于sv的扩展,目前也被大多数EDA工具支持。
string test_str;
test_str = $sformatf("this is a %s string", "sformatf");
test_str = $psprintf("this is a %s string", "psprintf");
在进行uvm_info的打印过程中,有时会存在字符串过长,需要对字符串进行跨行书写。可以使用以下语法,实现字符串的跨行书写。
string test_str;
//{}连接
test_str = {"line1"
"line2"};
//define连接
`define def_str "line1 \
line2"
test_str = `def_str;
//使用sformat进行拼接
test_str = $sformat("line1 %s",
"line2");
//使用"\"续行
test_str = "line1 \
line2"
此外,还有$sformat系统函数,同样可以实现字符串的格式化。相比$sformatf系统函数,多了一个输出参数,但不会返回字符串值。
string test_str;
$sformat(test_str,"this is a %s string", "sformat");
字符串的左对齐,可以说使用%-10s格式化占位符来实现。
$display($sformatf(%-50s","left justifying string");
//left justifying string
$display($sformatf(%50s","right justifying string");
// left justifying string
更多推荐




所有评论(0)