OSDN Git Service

[ORC] Add a C API function to set the ExecutionSession error reporter.
authorLang Hames <lhames@gmail.com>
Thu, 1 Oct 2020 18:24:34 +0000 (11:24 -0700)
committerLang Hames <lhames@gmail.com>
Mon, 19 Oct 2020 08:59:03 +0000 (01:59 -0700)
llvm/include/llvm-c/Orc.h
llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp

index 8c620fa..50caae1 100644 (file)
@@ -46,10 +46,15 @@ typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef;
 /**
  * A reference to an orc::SymbolStringPool table entry.
  */
-typedef struct LLVMOrcQuaqueSymbolStringPoolEntryPtr
+typedef struct LLVMOrcOpaqueSymbolStringPoolEntry
     *LLVMOrcSymbolStringPoolEntryRef;
 
 /**
+ * Error reporter function.
+ */
+typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err);
+
+/**
  * A reference to an orc::JITDylib instance.
  */
 typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef;
@@ -93,6 +98,19 @@ typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef;
 typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef;
 
 /**
+ * Attach a custom error reporter function to the ExecutionSession.
+ *
+ * The error reporter will be called to deliver failure notices that can not be
+ * directly reported to a caller. For example, failure to resolve symbols in
+ * the JIT linker is typically reported via the error reporter (callers
+ * requesting definitions from the JIT will typically be delivered a
+ * FailureToMaterialize error instead).
+ */
+void LLVMOrcExecutionSessionSetErrorReporter(
+    LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
+    void *Ctx);
+
+/**
  * Intern a string in the ExecutionSession's SymbolStringPool and return a
  * reference to it. This increments the ref-count of the pool entry, and the
  * returned value should be released once the client is done with it by
index b0aa1cf..1179f67 100644 (file)
@@ -58,6 +58,13 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLJIT, LLVMOrcLLJITRef)
 
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
 
+void LLVMOrcExecutionSessionSetErrorReporter(
+    LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
+    void *Ctx) {
+  unwrap(ES)->setErrorReporter(
+      [=](Error Err) { ReportError(Ctx, wrap(std::move(Err))); });
+}
+
 LLVMOrcSymbolStringPoolEntryRef
 LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name) {
   return wrap(