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
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 a single unsigned value into the stream at the current file
78 /// position. The value will be byte swapped if needed to match the byte
79 /// order specified during construction. The size of the value is specified
80 /// by the Size parameter.
81 ///
82 /// \param Value The value to write into the stream. The higher bits which
83 /// don't fit into ByteSize should be zero.
84 /// \param ByteSize The size of the value to write in bytes. Can be 1-8.
85 LLVM_ABI void writeUnsigned(uint64_t Value, size_t ByteSize);
86
87 /// Write an array of uint8_t values into the stream at the current file
88 /// position.
89 ///
90 /// \param Data An array of values to write into the stream.
92
93 /// Write a NULL terminated C string into the stream at the current file
94 /// position. The entire contents of Str will be written into the steam at
95 /// the current file position and then an extra NULL termation byte will be
96 /// written. It is up to the user to ensure that Str doesn't contain any NULL
97 /// characters unless the additional NULL characters are desired.
98 ///
99 /// \param Str The value to write into the stream.
101
102 /// Fixup a uint32_t value at the specified offset in the stream. This
103 /// function will save the current file position, seek to the specified
104 /// offset, overwrite the data using Value, and then restore the file
105 /// position to the previous file position.
106 ///
107 /// \param Value The value to write into the stream.
108 /// \param Offset The offset at which to write the Value within the stream.
110
111 /// Pad with zeroes at the current file position until the current file
112 /// position matches the specified alignment.
113 ///
114 /// \param Align An integer speciying the desired alignment. This does not
115 /// need to be a power of two.
116 LLVM_ABI void alignTo(size_t Align);
117
118 /// Return the current offset within the file.
119 ///
120 /// \return The unsigned offset from the start of the file of the current
121 /// file position.
123
125 return OS;
126 }
127
128 llvm::endianness getByteOrder() const { return ByteOrder; }
129
130private:
131 FileWriter(const FileWriter &rhs) = delete;
132 void operator=(const FileWriter &rhs) = delete;
133};
134
135} // namespace gsym
136} // namespace llvm
137
138#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:124
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_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:128
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