LLVM 18.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"
13#include "llvm/Support/Endian.h"
14
15#include <stddef.h>
16#include <stdint.h>
17#include <sys/types.h>
18
19namespace llvm {
20class raw_pwrite_stream;
21
22namespace gsym {
23
24/// A simplified binary data writer class that doesn't require targets, target
25/// definitions, architectures, or require any other optional compile time
26/// libraries to be enabled via the build process. This class needs the ability
27/// to seek to different spots in the binary stream that is produces to fixup
28/// offsets and sizes.
32public:
34 : OS(S), ByteOrder(B) {}
36 /// Write a single uint8_t value into the stream at the current file
37 /// position.
38 ///
39 /// \param Value The value to write into the stream.
40 void writeU8(uint8_t Value);
41
42 /// Write a single uint16_t value into the stream at the current file
43 /// position. The value will be byte swapped if needed to match the byte
44 /// order specified during construction.
45 ///
46 /// \param Value The value to write into the stream.
48
49 /// Write a single uint32_t value into the stream at the current file
50 /// position. The value will be byte swapped if needed to match the byte
51 /// order specified during construction.
52 ///
53 /// \param Value The value to write into the stream.
55
56 /// Write a single uint64_t value into the stream at the current file
57 /// position. The value will be byte swapped if needed to match the byte
58 /// order specified during construction.
59 ///
60 /// \param Value The value to write into the stream.
62
63 /// Write the value into the stream encoded using signed LEB128 at the
64 /// current file position.
65 ///
66 /// \param Value The value to write into the stream.
67 void writeSLEB(int64_t Value);
68
69 /// Write the value into the stream encoded using unsigned LEB128 at the
70 /// current file position.
71 ///
72 /// \param Value The value to write into the stream.
74
75 /// Write an array of uint8_t values into the stream at the current file
76 /// position.
77 ///
78 /// \param Data An array of values to write into the stream.
80
81 /// Write a NULL terminated C string into the stream at the current file
82 /// position. The entire contents of Str will be written into the steam at
83 /// the current file position and then an extra NULL termation byte will be
84 /// written. It is up to the user to ensure that Str doesn't contain any NULL
85 /// characters unless the additional NULL characters are desired.
86 ///
87 /// \param Str The value to write into the stream.
89
90 /// Fixup a uint32_t value at the specified offset in the stream. This
91 /// function will save the current file position, seek to the specified
92 /// offset, overwrite the data using Value, and then restore the file
93 /// position to the previous file position.
94 ///
95 /// \param Value The value to write into the stream.
96 /// \param Offset The offset at which to write the Value within the stream.
98
99 /// Pad with zeroes at the current file position until the current file
100 /// position matches the specified alignment.
101 ///
102 /// \param Align An integer speciying the desired alignment. This does not
103 /// need to be a power of two.
104 void alignTo(size_t Align);
105
106 /// Return the current offset within the file.
107 ///
108 /// \return The unsigned offset from the start of the file of the current
109 /// file position.
110 uint64_t tell();
111
113 return OS;
114 }
115
116 llvm::support::endianness getByteOrder() const { return ByteOrder; }
117
118private:
119 FileWriter(const FileWriter &rhs) = delete;
120 void operator=(const FileWriter &rhs) = delete;
121};
122
123} // namespace gsym
124} // namespace llvm
125
126#endif // LLVM_DEBUGINFO_GSYM_FILEWRITER_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
raw_pwrite_stream & OS
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:50
LLVM Value Representation.
Definition: Value.h:74
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition: FileWriter.h:29
llvm::raw_pwrite_stream & get_stream()
Definition: FileWriter.h:112
uint64_t tell()
Return the current offset within the file.
Definition: FileWriter.cpp:66
void writeULEB(uint64_t Value)
Write the value into the stream encoded using unsigned LEB128 at the current file position.
Definition: FileWriter.cpp:26
void writeU16(uint16_t Value)
Write a single uint16_t value into the stream at the current file position.
Definition: FileWriter.cpp:37
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::support::endianness getByteOrder() const
Definition: FileWriter.h:116
void writeSLEB(int64_t Value)
Write the value into the stream encoded using signed LEB128 at the current file position.
Definition: FileWriter.cpp:19
void writeU8(uint8_t Value)
Write a single uint8_t value into the stream at the current file position.
Definition: FileWriter.cpp:33
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
FileWriter(llvm::raw_pwrite_stream &S, llvm::support::endianness B)
Definition: FileWriter.h:33
void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
Definition: FileWriter.cpp:42
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
void writeNullTerminated(llvm::StringRef Str)
Write a NULL terminated C string into the stream at the current file position.
Definition: FileWriter.cpp:62
void writeU64(uint64_t Value)
Write a single uint64_t value into the stream at the current file position.
Definition: FileWriter.cpp:47
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:428
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39