Line data Source code
1 : //===- StringTable.h - CodeView String Table Reader/Writer ------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGTABLE_H
11 : #define LLVM_DEBUGINFO_CODEVIEW_STRINGTABLE_H
12 :
13 : #include "llvm/ADT/StringMap.h"
14 : #include "llvm/ADT/StringRef.h"
15 :
16 : #include "llvm/Support/BinaryStreamRef.h"
17 : #include "llvm/Support/Error.h"
18 :
19 : #include <stdint.h>
20 :
21 : namespace llvm {
22 :
23 : class BinaryStreamReader;
24 : class BinaryStreamRef;
25 : class BinaryStreamWriter;
26 :
27 : namespace codeview {
28 :
29 : /// Represents a read-only view of a CodeView string table. This is a very
30 : /// simple flat buffer consisting of null-terminated strings, where strings
31 : /// are retrieved by their offset in the buffer. StringTableRef does not own
32 : /// the underlying storage for the buffer.
33 610 : class StringTableRef {
34 : public:
35 : StringTableRef();
36 :
37 : Error initialize(BinaryStreamRef Contents);
38 :
39 : Expected<StringRef> getString(uint32_t Offset) const;
40 :
41 273 : bool valid() const { return Stream.valid(); }
42 :
43 : private:
44 : BinaryStreamRef Stream;
45 : };
46 :
47 : /// Represents a read-write view of a CodeView string table. StringTable owns
48 : /// the underlying storage for the table, and is capable of serializing the
49 : /// string table into a format understood by StringTableRef.
50 87 : class StringTable {
51 : public:
52 : // If string S does not exist in the string table, insert it.
53 : // Returns the ID for S.
54 : uint32_t insert(StringRef S);
55 :
56 : // Return the ID for string S. Assumes S exists in the table.
57 : uint32_t getStringId(StringRef S) const;
58 :
59 : uint32_t calculateSerializedSize() const;
60 : Error commit(BinaryStreamWriter &Writer) const;
61 :
62 : uint32_t size() const;
63 :
64 29 : StringMap<uint32_t>::const_iterator begin() const { return Strings.begin(); }
65 :
66 29 : StringMap<uint32_t>::const_iterator end() const { return Strings.end(); }
67 :
68 : private:
69 : StringMap<uint32_t> Strings;
70 : uint32_t StringSize = 1;
71 : };
72 : }
73 : }
74 :
75 : #endif
|