X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FObject%2FYAML.cpp;h=c527bde090e8e6ea2127695e4063628e42427129;hb=bb96dfcf4f58ae7152f4be92254a0bb1c0995e6d;hp=b33cf3410f653171ad9f2e7602ec9ca754523509;hpb=639adc59f86d0526dbace4a1ecc4924c6c52e1cd;p=oota-llvm.git diff --git a/lib/Object/YAML.cpp b/lib/Object/YAML.cpp index b33cf3410f6..c527bde090e 100644 --- a/lib/Object/YAML.cpp +++ b/lib/Object/YAML.cpp @@ -13,28 +13,16 @@ //===----------------------------------------------------------------------===// #include "llvm/Object/YAML.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" +#include using namespace llvm; using namespace object::yaml; void yaml::ScalarTraits::output( const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) { - ArrayRef Data = Val.getBinary(); - for (ArrayRef::iterator I = Data.begin(), E = Data.end(); I != E; - ++I) { - uint8_t Byte = *I; - Out << hexdigit(Byte >> 4); - Out << hexdigit(Byte & 0xf); - } -} - -// Can't find this anywhere else in the codebase (clang has one, but it has -// some baggage). Deduplicate as required. -static bool isHexDigit(uint8_t C) { - return ('0' <= C && C <= '9') || - ('A' <= C && C <= 'F') || - ('a' <= C && C <= 'f'); + Val.writeAsHex(Out); } StringRef yaml::ScalarTraits::input( @@ -44,14 +32,14 @@ StringRef yaml::ScalarTraits::input( // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here? // (e.g. a caret pointing to the offending character). for (unsigned I = 0, N = Scalar.size(); I != N; ++I) - if (!isHexDigit(Scalar[I])) + if (!isxdigit(Scalar[I])) return "BinaryRef hex string must contain only hex digits."; Val = object::yaml::BinaryRef(Scalar); return StringRef(); } void BinaryRef::writeAsBinary(raw_ostream &OS) const { - if (isBinary) { + if (!DataIsHexString) { OS.write((const char *)Data.data(), Data.size()); return; } @@ -61,3 +49,20 @@ void BinaryRef::writeAsBinary(raw_ostream &OS) const { OS.write(Byte); } } + +void BinaryRef::writeAsHex(raw_ostream &OS) const { + if (binary_size() == 0) { + OS << "\"\""; + return; + } + if (DataIsHexString) { + OS.write((const char *)Data.data(), Data.size()); + return; + } + for (ArrayRef::iterator I = Data.begin(), E = Data.end(); I != E; + ++I) { + uint8_t Byte = *I; + OS << hexdigit(Byte >> 4); + OS << hexdigit(Byte & 0xf); + } +}