This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Pre-compiled headers


I vaguely remember that RMS's partially implemented design used
a third idea:

#3 Only scan certain definitions if they are needed in the actual
program.  I don't remember how this was done.  However, we could
do something like spit the header file into section, one for
echo declaration/definition (macro, extern, class, ...), and for
each section specify the names it provides definitions for.
Then lazily scan those sections when needed.

For example:

struct pair { struct pair* car, cdr; };

This defines `pair'.  So when the include file is read,
the compiler remembers:
        "pair", "struct pair { struct pair* car, cdr; };"

When/if the compiler later sees the identifier "pair", it
scans the definition of pair.

(It's been a while, so I may be mis-remembering RMS's idea.)

Finally, a hybrid of #1 and #2:

#2a:  Instead of just tokenizing each header file, we store
a pre-compiled version that actually contains tree nodes
in the binary format of the host system.  For example,
the 'struct pair' would contain a struct tree_type in the
actual pre-compiled file.  Reading in the header file is then
just a matter of reading or mmap'ing the file into a block
of member and performing relocation.  Relocation means walking
over the tree nodes and fixing up pointers.

One tricky part is that the compile file should only contain
references to the definition in the current header.  References
to definition in other files need to be handled as "extern
references".  This suggests using shared library technology
might be worth considering.  Each header file gets compiled
into a .so file.  Instead of reading the header file, we just
dlopen it.  Any header files it depends on get dlopen'ed first.
Cross-references get handled by the dynamic linker.  An optimization
is to compile all the header files of an entire library into a
shared library;  when a header gets #included, then the names
it defines get added to the appropriate namespace.

Of course IDENTIFIER_NODEs have to be handled specially, perhaps
by putting them in a special symbols section.

Gdb used a similar idea, but it got dropped in favor of
"partial symtabs".
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]