LLVM  16.0.0git
YAML.cpp
Go to the documentation of this file.
1 //===- YAML.cpp - YAMLIO utilities for object files -----------------------===//
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 utility classes for handling the YAML representation of
10 // object files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ObjectYAML/YAML.h"
15 #include "llvm/ADT/StringExtras.h"
17 #include <cctype>
18 #include <cstdint>
19 
20 using namespace llvm;
21 
23  const yaml::BinaryRef &Val, void *, raw_ostream &Out) {
24  Val.writeAsHex(Out);
25 }
26 
28  yaml::BinaryRef &Val) {
29  if (Scalar.size() % 2 != 0)
30  return "BinaryRef hex string must contain an even number of nybbles.";
31  // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
32  // (e.g. a caret pointing to the offending character).
33  if (!llvm::all_of(Scalar, llvm::isHexDigit))
34  return "BinaryRef hex string must contain only hex digits.";
35  Val = yaml::BinaryRef(Scalar);
36  return {};
37 }
38 
40  if (!DataIsHexString) {
41  OS.write((const char *)Data.data(), std::min<uint64_t>(N, Data.size()));
42  return;
43  }
44 
45  for (uint64_t I = 0, E = std::min<uint64_t>(N, Data.size() / 2); I != E;
46  ++I) {
47  uint8_t Byte = llvm::hexDigitValue(Data[I * 2]);
48  Byte <<= 4;
49  Byte |= llvm::hexDigitValue(Data[I * 2 + 1]);
50  OS.write(Byte);
51  }
52 }
53 
55  if (binary_size() == 0)
56  return;
57  if (DataIsHexString) {
58  OS.write((const char *)Data.data(), Data.size());
59  return;
60  }
61  for (uint8_t Byte : Data)
62  OS << hexdigit(Byte >> 4) << hexdigit(Byte & 0xf);
63 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
output
Current output
Definition: README.txt:1350
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:161
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1734
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
YAML.h
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:218
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
input
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
Definition: README.txt:10
llvm::NVPTX::PTXLdStInstCode::Scalar
@ Scalar
Definition: NVPTX.h:122
uint64_t
llvm::yaml::BinaryRef::writeAsBinary
void writeAsBinary(raw_ostream &OS, uint64_t N=UINT64_MAX) const
Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_os...
Definition: YAML.cpp:39
I
#define I(x, y, z)
Definition: MD5.cpp:58
StringExtras.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::yaml::BinaryRef
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
N
#define N
isHexDigit
static bool isHexDigit(const char C)
Definition: RustDemangle.cpp:175
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::yaml::BinaryRef::writeAsHex
void writeAsHex(raw_ostream &OS) const
Write the contents (regardless of whether it is binary or a hex string) as hex to the given raw_ostre...
Definition: YAML.cpp:54
raw_ostream.h