Should this substitution be compilable?

V

valentin tihomirov

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

Mike Treseler

valentin said:
- 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
 
V

valentin tihomirov

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

Nicolas Matringe

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

rickman

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

(e-mail address removed)
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
 
J

Jim Lewis

rickman said:
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:[email protected]
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
J

Jim Lewis

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 said:
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:[email protected]
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
R

rickman

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

(e-mail address removed)
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
 
J

Jim Lewis

rickman said:
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:[email protected]
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
P

Paul Uiterlinden

rickman said:
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.
 
V

valentin tihomirov

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.
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top