diff options
author | Lang Hames <lhames@gmail.com> | 2018-08-15 18:42:11 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-08-15 18:42:11 +0000 |
commit | 00fb14da274efc35afa4eba6019050bbcf605ead (patch) | |
tree | 4bc31d4a6a20d3091c7406ba15bafcca3d3bfc5f /llvm/lib/Support/Error.cpp | |
parent | 5222cb601b9a04df93cc3603ede80cc0e3dc9940 (diff) | |
download | llvm-00fb14da274efc35afa4eba6019050bbcf605ead.zip llvm-00fb14da274efc35afa4eba6019050bbcf605ead.tar.gz llvm-00fb14da274efc35afa4eba6019050bbcf605ead.tar.bz2 |
[Support] Add a basic C API for llvm::Error.
Summary:
The C-API supports consuming errors, converting an error to a string error
message, and querying an error's type. Other LLVM C APIs that wish to use
llvm::Error can supply error-type-id checkers and custom
error-to-structured-type converters for any custom errors they provide.
Reviewers: bogner, zturner, labath, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D50716
llvm-svn: 339802
Diffstat (limited to 'llvm/lib/Support/Error.cpp')
-rw-r--r-- | llvm/lib/Support/Error.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp index 83345bf..d66e0e5 100644 --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -126,6 +126,26 @@ void report_fatal_error(Error Err, bool GenCrashDiag) { report_fatal_error(ErrMsg); } +} // end namespace llvm + +LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err) { + return reinterpret_cast<ErrorInfoBase *>(Err)->dynamicClassID(); +} + +void LLVMConsumeError(LLVMErrorRef Err) { consumeError(unwrap(Err)); } + +char *LLVMGetErrorMessage(LLVMErrorRef Err) { + std::string Tmp = toString(unwrap(Err)); + char *ErrMsg = new char[Tmp.size() + 1]; + memcpy(ErrMsg, Tmp.data(), Tmp.size()); + ErrMsg[Tmp.size()] = '\0'; + return ErrMsg; +} + +void LLVMDisposeErrorMessage(char *ErrMsg) { delete[] ErrMsg; } + +LLVMErrorTypeId LLVMGetStringErrorTypeId() { + return reinterpret_cast<void *>(&StringError::ID); } #ifndef _MSC_VER |