LCOV - code coverage report
Current view: top level - lib/ObjectYAML - YAML.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 21 25 84.0 %
Date: 2017-09-14 15:23:50 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- YAML.cpp - YAMLIO utilities for object files -----------------------===//
       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 utility classes for handling the YAML representation of
      11             : // object files.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #include "llvm/ObjectYAML/YAML.h"
      16             : #include "llvm/ADT/StringExtras.h"
      17             : #include "llvm/Support/raw_ostream.h"
      18             : #include <cctype>
      19             : #include <cstdint>
      20             : 
      21             : using namespace llvm;
      22             : 
      23          77 : void yaml::ScalarTraits<yaml::BinaryRef>::output(
      24             :     const yaml::BinaryRef &Val, void *, raw_ostream &Out) {
      25          77 :   Val.writeAsHex(Out);
      26          77 : }
      27             : 
      28         428 : StringRef yaml::ScalarTraits<yaml::BinaryRef>::input(StringRef Scalar, void *,
      29             :                                                      yaml::BinaryRef &Val) {
      30         428 :   if (Scalar.size() % 2 != 0)
      31           0 :     return "BinaryRef hex string must contain an even number of nybbles.";
      32             :   // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
      33             :   // (e.g. a caret pointing to the offending character).
      34       18334 :   for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
      35       35812 :     if (!isxdigit(Scalar[I]))
      36           0 :       return "BinaryRef hex string must contain only hex digits.";
      37         428 :   Val = yaml::BinaryRef(Scalar);
      38         428 :   return {};
      39             : }
      40             : 
      41         460 : void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {
      42         460 :   if (!DataIsHexString) {
      43          55 :     OS.write((const char *)Data.data(), Data.size());
      44          55 :     return;
      45             :   }
      46        9339 :   for (unsigned I = 0, N = Data.size(); I != N; I += 2) {
      47             :     uint8_t Byte;
      48       26802 :     StringRef((const char *)&Data[I],  2).getAsInteger(16, Byte);
      49        8934 :     OS.write(Byte);
      50             :   }
      51             : }
      52             : 
      53          77 : void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const {
      54          77 :   if (binary_size() == 0)
      55             :     return;
      56          46 :   if (DataIsHexString) {
      57           0 :     OS.write((const char *)Data.data(), Data.size());
      58           0 :     return;
      59             :   }
      60        1258 :   for (uint8_t Byte : Data)
      61        5830 :     OS << hexdigit(Byte >> 4) << hexdigit(Byte & 0xf);
      62             : }

Generated by: LCOV version 1.13