<div class="gmail_quote"><div>To avoid unexpected troubles when doing svn update, I copy the whole clang/Driver directory to another place and do all things in that directory, and linking against the necessary LLVM/clang libraries to build a custom driver.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">More specifically, you need to modify the following to use the<br>
AnalysisConsumer interface:<br>
<br>
--------------------<br>
<br>
Driver/AnalysisConsumer.h:<br>
<br>
Add a new value to the enum Analyses:<br>
<br>
enum Analyses {<br>
CFGDump,<br>
CFGView,<br>
WarnDeadStores,<br>
WarnUninitVals,<br>
DisplayLiveVariables,<br>
CheckerCFRef,<br>
CheckerSimple,<br>
MyChecker // <--------------------------<br>
};<br>
<br>
--------------------<br>
<br>
Driver/AnalysisConsumer.cpp:<br>
<br>
1) Add a static "Action" function that calls your checker using the<br>
appropriate arguments.<br>
<br>
static void ActionMyChecker(AnalysisManager& mgr) {<br>
// Call the checker using arguments provided by queries to<br>
AnalysisManager.<br>
...<br>
}<br>
<br>
<br>
2) Add a case in CreateAnalysisConsumer for your Analysis using the<br>
enum value you added to Driver/AnalysisConsumer.h:<br>
<br>
ASTConsumer* clang::CreateAnalysisConsumer(...) {<br>
<br>
...<br>
<br>
for ( ; Beg != End ; ++Beg)<br>
switch (*Beg) {<br>
case WarnDeadStores:<br>
C->addCodeAction(&ActionDeadStores);<br>
break;<br>
<br>
case WarnUninitVals:<br>
C->addCodeAction(&ActionUninitVals);<br>
break;<br>
<br>
// ADD A CASE HERE<br>
case MyChecker:<br>
C->addCodeAction(&ActionMyChecker);<br>
break;<br>
<br>
--------------------<br>
<br>
Driver/Clang.cpp:<br>
<br>
Add your command line argument to "Analyses"<br>
<br>
static llvm::cl::list<Analyses><br>
AnalysisList(llvm::cl::desc("Available Source Code Analyses:"),<br>
llvm::cl::values(<br>
clEnumValN(CFGDump, "cfg-dump", "Display Control-Flow Graphs"),<br>
clEnumValN(CFGView, "cfg-view", "View Control-Flow Graphs using<br>
GraphViz"),<br>
clEnumValN(DisplayLiveVariables, "dump-live-variables",<br>
"Print results of live variable analysis"),<br>
clEnumValN(WarnDeadStores, "warn-dead-stores",<br>
"Flag warnings of stores to dead variables"),<br>
clEnumValN(WarnUninitVals, "warn-uninit-values",<br>
"Flag warnings of uses of unitialized variables"),<br>
clEnumValN(CheckerSimple, "checker-simple",<br>
"Perform simple path-sensitive checks."),<br>
clEnumValN(CheckerCFRef, "checker-cfref",<br>
"Run the [Core] Foundation reference count checker"),<br>
clEnumValnN(MyChecker, "my-checker", //<br>
<------------------------------------------<br>
"My Custom Checker"),<br>
clEnumValEnd));<br>
<font color="#888888"><br>
<br>
- Ted<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>