DwarfAccelTable.h revision bcbd3a4637f33036d05833364e180f9dfaabb67c
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
17bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/ADT/StringMap.h"
18bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/MC/MCSymbol.h"
19bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/Dwarf.h"
20bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/DataTypes.h"
21bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/Debug.h"
22bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/ErrorHandling.h"
23bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/Format.h"
24bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include "llvm/Support/FormattedStream.h"
25bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include <vector>
26bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#include <map>
27bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
28bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// The apple dwarf accelerator tables are an indirect hash table optimized
29bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// for null lookup rather than access to known data. They are output into
30bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// an on-disk format that looks like this:
31bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
32bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// .-------------.
33bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  HEADER     |
34bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
35bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  BUCKETS    |
36bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
37bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  HASHES     |
38bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
39bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  OFFSETS    |
40bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |-------------|
41bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// |  DATA       |
42bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// `-------------'
43bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
44bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// where the header contains a magic number, version, type of hash function,
45bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// the number of buckets, total number of hashes, and room for a special
46bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// struct of data and the length of that struct.
47bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
48bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// The buckets contain an index (e.g. 6) into the hashes array. The hashes
49bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// section contains all of the 32-bit hash values in contiguous memory, and
50bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// the offsets contain the offset into the data area for the particular
51bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// hash.
52bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher//
53bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// For a lookup example, we could hash a function name and take it modulo the
54bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// number of buckets giving us our bucket. From there we take the bucket value
55bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// as an index into the hashes table and look at each successive hash as long
56bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// as the hash value is still the same modulo result (bucket value) as earlier.
57bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// If we have a match we look at that same entry in the offsets table and
58bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher// grab the offset in the data for our final match.
59bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
60bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christophernamespace llvm {
61bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
62bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherclass AsmPrinter;
63bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherclass DIE;
64bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherclass DwarfDebug;
65bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
66bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherclass DwarfAccelTable {
67bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
68bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  enum HashFunctionType {
69bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eHashFunctionDJB = 0u
70bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
71bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
72bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  static uint32_t HashDJB (const char *s) {
73bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t h = 5381;
74bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    for (unsigned char c = *s; c; c = *++s)
75bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      h = ((h << 5) + h) + c;
76bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    return h;
77bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  }
78bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
79bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Helper function to compute the number of buckets needed based on
80bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // the number of unique hashes.
81bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void ComputeBucketCount (void);
82bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
83bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct TableHeader {
84bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t   magic;           // 'HASH' magic value to allow endian detection
85bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint16_t   version;         // Version number.
86bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint16_t   hash_function;   // The hash function enumeration that was used.
87bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t   bucket_count;    // The number of buckets in this hash table.
88bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t   hashes_count;    // The total number of unique hash values
89bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher                                // and hash data offsets in this table.
90bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t   header_data_len; // The bytes to skip to get to the hash
91bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher                                // indexes (buckets) for correct alignment.
92bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    // Also written to disk is the implementation specific header data.
93bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
94bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    static const uint32_t MagicHash = 0x48415348;
95bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
96bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    TableHeader (uint32_t data_len) :
97bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      magic (MagicHash), version (1), hash_function (eHashFunctionDJB),
98bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      bucket_count (0), hashes_count (0), header_data_len (data_len)
99bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    {};
100bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
101bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
102bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print(raw_ostream &O) {
103bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "Magic: " << format("0x%x", magic) << "\n"
104bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Version: " << version << "\n"
105bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Hash Function: " << hash_function << "\n"
106bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Bucket Count: " << bucket_count << "\n"
107bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Header Data Length: " << header_data_len << "\n";
108bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
109bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void dump() { print(dbgs()); }
110bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
111bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
112bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
113bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopherpublic:
114bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // The HeaderData describes the form of each set of data. In general this
115bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // is as a list of atoms (atom_count) where each atom contains a type
116bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // (AtomType type) of data, and an encoding form (form). In the case of
117bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // data that is referenced via DW_FORM_ref_* the die_offset_base is
118bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // used to describe the offset for all forms in the list of atoms.
119bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // This also serves as a public interface of sorts.
120bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // When written to disk this will have the form:
121bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  //
122bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t die_offset_base
123bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t atom_count
124bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // atom_count Atoms
125bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  enum AtomType {
126bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeNULL       = 0u,
127bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeDIEOffset  = 1u,   // DIE offset, check form for encoding
128bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeCUOffset   = 2u,   // DIE offset of the compiler unit header that
129bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher                                // contains the item in question
130bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeTag        = 3u,   // DW_TAG_xxx value, should be encoded as
131bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher                                // DW_FORM_data1 (if no tags exceed 255) or
132bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher                                // DW_FORM_data2.
133bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeNameFlags  = 4u,   // Flags from enum NameFlags
134bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    eAtomTypeTypeFlags  = 5u    // Flags from enum TypeFlags
135bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
136bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
137bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Make these public so that they can be used as a general interface to
138bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // the class.
139bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct Atom {
140bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    AtomType type; // enum AtomType
141bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint16_t form; // DWARF DW_FORM_ defines
142bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
143bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    Atom(AtomType type, uint16_t form) : type(type), form(form) {};
144bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    static const char * AtomTypeString(enum AtomType);
145bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
146bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print(raw_ostream &O) {
147bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "Type: " << dwarf::TagString(type) << "\n"
148bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        << "Form: " << dwarf::FormEncodingString(form) << "\n";
149bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
150bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void dump() {
151bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      print(dbgs());
152bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
153bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
154bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
155bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
156bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher private:
157bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct TableHeaderData {
158bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
159bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t die_offset_base;
160bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    std::vector<Atom> Atoms;
161bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
162bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    TableHeaderData(DwarfAccelTable::Atom Atom, uint32_t offset = 0)
163bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    : die_offset_base(offset) {
164bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      Atoms.push_back(Atom);
165bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
166bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
167bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
168bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void print (raw_ostream &O) {
169bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "die_offset_base: " << die_offset_base << "\n";
170bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      for (size_t i = 0; i < Atoms.size(); i++)
171bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        Atoms[i].print(O);
172bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
173bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void dump() {
174bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      print(dbgs());
175bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
176bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
177bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
178bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
179bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // The data itself consists of a str_offset (to deal with collisions in
180bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // some magical way? this looks like the KeyType from the spec, which
181bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // should mean an integer compare on read), a count of the DIEs in the
182bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // hash and the offsets to the DIEs themselves.
183bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // On disk each data section is ended with a 0 KeyType as the end of the
184bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // hash chain.
185bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // On output this looks like:
186bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t str_offset
187bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // uint32_t hash_data_count
188bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // HashData[hash_data_count]
189bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  struct HashData {
190bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    StringRef Str;
191bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    uint32_t HashValue;
192bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    MCSymbol *Sym;
193bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    std::vector<uint32_t> DIEOffsets; // offsets
194bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    HashData(StringRef S) : Str(S) {
195bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      HashValue = DwarfAccelTable::HashDJB(S.str().c_str());
196bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
197bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void addOffset(uint32_t off) { DIEOffsets.push_back(off); }
198bcbd3a4637f33036d05833364e180f9dfaabb67cEric 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";
202bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "  Symbol: " ;
203bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      if (Sym) Sym->print(O);
204bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      else O << "<none>";
205bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      O << "\n";
206bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      for (size_t i = 0; i < DIEOffsets.size(); i++)
207bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher        O << "  Offset: " << DIEOffsets[i] << "\n";
208bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
209bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    void dump() {
210bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher      print(dbgs());
211bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    }
212bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher    #endif
213bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  };
214bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
215bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  DwarfAccelTable(const DwarfAccelTable&); // DO NOT IMPLEMENT
216bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void operator=(const DwarfAccelTable&);  // DO NOT IMPLEMENT
217bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
218bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Internal Functions
219bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitHeader(AsmPrinter *);
220bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitBuckets(AsmPrinter *);
221bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitHashes(AsmPrinter *);
222bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitOffsets(AsmPrinter *, MCSymbol *);
223bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void EmitData(AsmPrinter *, DwarfDebug *D);
224bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
225bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Output Variables
226bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  TableHeader Header;
227bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  TableHeaderData HeaderData;
228bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  std::vector<HashData*> Data;
229bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
230bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // String Data
231bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  typedef std::vector<DIE*> DIEArray;
232bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  typedef StringMap<DIEArray> StringEntries;
233bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  StringEntries Entries;
234bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
235bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Buckets/Hashes/Offsets
236bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  typedef std::vector<HashData*> HashList;
237bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  typedef std::vector<HashList> BucketList;
238bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  BucketList Buckets;
239bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  HashList Hashes;
240bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
241bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  // Public Implementation
242bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher public:
243bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  DwarfAccelTable(DwarfAccelTable::Atom Atom);
244bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void AddName(StringRef, DIE*);
245bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void FinalizeTable(AsmPrinter *, const char *);
246bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void Emit(AsmPrinter *, MCSymbol *, DwarfDebug *);
247bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#ifndef NDEBUG
248bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void print(raw_ostream &O);
249bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher  void dump() { print(dbgs()); }
250bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
251bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher};
252bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher
253bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher}
254bcbd3a4637f33036d05833364e180f9dfaabb67cEric Christopher#endif
255