diff options
Diffstat (limited to 'include/llvm/Support/YAMLTraits.h')
-rw-r--r-- | include/llvm/Support/YAMLTraits.h | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index fb2badfd93bad..bc3fa8ad11dab 100644 --- a/include/llvm/Support/YAMLTraits.h +++ b/include/llvm/Support/YAMLTraits.h @@ -10,8 +10,6 @@ #ifndef LLVM_SUPPORT_YAMLTRAITS_H #define LLVM_SUPPORT_YAMLTRAITS_H -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -19,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" @@ -512,11 +511,11 @@ public: template <typename FBT, typename T> void enumFallback(T &Val) { - if ( matchEnumFallback() ) { + if (matchEnumFallback()) { // FIXME: Force integral conversion to allow strong typedefs to convert. - FBT Res = (uint64_t)Val; + FBT Res = static_cast<typename FBT::BaseType>(Val); yamlize(*this, Res, true); - Val = (uint64_t)Res; + Val = static_cast<T>(static_cast<typename FBT::BaseType>(Res)); } } @@ -858,6 +857,32 @@ struct ScalarTraits<double> { 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 <typename value_type, support::endianness endian, size_t alignment> +struct ScalarTraits<support::detail::packed_endian_specific_integral< + value_type, endian, alignment>> { + typedef support::detail::packed_endian_specific_integral<value_type, endian, + alignment> + endian_type; + + static void output(const endian_type &E, void *Ctx, + llvm::raw_ostream &Stream) { + ScalarTraits<value_type>::output(static_cast<value_type>(E), Ctx, Stream); + } + static StringRef input(StringRef Str, void *Ctx, endian_type &E) { + value_type V; + auto R = ScalarTraits<value_type>::input(Str, Ctx, V); + E = static_cast<endian_type>(V); + return R; + } + + static bool mustQuote(StringRef Str) { + return ScalarTraits<value_type>::mustQuote(Str); + } +}; + // Utility for use within MappingTraits<>::mapping() method // to [de]normalize an object for use with YAML conversion. template <typename TNorm, typename TFinal> @@ -894,12 +919,16 @@ private: // to [de]normalize an object for use with YAML conversion. template <typename TNorm, typename TFinal> struct MappingNormalizationHeap { - MappingNormalizationHeap(IO &i_o, TFinal &Obj) + MappingNormalizationHeap(IO &i_o, TFinal &Obj, + llvm::BumpPtrAllocator *allocator) : io(i_o), BufPtr(nullptr), Result(Obj) { if ( io.outputting() ) { BufPtr = new (&Buffer) TNorm(io, Obj); } - else { + else if (allocator) { + BufPtr = allocator->Allocate<TNorm>(); + new (BufPtr) TNorm(io); + } else { BufPtr = new TNorm(io); } } @@ -1166,6 +1195,7 @@ private: bool operator==(const _base &rhs) const { return value == rhs; } \ bool operator<(const _type &rhs) const { return value < rhs.value; } \ _base value; \ + typedef _base BaseType; \ }; /// |