在为自定义数组类型实现function "or"
时,我决定查看"or"
std_logic_vector
的实现。
在那里我偶然发现了这样的代码:
(解压缩,我不知道是否有像copytright这样的东西,因为每个供应商都可以拥有自己的实现)。
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";
答案 0 :(得分:4)
这是一种编码风格的东西。如果你用assert
做,你必须否定这个条件。如果你写了多个,exlusive elsifs
,你总是要反驳你头脑中的第一个条件,以确定你已经在if语句中涵盖了哪些情况。至少这就是为什么我在一个相似的时尚中做到这一点,但我总是将断言全部省略,只使用report ... severity failure;
。
一个例子是以下片段:
答:
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;
B:
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 A的哪个条件在剪切B中发挥作用,尤其是else
子句,并且在此示例中只检查了一个数值。