blob: e355a94e41517dba263473af706282c038034a51 [file] [log] [blame]
Zhongxing Xudc3240c2009-07-16 01:00:25 +00001#include "clang/Analysis/CallGraph.h"
2
3#include "clang/Basic/FileManager.h"
4#include "clang/Index/TranslationUnit.h"
5#include "llvm/Support/CommandLine.h"
6#include "llvm/Support/raw_ostream.h"
7using namespace clang;
8using namespace idx;
9
10static llvm::cl::list<std::string>
11InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>"));
12
13// FIXME: this duplicates the one in index-test.cpp.
14class TUnit : public TranslationUnit {
15public:
16 TUnit(ASTUnit *ast, const std::string &filename)
17 : AST(ast), Filename(filename) {}
18 ASTContext &getASTContext() { return AST->getASTContext(); }
19 llvm::OwningPtr<ASTUnit> AST;
20 std::string Filename;
21};
22
23int main(int argc, char **argv) {
24 llvm::cl::ParseCommandLineOptions(argc, argv, "clang-wpa");
25 FileManager FileMgr;
26 std::vector<TUnit*> TUnits;
27
28 if (InputFilenames.empty())
29 return 0;
30
31 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
32 const std::string &InFile = InputFilenames[i];
33
34 std::string ErrMsg;
35 llvm::OwningPtr<ASTUnit> AST;
36
37 AST.reset(ASTUnit::LoadFromPCHFile(InFile, FileMgr, &ErrMsg));
38
39 if (!AST) {
40 llvm::errs() << "[" << InFile << "] error: " << ErrMsg << '\n';
41 return 1;
42 }
43
44 TUnit *TU = new TUnit(AST.take(), InFile);
45 TUnits.push_back(TU);
46 }
47
48 llvm::OwningPtr<CallGraph> CG;
49 CG.reset(new CallGraph());
50
51 for (unsigned i = 0, e = TUnits.size(); i != e; ++i)
52 CG->addTU(*(TUnits[i]->AST));
53
54 CG->dump();
55}