llvm.org GIT mirror llvm / daaa8b7
Added command-line option to output llvm-cov to file. Added -o option to llvm-cov. If no output file is specified, it defaults to STDOUT. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193899 91177308-0d34-0410-b5e6-96231b3b80d8 Yuchen Wu 6 years ago
3 changed file(s) with 22 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
234234 LineInfo[Filename][Line-1] += Count;
235235 }
236236 void setProgramCount(uint32_t PC) { ProgramCount = PC; }
237 void print(StringRef gcnoFile, StringRef gcdaFile);
237 void print(raw_fd_ostream &OS, StringRef gcnoFile, StringRef gcdaFile);
238238 private:
239239 StringMap LineInfo;
240240 uint32_t ProgramCount;
249249 // FileInfo implementation.
250250
251251 /// print - Print source files with collected line count information.
252 void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) {
252 void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
253 StringRef gcdaFile) {
253254 for (StringMap::iterator I = LineInfo.begin(), E = LineInfo.end();
254255 I != E; ++I) {
255256 StringRef Filename = I->first();
256 outs() << " -: 0:Source:" << Filename << "\n";
257 outs() << " -: 0:Graph:" << gcnoFile << "\n";
258 outs() << " -: 0:Data:" << gcdaFile << "\n";
259 outs() << " -: 0:Programs:" << ProgramCount << "\n";
257 OS << " -: 0:Source:" << Filename << "\n";
258 OS << " -: 0:Graph:" << gcnoFile << "\n";
259 OS << " -: 0:Data:" << gcdaFile << "\n";
260 OS << " -: 0:Programs:" << ProgramCount << "\n";
260261 LineCounts &L = LineInfo[Filename];
261262 OwningPtr Buff;
262263 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
268269 while (!AllLines.empty()) {
269270 if (L.find(i) != L.end()) {
270271 if (L[i] == 0)
271 outs() << " #####:";
272 OS << " #####:";
272273 else
273 outs() << format("%9lu:", L[i]);
274 OS << format("%9lu:", L[i]);
274275 } else {
275 outs() << " -:";
276 OS << " -:";
276277 }
277278 std::pair P = AllLines.split('\n');
278279 if (AllLines != P.first)
279 outs() << format("%5u:", i+1) << P.first;
280 outs() << "\n";
280 OS << format("%5u:", i+1) << P.first;
281 OS << "\n";
281282 AllLines = P.second;
282283 ++i;
283284 }
1616 #include "llvm/Support/ManagedStatic.h"
1717 #include "llvm/Support/MemoryObject.h"
1818 #include "llvm/Support/PrettyStackTrace.h"
19 #include "llvm/Support/raw_ostream.h"
1920 #include "llvm/Support/Signals.h"
2021 #include "llvm/Support/system_error.h"
2122 using namespace llvm;
2930 static cl::opt
3031 InputGCDA("gcda", cl::desc(""), cl::init(""));
3132
33 static cl::opt
34 OutputFile("o", cl::desc(""), cl::init("-"));
35
3236
3337 //===----------------------------------------------------------------------===//
3438 int main(int argc, char **argv) {
3842 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
3943
4044 cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
45
46 std::string ErrorInfo;
47 raw_fd_ostream OS(OutputFile.c_str(), ErrorInfo);
48 if (!ErrorInfo.empty())
49 errs() << ErrorInfo << "\n";
4150
4251 GCOVFile GF;
4352 if (InputGCNO.empty())
7382
7483 FileInfo FI;
7584 GF.collectLineCounts(FI);
76 FI.print(InputGCNO, InputGCDA);
85 FI.print(OS, InputGCNO, InputGCDA);
7786 return 0;
7887 }