LLVM  14.0.0git
FileWriter.cpp
Go to the documentation of this file.
1 //===- FileWriter.cpp -------------------------------------------*- 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 
10 #include "llvm/Support/LEB128.h"
12 #include <cassert>
13 
14 using namespace llvm;
15 using namespace gsym;
16 
18 
19 void FileWriter::writeSLEB(int64_t S) {
20  uint8_t Bytes[32];
21  auto Length = encodeSLEB128(S, Bytes);
22  assert(Length < sizeof(Bytes));
23  OS.write(reinterpret_cast<const char *>(Bytes), Length);
24 }
25 
27  uint8_t Bytes[32];
28  auto Length = encodeULEB128(U, Bytes);
29  assert(Length < sizeof(Bytes));
30  OS.write(reinterpret_cast<const char *>(Bytes), Length);
31 }
32 
33 void FileWriter::writeU8(uint8_t U) {
34  OS.write(reinterpret_cast<const char *>(&U), sizeof(U));
35 }
36 
38  const uint16_t Swapped = support::endian::byte_swap(U, ByteOrder);
39  OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));
40 }
41 
43  const uint32_t Swapped = support::endian::byte_swap(U, ByteOrder);
44  OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));
45 }
46 
48  const uint64_t Swapped = support::endian::byte_swap(U, ByteOrder);
49  OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));
50 }
51 
53  const uint32_t Swapped = support::endian::byte_swap(U, ByteOrder);
54  OS.pwrite(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped),
55  Offset);
56 }
57 
59  OS.write(reinterpret_cast<const char *>(Data.data()), Data.size());
60 }
61 
63  OS << Str << '\0';
64 }
65 
67  return OS.tell();
68 }
69 
70 void FileWriter::alignTo(size_t Align) {
71  off_t Offset = OS.tell();
72  off_t AlignedOffset = (Offset + Align - 1) / Align * Align;
73  if (AlignedOffset == Offset)
74  return;
75  off_t PadCount = AlignedOffset - Offset;
76  OS.write_zeros(PadCount);
77 }
llvm::raw_ostream::tell
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:135
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::raw_ostream::write_zeros
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
Definition: raw_ostream.cpp:502
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::gsym::FileWriter::writeData
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:58
llvm::gsym::FileWriter::alignTo
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:70
llvm::encodeSLEB128
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
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:220
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:186
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t
LEB128.h
FileWriter.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::gsym::FileWriter::writeU64
void writeU64(uint64_t Value)
Write a single uint64_t value into the stream at the current file position.
Definition: FileWriter.cpp:47
llvm::gsym::FileWriter::writeU16
void writeU16(uint16_t Value)
Write a single uint16_t value into the stream at the current file position.
Definition: FileWriter.cpp:37
llvm::gsym::FileWriter::writeU32
void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
Definition: FileWriter.cpp:42
llvm::ArrayRef< uint8_t >
llvm::gsym::FileWriter::writeSLEB
void writeSLEB(int64_t Value)
Write the value into the stream encoded using signed LEB128 at the current file position.
Definition: FileWriter.cpp:19
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
uint16_t
llvm::raw_pwrite_stream::pwrite
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
Definition: raw_ostream.h:425
llvm::gsym::FileWriter::writeULEB
void writeULEB(uint64_t Value)
Write the value into the stream encoded using unsigned LEB128 at the current file position.
Definition: FileWriter.cpp:26
llvm::support::endian::byte_swap
value_type byte_swap(value_type value, endianness endian)
Definition: Endian.h:49
llvm::gsym::FileWriter::fixup32
void fixup32(uint32_t Value, uint64_t Offset)
Fixup a uint32_t value at the specified offset in the stream.
Definition: FileWriter.cpp:52
llvm::gsym::FileWriter::writeU8
void writeU8(uint8_t Value)
Write a single uint8_t value into the stream at the current file position.
Definition: FileWriter.cpp:33
llvm::gsym::FileWriter::tell
uint64_t tell()
Return the current offset within the file.
Definition: FileWriter.cpp:66
llvm::encodeULEB128
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
raw_ostream.h
llvm::gsym::FileWriter::writeNullTerminated
void writeNullTerminated(llvm::StringRef Str)
Write a NULL terminated C string into the stream at the current file position.
Definition: FileWriter.cpp:62
llvm::gsym::FileWriter::~FileWriter
~FileWriter()
Definition: FileWriter.cpp:17