llvm/llvm/include/llvm/Support/Endian.h

//===- Endian.h - Utilities for IO with endian specific data ----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares generic functions to read and write endian specific data.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_SUPPORT_ENDIAN_H
#define LLVM_SUPPORT_ENDIAN_H

#include "llvm/ADT/bit.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/SwapByteOrder.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <type_traits>

namespace llvm {
namespace support {

// These are named values for common alignments.
enum {};

namespace detail {

/// ::value is either alignment, or alignof(T) if alignment is 0.
template<class T, int alignment>
struct PickAlignment {};

} // end namespace detail

namespace endian {

template <typename value_type>
[[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) {}

/// Swap the bytes of value to match the given endianness.
template <typename value_type, endianness endian>
[[nodiscard]] inline value_type byte_swap(value_type value) {}

/// Read a value of a particular endianness from memory.
template <typename value_type, std::size_t alignment = unaligned>
[[nodiscard]] inline value_type read(const void *memory, endianness endian) {}

template <typename value_type, endianness endian, std::size_t alignment>
[[nodiscard]] inline value_type read(const void *memory) {}

/// Read a value of a particular endianness from a buffer, and increment the
/// buffer past that value.
template <typename value_type, std::size_t alignment = unaligned,
          typename CharT>
[[nodiscard]] inline value_type readNext(const CharT *&memory,
                                         endianness endian) {}

template <typename value_type, endianness endian,
          std::size_t alignment = unaligned, typename CharT>
[[nodiscard]] inline value_type readNext(const CharT *&memory) {}

/// Write a value to memory with a particular endianness.
template <typename value_type, std::size_t alignment = unaligned>
inline void write(void *memory, value_type value, endianness endian) {}

template<typename value_type,
         endianness endian,
         std::size_t alignment>
inline void write(void *memory, value_type value) {}

/// Write a value of a particular endianness, and increment the buffer past that
/// value.
template <typename value_type, std::size_t alignment = unaligned,
          typename CharT>
inline void writeNext(CharT *&memory, value_type value, endianness endian) {}

template <typename value_type, endianness endian,
          std::size_t alignment = unaligned, typename CharT>
inline void writeNext(CharT *&memory, value_type value) {}

make_unsigned_t;

/// Read a value of a particular endianness from memory, for a location
/// that starts at the given bit offset within the first byte.
template <typename value_type, endianness endian, std::size_t alignment>
[[nodiscard]] inline value_type readAtBitAlignment(const void *memory,
                                                   uint64_t startBit) {}

/// Write a value to memory with a particular endianness, for a location
/// that starts at the given bit offset within the first byte.
template <typename value_type, endianness endian, std::size_t alignment>
inline void writeAtBitAlignment(void *memory, value_type value,
                                uint64_t startBit) {}

} // end namespace endian

namespace detail {

template <typename ValueType, endianness Endian, std::size_t Alignment,
          std::size_t ALIGN = PickAlignment<ValueType, Alignment>::value>
struct packed_endian_specific_integral {};

} // end namespace detail

ulittle16_t;
ulittle32_t;
ulittle64_t;

little16_t;
little32_t;
little64_t;

aligned_ulittle16_t;
aligned_ulittle32_t;
aligned_ulittle64_t;

aligned_little16_t;
aligned_little32_t;
aligned_little64_t;

ubig16_t;
ubig32_t;
ubig64_t;

big16_t;
big32_t;
big64_t;

aligned_ubig16_t;
aligned_ubig32_t;
aligned_ubig64_t;

aligned_big16_t;
aligned_big32_t;
aligned_big64_t;

unaligned_uint16_t;
unaligned_uint32_t;
unaligned_uint64_t;

unaligned_int16_t;
unaligned_int32_t;
unaligned_int64_t;

little_t;
big_t;

aligned_little_t;
aligned_big_t;

namespace endian {

template <typename T, endianness E> [[nodiscard]] inline T read(const void *P) {}

[[nodiscard]] inline uint16_t read16(const void *P, endianness E) {}
[[nodiscard]] inline uint32_t read32(const void *P, endianness E) {}
[[nodiscard]] inline uint64_t read64(const void *P, endianness E) {}

template <endianness E> [[nodiscard]] inline uint16_t read16(const void *P) {}
template <endianness E> [[nodiscard]] inline uint32_t read32(const void *P) {}
template <endianness E> [[nodiscard]] inline uint64_t read64(const void *P) {}

[[nodiscard]] inline uint16_t read16le(const void *P) {}
[[nodiscard]] inline uint32_t read32le(const void *P) {}
[[nodiscard]] inline uint64_t read64le(const void *P) {}
[[nodiscard]] inline uint16_t read16be(const void *P) {}
[[nodiscard]] inline uint32_t read32be(const void *P) {}
[[nodiscard]] inline uint64_t read64be(const void *P) {}

template <typename T, endianness E> inline void write(void *P, T V) {}

inline void write16(void *P, uint16_t V, endianness E) {}
inline void write32(void *P, uint32_t V, endianness E) {}
inline void write64(void *P, uint64_t V, endianness E) {}

template <endianness E> inline void write16(void *P, uint16_t V) {}
template <endianness E> inline void write32(void *P, uint32_t V) {}
template <endianness E> inline void write64(void *P, uint64_t V) {}

inline void write16le(void *P, uint16_t V) {}
inline void write32le(void *P, uint32_t V) {}
inline void write64le(void *P, uint64_t V) {}
inline void write16be(void *P, uint16_t V) {}
inline void write32be(void *P, uint32_t V) {}
inline void write64be(void *P, uint64_t V) {}

} // end namespace endian

} // end namespace support
} // end namespace llvm

#endif // LLVM_SUPPORT_ENDIAN_H