summaryrefslogtreecommitdiffstats
path: root/clang/tools/c-index-test/core_main.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2017-01-29 04:50:35 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2017-01-29 04:50:35 +0000
commit5fab85408232759b2e81e5878d558bd929276998 (patch)
tree860f217b3b30c3bb7663060cb2c2f2231f71f219 /clang/tools/c-index-test/core_main.cpp
parent688b69adf8f2b854cf3e532adc8db20e00638736 (diff)
downloadbcm5719-llvm-5fab85408232759b2e81e5878d558bd929276998.tar.gz
bcm5719-llvm-5fab85408232759b2e81e5878d558bd929276998.zip
[c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.
llvm-svn: 293416
Diffstat (limited to 'clang/tools/c-index-test/core_main.cpp')
-rw-r--r--clang/tools/c-index-test/core_main.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp
index 0ab24fb6ccb..33653e0b6dc 100644
--- a/clang/tools/c-index-test/core_main.cpp
+++ b/clang/tools/c-index-test/core_main.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
@@ -49,6 +50,13 @@ static cl::extrahelp MoreHelp(
"invocation\n"
);
+static cl::opt<std::string>
+ModuleFilePath("module-file",
+ cl::desc("Path to module file to print symbols from"));
+static cl::opt<std::string>
+ ModuleFormat("fmodule-format", cl::init("raw"),
+ cl::desc("Container format for clang modules and PCH, 'raw' or 'obj'"));
+
}
} // anonymous namespace
@@ -160,6 +168,39 @@ static bool printSourceSymbols(ArrayRef<const char *> Args) {
return false;
}
+static bool printSourceSymbolsFromModule(StringRef modulePath,
+ StringRef format) {
+ FileSystemOptions FileSystemOpts;
+ auto pchContOps = std::make_shared<PCHContainerOperations>();
+ // Register the support for object-file-wrapped Clang modules.
+ pchContOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
+ auto pchRdr = pchContOps->getReaderOrNull(format);
+ if (!pchRdr) {
+ errs() << "unknown module format: " << format << '\n';
+ return true;
+ }
+
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
+ CompilerInstance::createDiagnostics(new DiagnosticOptions());
+ std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
+ modulePath, *pchRdr, Diags,
+ FileSystemOpts, /*UseDebugInfo=*/false,
+ /*OnlyLocalDecls=*/true, None,
+ /*CaptureDiagnostics=*/false,
+ /*AllowPCHWithCompilerErrors=*/true,
+ /*UserFilesAreVolatile=*/false);
+ if (!AU) {
+ errs() << "failed to create TU for: " << modulePath << '\n';
+ return true;
+ }
+
+ auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs());
+ IndexingOptions IndexOpts;
+ indexASTUnit(*AU, DataConsumer, IndexOpts);
+
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// Helper Utils
//===----------------------------------------------------------------------===//
@@ -219,6 +260,10 @@ int indextest_core_main(int argc, const char **argv) {
}
if (options::Action == ActionType::PrintSourceSymbols) {
+ if (!options::ModuleFilePath.empty()) {
+ return printSourceSymbolsFromModule(options::ModuleFilePath,
+ options::ModuleFormat);
+ }
if (CompArgs.empty()) {
errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n";
return 1;
OpenPOWER on IntegriCloud