[Support] Add a C-API function to create a StringError instance.
authorLang Hames <lhames@gmail.com>
Fri, 16 Oct 2020 00:31:14 +0000 (17:31 -0700)
committerLang Hames <lhames@gmail.com>
Mon, 19 Oct 2020 08:59:04 +0000 (01:59 -0700)
This will allow C API clients to return errors from callbacks. This
functionality will be used in upcoming Orc C-bindings functions.

llvm/include/llvm-c/Error.h
llvm/lib/Support/Error.cpp

index 92f81bf..bc702ac 100644 (file)
@@ -62,6 +62,11 @@ void LLVMDisposeErrorMessage(char *ErrMsg);
  */
 LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
 
+/**
+ * Create a StringError.
+ */
+LLVMErrorRef LLVMCreateStringError(const char *ErrMsg);
+
 LLVM_C_EXTERN_C_END
 
 #endif
index 315a11e..e7ab438 100644 (file)
@@ -168,3 +168,7 @@ void LLVMDisposeErrorMessage(char *ErrMsg) { delete[] ErrMsg; }
 LLVMErrorTypeId LLVMGetStringErrorTypeId() {
   return reinterpret_cast<void *>(&StringError::ID);
 }
+
+LLVMErrorRef LLVMCreateStringError(const char *ErrMsg) {
+  return wrap(make_error<StringError>(ErrMsg, inconvertibleErrorCode()));
+}