[llvm-cov] Add a format option for the 'show' sub-command (mostly NFC)

llvm-svn: 273968
This commit is contained in:
Vedant Kumar 2016-06-28 00:15:54 +00:00
parent 3264fdd3ca
commit 635c83c1b4
5 changed files with 23 additions and 3 deletions

View 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

View 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() \

View 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)

View 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,

View 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,