aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-09 13:28:42 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-12-09 13:28:42 +0000
commitb1c73532ee8997fe5dfbeb7d223027bdf99758a0 (patch)
tree7d6e51c294ab6719475d660217aa0c0ad0526292 /llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
parent7fa27ce4a07f19b07799a767fc29416f3b625afb (diff)
downloadsrc-b1c73532ee8997fe5dfbeb7d223027bdf99758a0.tar.gz
src-b1c73532ee8997fe5dfbeb7d223027bdf99758a0.zip
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
index df65032da517..2abfbbad16ee 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -249,3 +249,37 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
// Ensure that all file ids have at least one mapping region.
assert(CurrentFileID == (VirtualFileMapping.size() - 1));
}
+
+void TestingFormatWriter::write(raw_ostream &OS, TestingFormatVersion Version) {
+ auto ByteSwap = [](uint64_t N) {
+ return support::endian::byte_swap<uint64_t, llvm::endianness::little>(N);
+ };
+
+ // Output a 64bit magic number.
+ auto Magic = ByteSwap(TestingFormatMagic);
+ OS.write(reinterpret_cast<char *>(&Magic), sizeof(Magic));
+
+ // Output a 64bit version field.
+ auto VersionLittle = ByteSwap(uint64_t(Version));
+ OS.write(reinterpret_cast<char *>(&VersionLittle), sizeof(VersionLittle));
+
+ // Output the ProfileNames data.
+ encodeULEB128(ProfileNamesData.size(), OS);
+ encodeULEB128(ProfileNamesAddr, OS);
+ OS << ProfileNamesData;
+
+ // Version2 adds an extra field to indicate the size of the
+ // CoverageMappingData.
+ if (Version == TestingFormatVersion::Version2)
+ encodeULEB128(CoverageMappingData.size(), OS);
+
+ // Coverage mapping data is expected to have an alignment of 8.
+ for (unsigned Pad = offsetToAlignment(OS.tell(), Align(8)); Pad; --Pad)
+ OS.write(uint8_t(0));
+ OS << CoverageMappingData;
+
+ // Coverage records data is expected to have an alignment of 8.
+ for (unsigned Pad = offsetToAlignment(OS.tell(), Align(8)); Pad; --Pad)
+ OS.write(uint8_t(0));
+ OS << CoverageRecordsData;
+}