diff options
Diffstat (limited to 'tools/index-test')
| -rw-r--r-- | tools/index-test/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | tools/index-test/Makefile | 6 | ||||
| -rw-r--r-- | tools/index-test/index-test.cpp | 46 | 
3 files changed, 27 insertions, 29 deletions
diff --git a/tools/index-test/CMakeLists.txt b/tools/index-test/CMakeLists.txt index 163afc4ac9f5..9472e580fbc5 100644 --- a/tools/index-test/CMakeLists.txt +++ b/tools/index-test/CMakeLists.txt @@ -3,8 +3,9 @@ set(LLVM_NO_RTTI 1)  set( LLVM_USED_LIBS    clangIndex    clangFrontend -  clangAnalysis +  clangDriver    clangSema +  clangAnalysis    clangAST    clangParse    clangLex @@ -14,6 +15,7 @@ set( LLVM_USED_LIBS  set( LLVM_LINK_COMPONENTS    bitreader    mc +  core    )  add_clang_executable(index-test diff --git a/tools/index-test/Makefile b/tools/index-test/Makefile index 8e7bfe554009..4ee98fc7cc99 100644 --- a/tools/index-test/Makefile +++ b/tools/index-test/Makefile @@ -18,8 +18,8 @@ TOOL_NO_EXPORTS = 1  include $(LEVEL)/Makefile.config -LINK_COMPONENTS := bitreader mc -USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangAnalysis.a clangSema.a \ -	   clangAST.a clangParse.a clangLex.a clangBasic.a +LINK_COMPONENTS := bitreader mc core +USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \ +	   clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a  include $(LLVM_SRC_ROOT)/Makefile.rules diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index dd7cbb21642c..ff9fd5431154 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -208,20 +208,26 @@ static void ProcessASTLocation(ASTLocation ASTLoc, Indexer &Idxer) {  static llvm::cl::opt<bool>  ASTFromSource("ast-from-source", -              llvm::cl::desc("Treat the inputs as source files to parse.")); +              llvm::cl::desc("Treat the inputs as source files to parse")); + +static llvm::cl::list<std::string> +CompilerArgs("arg", llvm::cl::desc("Extra arguments to use during parsing"));  static llvm::cl::list<std::string>  InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>")); -void CreateCompilerInvocation(const std::string &Filename, -                              CompilerInvocation &CI, Diagnostic &Diags, -                              const char *argv0) { +ASTUnit *CreateFromSource(const std::string &Filename, Diagnostic &Diags, +                          const char *Argv0) {    llvm::SmallVector<const char *, 16> Args;    Args.push_back(Filename.c_str()); - -  void *MainAddr = (void*) (intptr_t) CreateCompilerInvocation; -  CompilerInvocation::CreateFromArgs(CI, Args.data(), Args.data() + Args.size(), -                                     argv0, MainAddr, Diags); +  for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i) +    Args.push_back(CompilerArgs[i].c_str()); + +  void *MainAddr = (void*) (intptr_t) CreateFromSource; +  std::string ResourceDir = +    CompilerInvocation::GetResourcesPath(Argv0, MainAddr); +  return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(), +                                      Diags, ResourceDir);  }  int main(int argc, char **argv) { @@ -234,9 +240,9 @@ int main(int argc, char **argv) {    Indexer Idxer(Prog);    llvm::SmallVector<TUnit*, 4> TUnits; -  TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions(), false); +  DiagnosticOptions DiagOpts;    llvm::OwningPtr<Diagnostic> Diags( -    CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv)); +    CompilerInstance::createDiagnostics(DiagOpts, argc, argv));    // If no input was specified, read from stdin.    if (InputFilenames.empty()) @@ -244,23 +250,13 @@ int main(int argc, char **argv) {    for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {      const std::string &InFile = InputFilenames[i]; - -    std::string ErrMsg;      llvm::OwningPtr<ASTUnit> AST; - -    if (ASTFromSource) { -      CompilerInvocation CI; -      CreateCompilerInvocation(InFile, CI, *Diags, argv[0]); -      AST.reset(ASTUnit::LoadFromCompilerInvocation(CI, *Diags)); -      if (!AST) -        ErrMsg = "unable to create AST"; -    } else -      AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg)); - -    if (!AST) { -      llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n'; +    if (ASTFromSource) +      AST.reset(CreateFromSource(InFile, *Diags, argv[0])); +    else +      AST.reset(ASTUnit::LoadFromPCHFile(InFile, *Diags)); +    if (!AST)        return 1; -    }      TUnit *TU = new TUnit(AST.take(), InFile);      TUnits.push_back(TU);  | 
