1317017Sdim//===- TpiHashing.h ---------------------------------------------*- C++ -*-===//
2317017Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6317017Sdim//
7317017Sdim//===----------------------------------------------------------------------===//
8317017Sdim
9317017Sdim#ifndef LLVM_DEBUGINFO_PDB_TPIHASHING_H
10317017Sdim#define LLVM_DEBUGINFO_PDB_TPIHASHING_H
11317017Sdim
12317017Sdim#include "llvm/DebugInfo/CodeView/TypeRecord.h"
13317017Sdim#include "llvm/Support/Error.h"
14317017Sdim
15317017Sdimnamespace llvm {
16317017Sdimnamespace pdb {
17317017Sdim
18321238SdimExpected<uint32_t> hashTypeRecord(const llvm::codeview::CVType &Type);
19317017Sdim
20344779Sdimstruct TagRecordHash {
21344779Sdim  explicit TagRecordHash(codeview::ClassRecord CR, uint32_t Full,
22344779Sdim                         uint32_t Forward)
23344779Sdim      : FullRecordHash(Full), ForwardDeclHash(Forward), Class(std::move(CR)) {
24344779Sdim    State = 0;
25344779Sdim  }
26344779Sdim
27344779Sdim  explicit TagRecordHash(codeview::EnumRecord ER, uint32_t Full,
28344779Sdim                         uint32_t Forward)
29344779Sdim      : FullRecordHash(Full), ForwardDeclHash(Forward), Enum(std::move(ER)) {
30344779Sdim    State = 1;
31344779Sdim  }
32344779Sdim
33344779Sdim  explicit TagRecordHash(codeview::UnionRecord UR, uint32_t Full,
34344779Sdim                         uint32_t Forward)
35344779Sdim      : FullRecordHash(Full), ForwardDeclHash(Forward), Union(std::move(UR)) {
36344779Sdim    State = 2;
37344779Sdim  }
38344779Sdim
39344779Sdim  uint32_t FullRecordHash;
40344779Sdim  uint32_t ForwardDeclHash;
41344779Sdim
42344779Sdim  codeview::TagRecord &getRecord() {
43344779Sdim    switch (State) {
44344779Sdim    case 0:
45344779Sdim      return Class;
46344779Sdim    case 1:
47344779Sdim      return Enum;
48344779Sdim    case 2:
49344779Sdim      return Union;
50344779Sdim    }
51344779Sdim    llvm_unreachable("unreachable!");
52344779Sdim  }
53344779Sdim
54344779Sdimprivate:
55344779Sdim  union {
56344779Sdim    codeview::ClassRecord Class;
57344779Sdim    codeview::EnumRecord Enum;
58344779Sdim    codeview::UnionRecord Union;
59344779Sdim  };
60344779Sdim
61344779Sdim  uint8_t State = 0;
62344779Sdim};
63344779Sdim
64344779Sdim/// Given a CVType referring to a class, structure, union, or enum, compute
65344779Sdim/// the hash of its forward decl and full decl.
66344779SdimExpected<TagRecordHash> hashTagRecord(const codeview::CVType &Type);
67344779Sdim
68317017Sdim} // end namespace pdb
69317017Sdim} // end namespace llvm
70317017Sdim
71317017Sdim#endif // LLVM_DEBUGINFO_PDB_TPIHASHING_H
72