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 175ffd83dbSDimitry Andric namespace lld { 185ffd83dbSDimitry Andric namespace macho { 195ffd83dbSDimitry Andric 205ffd83dbSDimitry Andric struct TrieNode; 215ffd83dbSDimitry Andric class Symbol; 225ffd83dbSDimitry Andric 235ffd83dbSDimitry Andric class TrieBuilder { 245ffd83dbSDimitry Andric public: 25*81ad6265SDimitry Andric ~TrieBuilder(); 26e8d8bef9SDimitry Andric void setImageBase(uint64_t addr) { imageBase = addr; } 275ffd83dbSDimitry Andric void addSymbol(const Symbol &sym) { exported.push_back(&sym); } 285ffd83dbSDimitry Andric // Returns the size in bytes of the serialized trie. 295ffd83dbSDimitry Andric size_t build(); 305ffd83dbSDimitry Andric void writeTo(uint8_t *buf) const; 315ffd83dbSDimitry Andric 325ffd83dbSDimitry Andric private: 335ffd83dbSDimitry Andric TrieNode *makeNode(); 345ffd83dbSDimitry Andric void sortAndBuild(llvm::MutableArrayRef<const Symbol *> vec, TrieNode *node, 355ffd83dbSDimitry Andric size_t lastPos, size_t pos); 365ffd83dbSDimitry Andric 37e8d8bef9SDimitry Andric uint64_t imageBase = 0; 385ffd83dbSDimitry Andric std::vector<const Symbol *> exported; 395ffd83dbSDimitry Andric std::vector<TrieNode *> nodes; 405ffd83dbSDimitry Andric }; 415ffd83dbSDimitry Andric 425ffd83dbSDimitry Andric using TrieEntryCallback = 435ffd83dbSDimitry Andric llvm::function_ref<void(const llvm::Twine & /*name*/, uint64_t /*flags*/)>; 445ffd83dbSDimitry Andric 455ffd83dbSDimitry Andric void parseTrie(const uint8_t *buf, size_t size, const TrieEntryCallback &); 465ffd83dbSDimitry Andric 475ffd83dbSDimitry Andric } // namespace macho 485ffd83dbSDimitry Andric } // namespace lld 495ffd83dbSDimitry Andric 505ffd83dbSDimitry Andric #endif 51