Well now I have seen what works and what does not. It still beats me,
however, as to why exactly the working examples work, and why the non-
working one does not.
Looking at the working 'no-component' example, it seems clear that, in
order for it to work, the compiler must take a look at the entity
declaration in question in order to even begin the instantiation.
Once this lookup is done, the default generic values are found and can
be applied.
However, I see no reason why exactly the same thing could not happen
if a component declaration is used. It is possible, at least in
principle, to do this, but the compiler still chooses not to.
The only guess I can make is that the presence of a component
declaration constitutes a promise that any instantiation would conform
exactly to the component declaration, saving the compiler the trouble
of actually hunting the corresponding entity down in a file elsewhere.
I think that last description is exactly correct. The whole point of
components is to permit separate compilation. Your description
of the component providing a "promise" about the entity's
appearance is spot-on. What's more, it is a promise that can
be checked later (at elaboration time) to ensure that the entity
indeed delivers what the component promised.
Many people here have good reasons for thinking that this
extra level of indirection is not sufficiently useful to justify
the trouble, and therefore they always use direct entity
instantiation. That is a perfectly justifiable point of view,
though I don't think I agree with it 100%.
To answer your specific question:
A default on a generic says "if the generic isn't wired-up, use this
value instead". You can do this in two places: the component,
or the entity (or neither, or both).
If you think of a component as a socket, and the entity as the
chip itself, then it starts to make some sense. VHDL can
bind a component with no default on its generic to an entity
with a default on that generic; but in that case, the entity
thinks the generic has been wired-up (to the generic
value coming through the component) and the component
requires that the generic be associated, since it has no
default. Not terribly useful.
It *is* useful to do it the other way around: put a default
on the component's generic, but not the entity's. If you
do that, and don't associate the generic on your component
instance, then the component's default will be used and
will be passed through to the entity. In fact, this is what
happens if you supply a default on both: the component's
default is passed through to the entity, and the entity's
default is ignored.
Of course, if you use direct instantiation of the entity
then any component declaration is irrelevant.
Despite what everyone has said about why it's better
to use direct instantiation of entities rather than
traditional component instantiation, there *are*
a few reasons why components come in useful.
One interesting possibility is to provide several
*different* component declarations for a given
entity; each component can have its own
specific value of default for a generic, for example.
You write the general-purpose entity only once, and
provide several different "application views" of it
by providing several components with different
defaults. Unfortunately, this probably means
that all the components need different names
and therefore you need to use explicit configuration
to bind them, so it's not as nice as you might hope.
--
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
(e-mail address removed)
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.