1 //===- ModuleSymbolTable.h - symbol table for in-memory IR ----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This class represents a symbol table built from in-memory IR. It provides 11 // access to GlobalValues and should only be used if such access is required 12 // (e.g. in the LTO implementation). 13 // 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H 17 #define LLVM_OBJECT_MODULESYMBOLTABLE_H 18 19 #include "llvm/ADT/PointerUnion.h" 20 #include "llvm/ADT/Triple.h" 21 #include "llvm/IR/Mangler.h" 22 #include "llvm/Object/SymbolicFile.h" 23 #include <string> 24 #include <utility> 25 26 namespace llvm { 27 28 class GlobalValue; 29 class RecordStreamer; 30 31 class ModuleSymbolTable { 32 public: 33 typedef std::pair<std::string, uint32_t> AsmSymbol; 34 typedef PointerUnion<GlobalValue *, AsmSymbol *> Symbol; 35 36 private: 37 Module *FirstMod = nullptr; 38 39 SpecificBumpPtrAllocator<AsmSymbol> AsmSymbols; 40 std::vector<Symbol> SymTab; 41 Mangler Mang; 42 43 public: 44 ArrayRef<Symbol> symbols() const { return SymTab; } 45 void addModule(Module *M); 46 47 void printSymbolName(raw_ostream &OS, Symbol S) const; 48 uint32_t getSymbolFlags(Symbol S) const; 49 50 /// Parse inline ASM and collect the symbols that are defined or referenced in 51 /// the current module. 52 /// 53 /// For each found symbol, call \p AsmSymbol with the name of the symbol found 54 /// and the associated flags. 55 static void CollectAsmSymbols( 56 const Module &M, 57 function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol); 58 }; 59 60 } 61 62 #endif 63