VHDL 中的标签有什么用?

What are labels used for in VHDL?

很多VHDL结构在声明前都有一个optional_label的选项,但是这个标签是用来做什么的?

这是来自 vdlande 的流程声明示例,显示了标签选项:

optional_label: process (optional sensitivity list)
    -- declarations
begin
    -- sequential statements
end process optional_label;

标签用于识别。

IEEE1076-2008 例如说

7.3.1 General

A configuration specification associates binding information with component labels representing instances of a given component declaration.

考虑下一段代码:

entity e is end entity;
architecture a of e is begin
    process is begin wait; end process;
    foo: process is begin wait; end process;
end architecture;

在模拟中(使用 modelsim)这将显示为

即label foo 是固定的,而另一个进程只是分配了一些引用,在本例中是行号。如果您正在使用属性、配置、别名等,您通常需要引用特定对象及其位置。为此你需要固定名称。

如果你查看 IEEE1076-2008 标准,你会发现几乎每个语句都可以有一个标签:ifcaseloop

正如 JHBonarius 所说,您可以使用标签在模拟器中识别事物,但标签也有其他用途:

i) 识别一长段代码的结尾,eg

my_if : if A = B then 
-- lots of lines of code
end if my_if;

ii) 跟踪复杂的代码,例如

my_if_1 : if A = B then
  my_if_2 : if A = B then
    my_if_3 : if A = B then
      my_if_4 : if A = B then
        my_if_5 : if A = B then
          my_if_6 : if A = B then
          -- blah blah blah
          end if my_if_6;
        end if my_if_5;
      end if my_if_4;
    end if my_if_3;
  end if my_if_2;
end if my_if_1;

iii) 标记断言通常是个好主意,这样它们就可以在 EDA 工具中轻松识别,例如:

enable_check : assert enable = '1';

iv) 如果你标记了一些东西,那么你可以 decorate 它带有一个属性(即附加一些其他 EDA 工具的元数据),例如这样的东西可能会停止合成器优化一些东西:

attribute KEEP : boolean;
attribute KEEP of g0:label is TRUE;
...
g0 : CLK_EN port map ( ...

(具体名称取决于合成器。)