<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>João,</p>
<p>I just got back around to trying the example program. I had to
make a few changes to get the code to compile. When I try the
program it says it is unable to find clang++ which is definitely
on my system. Do I need to hard code the path to clang++?<br>
</p>
<div class="moz-cite-prefix">On 11/11/18 2:33 PM, João Paulo
Labegalini de Carvalho wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGjvy2_RZBNf-vmcWuG+7JZaptDyYXiNu17qKoHoqUgiOF5KeQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Michael,
<div><br>
</div>
<div>The easiest way to use Clang API to
perform "standard" compiler tasks is
through the <a
href="https://clang.llvm.org/doxygen/classclang_1_1driver_1_1Driver.html"
moz-do-not-send="true">Driver class</a>.</div>
<div>Basically what you need to do is
setup a command line invocation, using
the flags from a compilation database
or adding your own, build a
Compilation object and execute it
through the driver.</div>
<div><br>
</div>
<div>For instance:</div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">std::string
CommandLine = "clang++ -Wall -O3
-emit-llvm -o test.bc test.cpp";</font></div>
<div><font face="monospace, monospace">clang::DiagnosticOptions*
DiagOptions = new
DiagnosticOptions();<br>
</font></div>
<div><font face="monospace, monospace">clang::DiagnosticConsumer
*DiagClient = new
TextDiagnosticPrinter(llvm::errs(),
DiagOptions);<br>
</font></div>
<div><font face="monospace, monospace">llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>
DiagID(new clang::DiagnosticIDs());<br>
</font></div>
<div><font face="monospace, monospace">clang::DiagnosticsEngine
Diags(DiagID, DiagOptions,
DiagClient);<br>
</font></div>
<div><font face="monospace, monospace">clang::driver::Driver
TheDriver("clang++",
llvm::sys::getDefaultTargetTriple(),
Diags);</font></div>
<div><font face="monospace, monospace">const
std::unique_ptr<driver::Compilation>
compilation(TheDriver.BuildCompilation(CommandLine));<br>
</font></div>
<div><font face="monospace, monospace">if
(!compilation) { llvm::errs()
<< "failed to build
compilation object!\n"; }<br>
</font></div>
<div><font face="monospace, monospace">llvm::SmallVector<std::pair<int,
const driver::Command*>,10>
failingCommands;<br>
</font></div>
<div><font face="monospace, monospace">int
res =
TheDriver.ExecuteCompilation(*compilation,
failingCommands);<br>
</font></div>
<div>
<div><font face="monospace, monospace">if
(res < 0) {</font></div>
<div><font face="monospace, monospace">
ProcessingFailed = true;</font></div>
<div><font face="monospace, monospace">
for (const std::pair<int, const
driver::Command*>& p :
failingCommands) {</font></div>
<div><font face="monospace, monospace">
if (p.first) {</font></div>
<div><font face="monospace, monospace">
TheDriver.generateCompilationDiagnostics(*compilation,
*p.second);</font></div>
<div><font face="monospace, monospace">
}</font></div>
<div><font face="monospace, monospace">
}</font></div>
<div><font face="monospace, monospace">}</font></div>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Sun, Nov 11, 2018 at 6:53 PM Michael Collison
via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org"
moz-do-not-send="true">cfe-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">I have a
requirement to parse a .cpp file to a .ast file and a .bc
file. <br>
I have the parsing, with filtering of the AST working using
the the <br>
tooling tempalte on this page: <br>
<a href="https://clang.llvm.org/docs/RAVFrontendAction.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://clang.llvm.org/docs/RAVFrontendAction.html</a>.
I also need to <br>
generate LLVM code to write out to a .bc file. I tried using :<br>
<br>
tool.run
(newFrontEndActionFactory<EmitBCAction>().get())<br>
<br>
where tool is an instance of ClangTool but received an error
saying "not <br>
enough position command line arguments specified". Any ideas?
Are there <br>
any examples I can look at?<br>
<br>
Regards,<br>
<br>
Michael Collison<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank"
moz-do-not-send="true">cfe-dev@lists.llvm.org</a><br>
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>João Paulo L. de Carvalho<br>
Computer Science | IC-UNICAMP | Campinas , SP - Brazil</div>
<div><a href="mailto:jaopaulolc@gmail.com" target="_blank"
moz-do-not-send="true">jaopaulolc@gmail.com</a></div>
<div><a href="mailto:joao.carvalho@ic.unicamp.br"
target="_blank" moz-do-not-send="true">joao.carvalho@ic.unicamp.br</a><br>
<a href="mailto:j160924@dac.unicamp.br" target="_blank"
moz-do-not-send="true">j160924@dac.unicamp.br</a></div>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>