Index: include/llvm/Support/YAMLTraits.h =================================================================== --- include/llvm/Support/YAMLTraits.h +++ include/llvm/Support/YAMLTraits.h @@ -17,6 +17,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/Regex.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" @@ -856,6 +857,32 @@ static bool mustQuote(StringRef) { return false; } }; +// For endian types, we just use the existing ScalarTraits for the underlying +// type. This way endian aware types are supported whenever a ScalarTraits +// is defined for the underlying type. +template +struct ScalarTraits> { + typedef support::detail::packed_endian_specific_integral + endian_type; + + static void output(const endian_type &E, void *Ctx, + llvm::raw_ostream &Stream) { + ScalarTraits::output(static_cast(E), Ctx, Stream); + } + static StringRef input(StringRef Str, void *Ctx, endian_type &E) { + value_type V; + auto R = ScalarTraits::input(Str, Ctx, V); + E = static_cast(V); + return R; + } + + static bool mustQuote(StringRef Str) { + return ScalarTraits::mustQuote(Str); + } +}; + // Utility for use within MappingTraits<>::mapping() method // to [de]normalize an object for use with YAML conversion. template