[PATCH] D77385: [clangd] Add index export to dexp
Mark Nauwelaerts via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 10 06:25:43 PDT 2020
mnauw updated this revision to Diff 256557.
mnauw edited the summary of this revision.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77385/new/
https://reviews.llvm.org/D77385
Files:
clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -259,6 +259,56 @@
}
};
+class Export : public Command {
+ llvm::cl::opt<IndexFileFormat> Format{
+ "format",
+ llvm::cl::desc("Format of index export"),
+ llvm::cl::values(
+ clEnumValN(IndexFileFormat::YAML, "yaml",
+ "human-readable YAML format"),
+ clEnumValN(IndexFileFormat::RIFF, "binary", "binary RIFF format")),
+ llvm::cl::init(IndexFileFormat::YAML),
+ };
+ llvm::cl::opt<std::string> OutputFile{
+ "output-file",
+ llvm::cl::Positional,
+ llvm::cl::Required,
+ llvm::cl::desc("Output file for export"),
+ };
+
+public:
+ void run() {
+ using namespace clang::clangd;
+ // Read input file (as specified in global option)
+ auto Buffer = llvm::MemoryBuffer::getFile(IndexPath);
+ if (!Buffer) {
+ llvm::errs() << llvm::formatv("Can't open {0}", IndexPath) << "\n";
+ return;
+ }
+
+ // Auto-detects input format when parsing
+ auto IndexIn = clang::clangd::readIndexFile(Buffer->get()->getBuffer());
+ if (!IndexIn) {
+ llvm::errs() << llvm::toString(IndexIn.takeError()) << "\n";
+ return;
+ }
+
+ // Prepare output file
+ std::error_code EC;
+ llvm::raw_fd_ostream OutputStream(OutputFile, EC);
+ if (EC) {
+ llvm::errs() << llvm::formatv("Can't open {0} for writing", OutputFile)
+ << "\n";
+ return;
+ }
+
+ // Export
+ clang::clangd::IndexFileOut IndexOut(IndexIn.get());
+ IndexOut.Format = Format;
+ OutputStream << IndexOut;
+ }
+};
+
struct {
const char *Name;
const char *Description;
@@ -269,6 +319,7 @@
std::make_unique<Lookup>},
{"refs", "Find references by ID or qualified name",
std::make_unique<Refs>},
+ {"export", "Export index", std::make_unique<Export>},
};
std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77385.256557.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200410/0f833ca4/attachment.bin>
More information about the cfe-commits
mailing list