[cfe-dev] Borland-style PCHs in clang

dawn at burble.org dawn at burble.org
Wed Sep 29 11:32:34 PDT 2010


What happens when the PCH preamble is found to be invalid or
out-of-date?  Is there any automatic regeneration?

-Dawn

On Wed, Sep 29, 2010 at 07:59:17AM -0700, Douglas Gregor wrote:
> 
> On Sep 29, 2010, at 12:12 AM, dawn at burble.org wrote:
> 
> > Sounds great.  What's your "preamble support"??
> 
> It's an optimization that we use when we end up repeatedly parsing the same file (e.g., during code completion), which builds a precompiled header up to (and including) the last preprocessor directive at the top of the main file, e.g., for
> 
>   #include "MyClass.h"
>   #include <vector>
>   #include <map>
> 
>   void foo() { }
> 
> we would build a "precompiled preamble" containing everything up to and including the #include <map>. When we then use that precompiled preamble, we load the precompiled header and then instruct the lexer to start processing at the end of the preamble.
> 
> > May be you can point me to some code in clang that I can poke around
> > in??
> 
> Lexer::ComputePreamble figures out where the preamble ends; it could be taught to recognize #pragma hdrstop.
> 
> Preprocessor::setSkipMainFilePreamble() tells the preprocessor to skip some number of bytes at the beginning of the main file, so that it can resume at the proper place after loading a precompiled preamble.
> 
> For most of the rest of the system, a precompiled preamble is just a normal precompiled header. Nothing fancy here.
> 
> Set up for the precompiled preamble is a little messy. See lib/Frontend/ASTUnit.cpp, wherever it talks about preambles. 
> 
> 	- Doug
> 
> > -Dawn
> > 
> > On Tue, Sep 28, 2010 at 08:18:33PM -0700, Sebastian Redl wrote:
> >> 
> >> On Sep 28, 2010, at 6:35 PM, dawn at burble.org wrote:
> >> 
> >>> 
> >>> I'm trying to figure out the best way to support Borland style PCHs in
> >>> clang.  Suppose we have headers x.h and y.h and file x.c
> >>> as follows:
> >>> 
> >>>   #include "x.h"
> >>>   #include "y.h"
> >>>   #pragma hdrstop // everything above this line goes into the PCH
> >>> 
> >>> What's the best way to add this support to clang?
> >> 
> >> I think your best bet is to piggy-back on our preamble support. The main difference between that and #pragma hdrstop is that it finds the end of the includes automatically.
> >> 
> >> Sebastian
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list