Index: include/llvm/DebugInfo/CodeView/TypeRecord.h =================================================================== --- include/llvm/DebugInfo/CodeView/TypeRecord.h +++ include/llvm/DebugInfo/CodeView/TypeRecord.h @@ -313,15 +313,60 @@ }; // LF_STRING_ID -struct StringId { - TypeIndex id; +class StringId { +public: + static ErrorOr create(ArrayRef Data) { + if (Data.size() < sizeof(Layout)) + return object::make_error_code(object::object_error::parse_failed); + return StringId(Data); + } + + TypeIndex getId() const { + return reinterpret_cast(Buffer.data())->id; + } + +private: + StringId(ArrayRef Data) : Buffer(Data) {} + + struct Layout { + TypeIndex id; + }; + + ArrayRef Buffer; }; // LF_FUNC_ID -struct FuncId { - TypeIndex ParentScope; - TypeIndex FunctionType; - // Name: The null-terminated name follows. +class FuncId { +public: + static ErrorOr create(ArrayRef Data) { + if (Data.size() < sizeof(Layout)) + return object::make_error_code(object::object_error::parse_failed); + return FuncId(Data); + } + + TypeIndex getParentScope() const { + return reinterpret_cast(Buffer.data())->ParentScope; + } + + TypeIndex getFunctionType() const { + return reinterpret_cast(Buffer.data())->FunctionType; + } + + StringRef getName() const { + const uint8_t *Data = Buffer.data() + sizeof(Layout); + return StringRef(reinterpret_cast(Data)); + } + +private: + FuncId(ArrayRef Data) : Buffer(Data) {} + + struct Layout { + TypeIndex ParentScope; + TypeIndex FunctionType; + // Name: The null-terminated name follows. + }; + + ArrayRef Buffer; }; // LF_CLASS, LF_STRUCTURE, LF_INTERFACE