1 //===--- LogicalDylib.h - Simulates dylib-style symbol lookup ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Simulates symbol resolution inside a dylib.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
15 #define LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
20 template <typename BaseLayerT,
21 typename LogicalModuleResources,
22 typename LogicalDylibResources>
25 typedef typename BaseLayerT::ModuleSetHandleT BaseLayerModuleSetHandleT;
28 typedef std::vector<BaseLayerModuleSetHandleT> BaseLayerHandleList;
30 struct LogicalModule {
31 // Make this move-only to ensure they don't get duplicated across moves of
32 // LogicalDylib or anything like that.
33 LogicalModule(LogicalModule &&) = default;
34 LogicalModule() = default;
35 LogicalModuleResources Resources;
36 BaseLayerHandleList BaseLayerHandles;
38 typedef std::vector<LogicalModule> LogicalModuleList;
42 typedef typename BaseLayerHandleList::iterator BaseLayerHandleIterator;
43 typedef typename LogicalModuleList::iterator LogicalModuleHandle;
45 LogicalDylib(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
48 for (auto &LM : LogicalModules)
49 for (auto BLH : LM.BaseLayerHandles)
50 BaseLayer.removeModuleSet(BLH);
53 // If possible, remove this and ~LogicalDylib once the work in the dtor is
54 // moved to members (eg: self-unregistering base layer handles).
55 LogicalDylib(LogicalDylib &&RHS) = default;
57 LogicalModuleHandle createLogicalModule() {
58 LogicalModules.push_back(LogicalModule());
59 return std::prev(LogicalModules.end());
62 void addToLogicalModule(LogicalModuleHandle LMH,
63 BaseLayerModuleSetHandleT BaseLayerHandle) {
64 LMH->BaseLayerHandles.push_back(BaseLayerHandle);
67 LogicalModuleResources& getLogicalModuleResources(LogicalModuleHandle LMH) {
68 return LMH->Resources;
71 BaseLayerHandleIterator moduleHandlesBegin(LogicalModuleHandle LMH) {
72 return LMH->BaseLayerHandles.begin();
75 BaseLayerHandleIterator moduleHandlesEnd(LogicalModuleHandle LMH) {
76 return LMH->BaseLayerHandles.end();
79 JITSymbol findSymbolInLogicalModule(LogicalModuleHandle LMH,
80 const std::string &Name) {
81 for (auto BLH : LMH->BaseLayerHandles)
82 if (auto Symbol = BaseLayer.findSymbolIn(BLH, Name, false))
87 JITSymbol findSymbolInternally(LogicalModuleHandle LMH,
88 const std::string &Name) {
89 if (auto Symbol = findSymbolInLogicalModule(LMH, Name))
92 for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end();
95 if (auto Symbol = findSymbolInLogicalModule(LMI, Name))
102 JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
103 for (auto &LM : LogicalModules)
104 for (auto BLH : LM.BaseLayerHandles)
106 BaseLayer.findSymbolIn(BLH, Name, ExportedSymbolsOnly))
111 LogicalDylibResources& getDylibResources() { return DylibResources; }
114 BaseLayerT BaseLayer;
115 LogicalModuleList LogicalModules;
116 LogicalDylibResources DylibResources;
120 } // End namespace orc.
121 } // End namespace llvm.
123 #endif // LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H