<div dir="ltr">On Tue, Aug 13, 2013 at 6:19 AM, Yao SHEN <span dir="ltr"><<a href="mailto:yaoshen@andrew.cmu.edu" target="_blank">yaoshen@andrew.cmu.edu</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello,<br>
<br>
This is Yao Shen. I got a problem recently and hope someone here can help me.<br>
<br>
I am using llvm+clang to parse c/c++ codes. My objective is to do some instrumentations towards these codes by inserting instructions into the codes.<br>
<br>
The problem is: the codes are somewhat large. They usually larger than 50M. And there are a lot of header files shared by c/c++ files. All of these make the parsing process very slowly (> 30 minutes).<br>
<br>
So I am think if I can use PCH. In the first step, I will compile all of the header files into PCHs. And then when parsing c/c++ files, I load corresponding PCH files in the PPCallback using ASTReader. It works when the header file is simple (not including other headers). However, if there is a chained including, it cannot work.<br>

<br>
For example, if A.h includes B.h, and if I first convert B.h into B.h.pch, and A.h into A.h.pch, then when parsing main.c which includes A.h, the identifiers in B.h cannot be recognized. And if the main.c include both A.h and B.h, the parse will not pass successfully even if I use #ifdef... in B.h to avoid redefinitions.<br>

<br>
Maybe I have to use chainedincludesSource. However, there is few guides I can get. I don't know how to use it.<br>
<br>
Is there anyone who can help? Do you think using PPCallback::InclusionDirective is a right way in this situation?<br><br></blockquote><div><br></div><div>You might want to consider modifying your source code to use modules; see <a href="http://clang.llvm.org/docs/Modules.html">http://clang.llvm.org/docs/Modules.html</a> .  Alternatively, instead of compiling individual headers using PCH, you could precompile one big header which includes all the commonly used headers in your project.</div>
<div><br></div><div>This is a hard problem; if it were easy, clang would do it for you already. :)</div><div><br></div><div>-Eli</div></div></div></div>