Debug info (LTO): Move the creation of accessibility flags to
[oota-llvm.git] / tools / llvm-cov / llvm-cov.cpp
1 //===- 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 //
10 // llvm-cov is a command line tools to analyze and report coverage information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ADT/OwningPtr.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/GCOV.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"
22 using namespace llvm;
23
24 static cl::opt<bool>
25 DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file"));
26
27 static cl::opt<std::string>
28 InputGCNO("gcno", cl::desc("<input gcno file>"), cl::init(""));
29
30 static cl::opt<std::string>
31 InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
32
33 static cl::opt<bool>
34 AllBlocks("a", cl::init(false), cl::desc("display all block info"));
35
36 static cl::opt<bool>
37 BranchInfo("b", cl::init(false), cl::desc("display branch info"));
38
39 static cl::opt<bool>
40 BranchCount("c", cl::init(false), cl::desc("display branch counts instead of \
41                                             probabilities (requires -b)"));
42
43 static cl::opt<bool>
44 FuncCoverage("f", cl::init(false), cl::desc("output function coverage"));
45
46 static cl::opt<bool>
47 UncondBranch("u", cl::init(false), cl::desc("display unconditional branch info \
48                                              (requires -b)"));
49
50 //===----------------------------------------------------------------------===//
51 int main(int argc, char **argv) {
52   // Print a stack trace if we signal out.
53   sys::PrintStackTraceOnErrorSignal();
54   PrettyStackTraceProgram X(argc, argv);
55   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
56
57   cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
58
59   GCOVFile GF;
60   if (InputGCNO.empty())
61     errs() << " " << argv[0] << ": No gcov input file!\n";
62
63   OwningPtr<MemoryBuffer> GCNO_Buff;
64   if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
65     errs() << InputGCNO << ": " << ec.message() << "\n";
66     return 1;
67   }
68   GCOVBuffer GCNO_GB(GCNO_Buff.get());
69   if (!GF.readGCNO(GCNO_GB)) {
70     errs() << "Invalid .gcno File!\n";
71     return 1;
72   }
73
74   if (!InputGCDA.empty()) {
75     OwningPtr<MemoryBuffer> GCDA_Buff;
76     if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
77       errs() << InputGCDA << ": " << ec.message() << "\n";
78       return 1;
79     }
80     GCOVBuffer GCDA_GB(GCDA_Buff.get());
81     if (!GF.readGCDA(GCDA_GB)) {
82       errs() << "Invalid .gcda File!\n";
83       return 1;
84     }
85   }
86
87   if (DumpGCOV)
88     GF.dump();
89
90   GCOVOptions Options(AllBlocks, BranchInfo, BranchCount, FuncCoverage,
91                       UncondBranch);
92   FileInfo FI(Options);
93   GF.collectLineCounts(FI);
94   FI.print(InputGCNO, InputGCDA);
95   return 0;
96 }