Mercurial > hg > CbC > CbC_llvm
comparison include/llvm/ObjectYAML/YAML.h @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- YAML.h ---------------------------------------------------*- C++ -*-===// | 1 //===- YAML.h ---------------------------------------------------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 #ifndef LLVM_OBJECTYAML_YAML_H | 9 #ifndef LLVM_OBJECTYAML_YAML_H |
11 #define LLVM_OBJECTYAML_YAML_H | 10 #define LLVM_OBJECTYAML_YAML_H |
19 | 18 |
20 class raw_ostream; | 19 class raw_ostream; |
21 | 20 |
22 namespace yaml { | 21 namespace yaml { |
23 | 22 |
24 /// \brief Specialized YAMLIO scalar type for representing a binary blob. | 23 /// Specialized YAMLIO scalar type for representing a binary blob. |
25 /// | 24 /// |
26 /// A typical use case would be to represent the content of a section in a | 25 /// A typical use case would be to represent the content of a section in a |
27 /// binary file. | 26 /// binary file. |
28 /// This class has custom YAMLIO traits for convenient reading and writing. | 27 /// This class has custom YAMLIO traits for convenient reading and writing. |
29 /// It renders as a string of hex digits in a YAML file. | 28 /// It renders as a string of hex digits in a YAML file. |
62 /// } // end namespace llvm | 61 /// } // end namespace llvm |
63 /// \endcode | 62 /// \endcode |
64 class BinaryRef { | 63 class BinaryRef { |
65 friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS); | 64 friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS); |
66 | 65 |
67 /// \brief Either raw binary data, or a string of hex bytes (must always | 66 /// Either raw binary data, or a string of hex bytes (must always |
68 /// be an even number of characters). | 67 /// be an even number of characters). |
69 ArrayRef<uint8_t> Data; | 68 ArrayRef<uint8_t> Data; |
70 | 69 |
71 /// \brief Discriminator between the two states of the `Data` member. | 70 /// Discriminator between the two states of the `Data` member. |
72 bool DataIsHexString = true; | 71 bool DataIsHexString = true; |
73 | 72 |
74 public: | 73 public: |
75 BinaryRef() = default; | 74 BinaryRef() = default; |
76 BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {} | 75 BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {} |
77 BinaryRef(StringRef Data) | 76 BinaryRef(StringRef Data) : Data(arrayRefFromStringRef(Data)) {} |
78 : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()) {} | |
79 | 77 |
80 /// \brief The number of bytes that are represented by this BinaryRef. | 78 /// The number of bytes that are represented by this BinaryRef. |
81 /// This is the number of bytes that writeAsBinary() will write. | 79 /// This is the number of bytes that writeAsBinary() will write. |
82 ArrayRef<uint8_t>::size_type binary_size() const { | 80 ArrayRef<uint8_t>::size_type binary_size() const { |
83 if (DataIsHexString) | 81 if (DataIsHexString) |
84 return Data.size() / 2; | 82 return Data.size() / 2; |
85 return Data.size(); | 83 return Data.size(); |
86 } | 84 } |
87 | 85 |
88 /// \brief Write the contents (regardless of whether it is binary or a | 86 /// Write the contents (regardless of whether it is binary or a |
89 /// hex string) as binary to the given raw_ostream. | 87 /// hex string) as binary to the given raw_ostream. |
90 void writeAsBinary(raw_ostream &OS) const; | 88 void writeAsBinary(raw_ostream &OS) const; |
91 | 89 |
92 /// \brief Write the contents (regardless of whether it is binary or a | 90 /// Write the contents (regardless of whether it is binary or a |
93 /// hex string) as hex to the given raw_ostream. | 91 /// hex string) as hex to the given raw_ostream. |
94 /// | 92 /// |
95 /// For example, a possible output could be `DEADBEEFCAFEBABE`. | 93 /// For example, a possible output could be `DEADBEEFCAFEBABE`. |
96 void writeAsHex(raw_ostream &OS) const; | 94 void writeAsHex(raw_ostream &OS) const; |
97 }; | 95 }; |