Zhongxing Xu | dc3240c | 2009-07-16 01:00:25 +0000 | [diff] [blame^] | 1 | #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" |
| 7 | using namespace clang; |
| 8 | using namespace idx; |
| 9 | |
| 10 | static llvm::cl::list<std::string> |
| 11 | InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>")); |
| 12 | |
| 13 | // FIXME: this duplicates the one in index-test.cpp. |
| 14 | class TUnit : public TranslationUnit { |
| 15 | public: |
| 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 | |
| 23 | int 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 | } |