blob: aa7e3b0d4a14b17c51013184afd342f3375f09a1 [file] [log] [blame]
Jez Ng9854edd2020-04-29 22:42:191//===- 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"
Jez Ng7bbdbacd2020-04-23 03:00:5713#include "llvm/ADT/STLExtras.h"
Jez Ng9854edd2020-04-29 22:42:1914
15#include <vector>
16
Nico Weberbf20d432022-08-07 14:37:4917namespace lld::macho {
Jez Ng9854edd2020-04-29 22:42:1918
19struct TrieNode;
20class Symbol;
21
22class TrieBuilder {
23public:
Vy Nguyen0d5e2762022-03-14 22:41:5724 ~TrieBuilder();
Jez Ngabd70fb2020-09-16 18:20:1025 void setImageBase(uint64_t addr) { imageBase = addr; }
Jez Ng9854edd2020-04-29 22:42:1926 void addSymbol(const Symbol &sym) { exported.push_back(&sym); }
27 // Returns the size in bytes of the serialized trie.
28 size_t build();
Kellie Medlin6cb07312020-05-01 23:29:0629 void writeTo(uint8_t *buf) const;
Jez Ng9854edd2020-04-29 22:42:1930
31private:
32 TrieNode *makeNode();
33 void sortAndBuild(llvm::MutableArrayRef<const Symbol *> vec, TrieNode *node,
34 size_t lastPos, size_t pos);
35
Jez Ngabd70fb2020-09-16 18:20:1036 uint64_t imageBase = 0;
Jez Ng9854edd2020-04-29 22:42:1937 std::vector<const Symbol *> exported;
38 std::vector<TrieNode *> nodes;
39};
40
Jez Ng7bbdbacd2020-04-23 03:00:5741using TrieEntryCallback =
42 llvm::function_ref<void(const llvm::Twine & /*name*/, uint64_t /*flags*/)>;
43
44void parseTrie(const uint8_t *buf, size_t size, const TrieEntryCallback &);
45
Nico Weberbf20d432022-08-07 14:37:4946} // namespace lld::macho
Jez Ng9854edd2020-04-29 22:42:1947
48#endif