LLVM  14.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"
18 #include "llvm/Support/Endian.h"
21 
22 namespace llvm {
23 namespace support {
24 
25 namespace endian {
26 
27 template <typename value_type>
28 inline void write(raw_ostream &os, value_type value, endianness endian) {
29  value = byte_swap<value_type>(value, endian);
30  os.write((const char *)&value, sizeof(value_type));
31 }
32 
33 template <>
34 inline void write<float>(raw_ostream &os, float value, endianness endian) {
35  write(os, FloatToBits(value), endian);
36 }
37 
38 template <>
39 inline void write<double>(raw_ostream &os, double value,
41  write(os, DoubleToBits(value), endian);
42 }
43 
44 template <typename value_type>
45 inline void write(raw_ostream &os, ArrayRef<value_type> vals,
47  for (value_type v : vals)
48  write(os, v, endian);
49 }
50 
51 /// Adapter to write values to a stream in a particular byte order.
52 struct Writer {
56  template <typename value_type> void write(ArrayRef<value_type> Val) {
57  endian::write(OS, Val, Endian);
58  }
59  template <typename value_type> void write(value_type Val) {
60  endian::write(OS, Val, Endian);
61  }
62 };
63 
64 } // end namespace endian
65 
66 } // end namespace support
67 } // end namespace llvm
68 
69 #endif
MathExtras.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::support::endian::Writer::Writer
Writer(raw_ostream &OS, endianness Endian)
Definition: EndianStream.h:55
llvm::FloatToBits
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
Definition: MathExtras.h:663
llvm::support::endian::Writer::write
void write(value_type Val)
Definition: EndianStream.h:59
llvm::support::endian::Writer
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:52
llvm::support::endian
Definition: Endian.h:42
llvm::support::endian::Writer::OS
raw_ostream & OS
Definition: EndianStream.h:53
llvm::DoubleToBits
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
Definition: MathExtras.h:653
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:220
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::support::endian::write
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:97
ArrayRef.h
llvm::support::endian::write< float >
void write< float >(raw_ostream &os, float value, endianness endian)
Definition: EndianStream.h:34
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::support::endian::Writer::write
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:56
llvm::support::endian::Writer::Endian
endianness Endian
Definition: EndianStream.h:54
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::support::endian::write< double >
void write< double >(raw_ostream &os, double value, endianness endian)
Definition: EndianStream.h:39
raw_ostream.h
Endian.h