Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 1 | //===- 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 Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 10 | // llvm-cov is a command line tools to analyze and report coverage information. |
| 11 | // |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/OwningPtr.h" |
| 15 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 58c6200 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 16 | #include "llvm/Support/GCOV.h" |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 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 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | int 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 | |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 43 | GCOVFile GF; |
| 44 | if (InputGCNO.empty()) |
| 45 | errs() << " " << argv[0] << ": No gcov input file!\n"; |
| 46 | |
Devang Patel | 7a50202 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 47 | OwningPtr<MemoryBuffer> GCNO_Buff; |
| 48 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 49 | errs() << InputGCNO << ": " << ec.message() << "\n"; |
| 50 | return 1; |
| 51 | } |
Devang Patel | 7a50202 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 52 | GCOVBuffer GCNO_GB(GCNO_Buff.take()); |
| 53 | if (!GF.read(GCNO_GB)) { |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 54 | errs() << "Invalid .gcno File!\n"; |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | if (!InputGCDA.empty()) { |
Devang Patel | 7a50202 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 59 | OwningPtr<MemoryBuffer> GCDA_Buff; |
| 60 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 61 | errs() << InputGCDA << ": " << ec.message() << "\n"; |
| 62 | return 1; |
| 63 | } |
Devang Patel | 7a50202 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 64 | GCOVBuffer GCDA_GB(GCDA_Buff.take()); |
| 65 | if (!GF.read(GCDA_GB)) { |
Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 66 | errs() << "Invalid .gcda File!\n"; |
| 67 | return 1; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | if (DumpGCOV) |
| 73 | GF.dump(); |
| 74 | |
| 75 | FileInfo FI; |
| 76 | GF.collectLineCounts(FI); |
| 77 | return 0; |
| 78 | } |