blob: ae789fa9ae3cfd1675c28f04f84b265c4e1ee4a7 [file] [log] [blame]
Zhongxing Xu22daf792009-07-16 01:03:49 +00001//===--- clang-wpa.cpp - clang whole program analyzer ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tool reads a sequence of precompiled AST files, and do various
11// cross translation unit analyses.
12//
13//===----------------------------------------------------------------------===//
14
Zhongxing Xudc3240c2009-07-16 01:00:25 +000015#include "clang/Basic/FileManager.h"
Daniel Dunbar31b87d82009-09-21 03:03:39 +000016#include "clang/Basic/SourceManager.h"
Daniel Dunbar8fd57fe2009-12-03 07:20:04 +000017#include "clang/Frontend/ASTUnit.h"
Daniel Dunbar5262fda2009-12-03 01:45:44 +000018#include "clang/Frontend/CompilerInstance.h"
Daniel Dunbar8fd57fe2009-12-03 07:20:04 +000019#include "clang/Index/CallGraph.h"
Zhongxing Xudc3240c2009-07-16 01:00:25 +000020#include "llvm/Support/CommandLine.h"
21#include "llvm/Support/raw_ostream.h"
22using namespace clang;
23using namespace idx;
24
25static llvm::cl::list<std::string>
26InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>"));
27
Zhongxing Xudc3240c2009-07-16 01:00:25 +000028int main(int argc, char **argv) {
29 llvm::cl::ParseCommandLineOptions(argc, argv, "clang-wpa");
30 FileManager FileMgr;
Argyrios Kyrtzidis05945452009-07-29 23:39:09 +000031 std::vector<ASTUnit*> ASTUnits;
Zhongxing Xudc3240c2009-07-16 01:00:25 +000032
33 if (InputFilenames.empty())
34 return 0;
35
Daniel Dunbarbb3503a2009-12-06 09:56:30 +000036 DiagnosticOptions DiagOpts;
Daniel Dunbar5262fda2009-12-03 01:45:44 +000037 llvm::OwningPtr<Diagnostic> Diags(
Daniel Dunbarbb3503a2009-12-06 09:56:30 +000038 CompilerInstance::createDiagnostics(DiagOpts, argc, argv));
Daniel Dunbar31b87d82009-09-21 03:03:39 +000039
Zhongxing Xudc3240c2009-07-16 01:00:25 +000040 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
41 const std::string &InFile = InputFilenames[i];
Daniel Dunbar5262fda2009-12-03 01:45:44 +000042 llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, *Diags));
43 if (!AST)
Zhongxing Xudc3240c2009-07-16 01:00:25 +000044 return 1;
Zhongxing Xudc3240c2009-07-16 01:00:25 +000045
Argyrios Kyrtzidis05945452009-07-29 23:39:09 +000046 ASTUnits.push_back(AST.take());
Zhongxing Xudc3240c2009-07-16 01:00:25 +000047 }
48
49 llvm::OwningPtr<CallGraph> CG;
50 CG.reset(new CallGraph());
51
Argyrios Kyrtzidis05945452009-07-29 23:39:09 +000052 for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i)
Zhongxing Xuf20288c2009-10-28 12:23:03 +000053 CG->addTU(ASTUnits[i]->getASTContext());
Zhongxing Xudc3240c2009-07-16 01:00:25 +000054
Zhongxing Xu56a5d802009-07-23 13:39:38 +000055 CG->ViewCallGraph();
Zhongxing Xudc3240c2009-07-16 01:00:25 +000056}