LLVM 23.0.0git
FileWriter.h
Go to the documentation of this file.
1//===- FileWriter.h ---------------------------------------------*- 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#ifndef LLVM_DEBUGINFO_GSYM_FILEWRITER_H
10#define LLVM_DEBUGINFO_GSYM_FILEWRITER_H
11
12#include "llvm/ADT/ArrayRef.h"
14#include "llvm/Support/Endian.h"
15
16#include <stddef.h>
17#include <stdint.h>
18#include <sys/types.h>
19
20namespace llvm {
22
23namespace gsym {
24
25/// A simplified binary data writer class that doesn't require targets, target
26/// definitions, architectures, or require any other optional compile time
27/// libraries to be enabled via the build process. This class needs the ability
28/// to seek to different spots in the binary stream that is produces to fixup
29/// offsets and sizes.
32 llvm::endianness ByteOrder;
33 uint8_t StringOffsetSize = 4;
34
35public:
37 : OS(S), ByteOrder(B) {}
39 /// Write a single uint8_t value into the stream at the current file
40 /// position.
41 ///
42 /// \param Value The value to write into the stream.
44
45 /// Write a single uint16_t value into the stream at the current file
46 /// position. The value will be byte swapped if needed to match the byte
47 /// order specified during construction.
48 ///
49 /// \param Value The value to write into the stream.
51
52 /// Write a single uint32_t value into the stream at the current file
53 /// position. The value will be byte swapped if needed to match the byte
54 /// order specified during construction.
55 ///
56 /// \param Value The value to write into the stream.
58
59 /// Write a single uint64_t value into the stream at the current file
60 /// position. The value will be byte swapped if needed to match the byte
61 /// order specified during construction.
62 ///
63 /// \param Value The value to write into the stream.
65
66 /// Write the value into the stream encoded using signed LEB128 at the
67 /// current file position.
68 ///
69 /// \param Value The value to write into the stream.
70 LLVM_ABI void writeSLEB(int64_t Value);
71
72 /// Write the value into the stream encoded using unsigned LEB128 at the
73 /// current file position.
74 ///
75 /// \param Value The value to write into the stream.
77
78 /// Write a single unsigned value into the stream at the current file
79 /// position. The value will be byte swapped if needed to match the byte
80 /// order specified during construction. The size of the value is specified
81 /// by the Size parameter.
82 ///
83 /// \param Value The value to write into the stream. The higher bits which
84 /// don't fit into ByteSize should be zero.
85 /// \param ByteSize The size of the value to write in bytes. Can be 1-8.
86 LLVM_ABI void writeUnsigned(uint64_t Value, size_t ByteSize);
87
88 /// Write a string table offset of StringOffsetSize bytes into the stream.
89 ///
90 /// \param Value The string table offset to write.
92
93 /// Write an array of uint8_t values into the stream at the current file
94 /// position.
95 ///
96 /// \param Data An array of values to write into the stream.
98
99 /// Write a NULL terminated C string into the stream at the current file
100 /// position. The entire contents of Str will be written into the steam at
101 /// the current file position and then an extra NULL termation byte will be
102 /// written. It is up to the user to ensure that Str doesn't contain any NULL
103 /// characters unless the additional NULL characters are desired.
104 ///
105 /// \param Str The value to write into the stream.
107
108 /// Fixup a uint32_t value at the specified offset in the stream. This
109 /// function will save the current file position, seek to the specified
110 /// offset, overwrite the data using Value, and then restore the file
111 /// position to the previous file position.
112 ///
113 /// \param Value The value to write into the stream.
114 /// \param Offset The offset at which to write the Value within the stream.
116
117 /// Pad with zeroes at the current file position until the current file
118 /// position matches the specified alignment.
119 ///
120 /// \param Align An integer speciying the desired alignment. This does not
121 /// need to be a power of two.
122 LLVM_ABI void alignTo(size_t Align);
123
124 /// Return the current offset within the file.
125 ///
126 /// \return The unsigned offset from the start of the file of the current
127 /// file position.
129
131 return OS;
132 }
133
134 llvm::endianness getByteOrder() const { return ByteOrder; }
135
136 /// Get the string offset size for this writer.
137 uint8_t getStringOffsetSize() const { return StringOffsetSize; }
138 /// Set the string offset size for this writer.
139 void setStringOffsetSize(uint8_t Size) { StringOffsetSize = Size; }
140
141private:
142 FileWriter(const FileWriter &rhs) = delete;
143 void operator=(const FileWriter &rhs) = delete;
144};
145
146} // namespace gsym
147} // namespace llvm
148
149#endif // LLVM_DEBUGINFO_GSYM_FILEWRITER_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM Value Representation.
Definition Value.h:75
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition FileWriter.h:30
llvm::raw_pwrite_stream & get_stream()
Definition FileWriter.h:130
LLVM_ABI uint64_t tell()
Return the current offset within the file.
LLVM_ABI void writeULEB(uint64_t Value)
Write the value into the stream encoded using unsigned LEB128 at the current file position.
LLVM_ABI void writeU16(uint16_t Value)
Write a single uint16_t value into the stream at the current file position.
LLVM_ABI void fixup32(uint32_t Value, uint64_t Offset)
Fixup a uint32_t value at the specified offset in the stream.
LLVM_ABI void writeSLEB(int64_t Value)
Write the value into the stream encoded using signed LEB128 at the current file position.
LLVM_ABI void writeU8(uint8_t Value)
Write a single uint8_t value into the stream at the current file position.
LLVM_ABI void alignTo(size_t Align)
Pad with zeroes at the current file position until the current file position matches the specified al...
FileWriter(llvm::raw_pwrite_stream &S, llvm::endianness B)
Definition FileWriter.h:36
LLVM_ABI void writeStringOffset(uint64_t Value)
Write a string table offset of StringOffsetSize bytes into the stream.
LLVM_ABI void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
void setStringOffsetSize(uint8_t Size)
Set the string offset size for this writer.
Definition FileWriter.h:139
LLVM_ABI void writeData(llvm::ArrayRef< uint8_t > Data)
Write an array of uint8_t values into the stream at the current file position.
uint8_t getStringOffsetSize() const
Get the string offset size for this writer.
Definition FileWriter.h:137
LLVM_ABI void writeNullTerminated(llvm::StringRef Str)
Write a NULL terminated C string into the stream at the current file position.
LLVM_ABI void writeUnsigned(uint64_t Value, size_t ByteSize)
Write a single unsigned value into the stream at the current file position.
llvm::endianness getByteOrder() const
Definition FileWriter.h:134
LLVM_ABI void writeU64(uint64_t Value)
Write a single uint64_t value into the stream at the current file position.
An abstract base class for streams implementations that also support a pwrite operation.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
endianness
Definition bit.h:71
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39