Selon Peter Ashenden <peter@ashenden.com.au>:
> Yannick,
>
> The intention is for formal types to be allowed in any place where you can
> have a generic list. So that includes entities, components and blocks as
> well as packages and subprograms.
>
> Regarding your example: The entity declaration is fine, but the process in
> the architecture has a problem. Since the formal type could be associated
> with any actual type, there is no guarantee that the actual will eb a
> discrete type. So it would not be legal to use the 'low, 'high and 'succ
> attributes.
>
> An earlier version of the type-generics proposal was based more closely on
> Ada's type generics, and would have allowed you to specify that the formal
> type be a discrete type. However, in the interest of keeping the current
> proposal for VHDL simple and compatible with future extensions for
> object-oriented types, no type classing is provided for formal type
> generics.
>
> You could, however, revise your example as follows:
>
> entity counter is
> generic ( type count_type; low, high : count_type;
> function succ ( V : count_type ) return count_type );
> port ( clk : in bit; data : out count_type );
> end entity counter;
>
> architecture behavioral of counter is
> begin
> count_behavior : process is
> variable count : count_type := low;
> begin
> data <= count;
> wait until clk = '1';
> if count = high then
> count := succ(count);
> else
> count := low;
> end if;
> end process count_behavior;
> end architecture behavioral;
>
> You could then instantiate the entity as follows:
>
> c : entity work.counter(behavioral)
> generic map ( T, T'low, T'high, T'succ )
> port map ( ... );
>
> I'm assuming here that, since the 'succ attribute is a function, it can be
> associated as an actual with the formal subprogram generic. This is
> something not explicitly mentioned in the current proposal, but seems to
> make sense.
>
> Cheers,
>
> PA
Do you mean protected types are second-class types ?
It appears it would be very impossible to associate access/file/protected
types to formal types, doesn't it ?
Tristan.
Received on Wed Jan 19 01:49:09 2005
This archive was generated by hypermail 2.1.8 : Wed Jan 19 2005 - 01:49:47 PST