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
17 #include "llvm/ADT/iterator.h"
18 #include "llvm/ADT/Optional.h"
23 template <typename BaseLayerT,
24 typename LogicalModuleResources,
25 typename LogicalDylibResources>
28 typedef typename BaseLayerT::ModuleSetHandleT BaseLayerModuleSetHandleT;
31 typedef std::vector<BaseLayerModuleSetHandleT> BaseLayerHandleList;
33 struct LogicalModule {
34 LogicalModuleResources Resources;
35 BaseLayerHandleList BaseLayerHandles;
37 typedef std::vector<LogicalModule> LogicalModuleList;
41 typedef typename BaseLayerHandleList::iterator BaseLayerHandleIterator;
42 typedef typename LogicalModuleList::iterator LogicalModuleHandle;
44 LogicalDylib(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
47 for (auto &LM : LogicalModules)
48 for (auto BLH : LM.BaseLayerHandles)
49 BaseLayer.removeModuleSet(BLH);
52 LogicalModuleHandle createLogicalModule() {
53 LogicalModules.push_back(LogicalModule());
54 return std::prev(LogicalModules.end());
57 void addToLogicalModule(LogicalModuleHandle LMH,
58 BaseLayerModuleSetHandleT BaseLayerHandle) {
59 LMH->BaseLayerHandles.push_back(BaseLayerHandle);
62 LogicalModuleResources& getLogicalModuleResources(LogicalModuleHandle LMH) {
63 return LMH->Resources;
66 BaseLayerHandleIterator moduleHandlesBegin(LogicalModuleHandle LMH) {
67 return LMH->BaseLayerHandles.begin();
70 BaseLayerHandleIterator moduleHandlesEnd(LogicalModuleHandle LMH) {
71 return LMH->BaseLayerHandles.end();
74 JITSymbol findSymbolInLogicalModule(LogicalModuleHandle LMH,
75 const std::string &Name) {
76 for (auto BLH : LMH->BaseLayerHandles)
77 if (auto Symbol = BaseLayer.findSymbolIn(BLH, Name, false))
82 JITSymbol findSymbolInternally(LogicalModuleHandle LMH,
83 const std::string &Name) {
84 if (auto Symbol = findSymbolInLogicalModule(LMH, Name))
87 for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end();
90 if (auto Symbol = findSymbolInLogicalModule(LMI, Name))
97 JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
98 for (auto &LM : LogicalModules)
99 for (auto BLH : LM.BaseLayerHandles)
101 BaseLayer.findSymbolIn(BLH, Name, ExportedSymbolsOnly))
106 LogicalDylibResources& getDylibResources() { return DylibResources; }
109 BaseLayerT BaseLayer;
110 LogicalModuleList LogicalModules;
111 LogicalDylibResources DylibResources;
115 } // End namespace orc.
116 } // End namespace llvm.
118 #endif // LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H