LLVM  3.7.0
LogicalDylib.h
Go to the documentation of this file.
1 //===--- LogicalDylib.h - Simulates dylib-style symbol lookup ---*- C++ -*-===//
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 // Simulates symbol resolution inside a dylib.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
15 #define LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
16 
17 namespace llvm {
18 namespace orc {
19 
20 template <typename BaseLayerT,
21  typename LogicalModuleResources,
22  typename LogicalDylibResources>
23 class LogicalDylib {
24 public:
25  typedef typename BaseLayerT::ModuleSetHandleT BaseLayerModuleSetHandleT;
26 private:
27 
28  typedef std::vector<BaseLayerModuleSetHandleT> BaseLayerHandleList;
29 
30  struct LogicalModule {
31  LogicalModuleResources Resources;
32  BaseLayerHandleList BaseLayerHandles;
33  };
34  typedef std::vector<LogicalModule> LogicalModuleList;
35 
36 public:
37 
38  typedef typename BaseLayerHandleList::iterator BaseLayerHandleIterator;
39  typedef typename LogicalModuleList::iterator LogicalModuleHandle;
40 
41  LogicalDylib(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
42 
44  for (auto &LM : LogicalModules)
45  for (auto BLH : LM.BaseLayerHandles)
46  BaseLayer.removeModuleSet(BLH);
47  }
48 
50  LogicalModules.push_back(LogicalModule());
51  return std::prev(LogicalModules.end());
52  }
53 
55  BaseLayerModuleSetHandleT BaseLayerHandle) {
56  LMH->BaseLayerHandles.push_back(BaseLayerHandle);
57  }
58 
59  LogicalModuleResources& getLogicalModuleResources(LogicalModuleHandle LMH) {
60  return LMH->Resources;
61  }
62 
64  return LMH->BaseLayerHandles.begin();
65  }
66 
68  return LMH->BaseLayerHandles.end();
69  }
70 
72  const std::string &Name) {
73  for (auto BLH : LMH->BaseLayerHandles)
74  if (auto Symbol = BaseLayer.findSymbolIn(BLH, Name, false))
75  return Symbol;
76  return nullptr;
77  }
78 
80  const std::string &Name) {
81  if (auto Symbol = findSymbolInLogicalModule(LMH, Name))
82  return Symbol;
83 
84  for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end();
85  LMI != LME; ++LMI) {
86  if (LMI != LMH)
87  if (auto Symbol = findSymbolInLogicalModule(LMI, Name))
88  return Symbol;
89  }
90 
91  return nullptr;
92  }
93 
94  JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
95  for (auto &LM : LogicalModules)
96  for (auto BLH : LM.BaseLayerHandles)
97  if (auto Symbol =
98  BaseLayer.findSymbolIn(BLH, Name, ExportedSymbolsOnly))
99  return Symbol;
100  return nullptr;
101  }
102 
103  LogicalDylibResources& getDylibResources() { return DylibResources; }
104 
105 protected:
106  BaseLayerT BaseLayer;
107  LogicalModuleList LogicalModules;
108  LogicalDylibResources DylibResources;
109 
110 };
111 
112 } // End namespace orc.
113 } // End namespace llvm.
114 
115 #endif // LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
LogicalModuleResources & getLogicalModuleResources(LogicalModuleHandle LMH)
Definition: LogicalDylib.h:59
BaseLayerHandleIterator moduleHandlesBegin(LogicalModuleHandle LMH)
Definition: LogicalDylib.h:63
void addToLogicalModule(LogicalModuleHandle LMH, BaseLayerModuleSetHandleT BaseLayerHandle)
Definition: LogicalDylib.h:54
LogicalDylib(BaseLayerT &BaseLayer)
Definition: LogicalDylib.h:41
LogicalDylibResources & getDylibResources()
Definition: LogicalDylib.h:103
Represents a symbol in the JIT.
Definition: JITSymbol.h:29
BaseLayerHandleIterator moduleHandlesEnd(LogicalModuleHandle LMH)
Definition: LogicalDylib.h:67
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly)
Definition: LogicalDylib.h:94
LogicalModuleHandle createLogicalModule()
Definition: LogicalDylib.h:49
BaseLayerT::ModuleSetHandleT BaseLayerModuleSetHandleT
Definition: LogicalDylib.h:25
LogicalModuleList::iterator LogicalModuleHandle
Definition: LogicalDylib.h:39
LogicalDylibResources DylibResources
Definition: LogicalDylib.h:108
BaseLayerHandleList::iterator BaseLayerHandleIterator
Definition: LogicalDylib.h:38
LogicalModuleList LogicalModules
Definition: LogicalDylib.h:107
JITSymbol findSymbolInternally(LogicalModuleHandle LMH, const std::string &Name)
Definition: LogicalDylib.h:79
JITSymbol findSymbolInLogicalModule(LogicalModuleHandle LMH, const std::string &Name)
Definition: LogicalDylib.h:71