Skip to content

Commit

Permalink
[llvm-cov] Add a format option for the 'show' sub-command (mostly NFC)
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273968 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vedantk committed Jun 28, 2016
1 parent 2aa8ecf commit 0347ce7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/CommandGuide/llvm-cov.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/tools/llvm-cov/prevent_false_instantiations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() \
Expand Down
8 changes: 8 additions & 0 deletions tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tools/llvm-cov/CoverageViewOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions tools/llvm-cov/SourceCoverageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0347ce7

Please sign in to comment.