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
21namespace llvm {
22
23class raw_ostream;
24
25namespace coverage {
26
27/// Writer of the filenames section for the instrumentation
28/// based code coverage.
29class CoverageFilenamesSectionWriter {
30 ArrayRef<std::string> Filenames;
31
32public:
33 CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
34
35 /// Write encoded filenames to the given output stream. If \p Compress is
36 /// true, attempt to compress the filenames.
37 void write(raw_ostream &OS, bool Compress = true);
38};
39
40/// Writer for instrumentation based coverage mapping data.
41class CoverageMappingWriter {
42 ArrayRef<unsigned> VirtualFileMapping;
43 ArrayRef<CounterExpression> Expressions;
44 MutableArrayRef<CounterMappingRegion> MappingRegions;
45
46public:
47 CoverageMappingWriter(ArrayRef<unsigned> VirtualFileMapping,
48 ArrayRef<CounterExpression> Expressions,
49 MutableArrayRef<CounterMappingRegion> MappingRegions)
50 : VirtualFileMapping(VirtualFileMapping), Expressions(Expressions),
51 MappingRegions(MappingRegions) {}
52
53 /// Write encoded coverage mapping data to the given output stream.
54 void write(raw_ostream &OS);
55};
56
57/// Writer for the coverage mapping testing format.
58class TestingFormatWriter {
59 uint64_t ProfileNamesAddr;
60 StringRef ProfileNamesData;
61 StringRef CoverageMappingData;
62 StringRef CoverageRecordsData;
63
64public:
65 TestingFormatWriter(uint64_t ProfileNamesAddr, StringRef ProfileNamesData,
66 StringRef CoverageMappingData,
67 StringRef CoverageRecordsData)
68 : ProfileNamesAddr(ProfileNamesAddr), ProfileNamesData(ProfileNamesData),
69 CoverageMappingData(CoverageMappingData),
70 CoverageRecordsData(CoverageRecordsData) {}
71
72 /// Encode to the given output stream.
73 void
74 write(raw_ostream &OS,
75 TestingFormatVersion Version = TestingFormatVersion::CurrentVersion);
76};
77
78} // end namespace coverage
79
80} // end namespace llvm
81
82#endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
83

source code of llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h