1 //===- FileWriter.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/GSYM/FileWriter.h"
11 #include "llvm/Support/LEB128.h"
12 #include "llvm/Support/raw_ostream.h"
18 FileWriter::~FileWriter() { OS
.flush(); }
20 void FileWriter::writeSLEB(int64_t S
) {
22 auto Length
= encodeSLEB128(S
, Bytes
);
23 assert(Length
< sizeof(Bytes
));
24 OS
.write(reinterpret_cast<const char *>(Bytes
), Length
);
27 void FileWriter::writeULEB(uint64_t U
) {
29 auto Length
= encodeULEB128(U
, Bytes
);
30 assert(Length
< sizeof(Bytes
));
31 OS
.write(reinterpret_cast<const char *>(Bytes
), Length
);
34 void FileWriter::writeU8(uint8_t U
) {
35 OS
.write(reinterpret_cast<const char *>(&U
), sizeof(U
));
38 void FileWriter::writeU16(uint16_t U
) {
39 const uint16_t Swapped
= support::endian::byte_swap(U
, ByteOrder
);
40 OS
.write(reinterpret_cast<const char *>(&Swapped
), sizeof(Swapped
));
43 void FileWriter::writeU32(uint32_t U
) {
44 const uint32_t Swapped
= support::endian::byte_swap(U
, ByteOrder
);
45 OS
.write(reinterpret_cast<const char *>(&Swapped
), sizeof(Swapped
));
48 void FileWriter::writeU64(uint64_t U
) {
49 const uint64_t Swapped
= support::endian::byte_swap(U
, ByteOrder
);
50 OS
.write(reinterpret_cast<const char *>(&Swapped
), sizeof(Swapped
));
53 void FileWriter::fixup32(uint32_t U
, uint64_t Offset
) {
54 const uint32_t Swapped
= support::endian::byte_swap(U
, ByteOrder
);
55 OS
.pwrite(reinterpret_cast<const char *>(&Swapped
), sizeof(Swapped
),
59 void FileWriter::writeData(llvm::ArrayRef
<uint8_t> Data
) {
60 OS
.write(reinterpret_cast<const char *>(Data
.data()), Data
.size());
63 void FileWriter::writeNullTerminated(llvm::StringRef Str
) {
67 uint64_t FileWriter::tell() {
71 void FileWriter::alignTo(size_t Align
) {
72 off_t Offset
= OS
.tell();
73 off_t AlignedOffset
= (Offset
+ Align
- 1) / Align
* Align
;
74 if (AlignedOffset
== Offset
)
76 off_t PadCount
= AlignedOffset
- Offset
;
77 OS
.write_zeros(PadCount
);