LLVM 22.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
34public:
36 : OS(S), ByteOrder(B) {}
38 /// Write a single uint8_t value into the stream at the current file
39 /// position.
40 ///
41 /// \param Value The value to write into the stream.
43
44 /// Write a single uint16_t value into the stream at the current file
45 /// position. The value will be byte swapped if needed to match the byte
46 /// order specified during construction.
47 ///
48 /// \param Value The value to write into the stream.
50
51 /// Write a single uint32_t value into the stream at the current file
52 /// position. The value will be byte swapped if needed to match the byte
53 /// order specified during construction.
54 ///
55 /// \param Value The value to write into the stream.
57
58 /// Write a single uint64_t value into the stream at the current file
59 /// position. The value will be byte swapped if needed to match the byte
60 /// order specified during construction.
61 ///
62 /// \param Value The value to write into the stream.
64
65 /// Write the value into the stream encoded using signed LEB128 at the
66 /// current file position.
67 ///
68 /// \param Value The value to write into the stream.
69 LLVM_ABI void writeSLEB(int64_t Value);
70
71 /// Write the value into the stream encoded using unsigned LEB128 at the
72 /// current file position.
73 ///
74 /// \param Value The value to write into the stream.
76
77 /// Write an array of uint8_t values into the stream at the current file
78 /// position.
79 ///
80 /// \param Data An array of values to write into the stream.
82
83 /// Write a NULL terminated C string into the stream at the current file
84 /// position. The entire contents of Str will be written into the steam at
85 /// the current file position and then an extra NULL termation byte will be
86 /// written. It is up to the user to ensure that Str doesn't contain any NULL
87 /// characters unless the additional NULL characters are desired.
88 ///
89 /// \param Str The value to write into the stream.
91
92 /// Fixup a uint32_t value at the specified offset in the stream. This
93 /// function will save the current file position, seek to the specified
94 /// offset, overwrite the data using Value, and then restore the file
95 /// position to the previous file position.
96 ///
97 /// \param Value The value to write into the stream.
98 /// \param Offset The offset at which to write the Value within the stream.
100
101 /// Pad with zeroes at the current file position until the current file
102 /// position matches the specified alignment.
103 ///
104 /// \param Align An integer speciying the desired alignment. This does not
105 /// need to be a power of two.
106 LLVM_ABI void alignTo(size_t Align);
107
108 /// Return the current offset within the file.
109 ///
110 /// \return The unsigned offset from the start of the file of the current
111 /// file position.
113
115 return OS;
116 }
117
118 llvm::endianness getByteOrder() const { return ByteOrder; }
119
120private:
121 FileWriter(const FileWriter &rhs) = delete;
122 void operator=(const FileWriter &rhs) = delete;
123};
124
125} // namespace gsym
126} // namespace llvm
127
128#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:41
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:114
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:35
LLVM_ABI void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
LLVM_ABI void writeData(llvm::ArrayRef< uint8_t > Data)
Write an array of uint8_t values into the stream at the current file position.
LLVM_ABI void writeNullTerminated(llvm::StringRef Str)
Write a NULL terminated C string into the stream at the current file position.
llvm::endianness getByteOrder() const
Definition FileWriter.h:118
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:477
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
endianness
Definition bit.h:71
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39