summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Silva <silvas@purdue.edu>2013-06-05 23:47:23 +0000
committerSean Silva <silvas@purdue.edu>2013-06-05 23:47:23 +0000
commit4370ddb8b821bda66478160c1a1c5714a1877d85 (patch)
tree9632d15c08a003962b84c09394459c9d8825a53f
parentc170230b3a8c1e0a43614a929061ad24888bfe52 (diff)
downloadllvm-4370ddb8b821bda66478160c1a1c5714a1877d85.tar.gz
llvm-4370ddb8b821bda66478160c1a1c5714a1877d85.tar.bz2
llvm-4370ddb8b821bda66478160c1a1c5714a1877d85.tar.xz
Add writeAsHex(raw_ostream &) method to BinaryRef.
This hides the implementation. A future commit will remove the error-prone getHex() and getBinary() methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183352 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/YAML.h5
-rw-r--r--lib/Object/YAML.cpp21
2 files changed, 19 insertions, 7 deletions
diff --git a/include/llvm/Object/YAML.h b/include/llvm/Object/YAML.h
index 41fe952456..e349e35dd4 100644
--- a/include/llvm/Object/YAML.h
+++ b/include/llvm/Object/YAML.h
@@ -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;
};
}
diff --git a/lib/Object/YAML.cpp b/lib/Object/YAML.cpp
index cf6e616241..e63bd5df27 100644
--- a/lib/Object/YAML.cpp
+++ b/lib/Object/YAML.cpp
@@ -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_ostream &OS) const {
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);
+ }
+}