15ffd83dbSDimitry Andric //===- ExportTrie.h ---------------------------------------------*- C++ -*-===// 25ffd83dbSDimitry Andric // 35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ffd83dbSDimitry Andric // 75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 85ffd83dbSDimitry Andric 95ffd83dbSDimitry Andric #ifndef LLD_MACHO_EXPORT_TRIE_H 105ffd83dbSDimitry Andric #define LLD_MACHO_EXPORT_TRIE_H 115ffd83dbSDimitry Andric 125ffd83dbSDimitry Andric #include "llvm/ADT/ArrayRef.h" 135ffd83dbSDimitry Andric #include "llvm/ADT/STLExtras.h" 145ffd83dbSDimitry Andric 155ffd83dbSDimitry Andric #include <vector> 165ffd83dbSDimitry Andric 17*bdd1243dSDimitry Andric namespace lld::macho { 185ffd83dbSDimitry Andric 195ffd83dbSDimitry Andric struct TrieNode; 205ffd83dbSDimitry Andric class Symbol; 215ffd83dbSDimitry Andric 225ffd83dbSDimitry Andric class TrieBuilder { 235ffd83dbSDimitry Andric public: 2481ad6265SDimitry Andric ~TrieBuilder(); setImageBase(uint64_t addr)25e8d8bef9SDimitry Andric void setImageBase(uint64_t addr) { imageBase = addr; } addSymbol(const Symbol & sym)265ffd83dbSDimitry Andric void addSymbol(const Symbol &sym) { exported.push_back(&sym); } 275ffd83dbSDimitry Andric // Returns the size in bytes of the serialized trie. 285ffd83dbSDimitry Andric size_t build(); 295ffd83dbSDimitry Andric void writeTo(uint8_t *buf) const; 305ffd83dbSDimitry Andric 315ffd83dbSDimitry Andric private: 325ffd83dbSDimitry Andric TrieNode *makeNode(); 335ffd83dbSDimitry Andric void sortAndBuild(llvm::MutableArrayRef<const Symbol *> vec, TrieNode *node, 345ffd83dbSDimitry Andric size_t lastPos, size_t pos); 355ffd83dbSDimitry Andric 36e8d8bef9SDimitry Andric uint64_t imageBase = 0; 375ffd83dbSDimitry Andric std::vector<const Symbol *> exported; 385ffd83dbSDimitry Andric std::vector<TrieNode *> nodes; 395ffd83dbSDimitry Andric }; 405ffd83dbSDimitry Andric 415ffd83dbSDimitry Andric using TrieEntryCallback = 425ffd83dbSDimitry Andric llvm::function_ref<void(const llvm::Twine & /*name*/, uint64_t /*flags*/)>; 435ffd83dbSDimitry Andric 445ffd83dbSDimitry Andric void parseTrie(const uint8_t *buf, size_t size, const TrieEntryCallback &); 455ffd83dbSDimitry Andric 46*bdd1243dSDimitry Andric } // namespace lld::macho 475ffd83dbSDimitry Andric 485ffd83dbSDimitry Andric #endif 49