Should this substitution be compilable?

Discussion in 'VHDL' started by valentin tihomirov, Nov 28, 2004.

  1. compiler accepts this:
    constant LOG2: positive := UTILS.BITS_TO_FIT(X);
    constant C: Integer := UTILS.MUX2(WIDTH, LOG2, COND);

    but not this:

    constant C: Integer := MUX2(WIDTH, BITS_TO_FIT(X), COND);

    errors:
    - Cannot find function MUX2 for these actuals
    - Assignment target incompatible with right side. Expected type
    "INTEGER"

    the functions used:
    function BITS_TO_FIT(N: natural) return positive; -- "log2_ceiling"
    function MUX2(I0, I1: Integer; SEL: boolean) return Integer;

    Just wanted to avoid intermediate constant LOG2 as it has no sense per se.
    valentin tihomirov, Nov 28, 2004
    #1
    1. Advertising

  2. valentin tihomirov wrote:

    > - Cannot find function MUX2 for these actuals
    > - Assignment target incompatible with right side. Expected type
    > "INTEGER"



    Just a type mismatch. Modify function MUX2:

    function MUX2(I0, I1: positive; SEL: boolean) return positive;

    -- Mike Treseler
    Mike Treseler, Nov 28, 2004
    #2
    1. Advertising

  3. >
    > Just a type mismatch. Modify function MUX2:
    >
    > function MUX2(I0, I1: positive; SEL: boolean) return positive;


    But positive is subtype of integer; thus, any positive must be acceptable at
    integer position. For this reason MUX2(LOG2) is compilable. I see nothing
    which could prevent MUX2(Integer(GET_POSITIVE())) from compilation.
    valentin tihomirov, Nov 28, 2004
    #3
  4. valentin tihomirov a écrit:
    > compiler accepts this:
    > constant LOG2: positive := UTILS.BITS_TO_FIT(X);
    > constant C: Integer := UTILS.MUX2(WIDTH, LOG2, COND);
    >
    > but not this:
    >
    > constant C: Integer := MUX2(WIDTH, BITS_TO_FIT(X), COND);


    Have you tried this:

    constant C: Integer := UTILS.MUX2(WIDTH, UTILS.BITS_TO_FIT(X), COND); ?

    That's the only obvious difference I can see.

    --
    ____ _ __ ___
    | _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le -
    | | | | | (_| |_| | Invalid return address: remove the -
    |_| |_|_|\__|\___/
    Nicolas Matringe, Nov 29, 2004
    #4
  5. Mohammed khader, Nov 29, 2004
    #5
  6. Yes, I've tried the full name. Result is the same.
    valentin tihomirov, Nov 29, 2004
    #6
  7. valentin tihomirov

    rickman Guest

    Mohammed khader wrote:
    >
    > Hi valentin,
    >
    > I had the same problem few days ago. Go to this link..
    >
    > http://groups.google.com/groups?hl=en&lr=&q=Simulation error while writing&meta=group=comp.lang.vhdl
    >
    > What I understood was a function CANNOT take parameters which are
    > expression .So nested functions are not possible like in C lang.
    > Still not Completely Clear Why is it so ....... Hope to find this time
    > from this thread...


    When I checked the LRM, it says that the formal parameter may only be a
    function if it is a type conversion. So a function with two parameters
    is not acceptable.

    --

    Rick "rickman" Collins


    Ignore the reply address. To email me use the above address with the XY
    removed.

    Arius - A Signal Processing Solutions Company
    Specializing in DSP and FPGA design URL http://www.arius.com
    4 King Ave 301-682-7772 Voice
    Frederick, MD 21701-3110 301-682-7666 FAX
    rickman, Nov 29, 2004
    #7
  8. valentin tihomirov

    Jim Lewis Guest

    rickman wrote:
    > Mohammed khader wrote:
    >
    >>Hi valentin,
    >>
    >> I had the same problem few days ago. Go to this link..
    >>
    >> http://groups.google.com/groups?hl=en&lr=&q=Simulation error while writing&meta=group=comp.lang.vhdl
    >>
    >> What I understood was a function CANNOT take parameters which are
    >>expression .So nested functions are not possible like in C lang.
    >>Still not Completely Clear Why is it so ....... Hope to find this time
    >>from this thread...

    >
    >
    > When I checked the LRM, it says that the formal parameter may only be a
    > function if it is a type conversion. So a function with two parameters
    > is not acceptable.


    The formal parameter is the name on the left of named association.
    Here there is not formal parameter specified since the call is
    by positional association.

    However, the actual parameter to a subprogram may be an expression
    if the class of the object is a constant (which it is here because
    the mode when not specified defaults to in and the class when not
    specified for mode in defaults to constant).

    Cheers,
    Jim
    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis, Nov 29, 2004
    #8
  9. valentin tihomirov

    Jim Lewis Guest

    Valentin,
    Can't really narrow your problem down without seeing more.

    First as an experiment, have you checked that the
    original code still compiles?

    _If it does not work_, did you move where the constants
    or subprograms are defined? If the subprograms and
    the constants are in the same package, then the subprograms
    need to be declared before the constants.

    _If it does not work_, did you accidentially compile
    UTILS into more than one named library that is currently
    visible? In this case Mux2 will be hidden unless you
    also specify th elibrary name:

    constant LOG2: positive := work.UTILS.BITS_TO_FIT(X);
    constant C: Integer := work.UTILS.MUX2(WIDTH, LOG2, COND);


    Given the declarations of the subprograms if the first
    form did not break, it seems the second form should work.
    Just to humor the compiler, you might try typecasting
    the positive argument into being integer:

    constant C: Integer := work.UTILS.MUX2(WIDTH, integer(WORK.UTILS.BITS_TO_FIT(X)), COND);


    If none of the above work, I would exit the tool and delete
    the library and any tool generated ini files (unless you have
    customized them). Then I would try again.

    Cheers,
    Jim







    valentin tihomirov wrote:
    > compiler accepts this:
    > constant LOG2: positive := UTILS.BITS_TO_FIT(X);
    > constant C: Integer := UTILS.MUX2(WIDTH, LOG2, COND);
    >
    > but not this:
    >
    > constant C: Integer := MUX2(WIDTH, BITS_TO_FIT(X), COND);
    >
    > errors:
    > - Cannot find function MUX2 for these actuals
    > - Assignment target incompatible with right side. Expected type
    > "INTEGER"
    >
    > the functions used:
    > function BITS_TO_FIT(N: natural) return positive; -- "log2_ceiling"
    > function MUX2(I0, I1: Integer; SEL: boolean) return Integer;
    >
    > Just wanted to avoid intermediate constant LOG2 as it has no sense per se.
    >
    >



    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis, Nov 29, 2004
    #9
  10. valentin tihomirov

    rickman Guest

    Jim Lewis wrote:
    >
    > rickman wrote:
    > > Mohammed khader wrote:
    > >
    > >>Hi valentin,
    > >>
    > >> I had the same problem few days ago. Go to this link..
    > >>
    > >> http://groups.google.com/groups?hl=en&lr=&q=Simulation error while writing&meta=group=comp.lang.vhdl
    > >>
    > >> What I understood was a function CANNOT take parameters which are
    > >>expression .So nested functions are not possible like in C lang.
    > >>Still not Completely Clear Why is it so ....... Hope to find this time
    > >>from this thread...

    > >
    > >
    > > When I checked the LRM, it says that the formal parameter may only be a
    > > function if it is a type conversion. So a function with two parameters
    > > is not acceptable.

    >
    > The formal parameter is the name on the left of named association.
    > Here there is not formal parameter specified since the call is
    > by positional association.
    >
    > However, the actual parameter to a subprogram may be an expression
    > if the class of the object is a constant (which it is here because
    > the mode when not specified defaults to in and the class when not
    > specified for mode in defaults to constant).


    Sorry, I mixed up my formal and actual. I meant actual which is how the
    OP is using the function within a function call.

    I don't see in the LRM where it says the actual can be a constant
    function call. But then this is a very hard to read section (4.3.2.2)
    and I could easily be misinterpreting it.

    --

    Rick "rickman" Collins


    Ignore the reply address. To email me use the above address with the XY
    removed.

    Arius - A Signal Processing Solutions Company
    Specializing in DSP and FPGA design URL http://www.arius.com
    4 King Ave 301-682-7772 Voice
    Frederick, MD 21701-3110 301-682-7666 FAX
    rickman, Nov 29, 2004
    #10
  11. valentin tihomirov

    Jim Lewis Guest

    rickman wrote:
    > Jim Lewis wrote:
    >
    >>rickman wrote:
    >>
    >>>Mohammed khader wrote:
    >>>
    >>>
    >>>>Hi valentin,
    >>>>
    >>>> I had the same problem few days ago. Go to this link..
    >>>>
    >>>>http://groups.google.com/groups?hl=en&lr=&q=Simulation error while writing&meta=group=comp.lang.vhdl
    >>>>
    >>>>What I understood was a function CANNOT take parameters which are
    >>>>expression .So nested functions are not possible like in C lang.
    >>>>Still not Completely Clear Why is it so ....... Hope to find this time
    >>>
    >>>>from this thread...
    >>>
    >>>
    >>>When I checked the LRM, it says that the formal parameter may only be a
    >>>function if it is a type conversion. So a function with two parameters
    >>>is not acceptable.

    >>
    >>The formal parameter is the name on the left of named association.
    >>Here there is not formal parameter specified since the call is
    >>by positional association.
    >>
    >>However, the actual parameter to a subprogram may be an expression
    >>if the class of the object is a constant (which it is here because
    >>the mode when not specified defaults to in and the class when not
    >>specified for mode in defaults to constant).

    >
    >
    > Sorry, I mixed up my formal and actual. I meant actual which is how the
    > OP is using the function within a function call.
    >
    > I don't see in the LRM where it says the actual can be a constant
    > function call. But then this is a very hard to read section (4.3.2.2)
    > and I could easily be misinterpreting it.


    Rick,

    I am reading primarily from LRM section 2.1.1

    Cheers,
    Jim
    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis, Nov 29, 2004
    #11
  12. rickman wrote:
    > Mohammed khader wrote:
    >
    >>Hi valentin,
    >>
    >> I had the same problem few days ago. Go to this link..
    >>
    >> http://groups.google.com/groups?hl=en&lr=&q=Simulation error while writing&meta=group=comp.lang.vhdl
    >>
    >> What I understood was a function CANNOT take parameters which are
    >>expression .So nested functions are not possible like in C lang.
    >>Still not Completely Clear Why is it so ....... Hope to find this time
    >>from this thread...

    >
    >
    > When I checked the LRM, it says that the formal parameter may only be a
    > function if it is a type conversion. So a function with two parameters
    > is not acceptable.


    That statement is valid for port maps (if I'm not mistaken, I do not
    have the LRM available right now). The OP did not instantiate a
    component, he merely uses the return value of one function as parameter
    to another function (whose return value is assigned to a constant). I
    can't see anything wrong with that.

    Paul.
    Paul Uiterlinden, Nov 30, 2004
    #12
  13. Thanks for the participation. The problem was with the tool indeed.

    this line started to compile
    constant A: Integer := UTILS.MUX2(W, UTILS.BITS_TO_FIT(X), FLAG);

    after the following declaration:
    use UTILS.MUX2;

    May be this is because MUX2 is overloaded. Unfortunately, we have no general
    ternary operator so far.
    valentin tihomirov, Nov 30, 2004
    #13
    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. VisionSet
    Replies:
    3
    Views:
    2,041
    Andrew Thompson
    Sep 2, 2004
  2. Robert Bralic
    Replies:
    4
    Views:
    3,040
  3. Crypto Loko
    Replies:
    3
    Views:
    310
    Crypto Loko
    Oct 16, 2005
  4. ~~~ .NET Ed ~~~

    How should control images should be handled?

    ~~~ .NET Ed ~~~, Oct 31, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    235
    John Saunders
    Nov 3, 2004
  5. bookaa bookaa
    Replies:
    12
    Views:
    97
    Steven D'Aprano
    May 27, 2014
Loading...

Share This Page