Are constants not locally static?

Discussion in 'VHDL' started by M. Norton, Oct 16, 2008.

  1. M. Norton

    M. Norton Guest

    Well this one was a new one on me. Granted this is a warning, but
    thought it might be worth running down, as it seemed to be one of
    those warnings I want to make certain disappear. From Modelsim:

    ** Warning: blah blah(183): Case choice must be a locally static

    So, here's the structure I have. In a package I created an array of
    records and defined them, like so:

    type filt_record is record
    name : string(1 to 18);
    address : std_logic_vector(10 downto 0);
    weight : integer;
    a429_label : std_logic_vector(7 downto 0);
    end record filt_record;

    type filt_table is array (0 to NUM_CHANNELS-1) of filt record;

    constant FILT_DATA : filt_table := (
    0 => ("Display Brightness", "000--------", 1, "01000000"),
    ... yada yada ...
    27 => ("Combiner +12V ", "111-----111", 16, "10110001"));

    Okay, so far, so good. Also, so I could refer to the indicies by
    name, I created a number of constants mapping name to integer, like

    constant DISPLAY_BRIGHTNESS : integer := 0;
    constant COMB_P12V : integer := 27;

    Seems fine. So onto the code that caused the warning. The package is
    declared properly, and so forth earlier. The signal below
    "label_value" is a signal and is a smaller slice of a larger input
    std_logic_vector port. So it's well declared.

    LABEL_CHECKING : process is
    wait until some'event;

    -- Perform some specific label checks
    case label_value is
    when FILT_DATA(COMB_BACKLIGHT).a429_label =>
    -- Do some stuff
    when others =>
    end case;
    end loop;
    end process LABEL_CHECKING;

    The only thing I can think is that the compiler thinks
    FILT_DATA(COMB_BACKLIGHT).a429_label is not locally static. However,
    FILT_DATA is a constant array of records and COMB_BACKLIGHT is one of
    those array index constants. It seems to me like everything in the
    "when" statement should evaluate to something that cannot change.

    So, is Modelsim throwing a warning about nothing, or is there
    something I've missed?

    Thanks for any help with this oddball warning.

    Best regards,
    Mark Norton
    M. Norton, Oct 16, 2008
    1. Advertisements

  2. It's not.
    Either simplify the condition or use if/then/elsif...

    -- Mike Treseler

    57 Thu Oct 16 /evtfs/home/tres> verror 1186
    vcom Message # 1186:
    When the expression is of an array type, the length of the array must
    be known at compile time. The simulator is less restrictive than the
    LRM requires as long as the array length of the expression can be
    determined in the compiler.
    IEEE Std 1076-1993, 8.8 Case statement:

    If the expression is of a one-dimensional character array type, then
    the expression must be one of the following:
    -- The name of an object whose subtype is locally static
    -- An indexed name whose prefix is one of the members of this list
    and whose indexing expressions are locally static expressions
    -- A slice name whose prefix is one of the members of this list and
    whose discrete range is a locally static discrete range
    -- A function call whose return type mark denotes a locally static
    -- A qualified expression or type conversion whose type mark
    denotes a locally static subtype

    It is an error if the element subtype of the one-dimensional character
    array type is not a locally static subtype.
    Mike Treseler, Oct 16, 2008
    1. Advertisements

  3. M. Norton

    M. Norton Guest

    Thank you. I had thought you couldn't get much more static than a
    constant array with a constant index, but perhaps there's a granite or
    bedrock declaration someplace ;-). I'll just chalk it up to a quirk
    of the language.

    M. Norton, Oct 17, 2008
  4. An indexed name is never locally static, nor is a selected name.
    The name you have is a selected name of an indexed name, so
    it is not locally static. See 7.4.1 Locally static primaries
    and 7.4.2 Globally static primaries. Subelements (that is,
    indexed names and/or selected names) are on the list in 7.4.2
    but not on the list in 7.4.1.

    While what you have can be considered globally static, it is
    never considered locally static. Since the compiler knows the
    array length of the value it's allowed (but not compliant,
    hence the warning).
    James Unterburger, Oct 17, 2008
  5. M. Norton

    M. Norton Guest

    Thank you. I suppose I don't truly comprehend the distinction between
    globally and locally static. The question I ask myself is, if
    something is globally static, how could it be less static at a lower
    level of scope?

    However, it's a language definition thing and that's not really my
    forte. It's sufficient to understand that even though everything is a
    constant, I can't use anything with an index or a record selection as
    an expression in a case statement, but would be valid for an if/then
    logic expression.
    M. Norton, Oct 20, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.