| 2098 | }; |
| 2099 | |
| 2100 | class OrcThreadSafeModule { |
| 2101 | public: |
| 2102 | constexpr OrcThreadSafeModule() noexcept = default; |
| 2103 | constexpr OrcThreadSafeModule(LLVMOrcThreadSafeModuleRef R) noexcept |
| 2104 | : Ref(R) {} |
| 2105 | OrcThreadSafeModule(const OrcThreadSafeModule &) = delete; |
| 2106 | OrcThreadSafeModule &operator=(const OrcThreadSafeModule &) = delete; |
| 2107 | OrcThreadSafeModule(OrcThreadSafeModule &&B) noexcept |
| 2108 | : OrcThreadSafeModule() { |
| 2109 | swap(*this, B); |
| 2110 | } |
| 2111 | OrcThreadSafeModule &operator=(OrcThreadSafeModule &&B) noexcept { |
| 2112 | swap(*this, B); |
| 2113 | return *this; |
| 2114 | } |
| 2115 | |
| 2116 | OrcThreadSafeModule(Module &&M, OrcThreadSafeContext &C) noexcept |
| 2117 | : Ref(LLVMOrcCreateNewThreadSafeModule(M.release(), C.unwrap())) {} |
| 2118 | ~OrcThreadSafeModule() noexcept { LLVMOrcDisposeThreadSafeModule(Ref); } |
| 2119 | |
| 2120 | constexpr operator bool() const noexcept { return Ref != nullptr; } |
| 2121 | constexpr auto &unwrap() const noexcept { return Ref; } |
| 2122 | constexpr auto &unwrap() noexcept { return Ref; } |
| 2123 | LLVMOrcThreadSafeModuleRef release() noexcept { |
| 2124 | return std::exchange(Ref, nullptr); |
| 2125 | } |
| 2126 | friend void swap(OrcThreadSafeModule &LHS, |
| 2127 | OrcThreadSafeModule &RHS) noexcept { |
| 2128 | using std::swap; |
| 2129 | swap(LHS.Ref, RHS.Ref); |
| 2130 | } |
| 2131 | Error withModuleDo(LLVMOrcGenericIRModuleOperationFunction F, |
| 2132 | void *Ctx) noexcept { |
| 2133 | return LLVMOrcThreadSafeModuleWithModuleDo(Ref, F, Ctx); |
| 2134 | } |
| 2135 | |
| 2136 | private: |
| 2137 | LLVMOrcThreadSafeModuleRef Ref = nullptr; |
| 2138 | }; |
| 2139 | |
| 2140 | class OrcJITDylib { |
| 2141 | public: |