blob: 0ecb28accbfba1504e1f66d304ebfbf6952e2325 [file] [log] [blame]
Devang Patel37140652011-09-28 18:50:00 +00001//===- tools/llvm-cov/llvm-cov.cpp - LLVM coverage tool -------------------===//
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//
Devang Patel37140652011-09-28 18:50:00 +000010// llvm-cov is a command line tools to analyze and report coverage information.
11//
Devang Patel37140652011-09-28 18:50:00 +000012//===----------------------------------------------------------------------===//
13
14#include "GCOVReader.h"
15#include "llvm/ADT/OwningPtr.h"
16#include "llvm/Support/CommandLine.h"
17#include "llvm/Support/ManagedStatic.h"
18#include "llvm/Support/MemoryObject.h"
19#include "llvm/Support/PrettyStackTrace.h"
20#include "llvm/Support/Signals.h"
21#include "llvm/Support/system_error.h"
22using namespace llvm;
23
24static cl::opt<bool>
25DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file"));
26
27static cl::opt<std::string>
28InputGCNO("gcno", cl::desc("<input gcno file>"), cl::init(""));
29
30static cl::opt<std::string>
31InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
32
33
34//===----------------------------------------------------------------------===//
35int main(int argc, char **argv) {
36 // Print a stack trace if we signal out.
37 sys::PrintStackTraceOnErrorSignal();
38 PrettyStackTraceProgram X(argc, argv);
39 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
40
41 cl::ParseCommandLineOptions(argc, argv, "llvm cov\n");
42
43
44 GCOVFile GF;
45 if (InputGCNO.empty())
46 errs() << " " << argv[0] << ": No gcov input file!\n";
47
Devang Patela9e8a252011-09-29 16:46:47 +000048 OwningPtr<MemoryBuffer> GCNO_Buff;
49 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
Devang Patel37140652011-09-28 18:50:00 +000050 errs() << InputGCNO << ": " << ec.message() << "\n";
51 return 1;
52 }
Devang Patela9e8a252011-09-29 16:46:47 +000053 GCOVBuffer GCNO_GB(GCNO_Buff.take());
54 if (!GF.read(GCNO_GB)) {
Devang Patel37140652011-09-28 18:50:00 +000055 errs() << "Invalid .gcno File!\n";
56 return 1;
57 }
58
59 if (!InputGCDA.empty()) {
Devang Patela9e8a252011-09-29 16:46:47 +000060 OwningPtr<MemoryBuffer> GCDA_Buff;
61 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
Devang Patel37140652011-09-28 18:50:00 +000062 errs() << InputGCDA << ": " << ec.message() << "\n";
63 return 1;
64 }
Devang Patela9e8a252011-09-29 16:46:47 +000065 GCOVBuffer GCDA_GB(GCDA_Buff.take());
66 if (!GF.read(GCDA_GB)) {
Devang Patel37140652011-09-28 18:50:00 +000067 errs() << "Invalid .gcda File!\n";
68 return 1;
69 }
70 }
71
72
73 if (DumpGCOV)
74 GF.dump();
75
76 FileInfo FI;
77 GF.collectLineCounts(FI);
78 return 0;
79}