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::macho { |
18 | |
19 | struct TrieNode; |
20 | class Symbol; |
21 | |
22 | class TrieBuilder { |
23 | public: |
24 | ~TrieBuilder(); |
25 | void setImageBase(uint64_t addr) { imageBase = addr; } |
26 | void addSymbol(const Symbol &sym) { exported.push_back(x: &sym); } |
27 | // Returns the size in bytes of the serialized trie. |
28 | size_t build(); |
29 | void writeTo(uint8_t *buf) const; |
30 | |
31 | private: |
32 | TrieNode *makeNode(); |
33 | void sortAndBuild(llvm::MutableArrayRef<const Symbol *> vec, TrieNode *node, |
34 | size_t lastPos, size_t pos); |
35 | |
36 | uint64_t imageBase = 0; |
37 | std::vector<const Symbol *> exported; |
38 | std::vector<TrieNode *> nodes; |
39 | }; |
40 | |
41 | using TrieEntryCallback = |
42 | llvm::function_ref<void(const llvm::Twine & /*name*/, uint64_t /*flags*/)>; |
43 | |
44 | void parseTrie(const uint8_t *buf, size_t size, const TrieEntryCallback &); |
45 | |
46 | } // namespace lld::macho |
47 | |
48 | #endif |
49 | |