1bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//==-- llvm/CodeGen/DwarfAccelTable.h - Dwarf Accelerator Tables -*- C++ -*-==//
2bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
3bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//                     The LLVM Compiler Infrastructure
4bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
5bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// This file is distributed under the University of Illinois Open Source
6bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// License. See LICENSE.TXT for details.
7bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
8bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//===----------------------------------------------------------------------===//
9bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
10bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// This file contains support for writing dwarf accelerator tables.
11bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
12bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//===----------------------------------------------------------------------===//
13bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
14bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef CODEGEN_ASMPRINTER_DWARFACCELTABLE_H__
15bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#define CODEGEN_ASMPRINTER_DWARFACCELTABLE_H__
16bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
17a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include "DIE.h"
1836c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer#include "llvm/ADT/ArrayRef.h"
19a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include "llvm/ADT/StringMap.h"
20bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/MC/MCSymbol.h"
21dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines#include "llvm/Support/Compiler.h"
22bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/DataTypes.h"
23bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/Debug.h"
24a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include "llvm/Support/Dwarf.h"
25bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/ErrorHandling.h"
26bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/Format.h"
27bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/FormattedStream.h"
28a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include <vector>
29bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
3009ac3d841367d5d56328eade506c951e0dc3a72dEric Christopher// The dwarf accelerator tables are an indirect hash table optimized
31bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// for null lookup rather than access to known data. They are output into
32bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// an on-disk format that looks like this:
33bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
34bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// .-------------.
35bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  HEADER     |
36bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
37bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  BUCKETS    |
38bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
39bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  HASHES     |
40bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
41bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  OFFSETS    |
42bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
43bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  DATA       |
44bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// `-------------'
45bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
46bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// where the header contains a magic number, version, type of hash function,
47bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// the number of buckets, total number of hashes, and room for a special
48bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// struct of data and the length of that struct.
49bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
50bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// The buckets contain an index (e.g. 6) into the hashes array. The hashes
51bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// section contains all of the 32-bit hash values in contiguous memory, and
52bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// the offsets contain the offset into the data area for the particular
53bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// hash.
5472c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher//
55bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// For a lookup example, we could hash a function name and take it modulo the
56bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// number of buckets giving us our bucket. From there we take the bucket value
57bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// as an index into the hashes table and look at each successive hash as long
58bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// as the hash value is still the same modulo result (bucket value) as earlier.
59bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// If we have a match we look at that same entry in the offsets table and
60bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// grab the offset in the data for our final match.
61bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
62bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christophernamespace llvm {
63bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
64bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherclass AsmPrinter;
6536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass DwarfFile;
6672c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher
6755c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerclass DwarfAccelTable {
68bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
695b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  static uint32_t HashDJB(StringRef Str) {
70bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t h = 5381;
712dd5e1e64d718a0aeaaf988a54d5acc0ec70f243Eric Christopher    for (unsigned i = 0, e = Str.size(); i != e; ++i)
722dd5e1e64d718a0aeaaf988a54d5acc0ec70f243Eric Christopher      h = ((h << 5) + h) + Str[i];
73bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    return h;
74bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  }
75bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
76bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Helper function to compute the number of buckets needed based on
77bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // the number of unique hashes.
785b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  void ComputeBucketCount(void);
7972c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher
80bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct TableHeader {
815b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint32_t magic;           // 'HASH' magic value to allow endian detection
825b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint16_t version;         // Version number.
835b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint16_t hash_function;   // The hash function enumeration that was used.
845b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint32_t bucket_count;    // The number of buckets in this hash table.
855b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint32_t hashes_count;    // The total number of unique hash values
865b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher                              // and hash data offsets in this table.
875b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    uint32_t header_data_len; // The bytes to skip to get to the hash
885b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher                              // indexes (buckets) for correct alignment.
89bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    // Also written to disk is the implementation specific header data.
90bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
91bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    static const uint32_t MagicHash = 0x48415348;
9272c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher
935b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    TableHeader(uint32_t data_len)
94577056f89c840537b059ea4cef8d2ae18513cda0Eric Christopher        : magic(MagicHash), version(1),
95577056f89c840537b059ea4cef8d2ae18513cda0Eric Christopher          hash_function(dwarf::DW_hash_function_djb), bucket_count(0),
96577056f89c840537b059ea4cef8d2ae18513cda0Eric Christopher          hashes_count(0), header_data_len(data_len) {}
97bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
98bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
99bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print(raw_ostream &O) {
100bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "Magic: " << format("0x%x", magic) << "\n"
101bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Version: " << version << "\n"
102bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Hash Function: " << hash_function << "\n"
103bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Bucket Count: " << bucket_count << "\n"
104bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Header Data Length: " << header_data_len << "\n";
105bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
106bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void dump() { print(dbgs()); }
107bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
108bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
109bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
110bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherpublic:
111bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // The HeaderData describes the form of each set of data. In general this
112bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // is as a list of atoms (atom_count) where each atom contains a type
113bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // (AtomType type) of data, and an encoding form (form). In the case of
114bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // data that is referenced via DW_FORM_ref_* the die_offset_base is
115bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // used to describe the offset for all forms in the list of atoms.
116bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // This also serves as a public interface of sorts.
117bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // When written to disk this will have the form:
118bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  //
119bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t die_offset_base
120bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t atom_count
12172c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher  // atom_count Atoms
12272c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher
123bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Make these public so that they can be used as a general interface to
124bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // the class.
125bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct Atom {
126577056f89c840537b059ea4cef8d2ae18513cda0Eric Christopher    uint16_t type; // enum AtomType
127bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint16_t form; // DWARF DW_FORM_ defines
128bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
129dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    LLVM_CONSTEXPR Atom(uint16_t type, uint16_t form)
130dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines        : type(type), form(form) {}
131bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
132bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print(raw_ostream &O) {
133577056f89c840537b059ea4cef8d2ae18513cda0Eric Christopher      O << "Type: " << dwarf::AtomTypeString(type) << "\n"
134bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Form: " << dwarf::FormEncodingString(form) << "\n";
135bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
1365b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    void dump() { print(dbgs()); }
137bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
138bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
139bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
1405b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopherprivate:
141bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct TableHeaderData {
142bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t die_offset_base;
14336c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer    SmallVector<Atom, 1> Atoms;
14436c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer
14536c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer    TableHeaderData(ArrayRef<Atom> AtomList, uint32_t offset = 0)
1465b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher        : die_offset_base(offset), Atoms(AtomList.begin(), AtomList.end()) {}
147bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
148bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
1495b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    void print(raw_ostream &O) {
150bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "die_offset_base: " << die_offset_base << "\n";
151bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      for (size_t i = 0; i < Atoms.size(); i++)
152bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        Atoms[i].print(O);
153bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
1545b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    void dump() { print(dbgs()); }
155bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
156bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
157bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
15809ac3d841367d5d56328eade506c951e0dc3a72dEric Christopher  // The data itself consists of a str_offset, a count of the DIEs in the
159bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // hash and the offsets to the DIEs themselves.
160bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // On disk each data section is ended with a 0 KeyType as the end of the
161bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // hash chain.
162bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // On output this looks like:
163bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t str_offset
164bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t hash_data_count
165bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // HashData[hash_data_count]
166c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopherpublic:
167c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher  struct HashDataContents {
16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    const DIE *Die;   // Offsets
169c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher    char Flags; // Specific flags to output
170c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher
17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    HashDataContents(const DIE *D, char Flags) : Die(D), Flags(Flags) {}
1725b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher#ifndef NDEBUG
173c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher    void print(raw_ostream &O) const {
174c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher      O << "  Offset: " << Die->getOffset() << "\n";
175c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher      O << "  Tag: " << dwarf::TagString(Die->getTag()) << "\n";
176c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher      O << "  Flags: " << Flags << "\n";
177c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher    }
1785b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher#endif
179c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher  };
1805b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher
181c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopherprivate:
182dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  // String Data
183dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  struct DataArray {
184dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    MCSymbol *StrSym;
185dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    std::vector<HashDataContents *> Values;
186dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    DataArray() : StrSym(nullptr) {}
187dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  };
188dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  friend struct HashData;
189bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct HashData {
190bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    StringRef Str;
191bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t HashValue;
192bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    MCSymbol *Sym;
193dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    DwarfAccelTable::DataArray &Data; // offsets
194dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    HashData(StringRef S, DwarfAccelTable::DataArray &Data)
1955b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher        : Str(S), Data(Data) {
1962dd5e1e64d718a0aeaaf988a54d5acc0ec70f243Eric Christopher      HashValue = DwarfAccelTable::HashDJB(S);
197bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
1985b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher#ifndef NDEBUG
199bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print(raw_ostream &O) {
200bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "Name: " << Str << "\n";
201bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "  Hash Value: " << format("0x%x", HashValue) << "\n";
2025b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher      O << "  Symbol: ";
2035b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher      if (Sym)
2045b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher        Sym->print(O);
2055b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher      else
2065b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher        O << "<none>";
207bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "\n";
208dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines      for (HashDataContents *C : Data.Values) {
209dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines        O << "  Offset: " << C->Die->getOffset() << "\n";
210dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines        O << "  Tag: " << dwarf::TagString(C->Die->getTag()) << "\n";
211dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines        O << "  Flags: " << C->Flags << "\n";
212c36145f19c1e164f7d630b813e9970600d8f2976Eric Christopher      }
213bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
2145b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher    void dump() { print(dbgs()); }
2155b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher#endif
216bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
217bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
2185b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  DwarfAccelTable(const DwarfAccelTable &) LLVM_DELETED_FUNCTION;
2195b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  void operator=(const DwarfAccelTable &) LLVM_DELETED_FUNCTION;
220bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
221bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Internal Functions
222bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitHeader(AsmPrinter *);
223bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitBuckets(AsmPrinter *);
224bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitHashes(AsmPrinter *);
225bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitOffsets(AsmPrinter *, MCSymbol *);
22636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void EmitData(AsmPrinter *, DwarfFile *D);
22736c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer
22836c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer  // Allocator for HashData and HashDataContents.
22936c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer  BumpPtrAllocator Allocator;
23036c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer
231bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Output Variables
232bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  TableHeader Header;
233bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  TableHeaderData HeaderData;
2345b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  std::vector<HashData *> Data;
235bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
2365b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  typedef StringMap<DataArray, BumpPtrAllocator &> StringEntries;
237bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  StringEntries Entries;
238bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
239bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Buckets/Hashes/Offsets
2405b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopher  typedef std::vector<HashData *> HashList;
241bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  typedef std::vector<HashList> BucketList;
242bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  BucketList Buckets;
243bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  HashList Hashes;
24472c1655e0af6c87ffe687bed1f4ed263b1165c06Eric Christopher
245bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Public Implementation
2465b9544b526fb655a8abcbb2034206e1a25aa4690Eric Christopherpublic:
24736c38b81f0938974c0b1b5fde0b838d51466a94fBenjamin Kramer  DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom>);
248dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  void AddName(StringRef Name, MCSymbol *StrSym, const DIE *Die,
249dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines               char Flags = 0);
25003406c4f15b3bf0522763fe848cd40f9598b74e8Benjamin Kramer  void FinalizeTable(AsmPrinter *, StringRef);
25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void Emit(AsmPrinter *, MCSymbol *, DwarfFile *);
252bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
253bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void print(raw_ostream &O);
254bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void dump() { print(dbgs()); }
255bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
256bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher};
257bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher}
258bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
259