具有不同长度的 VHDL const 字符串数组

VHDL const string array with different length

我想在 Testbench 中创建一个字符串列表来加载不同的文件,例如。

我试过了:

type tastring ARRAY(iADCCount_C-1 downto 0) of string;
constant Filenames     : tastring := ("file.txt",
                                      "anotherfile.txt",
                                      "jetanotherfile.txt");

数组中不可能有可变长度的字符串。

另外:

type tpstring is access string;
type tpastring is ARRAY(iADCCount_C-1 downto 0) of tpstring;
constant Filenames     : tpastring := (new string'("file.txt"),
                                       new string'(anotherfile.txt"),
                                       new string'(jetanotherfile.txt"));

无效!您不能使访问类型常量。我想念什么吗?有没有办法制作一个字符串列表而不用将它们填充到相同的大小?

参见 this answer。据我所知,不可能有可变长度字符串数组。

如果您按照答案中的建议实现自定义 trim 函数,请尝试使用文件名中不能存在的固定间距字符(例如 windows 的 ?),因为它也将确保不会NUL 字符或其他非 prinatbles 的问题可能会导致使用不同的综合工具时出现问题。

你几乎是正确的:)

第二个代码片段必须使用变量,因为访问类型只能用于种类变量的对象。

type line_vector is array(iADCCount_C-1 downto 0) of line;
variable Filenames : line_vector := (
  new string'("file.txt"),
  new string'("anotherfile.txt"),
  new string'("jetanotherfile.txt")
);

注 1:添加了缺失的 " 个字符。
注2:类型line已经在VHDL中定义了。
注 3:类型 line_vector 将由 VHDL-2017.

定义

作为替代方案,您可以用字符 NUL 填充所有字符串。您可能想要实现两个函数来将字符串的大小调整为常量的大小和 trim 字符串(删除尾随的 NUL 个字符。