1 //===- YAML.h - YAMLIO utilities for object files ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares utility classes for handling the YAML representation of
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECT_YAML_H
16 #define LLVM_OBJECT_YAML_H
18 #include "llvm/Support/YAMLTraits.h"
24 /// In an object file this is just a binary blob. In an yaml file it is an hex
25 /// string. Using this avoid having to allocate temporary strings.
27 ArrayRef<uint8_t> Data;
31 BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), isBinary(true) {}
32 BinaryRef(StringRef Data)
33 : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()),
35 BinaryRef() : isBinary(false) {}
36 StringRef getHex() const {
38 return StringRef(reinterpret_cast<const char *>(Data.data()), Data.size());
40 ArrayRef<uint8_t> getBinary() const {
44 bool operator==(const BinaryRef &Ref) {
45 // Special case for default constructed BinaryRef.
46 if (Ref.Data.empty() && Data.empty())
49 return Ref.isBinary == isBinary && Ref.Data == Data;
57 template <> struct ScalarTraits<object::yaml::BinaryRef> {
58 static void output(const object::yaml::BinaryRef &, void *,
60 static StringRef input(StringRef, void *, object::yaml::BinaryRef &);