OSDN Git Service

[llvm-cov] Add a format option for the 'show' sub-command (mostly NFC)
authorVedant Kumar <vsk@apple.com>
Tue, 28 Jun 2016 00:15:54 +0000 (00:15 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 28 Jun 2016 00:15:54 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273968 91177308-0d34-0410-b5e6-96231b3b80d8

docs/CommandGuide/llvm-cov.rst
test/tools/llvm-cov/prevent_false_instantiations.h
tools/llvm-cov/CodeCoverage.cpp
tools/llvm-cov/CoverageViewOptions.h
tools/llvm-cov/SourceCoverageView.cpp

index d0e78a9..8e2806b 100644 (file)
@@ -236,6 +236,10 @@ OPTIONS
 
  Show code coverage only for functions that match the given regular expression.
 
+.. option:: -format=<FORMAT>
+
+ Use the specified output format. The supported formats are: "text".
+
 .. option:: -line-coverage-gt=<N>
 
  Show code coverage only for functions with line coverage greater than the
index a8c7207..45aaab6 100644 (file)
@@ -4,7 +4,7 @@
 // NAN-NOT: 0{{[ \t]+}}nan%{{[ \t]+}}0{{[ \t]+}}nan%
 
 // RUN: llvm-profdata merge %S/Inputs/prevent_false_instantiations.proftext -o %t.profdata
-// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s -check-prefix=INSTANTIATION
+// RUN: llvm-cov show -format text %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s -check-prefix=INSTANTIATION
 // RUN: llvm-cov report %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=NAN
 
 #define DO_SOMETHING() \
index 6ca2141..7ba8bfa 100644 (file)
@@ -399,6 +399,13 @@ int CodeCoverageTool::show(int argc, const char **argv,
                                    cl::desc("Show function instantiations"),
                                    cl::cat(ViewCategory));
 
+  cl::opt<CoverageViewOptions::OutputFormat> ShowFormat(
+      "format", cl::desc("Output format for line-based coverage reports"),
+      cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
+                            "Text output"),
+                 clEnumValEnd),
+      cl::init(CoverageViewOptions::OutputFormat::Text));
+
   auto Err = commandLineParser(argc, argv);
   if (Err)
     return Err;
@@ -410,6 +417,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
   ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
   ViewOpts.ShowExpandedRegions = ShowExpansions;
   ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
+  ViewOpts.ShowFormat = ShowFormat;
 
   auto Coverage = load();
   if (!Coverage)
index 1208fad..93bc09c 100644 (file)
@@ -16,6 +16,10 @@ namespace llvm {
 
 /// \brief The options for displaying the code coverage information.
 struct CoverageViewOptions {
+  enum class OutputFormat {
+    Text
+  };
+
   bool Debug;
   bool Colors;
   bool ShowLineNumbers;
@@ -25,6 +29,7 @@ struct CoverageViewOptions {
   bool ShowExpandedRegions;
   bool ShowFunctionInstantiations;
   bool ShowFullFilenames;
+  OutputFormat ShowFormat;
 
   /// \brief Change the output's stream color if the colors are enabled.
   ColoredRawOstream colored_ostream(raw_ostream &OS,
index 0c2a887..3309189 100644 (file)
@@ -50,8 +50,11 @@ std::unique_ptr<SourceCoverageView>
 SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File,
                            const CoverageViewOptions &Options,
                            coverage::CoverageData &&CoverageInfo) {
-  return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options,
-                                                   std::move(CoverageInfo));
+  switch (Options.ShowFormat) {
+  case CoverageViewOptions::OutputFormat::Text:
+    return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options,
+                                                     std::move(CoverageInfo));
+  }
 }
 
 void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,