【发布时间】:2021-04-17 20:53:53
【问题描述】:
我想$display 列中的字符串,例如固定宽度的表格。
但是,我不知道我的字符串的最大列宽是多少
提前。
假设我有一个 SystemVerilog 字符串数组 (names)。
当我$display他们时,我猜想列(10)的宽度,
但我的猜测太小了:
module tb;
string names [5];
initial begin
names = '{
"ALU" ,
"COMPARATOR_3" ,
"MEMORY" ,
"FLOP" ,
"ram_macro_with_a_long_name"
};
// Display all elements of the array
foreach (names[i]) begin
$display("| %10s |", names[i]);
end
end
endmodule
这是输出:
| ALU |
| COMPARATOR_3 |
| MEMORY |
| FLOP |
| ram_macro_with_a_long_name |
这是我想要的输出:
| ALU |
| COMPARATOR |
| MEMORY |
| FLOP |
| ram_macro_with_a_long_name |
我可以猜到一个非常大的数字(比如 100),但它可能要大得多 比我需要的。
如何自动缩放$display 的宽度?
【问题讨论】: