Subtyping issue

Discussion in 'VHDL' started by valentin tihomirov, Jun 30, 2005.

  1. I would like to restrict the space of characters.:
    subtype TMYCHAR is character ('a', '1', '.'); -- not supported

    I would like the interpriter to understand that the elements are characters
    so that character'pos attribute were applicable to them for ASCII code
    retreival. Like
    constant C: character := TMYCHAR'val(1);
    constant I: intger := character'pos(C); -- must be x61

    Unfortunately, VHDL supports only ranges rather than enumerations in the
    specification of subtype. How would you perform the convertion:
    type TMYCHAR is ('a', '1', '.');
    constant C: character := TMYCHAR'val(1);



    I fail to write a function TMYCHAR elements with characters :(

    function GET_ASCII(MC: TMYCHAR) return character is
    begin
    for C in character'left to character'right loop
    if C = MC then -- incompareble types
    return character'pos(C);
    end if;
    end loop;
    end;



    thanks in advance
    valentin tihomirov, Jun 30, 2005
    #1
    1. Advertising

  2. On Thu, 30 Jun 2005 15:46:28 +0300, "valentin tihomirov"
    <> wrote:

    >I would like to restrict the space of characters.:
    > subtype TMYCHAR is character ('a', '1', '.'); -- not supported
    >
    >I would like the interpriter to understand that the elements are characters
    >so that character'pos attribute were applicable to them for ASCII code
    >retreival. Like
    > constant C: character := TMYCHAR'val(1);
    > constant I: intger := character'pos(C); -- must be x61
    >
    >Unfortunately, VHDL supports only ranges rather than enumerations in the
    >specification of subtype.


    You are trying to specify a *set* of character. Modula-2 and Pascal
    supported sets. VHDL does not.

    > How would you perform the convertion:
    > type TMYCHAR is ('a', '1', '.');
    > constant C: character := TMYCHAR'val(1);


    One possible solution...

    function To_Character(C: TMYCHAR) return CHARACTER is
    begin
    return CHARACTER'VALUE(TMYCHAR'IMAGE(C));
    end

    Alternatively, try a lookup table:

    type Char_Lookup is array (TMYCHAR) of CHARACTER;
    constant To_Character: Char_Lookup :=
    ( 'a' => 'a'
    , '1' => '1'
    , '.' => '.'
    );

    In either case (function or lookup table) you can then write...

    constant C: CHARACTER := To_Character('1');

    HTH
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
    Tel: +44 (0)1425 471223 mail:
    Fax: +44 (0)1425 471573 Web: http://www.doulos.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Jun 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ragnar
    Replies:
    2
    Views:
    343
    Dan Cernat
    Nov 7, 2003
  2. shawn
    Replies:
    2
    Views:
    261
    shawn
    Oct 17, 2005
  3. Replies:
    3
    Views:
    370
  4. Srini
    Replies:
    11
    Views:
    966
    Arne Vajhøj
    Jun 1, 2008
  5. Michael Le Barbier Grünewald

    Subtyping iterators

    Michael Le Barbier Grünewald, May 9, 2012, in forum: C++
    Replies:
    5
    Views:
    396
Loading...

Share This Page