1

在实现function "or"for 自定义数组类型时,我决定看一下 for 的"or"实现std_logic_vector。在那里我偶然发现了这样的代码:

(摘录,我不知道是否有版权之类的东西,因为每个供应商都可以有自己的实现)。

funciton "or" (Left, Right: std_logic_vector) is
    ...
begin
    if Left'LENGTH /= Right'LENGTH then
        assert FALSE report
        "ErrorDifferentLengthVectors" severity failure;
    else
        ...
    end if;
end "or";

this over using the条件-part of the报告语句的优势在哪里?断言不会取消进一步的编译,还是需要将以下代码放在 else 分支中?

funciton "or" (Left, Right: std_logic_vector) is
    ...
begin
    assert Left'LENGTH = Right'LENGTH report
    "ErrorDifferentLengthVectors" severity failure;

    ...

end "or";
4

1 回答 1

4

这是一种编码风格的东西。如果你这样做,assert你必须否定条件。如果你写了多个排他性的,elsifs你总是必须在你的脑海中反转第一个条件,以找出你已经在 if 语句中涵盖的情况。至少这就是为什么我以类似的方式这样做的原因,但我将断言全部省略,只使用report ... severity failure;.

一个例子是以下片段:
A:

  signal value : natural := 0;

begin  -- architecture beh

  -- purpose: none
  do_something : process (all) is
  begin  -- process to_something
    if rst = '0' then                   -- asynchronous reset (active low)
      value <= 0,
    elsif rising_edge(clk) then         -- rising clock edge
        assert value >= 10 and value <= 99  report "Value out of range." severity failure;
        if value < 15 then
          do something;
        elsif value > 20 and value < 50 then
          do some other thing;
        else
          do yet another thing;
        end if;
      end if;
  end process do_something;

乙:

   signal value : natural := 0;

begin  -- architecture beh

  -- purpose: none
  do_something : process (all) is
  begin  -- process to_something
    if rst = '0' then                   -- asynchronous reset (active low)
      value <= 0,
    elsif rising_edge(clk) then         -- rising clock edge
        if value < 10 or value > 99 then
          report "Value out of range." severity failure;
        elsif value < 15 then
          do something;
        elsif value > 20 and value < 50 then
          do some other thing;
        else
          do yet another thing;
        end if;
      end if;
  end process do_something;

比在 Snipped B 中更难理解 Snipped A 的哪个条件发挥作用,尤其是else子句,并且在此示例中只检查一个数值。

于 2013-06-07T14:42:51.753 回答