[cfe-dev] LibTooling question

Nick Lewycky nlewycky at google.com
Wed Aug 1 12:53:03 PDT 2012


<div class="gmail_quote">On 1 August 2012 06:45, Manuel Klimek <span
dir="ltr"><<a href="mailto:klimek at google.com"
target="_blank">klimek at google.com</a>></span> wrote:<br><blockquote
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex;"><div class="im">On Tue, Jul 31, 2012 at 10:37
AM, Mario Schwalbe<br>
<<a href="mailto:mario at se.inf.tu-dresden.de">mario at se.inf.tu-dresden.de</a>>
wrote:<br>
> -----BEGIN PGP SIGNED MESSAGE-----<br>
> Hash: SHA1<br>
><br>
> Hi CLANGers,<br>
><br>
> I've been playing with Clang's LibTooling classes closely following<br>
> the tutorial at <a
href="http://clang.llvm.org/docs/LibTooling.html"
target="_blank">http://clang.llvm.org/docs/<wbr>LibTooling.html</a> in
order<br>
> to make use of clang as a frontend in our project.<br>
><br>
> However, I might need some assistence:<br>
><br>
> 1. Include headers: Using the ClangTool class (like the example
suggests)<br>
>    it cannot find its own headers. The documentation states:<br>
><br>
>    "Clang tools need their builtin headers and search
for them the same<br>
>     way clang does. Thus, the default location to look
for builtin headers<br>
>     is in a path $(dirname
/path/to/tool)/../lib/clang/3.<wbr>2/include relative<br>
>     to the tool binary."<br>
><br>
>    But apparently the passed pseudo argv[0] is
clang-tool, and, hence, the<br>
>    invocation contains:<br>
<br>
</div>That should only be the case if you use runToolOnCode, and not if you<br>
use ClangTool.<br>
<br>
Does the code live somewhere you can point me to?<br>
<div class="im"><br>
>       -resource-dir ../lib/clang/3.1<br>
>       -internal-isystem ../lib/clang/3.1/include<br>
><br>
>    on Linux. (Windows seems to work.) It this intended
behaviour?<br>
>    How can I set those paths? clang itself works. The
ToolInvocation class<br>
>    as well, if I pass a reasonable path as argv[0].<br>
><br>
> 2. I finally managed to run a SyntaxOnlyAction as well as
PrintPreprocessedAction.<br>
>    But how can I compile a module to LLVM IR?<br>
><br>
> 3. And is it possible to access the generated result (LLVM IR or
preprocessed<br>
>    source code) without first writing to disk and re-reading.<br>
<br>
</div>Regarding code generation I'm not sure :) The tooling is definitely<br>
built mainly with parsing in mind. I've looped in Nick for some<br>
comments on what might be necessary to get your use case
working...<br></blockquote><div><br></div><div>Yep, I've done this. I
create my own FrontendAction derived from clang::EmitLLVMOnlyAction.
 The replacement EndSourceFileAction() calls
this->EmitLLVMOnlyAction::EndSourceFileAction(); and then
takeModule() returns the
llvm::Module.</div><div><br></div><div>Nick</div><div> </div><blockquote
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex;">Cheers,<br>
/Manuel<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> Thanks in advance,<br>
> Mario<br>
> -----BEGIN PGP SIGNATURE-----<br>
> Version: GnuPG v1.4.11 (GNU/Linux)<br>
> Comment: Using GnuPG with Mozilla - <a
href="http://enigmail.mozdev.org/"
target="_blank">http://enigmail.mozdev.org/</a><br>
><br>
> iQEcBAEBAgAGBQJQF5kiAAoJEDv0fP<wbr>6GapNt1j8IAInVS4J2446fYTpxJF+<wbr>uUjSe<br>
> mV3rte0PyZ/fS1+70LfH+<wbr>etjjiP0PMhrvLKIvU5HazMZ2cn7ZpX<wbr>JXqopXQS/orcx<br>
> hzwTrYzRehfVOzv0ykW0XwI5yKqaOg<wbr>+SKZtyevBSMMY7go+<wbr>x7CXZQw9rNncetI7L<br>
> e4ITyzQmjQd/<wbr>Tal9OdWpDu2uB9Ma79QBmDYEm035jt<wbr>/twcEDATK91ZFgP5MSaCXQ<br>
> DPwWMZhG01vkR5uoBCQX4gVeLXlMrJ<wbr>JtaSM21ZNv1jZ4cfJdqMqoVTh7wZ/<wbr>VKL1t<br>
> jzvP0AyIWEg6VxI18do15KE2B7TKSz<wbr>q2vBpK0w7lgKbADS8qOZiQH+YzWHE+<wbr>Ahk=<br>
> =PvUf<br>
> -----END PGP SIGNATURE-----<br>
> ______________________________<wbr>_________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev at cs.uiuc.edu">cfe-dev at cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev"
target="_blank">http://lists.cs.uiuc.edu/<wbr>mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>



More information about the cfe-dev mailing list