xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- CoverageMappingWriter.h - Code coverage mapping writer ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for writing coverage mapping data for
10 // instrumentation based coverage.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
15 #define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace llvm {
23 
24 class raw_ostream;
25 
26 namespace coverage {
27 
28 /// Writer of the filenames section for the instrumentation
29 /// based code coverage.
30 class CoverageFilenamesSectionWriter {
31   ArrayRef<std::string> Filenames;
32 
33 public:
34   LLVM_ABI CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
35 
36   /// Write encoded filenames to the given output stream. If \p Compress is
37   /// true, attempt to compress the filenames.
38   LLVM_ABI void write(raw_ostream &OS, bool Compress = true);
39 };
40 
41 /// Writer for instrumentation based coverage mapping data.
42 class CoverageMappingWriter {
43   ArrayRef<unsigned> VirtualFileMapping;
44   ArrayRef<CounterExpression> Expressions;
45   MutableArrayRef<CounterMappingRegion> MappingRegions;
46 
47 public:
CoverageMappingWriter(ArrayRef<unsigned> VirtualFileMapping,ArrayRef<CounterExpression> Expressions,MutableArrayRef<CounterMappingRegion> MappingRegions)48   CoverageMappingWriter(ArrayRef<unsigned> VirtualFileMapping,
49                         ArrayRef<CounterExpression> Expressions,
50                         MutableArrayRef<CounterMappingRegion> MappingRegions)
51       : VirtualFileMapping(VirtualFileMapping), Expressions(Expressions),
52         MappingRegions(MappingRegions) {}
53 
54   /// Write encoded coverage mapping data to the given output stream.
55   LLVM_ABI void write(raw_ostream &OS);
56 };
57 
58 /// Writer for the coverage mapping testing format.
59 class TestingFormatWriter {
60   uint64_t ProfileNamesAddr;
61   StringRef ProfileNamesData;
62   StringRef CoverageMappingData;
63   StringRef CoverageRecordsData;
64 
65 public:
TestingFormatWriter(uint64_t ProfileNamesAddr,StringRef ProfileNamesData,StringRef CoverageMappingData,StringRef CoverageRecordsData)66   TestingFormatWriter(uint64_t ProfileNamesAddr, StringRef ProfileNamesData,
67                       StringRef CoverageMappingData,
68                       StringRef CoverageRecordsData)
69       : ProfileNamesAddr(ProfileNamesAddr), ProfileNamesData(ProfileNamesData),
70         CoverageMappingData(CoverageMappingData),
71         CoverageRecordsData(CoverageRecordsData) {}
72 
73   /// Encode to the given output stream.
74   LLVM_ABI void
75   write(raw_ostream &OS,
76         TestingFormatVersion Version = TestingFormatVersion::CurrentVersion);
77 };
78 
79 } // end namespace coverage
80 
81 } // end namespace llvm
82 
83 #endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
84