case expression and constants

R

Ralf Hildebrandt

Guest
Hi!

I have noticed a strange behavior in my (very old (1997?)) Cadence
Leapfrog with the following code:

-------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL,IEEE.Numeric_STD.ALL;

entity foobar is
end foobar;

architecture behavior of foobar is
constant bitwidth : integer:=6;

-- errors if one of the following lines is uncommented
--constant const : std_ulogic_vector(bitwidth-1 downto 0):=
std_ulogic_vector(to_unsigned(16#0A#,bitwidth));
--constant const : std_ulogic_vector(5 downto 0):=(others=>'0');

-- no error, if this is used
constant const : std_ulogic_vector(5 downto 0):="001001";

signal sig : std_ulogic_vector(bitwidth-1 downto 0);
begin

process
begin
case sig is
when const => assert false report "test!" severity error;
when others => null;
end case;
end process;

end behavior;
-------------

The error message is:
when const => assert false report "test!" severity error;
|
duluth: *E,380 (/folder/testfile.vhd,19): expecting a locally static
expression of type STD_ULOGIC_VECTOR and length 6 [8.7].


So my question is: Why do I get these errors, if I use one of the
uncommented constant definitions? The constant const is always locally
static.
(Note, that even the error message of my Leapfrog is errogenous: [8.7]
ist the chapter in the LRM, that deals with the if-statement, [8.8] is
for case.)

The commented definitions would be more handy - especially, the 1st one,
because then I could easily change the bitwidth.


Thanks!
Ralf
 
Ralf Hildebrandt a écrit :
Hi!

I have noticed a strange behavior in my (very old (1997?)) Cadence
Leapfrog with the following code:
[...]
-- errors if one of the following lines is uncommented
--constant const : std_ulogic_vector(bitwidth-1 downto 0):> std_ulogic_vector(to_unsigned(16#0A#,bitwidth));
This const is not locally static, because of the call to to_unsigned.

--constant const : std_ulogic_vector(5 downto 0):=(others=>'0');
An aggregate is never locally static.

-- no error, if this is used
constant const : std_ulogic_vector(5 downto 0):="001001";
A string literal is locally static.

[...]
The error message is:
when const => assert false report "test!" severity error;
|
duluth: *E,380 (/folder/testfile.vhd,19): expecting a locally static
expression of type STD_ULOGIC_VECTOR and length 6 [8.7].


So my question is: Why do I get these errors, if I use one of the
uncommented constant definitions? The constant const is always locally
static.
(Note, that even the error message of my Leapfrog is errogenous: [8.7]
ist the chapter in the LRM, that deals with the if-statement, [8.8] is
for case.)

The commented definitions would be more handy - especially, the 1st one,
because then I could easily change the bitwidth.
Leapfrog is right.
You may use an if statement.

JD.
 
john Doef wrote:

-- errors if one of the following lines is uncommented
--constant const : std_ulogic_vector(bitwidth-1 downto 0):=
std_ulogic_vector(to_unsigned(16#0A#,bitwidth));

This const is not locally static, because of the call to to_unsigned.
Thank you for the explanation!


Ralf
 
Ralf Hildebrandt wrote:
john Doef wrote:

-- errors if one of the following lines is uncommented
--constant const : std_ulogic_vector(bitwidth-1 downto 0):=
std_ulogic_vector(to_unsigned(16#0A#,bitwidth));

This const is not locally static, because of the call to to_unsigned.

Thank you for the explanation!
I was bit/annoyed by that exact same issue.

It makes more sense when you realize that to_unsigned, as a function
call, could be replaced by any arbitrary function that could do
who-knows-what.

Maybe VHDL needs something like Verilog-2001's constant functions?

-a
 

Welcome to EDABoard.com

Sponsor

Back
Top