LCOV - code coverage report
Current view: top level - include/llvm/Support - EndianStream.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 11 11 100.0 %
Date: 2017-09-14 15:23:50 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- EndianStream.h - Stream ops with endian specific data ----*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines utilities for operating on streams that have endian
      11             : // specific data.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_SUPPORT_ENDIANSTREAM_H
      16             : #define LLVM_SUPPORT_ENDIANSTREAM_H
      17             : 
      18             : #include "llvm/ADT/ArrayRef.h"
      19             : #include "llvm/Support/Endian.h"
      20             : #include "llvm/Support/raw_ostream.h"
      21             : 
      22             : namespace llvm {
      23             : namespace support {
      24             : 
      25             : namespace endian {
      26             : /// Adapter to write values to a stream in a particular byte order.
      27             : template <endianness endian> struct Writer {
      28             :   raw_ostream &OS;
      29     4815440 :   Writer(raw_ostream &OS) : OS(OS) {}
      30           8 :   template <typename value_type> void write(ArrayRef<value_type> Vals) {
      31          42 :     for (value_type V : Vals)
      32          50 :       write(V);
      33           8 :   }
      34             :   template <typename value_type> void write(value_type Val) {
      35    56674449 :     Val = byte_swap<value_type, endian>(Val);
      36    28339566 :     OS.write((const char *)&Val, sizeof(value_type));
      37             :   }
      38             : };
      39             : 
      40             : template <>
      41             : template <>
      42             : inline void Writer<little>::write<float>(float Val) {
      43           6 :   write(FloatToBits(Val));
      44             : }
      45             : 
      46             : template <>
      47             : template <>
      48             : inline void Writer<little>::write<double>(double Val) {
      49           2 :   write(DoubleToBits(Val));
      50             : }
      51             : 
      52             : template <>
      53             : template <>
      54             : inline void Writer<big>::write<float>(float Val) {
      55           2 :   write(FloatToBits(Val));
      56             : }
      57             : 
      58             : template <>
      59             : template <>
      60             : inline void Writer<big>::write<double>(double Val) {
      61           2 :   write(DoubleToBits(Val));
      62             : }
      63             : 
      64             : } // end namespace endian
      65             : 
      66             : } // end namespace support
      67             : } // end namespace llvm
      68             : 
      69             : #endif

Generated by: LCOV version 1.13