From: Vedant Kumar Date: Tue, 28 Jun 2016 00:15:54 +0000 (+0000) Subject: [llvm-cov] Add a format option for the 'show' sub-command (mostly NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0347ce77ead2b8f77f9aa2da2f849675532aaf42;p=llvm [llvm-cov] Add a format option for the 'show' sub-command (mostly NFC) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273968 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/CommandGuide/llvm-cov.rst b/docs/CommandGuide/llvm-cov.rst index d0e78a9a1d1..8e2806b0c61 100644 --- a/docs/CommandGuide/llvm-cov.rst +++ b/docs/CommandGuide/llvm-cov.rst @@ -236,6 +236,10 @@ OPTIONS Show code coverage only for functions that match the given regular expression. +.. option:: -format= + + Use the specified output format. The supported formats are: "text". + .. option:: -line-coverage-gt= Show code coverage only for functions with line coverage greater than the diff --git a/test/tools/llvm-cov/prevent_false_instantiations.h b/test/tools/llvm-cov/prevent_false_instantiations.h index a8c72076d16..45aaab6a28c 100644 --- a/test/tools/llvm-cov/prevent_false_instantiations.h +++ b/test/tools/llvm-cov/prevent_false_instantiations.h @@ -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() \ diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 6ca2141508a..7ba8bfaa9f3 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -399,6 +399,13 @@ int CodeCoverageTool::show(int argc, const char **argv, cl::desc("Show function instantiations"), cl::cat(ViewCategory)); + cl::opt 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) diff --git a/tools/llvm-cov/CoverageViewOptions.h b/tools/llvm-cov/CoverageViewOptions.h index 1208fad7917..93bc09ca9d8 100644 --- a/tools/llvm-cov/CoverageViewOptions.h +++ b/tools/llvm-cov/CoverageViewOptions.h @@ -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, diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index 0c2a8878f3b..3309189a935 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -50,8 +50,11 @@ std::unique_ptr SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File, const CoverageViewOptions &Options, coverage::CoverageData &&CoverageInfo) { - return llvm::make_unique(SourceName, File, Options, - std::move(CoverageInfo)); + switch (Options.ShowFormat) { + case CoverageViewOptions::OutputFormat::Text: + return llvm::make_unique(SourceName, File, Options, + std::move(CoverageInfo)); + } } void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,