comparison tools/llvm-readobj/StreamWriter.h @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children afa8332a0e37
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #ifndef LLVM_READOBJ_STREAMWRITER_H 10 #ifndef LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H
11 #define LLVM_READOBJ_STREAMWRITER_H 11 #define LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H
12 12
13 #include "llvm/ADT/ArrayRef.h" 13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/Support/DataTypes.h" 16 #include "llvm/Support/DataTypes.h"
17 #include "llvm/Support/Endian.h" 17 #include "llvm/Support/Endian.h"
18 #include "llvm/Support/raw_ostream.h" 18 #include "llvm/Support/raw_ostream.h"
19 #include <algorithm> 19 #include <algorithm>
20 20
79 template<typename T, typename TEnum> 79 template<typename T, typename TEnum>
80 void printEnum(StringRef Label, T Value, 80 void printEnum(StringRef Label, T Value,
81 ArrayRef<EnumEntry<TEnum> > EnumValues) { 81 ArrayRef<EnumEntry<TEnum> > EnumValues) {
82 StringRef Name; 82 StringRef Name;
83 bool Found = false; 83 bool Found = false;
84 for (size_t i = 0; i < EnumValues.size(); ++i) { 84 for (const auto &EnumItem : EnumValues) {
85 if (EnumValues[i].Value == Value) { 85 if (EnumItem.Value == Value) {
86 Name = EnumValues[i].Name; 86 Name = EnumItem.Name;
87 Found = true; 87 Found = true;
88 break; 88 break;
89 } 89 }
90 } 90 }
91 91
101 TFlag EnumMask = TFlag(0)) { 101 TFlag EnumMask = TFlag(0)) {
102 typedef EnumEntry<TFlag> FlagEntry; 102 typedef EnumEntry<TFlag> FlagEntry;
103 typedef SmallVector<FlagEntry, 10> FlagVector; 103 typedef SmallVector<FlagEntry, 10> FlagVector;
104 FlagVector SetFlags; 104 FlagVector SetFlags;
105 105
106 for (typename ArrayRef<FlagEntry>::const_iterator I = Flags.begin(), 106 for (const auto &Flag : Flags) {
107 E = Flags.end(); I != E; ++I) { 107 if (Flag.Value == 0)
108 if (I->Value == 0)
109 continue; 108 continue;
110 109
111 bool IsEnum = (I->Value & EnumMask) != 0; 110 bool IsEnum = (Flag.Value & EnumMask) != 0;
112 if ((!IsEnum && (Value & I->Value) == I->Value) || 111 if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
113 (IsEnum && (Value & EnumMask) == I->Value)) { 112 (IsEnum && (Value & EnumMask) == Flag.Value)) {
114 SetFlags.push_back(*I); 113 SetFlags.push_back(Flag);
115 } 114 }
116 } 115 }
117 116
118 std::sort(SetFlags.begin(), SetFlags.end(), &flagName<TFlag>); 117 std::sort(SetFlags.begin(), SetFlags.end(), &flagName<TFlag>);
119 118
120 startLine() << Label << " [ (" << hex(Value) << ")\n"; 119 startLine() << Label << " [ (" << hex(Value) << ")\n";
121 for (typename FlagVector::const_iterator I = SetFlags.begin(), 120 for (const auto &Flag : SetFlags) {
122 E = SetFlags.end(); 121 startLine() << " " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
123 I != E; ++I) {
124 startLine() << " " << I->Name << " (" << hex(I->Value) << ")\n";
125 } 122 }
126 startLine() << "]\n"; 123 startLine() << "]\n";
127 } 124 }
128 125
129 template<typename T> 126 template<typename T>
170 167
171 void printNumber(StringRef Label, int8_t Value) { 168 void printNumber(StringRef Label, int8_t Value) {
172 startLine() << Label << ": " << int(Value) << "\n"; 169 startLine() << Label << ": " << int(Value) << "\n";
173 } 170 }
174 171
172 void printBoolean(StringRef Label, bool Value) {
173 startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n';
174 }
175
176 template <typename T_>
177 void printList(StringRef Label, const SmallVectorImpl<T_> &List) {
178 startLine() << Label << ": [";
179 bool Comma = false;
180 for (const auto &Item : List) {
181 if (Comma)
182 OS << ", ";
183 OS << Item;
184 Comma = true;
185 }
186 OS << "]\n";
187 }
188
175 template<typename T> 189 template<typename T>
176 void printHex(StringRef Label, T Value) { 190 void printHex(StringRef Label, T Value) {
177 startLine() << Label << ": " << hex(Value) << "\n"; 191 startLine() << Label << ": " << hex(Value) << "\n";
178 } 192 }
179 193
198 void printBinary(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value) { 212 void printBinary(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value) {
199 printBinaryImpl(Label, Str, Value, false); 213 printBinaryImpl(Label, Str, Value, false);
200 } 214 }
201 215
202 void printBinary(StringRef Label, StringRef Str, ArrayRef<char> Value) { 216 void printBinary(StringRef Label, StringRef Str, ArrayRef<char> Value) {
203 ArrayRef<uint8_t> V(reinterpret_cast<const uint8_t*>(Value.data()), 217 auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
204 Value.size()); 218 Value.size());
205 printBinaryImpl(Label, Str, V, false); 219 printBinaryImpl(Label, Str, V, false);
206 } 220 }
207 221
208 void printBinary(StringRef Label, ArrayRef<uint8_t> Value) { 222 void printBinary(StringRef Label, ArrayRef<uint8_t> Value) {
209 printBinaryImpl(Label, StringRef(), Value, false); 223 printBinaryImpl(Label, StringRef(), Value, false);
210 } 224 }
211 225
212 void printBinary(StringRef Label, ArrayRef<char> Value) { 226 void printBinary(StringRef Label, ArrayRef<char> Value) {
213 ArrayRef<uint8_t> V(reinterpret_cast<const uint8_t*>(Value.data()), 227 auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
214 Value.size()); 228 Value.size());
215 printBinaryImpl(Label, StringRef(), V, false); 229 printBinaryImpl(Label, StringRef(), V, false);
216 } 230 }
217 231
218 void printBinary(StringRef Label, StringRef Value) { 232 void printBinary(StringRef Label, StringRef Value) {
219 ArrayRef<uint8_t> V(reinterpret_cast<const uint8_t*>(Value.data()), 233 auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
220 Value.size()); 234 Value.size());
221 printBinaryImpl(Label, StringRef(), V, false); 235 printBinaryImpl(Label, StringRef(), V, false);
222 } 236 }
223 237
224 void printBinaryBlock(StringRef Label, StringRef Value) { 238 void printBinaryBlock(StringRef Label, StringRef Value) {
225 ArrayRef<uint8_t> V(reinterpret_cast<const uint8_t*>(Value.data()), 239 auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
226 Value.size()); 240 Value.size());
227 printBinaryImpl(Label, StringRef(), V, true); 241 printBinaryImpl(Label, StringRef(), V, true);
228 } 242 }
229 243
230 raw_ostream& startLine() { 244 raw_ostream& startLine() {
231 printIndent(); 245 printIndent();