LLVM 17.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"
22
23namespace llvm {
24namespace support {
25
26namespace endian {
27
28template <typename value_type>
29inline void write(raw_ostream &os, value_type value, endianness endian) {
30 value = byte_swap<value_type>(value, endian);
31 os.write((const char *)&value, sizeof(value_type));
32}
33
34template <>
36 write(os, llvm::bit_cast<uint32_t>(value), endian);
37}
38
39template <>
40inline void write<double>(raw_ostream &os, double value,
42 write(os, llvm::bit_cast<uint64_t>(value), endian);
43}
44
45template <typename value_type>
48 for (value_type v : vals)
49 write(os, v, endian);
50}
51
52template <typename value_type>
53inline void write(SmallVectorImpl<char> &Out, value_type V, endianness E) {
54 V = byte_swap<value_type>(V, E);
55 Out.append((const char *)&V, (const char *)&V + sizeof(value_type));
56}
57
58/// Adapter to write values to a stream in a particular byte order.
59struct Writer {
63 template <typename value_type> void write(ArrayRef<value_type> Val) {
64 endian::write(OS, Val, Endian);
65 }
66 template <typename value_type> void write(value_type Val) {
67 endian::write(OS, Val, Endian);
68 }
69};
70
71} // end namespace endian
72
73} // end namespace support
74} // end namespace llvm
75
76#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
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:577
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:687
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< float >(raw_ostream &os, float value, endianness endian)
Definition: EndianStream.h:35
void write< double >(raw_ostream &os, double value, endianness endian)
Definition: EndianStream.h:40
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:97
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:59
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:63
void write(value_type Val)
Definition: EndianStream.h:66
Writer(raw_ostream &OS, endianness Endian)
Definition: EndianStream.h:62