blob: 9e2f154c233f63b564acc291b42062194d2c37c1 [file] [log] [blame]
Alex Lorenze82d89c2014-08-22 22:56:03 +00001//===- CodeCoverage.cpp - Coverage tool based on profiling instrumentation-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// The 'CodeCoverageTool' class implements a command line tool to analyze and
11// report coverage information using the profiling instrumentation and code
12// coverage mapping.
13//
14//===----------------------------------------------------------------------===//
15
Alex Lorenze82d89c2014-08-22 22:56:03 +000016#include "RenderingSupport.h"
17#include "CoverageViewOptions.h"
18#include "CoverageFilters.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000019#include "SourceCoverageView.h"
20#include "CoverageSummary.h"
21#include "CoverageReport.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/ADT/SmallString.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000024#include "llvm/ProfileData/InstrProfReader.h"
25#include "llvm/ProfileData/CoverageMapping.h"
26#include "llvm/ProfileData/CoverageMappingReader.h"
27#include "llvm/Support/CommandLine.h"
28#include "llvm/Support/FileSystem.h"
29#include "llvm/Support/ManagedStatic.h"
30#include "llvm/Support/MemoryObject.h"
31#include "llvm/Support/Format.h"
32#include "llvm/Support/Path.h"
33#include "llvm/Support/Signals.h"
34#include "llvm/Support/PrettyStackTrace.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000035#include <functional>
Justin Bognere53be062014-09-09 05:32:18 +000036#include <system_error>
Alex Lorenze82d89c2014-08-22 22:56:03 +000037
38using namespace llvm;
39using namespace coverage;
40
41namespace {
Alex Lorenze82d89c2014-08-22 22:56:03 +000042/// \brief The implementation of the coverage tool.
43class CodeCoverageTool {
44public:
45 enum Command {
46 /// \brief The show command.
47 Show,
48 /// \brief The report command.
49 Report
50 };
51
52 /// \brief Print the error message to the error output stream.
53 void error(const Twine &Message, StringRef Whence = "");
54
55 /// \brief Return a memory buffer for the given source file.
56 ErrorOr<const MemoryBuffer &> getSourceFile(StringRef SourceFile);
57
Justin Bogner953e2402014-09-20 15:31:56 +000058 /// \brief Create source views for the expansions of the view.
59 void attachExpansionSubViews(SourceCoverageView &View,
60 ArrayRef<ExpansionRecord> Expansions,
61 CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000062
Justin Bogner953e2402014-09-20 15:31:56 +000063 /// \brief Create the source view of a particular function.
Justin Bogner5a6edad2014-09-19 19:07:17 +000064 std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +000065 createFunctionView(const FunctionRecord &Function, CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000066
67 /// \brief Create the main source view of a particular source file.
Justin Bogner5a6edad2014-09-19 19:07:17 +000068 std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +000069 createSourceFileView(StringRef SourceFile, CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000070
71 /// \brief Load the coverage mapping data. Return true if an error occured.
Justin Bogner953e2402014-09-20 15:31:56 +000072 std::unique_ptr<CoverageMapping> load();
Alex Lorenze82d89c2014-08-22 22:56:03 +000073
74 int run(Command Cmd, int argc, const char **argv);
75
76 typedef std::function<int(int, const char **)> CommandLineParserType;
77
78 int show(int argc, const char **argv,
79 CommandLineParserType commandLineParser);
80
81 int report(int argc, const char **argv,
82 CommandLineParserType commandLineParser);
83
84 StringRef ObjectFilename;
85 CoverageViewOptions ViewOpts;
Justin Bogner953e2402014-09-20 15:31:56 +000086 std::string PGOFilename;
Alex Lorenze82d89c2014-08-22 22:56:03 +000087 CoverageFiltersMatchAll Filters;
88 std::vector<std::string> SourceFiles;
89 std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
90 LoadedSourceFiles;
Alex Lorenze82d89c2014-08-22 22:56:03 +000091 bool CompareFilenamesOnly;
Justin Bogner116c1662014-09-19 08:13:12 +000092 StringMap<std::string> RemappedFilenames;
Alex Lorenze82d89c2014-08-22 22:56:03 +000093};
94}
95
96void CodeCoverageTool::error(const Twine &Message, StringRef Whence) {
97 errs() << "error: ";
98 if (!Whence.empty())
99 errs() << Whence << ": ";
100 errs() << Message << "\n";
101}
102
103ErrorOr<const MemoryBuffer &>
104CodeCoverageTool::getSourceFile(StringRef SourceFile) {
Justin Bogner116c1662014-09-19 08:13:12 +0000105 // If we've remapped filenames, look up the real location for this file.
106 if (!RemappedFilenames.empty()) {
107 auto Loc = RemappedFilenames.find(SourceFile);
108 if (Loc != RemappedFilenames.end())
109 SourceFile = Loc->second;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000110 }
Justin Bogner116c1662014-09-19 08:13:12 +0000111 for (const auto &Files : LoadedSourceFiles)
112 if (sys::fs::equivalent(SourceFile, Files.first))
113 return *Files.second;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000114 auto Buffer = MemoryBuffer::getFile(SourceFile);
115 if (auto EC = Buffer.getError()) {
116 error(EC.message(), SourceFile);
117 return EC;
118 }
Justin Bogner116c1662014-09-19 08:13:12 +0000119 LoadedSourceFiles.push_back(
120 std::make_pair(SourceFile, std::move(Buffer.get())));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000121 return *LoadedSourceFiles.back().second;
122}
123
Justin Bogner953e2402014-09-20 15:31:56 +0000124void
125CodeCoverageTool::attachExpansionSubViews(SourceCoverageView &View,
126 ArrayRef<ExpansionRecord> Expansions,
127 CoverageMapping &Coverage) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000128 if (!ViewOpts.ShowExpandedRegions)
129 return;
Justin Bogner953e2402014-09-20 15:31:56 +0000130 for (const auto &Expansion : Expansions) {
131 auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion);
132 if (ExpansionCoverage.empty())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000133 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000134 auto SourceBuffer = getSourceFile(ExpansionCoverage.getFilename());
135 if (!SourceBuffer)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000136 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000137
138 auto SubViewExpansions = ExpansionCoverage.getExpansions();
139 auto SubView = llvm::make_unique<SourceCoverageView>(
140 SourceBuffer.get(), ViewOpts, std::move(ExpansionCoverage));
141 attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
142 View.addExpansion(Expansion.Region, std::move(SubView));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000143 }
144}
145
Justin Bogner5a6edad2014-09-19 19:07:17 +0000146std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +0000147CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
148 CoverageMapping &Coverage) {
149 auto FunctionCoverage = Coverage.getCoverageForFunction(Function);
150 if (FunctionCoverage.empty())
Justin Bogner5a6edad2014-09-19 19:07:17 +0000151 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000152 auto SourceBuffer = getSourceFile(FunctionCoverage.getFilename());
Justin Bogner5a6edad2014-09-19 19:07:17 +0000153 if (!SourceBuffer)
154 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000155
156 auto Expansions = FunctionCoverage.getExpansions();
157 auto View = llvm::make_unique<SourceCoverageView>(
158 SourceBuffer.get(), ViewOpts, std::move(FunctionCoverage));
159 attachExpansionSubViews(*View, Expansions, Coverage);
160
161 return View;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000162}
163
Justin Bogner953e2402014-09-20 15:31:56 +0000164std::unique_ptr<SourceCoverageView>
165CodeCoverageTool::createSourceFileView(StringRef SourceFile,
166 CoverageMapping &Coverage) {
Justin Bogner5a6edad2014-09-19 19:07:17 +0000167 auto SourceBuffer = getSourceFile(SourceFile);
168 if (!SourceBuffer)
169 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000170 auto FileCoverage = Coverage.getCoverageForFile(SourceFile);
171 if (FileCoverage.empty())
Justin Bogner5a6edad2014-09-19 19:07:17 +0000172 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000173
174 auto Expansions = FileCoverage.getExpansions();
175 auto View = llvm::make_unique<SourceCoverageView>(
176 SourceBuffer.get(), ViewOpts, std::move(FileCoverage));
177 attachExpansionSubViews(*View, Expansions, Coverage);
178
179 for (auto Function : Coverage.getInstantiations(SourceFile)) {
180 auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
181 auto SubViewExpansions = SubViewCoverage.getExpansions();
182 auto SubView = llvm::make_unique<SourceCoverageView>(
183 SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
184 attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
185
186 if (SubView) {
Justin Bogner5e1400a2014-09-17 05:33:20 +0000187 unsigned FileID = Function->CountedRegions.front().FileID;
188 unsigned Line = 0;
189 for (const auto &CR : Function->CountedRegions)
190 if (CR.FileID == FileID)
191 Line = std::max(CR.LineEnd, Line);
Justin Bogner953e2402014-09-20 15:31:56 +0000192 View->addInstantiation(Function->Name, Line, std::move(SubView));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000193 }
194 }
Justin Bogner5a6edad2014-09-19 19:07:17 +0000195 return View;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000196}
197
Justin Bogner953e2402014-09-20 15:31:56 +0000198std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
Justin Bogner19a93ba2014-09-20 17:19:52 +0000199 auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename);
Justin Bogner953e2402014-09-20 15:31:56 +0000200 if (std::error_code EC = CoverageOrErr.getError()) {
201 colored_ostream(errs(), raw_ostream::RED)
202 << "error: Failed to load coverage: " << EC.message();
203 errs() << "\n";
204 return nullptr;
205 }
206 auto Coverage = std::move(CoverageOrErr.get());
207 unsigned Mismatched = Coverage->getMismatchedCount();
208 if (Mismatched) {
209 colored_ostream(errs(), raw_ostream::RED)
210 << "warning: " << Mismatched << " functions have mismatched data. ";
211 errs() << "\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000212 }
Justin Bogner116c1662014-09-19 08:13:12 +0000213
214 if (CompareFilenamesOnly) {
Justin Bogner953e2402014-09-20 15:31:56 +0000215 auto CoveredFiles = Coverage.get()->getUniqueSourceFiles();
Justin Bogner116c1662014-09-19 08:13:12 +0000216 for (auto &SF : SourceFiles) {
217 StringRef SFBase = sys::path::filename(SF);
218 for (const auto &CF : CoveredFiles)
219 if (SFBase == sys::path::filename(CF)) {
220 RemappedFilenames[CF] = SF;
221 SF = CF;
222 break;
223 }
224 }
225 }
226
Justin Bogner953e2402014-09-20 15:31:56 +0000227 return Coverage;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000228}
229
230int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
231 // Print a stack trace if we signal out.
232 sys::PrintStackTraceOnErrorSignal();
233 PrettyStackTraceProgram X(argc, argv);
234 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
235
236 cl::list<std::string> InputSourceFiles(
237 cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore);
238
Justin Bogner953e2402014-09-20 15:31:56 +0000239 cl::opt<std::string, true> PGOFilename(
240 "instr-profile", cl::Required, cl::location(this->PGOFilename),
Alex Lorenze82d89c2014-08-22 22:56:03 +0000241 cl::desc(
242 "File with the profile data obtained after an instrumented run"));
243
244 cl::opt<bool> DebugDump("dump", cl::Optional,
245 cl::desc("Show internal debug dump"));
246
247 cl::opt<bool> FilenameEquivalence(
248 "filename-equivalence", cl::Optional,
Justin Bogner116c1662014-09-19 08:13:12 +0000249 cl::desc("Treat source files as equivalent to paths in the coverage data "
250 "when the file names match, even if the full paths do not"));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000251
252 cl::OptionCategory FilteringCategory("Function filtering options");
253
254 cl::list<std::string> NameFilters(
255 "name", cl::Optional,
256 cl::desc("Show code coverage only for functions with the given name"),
257 cl::ZeroOrMore, cl::cat(FilteringCategory));
258
259 cl::list<std::string> NameRegexFilters(
260 "name-regex", cl::Optional,
261 cl::desc("Show code coverage only for functions that match the given "
262 "regular expression"),
263 cl::ZeroOrMore, cl::cat(FilteringCategory));
264
265 cl::opt<double> RegionCoverageLtFilter(
266 "region-coverage-lt", cl::Optional,
267 cl::desc("Show code coverage only for functions with region coverage "
268 "less than the given threshold"),
269 cl::cat(FilteringCategory));
270
271 cl::opt<double> RegionCoverageGtFilter(
272 "region-coverage-gt", cl::Optional,
273 cl::desc("Show code coverage only for functions with region coverage "
274 "greater than the given threshold"),
275 cl::cat(FilteringCategory));
276
277 cl::opt<double> LineCoverageLtFilter(
278 "line-coverage-lt", cl::Optional,
279 cl::desc("Show code coverage only for functions with line coverage less "
280 "than the given threshold"),
281 cl::cat(FilteringCategory));
282
283 cl::opt<double> LineCoverageGtFilter(
284 "line-coverage-gt", cl::Optional,
285 cl::desc("Show code coverage only for functions with line coverage "
286 "greater than the given threshold"),
287 cl::cat(FilteringCategory));
288
289 auto commandLineParser = [&, this](int argc, const char **argv) -> int {
290 cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
291 ViewOpts.Debug = DebugDump;
292 CompareFilenamesOnly = FilenameEquivalence;
293
Alex Lorenze82d89c2014-08-22 22:56:03 +0000294 // Create the function filters
295 if (!NameFilters.empty() || !NameRegexFilters.empty()) {
296 auto NameFilterer = new CoverageFilters;
297 for (const auto &Name : NameFilters)
298 NameFilterer->push_back(llvm::make_unique<NameCoverageFilter>(Name));
299 for (const auto &Regex : NameRegexFilters)
300 NameFilterer->push_back(
301 llvm::make_unique<NameRegexCoverageFilter>(Regex));
302 Filters.push_back(std::unique_ptr<CoverageFilter>(NameFilterer));
303 }
304 if (RegionCoverageLtFilter.getNumOccurrences() ||
305 RegionCoverageGtFilter.getNumOccurrences() ||
306 LineCoverageLtFilter.getNumOccurrences() ||
307 LineCoverageGtFilter.getNumOccurrences()) {
308 auto StatFilterer = new CoverageFilters;
309 if (RegionCoverageLtFilter.getNumOccurrences())
310 StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
311 RegionCoverageFilter::LessThan, RegionCoverageLtFilter));
312 if (RegionCoverageGtFilter.getNumOccurrences())
313 StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
314 RegionCoverageFilter::GreaterThan, RegionCoverageGtFilter));
315 if (LineCoverageLtFilter.getNumOccurrences())
316 StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
317 LineCoverageFilter::LessThan, LineCoverageLtFilter));
318 if (LineCoverageGtFilter.getNumOccurrences())
319 StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
320 RegionCoverageFilter::GreaterThan, LineCoverageGtFilter));
321 Filters.push_back(std::unique_ptr<CoverageFilter>(StatFilterer));
322 }
323
Justin Bogner116c1662014-09-19 08:13:12 +0000324 for (const auto &File : InputSourceFiles) {
325 SmallString<128> Path(File);
326 if (std::error_code EC = sys::fs::make_absolute(Path)) {
327 errs() << "error: " << File << ": " << EC.message();
328 return 1;
329 }
330 SourceFiles.push_back(Path.str());
331 }
Alex Lorenze82d89c2014-08-22 22:56:03 +0000332 return 0;
333 };
334
335 // Parse the object filename
336 if (argc > 1) {
337 StringRef Arg(argv[1]);
338 if (Arg.equals_lower("-help") || Arg.equals_lower("-version")) {
339 cl::ParseCommandLineOptions(2, argv, "LLVM code coverage tool\n");
340 return 0;
341 }
342 ObjectFilename = Arg;
343
344 argv[1] = argv[0];
345 --argc;
346 ++argv;
347 } else {
348 errs() << sys::path::filename(argv[0]) << ": No executable file given!\n";
349 return 1;
350 }
351
352 switch (Cmd) {
353 case Show:
354 return show(argc, argv, commandLineParser);
355 case Report:
356 return report(argc, argv, commandLineParser);
357 }
358 return 0;
359}
360
361int CodeCoverageTool::show(int argc, const char **argv,
362 CommandLineParserType commandLineParser) {
363
364 cl::OptionCategory ViewCategory("Viewing options");
365
366 cl::opt<bool> ShowLineExecutionCounts(
367 "show-line-counts", cl::Optional,
368 cl::desc("Show the execution counts for each line"), cl::init(true),
369 cl::cat(ViewCategory));
370
371 cl::opt<bool> ShowRegions(
372 "show-regions", cl::Optional,
373 cl::desc("Show the execution counts for each region"),
374 cl::cat(ViewCategory));
375
376 cl::opt<bool> ShowBestLineRegionsCounts(
377 "show-line-counts-or-regions", cl::Optional,
378 cl::desc("Show the execution counts for each line, or the execution "
379 "counts for each region on lines that have multiple regions"),
380 cl::cat(ViewCategory));
381
382 cl::opt<bool> ShowExpansions("show-expansions", cl::Optional,
383 cl::desc("Show expanded source regions"),
384 cl::cat(ViewCategory));
385
386 cl::opt<bool> ShowInstantiations("show-instantiations", cl::Optional,
387 cl::desc("Show function instantiations"),
388 cl::cat(ViewCategory));
389
390 cl::opt<bool> NoColors("no-colors", cl::Optional,
391 cl::desc("Don't show text colors"), cl::init(false),
392 cl::cat(ViewCategory));
393
394 auto Err = commandLineParser(argc, argv);
395 if (Err)
396 return Err;
397
398 ViewOpts.Colors = !NoColors;
399 ViewOpts.ShowLineNumbers = true;
400 ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
401 !ShowRegions || ShowBestLineRegionsCounts;
402 ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts;
403 ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
404 ViewOpts.ShowExpandedRegions = ShowExpansions;
405 ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
406
Justin Bogner953e2402014-09-20 15:31:56 +0000407 auto Coverage = load();
408 if (!Coverage)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000409 return 1;
410
411 if (!Filters.empty()) {
412 // Show functions
Justin Bogner953e2402014-09-20 15:31:56 +0000413 for (const auto &Function : Coverage->getCoveredFunctions()) {
414 if (!Filters.matches(Function))
Alex Lorenze82d89c2014-08-22 22:56:03 +0000415 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000416
417 auto mainView = createFunctionView(Function, *Coverage);
Justin Bogner5a6edad2014-09-19 19:07:17 +0000418 if (!mainView) {
419 ViewOpts.colored_ostream(outs(), raw_ostream::RED)
Justin Bogner953e2402014-09-20 15:31:56 +0000420 << "warning: Could not read coverage for '" << Function.Name;
Justin Bogner5a6edad2014-09-19 19:07:17 +0000421 outs() << "\n";
422 continue;
423 }
Justin Bogner953e2402014-09-20 15:31:56 +0000424 ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << Function.Name
425 << ":";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000426 outs() << "\n";
Justin Bogner5a6edad2014-09-19 19:07:17 +0000427 mainView->render(outs(), /*WholeFile=*/false);
Justin Bogner953e2402014-09-20 15:31:56 +0000428 outs() << "\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000429 }
430 return 0;
431 }
432
433 // Show files
434 bool ShowFilenames = SourceFiles.size() != 1;
435
Justin Bogner116c1662014-09-19 08:13:12 +0000436 if (SourceFiles.empty())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000437 // Get the source files from the function coverage mapping
Justin Bogner953e2402014-09-20 15:31:56 +0000438 for (StringRef Filename : Coverage->getUniqueSourceFiles())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000439 SourceFiles.push_back(Filename);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000440
441 for (const auto &SourceFile : SourceFiles) {
Justin Bogner953e2402014-09-20 15:31:56 +0000442 auto mainView = createSourceFileView(SourceFile, *Coverage);
Justin Bogner5a6edad2014-09-19 19:07:17 +0000443 if (!mainView) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000444 ViewOpts.colored_ostream(outs(), raw_ostream::RED)
445 << "warning: The file '" << SourceFile << "' isn't covered.";
446 outs() << "\n";
447 continue;
448 }
449
450 if (ShowFilenames) {
451 ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << SourceFile << ":";
452 outs() << "\n";
453 }
Justin Bogner5a6edad2014-09-19 19:07:17 +0000454 mainView->render(outs(), /*Wholefile=*/true);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000455 if (SourceFiles.size() > 1)
456 outs() << "\n";
457 }
458
459 return 0;
460}
461
462int CodeCoverageTool::report(int argc, const char **argv,
463 CommandLineParserType commandLineParser) {
464 cl::opt<bool> NoColors("no-colors", cl::Optional,
465 cl::desc("Don't show text colors"), cl::init(false));
466
467 auto Err = commandLineParser(argc, argv);
468 if (Err)
469 return Err;
470
471 ViewOpts.Colors = !NoColors;
472
Justin Bogner953e2402014-09-20 15:31:56 +0000473 auto Coverage = load();
474 if (!Coverage)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000475 return 1;
476
477 CoverageSummary Summarizer;
Justin Bogner953e2402014-09-20 15:31:56 +0000478 Summarizer.createSummaries(Coverage->getCoveredFunctions());
Alex Lorenze82d89c2014-08-22 22:56:03 +0000479 CoverageReport Report(ViewOpts, Summarizer);
480 if (SourceFiles.empty() && Filters.empty()) {
481 Report.renderFileReports(llvm::outs());
482 return 0;
483 }
484
485 Report.renderFunctionReports(llvm::outs());
486 return 0;
487}
488
489int show_main(int argc, const char **argv) {
490 CodeCoverageTool Tool;
491 return Tool.run(CodeCoverageTool::Show, argc, argv);
492}
493
494int report_main(int argc, const char **argv) {
495 CodeCoverageTool Tool;
496 return Tool.run(CodeCoverageTool::Report, argc, argv);
497}