mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[ORC] Add convenience methods for creating DynamicLibraryFallbackGenerators for
libraries on disk, and for the current process. Avoids more boilerplate during JIT construction. llvm-svn: 343430
This commit is contained in:
parent
5ecad6afdc
commit
58ae100bfa
@ -215,8 +215,32 @@ public:
|
||||
class DynamicLibraryFallbackGenerator {
|
||||
public:
|
||||
using SymbolPredicate = std::function<bool(SymbolStringPtr)>;
|
||||
|
||||
static bool AllowAll(SymbolStringPtr Name) { return true; }
|
||||
|
||||
/// Create a DynamicLibraryFallbackGenerator that searches for symbols in the
|
||||
/// given sys::DynamicLibrary.
|
||||
/// Only symbols that match the 'Allow' predicate will be searched for.
|
||||
DynamicLibraryFallbackGenerator(sys::DynamicLibrary Dylib,
|
||||
const DataLayout &DL, SymbolPredicate Allow);
|
||||
const DataLayout &DL,
|
||||
SymbolPredicate Allow = AllowAll);
|
||||
|
||||
/// Permanently loads the library at the given path and, on success, returns
|
||||
/// a DynamicLibraryFallbackGenerator that will search it for symbol
|
||||
/// definitions matching the Allow predicate.
|
||||
/// On failure returns the reason the library failed to load.
|
||||
static Expected<DynamicLibraryFallbackGenerator>
|
||||
Load(const char *FileName, const DataLayout &DL,
|
||||
SymbolPredicate Allow = AllowAll);
|
||||
|
||||
/// Creates a DynamicLibraryFallbackGenerator that searches for symbols in
|
||||
/// the current process.
|
||||
static Expected<DynamicLibraryFallbackGenerator>
|
||||
CreateForCurrentProcess(const DataLayout &DL,
|
||||
SymbolPredicate Allow = AllowAll) {
|
||||
return Load(nullptr, DL, std::move(Allow));
|
||||
}
|
||||
|
||||
SymbolNameSet operator()(JITDylib &JD, const SymbolNameSet &Names);
|
||||
|
||||
private:
|
||||
|
@ -174,6 +174,15 @@ DynamicLibraryFallbackGenerator::DynamicLibraryFallbackGenerator(
|
||||
: Dylib(std::move(Dylib)), Allow(std::move(Allow)),
|
||||
GlobalPrefix(DL.getGlobalPrefix()) {}
|
||||
|
||||
Expected<DynamicLibraryFallbackGenerator> DynamicLibraryFallbackGenerator::Load(
|
||||
const char *FileName, const DataLayout &DL, SymbolPredicate Allow) {
|
||||
std::string ErrMsg;
|
||||
auto Lib = sys::DynamicLibrary::getPermanentLibrary(FileName, &ErrMsg);
|
||||
if (!Lib.isValid())
|
||||
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
|
||||
return DynamicLibraryFallbackGenerator(std::move(Lib), DL, std::move(Allow));
|
||||
}
|
||||
|
||||
SymbolNameSet DynamicLibraryFallbackGenerator::
|
||||
operator()(JITDylib &JD, const SymbolNameSet &Names) {
|
||||
orc::SymbolNameSet Added;
|
||||
|
@ -752,15 +752,6 @@ static orc::IRTransformLayer2::TransformFunction createDebugDumper() {
|
||||
int runOrcLazyJIT(const char *ProgName) {
|
||||
// Start setting up the JIT environment.
|
||||
|
||||
// First add lli's symbols into the JIT's search space.
|
||||
std::string ErrMsg;
|
||||
sys::DynamicLibrary LibLLI =
|
||||
sys::DynamicLibrary::getPermanentLibrary(nullptr, &ErrMsg);
|
||||
if (!LibLLI.isValid()) {
|
||||
errs() << "Error loading lli symbols: " << ErrMsg << ".\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse the main module.
|
||||
orc::ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
|
||||
SMDiagnostic Err;
|
||||
@ -802,9 +793,8 @@ int runOrcLazyJIT(const char *ProgName) {
|
||||
}
|
||||
return Dump(std::move(TSM), R);
|
||||
});
|
||||
J->getMainJITDylib().setFallbackDefinitionGenerator(
|
||||
orc::DynamicLibraryFallbackGenerator(
|
||||
std::move(LibLLI), DL, [](orc::SymbolStringPtr) { return true; }));
|
||||
J->getMainJITDylib().setFallbackDefinitionGenerator(ExitOnErr(
|
||||
orc::DynamicLibraryFallbackGenerator::CreateForCurrentProcess(DL)));
|
||||
|
||||
orc::MangleAndInterner Mangle(J->getExecutionSession(), DL);
|
||||
orc::LocalCXXRuntimeOverrides2 CXXRuntimeOverrides;
|
||||
|
Loading…
Reference in New Issue
Block a user