<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-GB link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Dear Clang aficionados,<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I’d like to adapt Clang to accept a C extension,
perform a bit of analysis and then output LLVM IR.  <o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>First, I learnt how to use Sema/ParseAST and
CodeGen/ModuleBuilder in the 2.6 release. However, since ParseAST in not re-enterable
I can’t do analysis and code generation at the same time.  So I’d
really appreciate if you could point me to the right way of doing this!<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Second, I’m looking to the development branch.  I
see some great looking API changes, such as introducing CompilerInstance and
CompilerInvocation, and a bunch of FrontendActions.  I was hoping to use
FrontendActions for implementing my analysis and code gen, but no luck so far.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>The minimal program <o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>/// \file  CompilerInstance.c<o:p></o:p></p>

<p class=MsoNormal>#include <clang/Frontend/FrontendActions.h><o:p></o:p></p>

<p class=MsoNormal>int main()<o:p></o:p></p>

<p class=MsoNormal>{<o:p></o:p></p>

<p class=MsoNormal>   clang::EmitLLVMOnlyAction emitLLVM;<o:p></o:p></p>

<p class=MsoNormal>}<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>results in:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>lib/VMCore/Pass.cpp:228: void
<unnamed>::PassRegistrar::RegisterPass(const llvm::PassInfo&):
Assertion `Inserted && "Pass registered multiple times!"'
failed.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>In addition, by trial and error I figured out that I needed
to link against many Clang and LLVM libraries, e.g. <o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>g++ ./CompilerInstance.o   -lclangFrontend
-lclangSema -lclangDriver -lclangAnalysis -lclangChecker -lclangRewrite
-lclangAST -lclangCodeGen -lclangLex -lclangBasic -lclangParse -lLLVMScalarOpts
-lLLVMInstCombine -lLLVMSelectionDAG -lLLVMipo -lLLVMipa -lLTO
-lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMCodeGen -lLLVMCore
-lLLVMMC -lLLVMSupport -lLLVMSystem -lLLVMTarget -lm -ldl –lpthread<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I find it weird that in order to use a FrontendAction that
only emits LLVM code I also need to link against so many optimisation libraries. 
Can I conclude from this experience that FrontendActions are not supposed to be
used like this? (The same happens when I first initialise a CompilerInstance
properly and then declare an EmitLLVMOnlyAction object.)  Again, what
would be the right way to do this?<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I’d really appreciate your help and hope to become
part of the developer community soon!<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Many thanks,<o:p></o:p></p>

<p class=MsoNormal>Anton.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>P.S. I’m almost as desperate as Devin Townsend’s
Ziltoid:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>[Narrator:] Having been rejected by the Planet smasher,
Ziltoid seeks the council of the Omnidimensional Creator.<br>
[Ziltoid:] Assuage my confusion about creation and the universe!<o:p></o:p></p>

<p class=MsoNormal>[Creator:] Yo! Ziltoid, what’s up dude?<o:p></o:p></p>

</div>

</body>

</html>