return the (value of) assignment

V

valtih1978

Guest
Here is a funny code that I have Modelsimed

process
function COMPUTE return boolean is
constant STR: string := "abc";
begin
-- Error1: Target of signal assignment
-- is not a signal.
--STR <= STR;

-- Error2: Constant "STR" cannot be target of
-- variable assignment statement.
--STR := STR;

-- Return assignment is OK!
return STR <= "xyz";
end function;


-- Error3: Type error resolving function call
-- "COMPUTE" as type std.STANDARD.STRING.
--constant STR: string := COMPUTE;

constant B2:boolean := COMPUTE;
begin
report "Computed b2 = " & boolean'image(B2);
wait;
end process;

I am getting "Computed b2 = true" in the output despite I do not see
anywhere how the assignment in the end of COMPUTE function evaluates to
a boolean. A stand-alone assignment would violate checks marked with
error1 and error2.
 
There is no assignment statement in your (uncommented) example code.

The statement here is "return <expression>" and the expression returns true if STR is less than or equal to "xyz".

VHDL defines the <= operator for l,r operands of the same type. The evaluation is based on the size of the arrays.

VHDL operators can be overloaded, to implement more complex operations, such as is done in numeric_std for

function "<=" (unsigned, unsigned) return boolean;

Which evaluates the contents of the arrays to determine the result.

A less ambiguous example would have been:

return STR := "xyz";

Since ":=" is not also a vhdl operator.

Andy
 
On 09/06/13 11:55, valtih1978 wrote:
Here is a funny code that I have Modelsimed

process
function COMPUTE return boolean is
constant STR: string := "abc";
begin
-- Error1: Target of signal assignment
-- is not a signal.
--STR <= STR;

-- Error2: Constant "STR" cannot be target of
-- variable assignment statement.
--STR := STR;

-- Return assignment is OK!
return STR <= "xyz";
end function;


-- Error3: Type error resolving function call
-- "COMPUTE" as type std.STANDARD.STRING.
--constant STR: string := COMPUTE;

constant B2:boolean := COMPUTE;
begin
report "Computed b2 = " & boolean'image(B2);
wait;
end process;

I am getting "Computed b2 = true" in the output despite I do not see anywhere how the
assignment in the end of COMPUTE function evaluates to a boolean. A stand-alone assignment
would violate checks marked with error1 and error2.

In your example, '<=' is getting interpreted as 'less than or equal to', not 'signal
assignment' here. It is true that "abc" <= "xyz", thus the returned boolean value.

Regards,
--
Tim McBrayer
MathWorks
 

Welcome to EDABoard.com

Sponsor

Back
Top