]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lld/MachO/ExportTrie.h
Import lib9p 9d5aee77bcc1bf0e79b0a3bfefff5fdf2146283c.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lld / MachO / ExportTrie.h
1 //===- ExportTrie.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLD_MACHO_EXPORT_TRIE_H
10 #define LLD_MACHO_EXPORT_TRIE_H
11
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/STLExtras.h"
14
15 #include <vector>
16
17 namespace lld {
18 namespace macho {
19
20 struct TrieNode;
21 class Symbol;
22
23 class TrieBuilder {
24 public:
25   void addSymbol(const Symbol &sym) { exported.push_back(&sym); }
26   // Returns the size in bytes of the serialized trie.
27   size_t build();
28   void writeTo(uint8_t *buf) const;
29
30 private:
31   TrieNode *makeNode();
32   void sortAndBuild(llvm::MutableArrayRef<const Symbol *> vec, TrieNode *node,
33                     size_t lastPos, size_t pos);
34
35   std::vector<const Symbol *> exported;
36   std::vector<TrieNode *> nodes;
37 };
38
39 using TrieEntryCallback =
40     llvm::function_ref<void(const llvm::Twine & /*name*/, uint64_t /*flags*/)>;
41
42 void parseTrie(const uint8_t *buf, size_t size, const TrieEntryCallback &);
43
44 } // namespace macho
45 } // namespace lld
46
47 #endif