case expression and constants

R

Ralf Hildebrandt

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
 
J

john Doef

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.
 
A

Andy Peters

Ralf said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top