On Apr 9, 3:53 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
> On Wed, 09 Apr 2008 10:31:02 +0200, Thomas Reinemann wrote:
> >Hi,
>
> >usually we have statements like this kind, to copy the value of a signal.
>
> > pgen_data : process (sclk) is
> > begin -- process pgen_data
> > if rising_edge(sclk) then -- rising clock edge
>
> > sfifo_alt <= sfifo_data_in;
>
> > end if;
> > end process pgen_data;
>
> >To do it right, we have to figure out the type of the right value and
> >copy it. During debugging this can be time consuming and can led to
> >errors. Just my wish, the possibility to copy the type of a signal via
> >a certain keyword perhaps "copy_type".
>
> VHDL doesn't (as far as I know) allow you to determine the type
> of an object. However, it does let you determine the subtype
> (vector range, etc) - as perhaps you already know:
>
> entity bar;
> generic (N: positive :=
;
> port ( P: in std_logic_vector(N-1 downto 0);
> Y: out integer range 1 to N );
> end;
> architecture foo of bar is
> signal S: std_logic_vector(P'range);
> signal I: integer range Y'range;
> begin
> S <= P; -- S definitely has the correct subtype
> Y <= I; -- I definitely has the correct subtype
> end;
>
> What you are asking for is something much more like a
> type generic (Ada) or template type (C++) and I'm sure
> VHDL <=2002 lacks such things - although there have been
> some interesting developments in the VHDL-200x proposals;
> someone else may be able to expand on that.
> --
> Jonathan Bromley, Consultant
>
> DOULOS - Developing Design Know-how
> VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
>
> Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
> jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com
>
> The contents of this message may contain personal views which
> are not the views of Doulos Ltd., unless specifically stated.
I'm not sure Y'range will work. The 'range attribute is limited to
constrained arrays or aliases or types thereof. You can determine the
bounds of a type or subtype using 'high and 'low, for example, but not
of a scalar object or port. In other words, if Y was of type my_int,
you could use "range my_int'low to my_int'high", but if Y was defined
as my_int, you could not use Y'low or Y'high.
Otherwise Jonathan's example is very good. If a local signal/variable
vector must be the same or related length as a port, it should be
coded as such. That way you are reminding the reader (which may be you
in a few weeks/months/years) that this object needs to have a certain
relation to that port. If you just use the same explicit range,
without using an attribute, the reader does not know whether it is
merely a coincidence, or it has to be the same range.
Taken a step further, this technique allows using unconstrained ports,
which become constrained when they are bound to signals in the
instantiation port map. The architecture must use these attributes to
determine the actual vector index range for that instantiation.
Andy