Hi Jordan,

thanks for your advice. It took me a while to get through the LibTooling. By mostly copying the code from your link, i wrote up a few lines of code. However since i am just setting up for testing, I have not gotten around to test this yet.

However i have a few questions: buildCFG takes four parameters:
- a Decl
- a Stmt
- an ASTContext
- buildOptions

To be honest i am not exactly clear on what is what here.

I called it like this:

myCFG = CFG::buildCFG(inFile, getBody(), *Context, cfgBuildOptions);

which i mostly copied from

http://clang.llvm.org/doxygen/AnalysisDeclContext_8cpp_source.html#l00179

I will append my current code. You will notice that i am fairly novice in terms of coding. Please excuse any blatant mistakes.

Best regards,
Viktor


Am 19.03.2014 17:47, schrieb Jordan Rose:
Both DumpCFG and ViewCFG are meant as debug tools for working on the
Clang static analyzer; in particular, the way the CFG is built for the
analyzer may not match your needs.

If you are willing to write your own tool based on Clang's C++
interface, you can get a parsed AST
<http://clang.llvm.org/docs/RAVFrontendAction.html> and then ask for the
CFG of any particular function using CFG::buildCFG. Note, though that
the C++ API is not stable from release to release.

Jordan
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"


using namespace clang;

class FindCFGConsumer : public ASTConsumer {
public:
    explicit FindCFGConsumer(ASTContext *Context)
                { }

    virtual void HandleTranslationUnit(ASTContext &Context) {
        myCFG = CFG::buildCFG(inFile, getBody(), *Context, cfgBuildOptions);
    }
}


class FindCFGFrontendAction : public clang::ASTFrontendAction {
public:
  virtual clang::ASTConsumer *CreateASTConsumer(
    clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
    return new FindCFGConsumer(&Compiler.getASTContext());
  }
};

int main(int argc, const char **argv) {
    
    clang::tooling::runToolOnCode(new FindCFGFrontendAction, argv[1]);
}
_______________________________________________
cfe-users mailing list
cfe-users@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to