[llvm] r183352 - Add writeAsHex(raw_ostream &) method to BinaryRef.
Sean Silva
silvas at purdue.edu
Wed Jun 5 16:47:23 PDT 2013
Author: silvas
Date: Wed Jun 5 18:47:23 2013
New Revision: 183352
URL: http://llvm.org/viewvc/llvm-project?rev=183352&view=rev
Log:
Add writeAsHex(raw_ostream &) method to BinaryRef.
This hides the implementation. A future commit will remove the
error-prone getHex() and getBinary() methods.
Modified:
llvm/trunk/include/llvm/Object/YAML.h
llvm/trunk/lib/Object/YAML.cpp
Modified: llvm/trunk/include/llvm/Object/YAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/YAML.h?rev=183352&r1=183351&r2=183352&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/YAML.h (original)
+++ llvm/trunk/include/llvm/Object/YAML.h Wed Jun 5 18:47:23 2013
@@ -61,6 +61,11 @@ public:
/// \brief Write the contents (regardless of whether it is binary or a
/// hex string) as binary to the given raw_ostream.
void writeAsBinary(raw_ostream &OS) const;
+ /// \brief Write the contents (regardless of whether it is binary or a
+ /// hex string) as hex to the given raw_ostream.
+ ///
+ /// For example, a possible output could be `DEADBEEFCAFEBABE`.
+ void writeAsHex(raw_ostream &OS) const;
};
}
Modified: llvm/trunk/lib/Object/YAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/YAML.cpp?rev=183352&r1=183351&r2=183352&view=diff
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (original)
+++ llvm/trunk/lib/Object/YAML.cpp Wed Jun 5 18:47:23 2013
@@ -20,13 +20,7 @@ using namespace object::yaml;
void yaml::ScalarTraits<object::yaml::BinaryRef>::output(
const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
- ArrayRef<uint8_t> Data = Val.getBinary();
- for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
- ++I) {
- uint8_t Byte = *I;
- Out << hexdigit(Byte >> 4);
- Out << hexdigit(Byte & 0xf);
- }
+ Val.writeAsHex(Out);
}
// Can't find this anywhere else in the codebase (clang has one, but it has
@@ -61,3 +55,16 @@ void BinaryRef::writeAsBinary(raw_ostrea
OS.write(Byte);
}
}
+
+void BinaryRef::writeAsHex(raw_ostream &OS) const {
+ if (DataIsHexString) {
+ OS.write((const char *)Data.data(), Data.size());
+ return;
+ }
+ for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
+ ++I) {
+ uint8_t Byte = *I;
+ OS << hexdigit(Byte >> 4);
+ OS << hexdigit(Byte & 0xf);
+ }
+}
More information about the llvm-commits
mailing list