LLVM  10.0.0svn
FileWriter.cpp
Go to the documentation of this file.
1 //===- FileWriter.cpp -------------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/LEB128.h"
13 #include <cassert>
14 
15 using namespace llvm;
16 using namespace gsym;
17 
19 
20 void FileWriter::writeSLEB(int64_t S) {
21  uint8_t Bytes[32];
22  auto Length = encodeSLEB128(S, Bytes);
23  assert(Length < sizeof(Bytes));
24  OS.write(reinterpret_cast<const char *>(Bytes), Length);
25 }
26 
27 void FileWriter::writeULEB(uint64_t U) {
28  uint8_t Bytes[32];
29  auto Length = encodeULEB128(U, Bytes);
30  assert(Length < sizeof(Bytes));
31  OS.write(reinterpret_cast<const char *>(Bytes), Length);
32 }
33 
34 void FileWriter::writeU8(uint8_t U) {
35  OS.write(reinterpret_cast<const char *>(&U), sizeof(U));
36 }
37 
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));
41 }
42 
44  const uint32_t Swapped = support::endian::byte_swap(U, ByteOrder);
45  OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));
46 }
47 
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));
51 }
52 
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),
56  Offset);
57 }
58 
60  OS.write(reinterpret_cast<const char *>(Data.data()), Data.size());
61 }
62 
64  OS << Str << '\0';
65 }
66 
67 uint64_t FileWriter::tell() {
68  return OS.tell();
69 }
70 
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)
75  return;
76  off_t PadCount = AlignedOffset - Offset;
77  OS.write_zeros(PadCount);
78 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void writeU8(uint8_t Value)
Write a single uint8_t value into the stream at the current file position.
Definition: FileWriter.cpp:34
void writeULEB(uint64_t Value)
Write the value into the stream encoded using unsigned LEB128 at the current file position...
Definition: FileWriter.cpp:27
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert &#39;NumZeros&#39; nulls.
void writeNullTerminated(llvm::StringRef Str)
Write a NULL terminated C string into the stream at the current file position.
Definition: FileWriter.cpp:63
void alignTo(size_t Align)
Pad with zeroes at the current file position until the current file position matches the specified al...
Definition: FileWriter.cpp:71
void fixup32(uint32_t Value, uint64_t Offset)
Fixup a uint32_t value at the specified offset in the stream.
Definition: FileWriter.cpp:53
void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
Definition: FileWriter.cpp:43
void writeU64(uint64_t Value)
Write a single uint64_t value into the stream at the current file position.
Definition: FileWriter.cpp:48
void writeData(llvm::ArrayRef< uint8_t > Data)
Write an array of uint8_t values into the stream at the current file position.
Definition: FileWriter.cpp:59
void writeSLEB(int64_t Value)
Write the value into the stream encoded using signed LEB128 at the current file position.
Definition: FileWriter.cpp:20
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
Definition: raw_ostream.h:366
const T * data() const
Definition: ArrayRef.h:145
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
raw_ostream & write(unsigned char C)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:23
uint64_t tell()
Return the current offset within the file.
Definition: FileWriter.cpp:67
value_type byte_swap(value_type value, endianness endian)
Definition: Endian.h:51
void writeU16(uint16_t Value)
Write a single uint16_t value into the stream at the current file position.
Definition: FileWriter.cpp:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:111
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48