LLVM 20.0.0git
EndianStream.h
Go to the documentation of this file.
1//===- EndianStream.h - Stream ops with endian specific data ----*- 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// This file defines utilities for operating on streams that have endian
10// specific data.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_ENDIANSTREAM_H
15#define LLVM_SUPPORT_ENDIANSTREAM_H
16
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/Support/Endian.h"
21
22namespace llvm {
23namespace support {
24
25namespace endian {
26
27template <typename value_type>
30 for (const auto orig : values) {
31 value_type value = byte_swap<value_type>(orig, endian);
32 os.write((const char *)&value, sizeof(value_type));
33 }
34}
35
36template <typename value_type>
37inline void write(raw_ostream &os, value_type value, endianness endian) {
38 value = byte_swap<value_type>(value, endian);
39 os.write((const char *)&value, sizeof(value_type));
40}
41
42template <>
44 write(os, llvm::bit_cast<uint32_t>(value), endian);
45}
46
47template <>
48inline void write<double>(raw_ostream &os, double value,
50 write(os, llvm::bit_cast<uint64_t>(value), endian);
51}
52
53template <typename value_type>
56 for (value_type v : vals)
57 write(os, v, endian);
58}
59
60template <typename value_type>
61inline void write(SmallVectorImpl<char> &Out, value_type V, endianness E) {
62 V = byte_swap<value_type>(V, E);
63 Out.append((const char *)&V, (const char *)&V + sizeof(value_type));
64}
65
66/// Adapter to write values to a stream in a particular byte order.
67struct Writer {
71 template <typename value_type> void write(ArrayRef<value_type> Val) {
72 endian::write(OS, Val, Endian);
73 }
74 template <typename value_type> void write(value_type Val) {
75 endian::write(OS, Val, Endian);
76 }
77};
78
79} // end namespace endian
80
81} // end namespace support
82} // end namespace llvm
83
84#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
Mark the given Function as meaning that it cannot be changed in any way mark any values that are used as this function s parameters or by its return values(according to Uses) live as well. void DeadArgumentEliminationPass
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:696
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & write(unsigned char C)
void write_array(raw_ostream &os, ArrayRef< value_type > values, endianness endian)
Definition: EndianStream.h:28
void write< float >(raw_ostream &os, float value, endianness endian)
Definition: EndianStream.h:43
void write< double >(raw_ostream &os, double value, endianness endian)
Definition: EndianStream.h:48
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:92
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
endianness
Definition: bit.h:70
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:67
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:71
void write(value_type Val)
Definition: EndianStream.h:74
Writer(raw_ostream &OS, endianness Endian)
Definition: EndianStream.h:70