diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2014-04-16 17:45:04 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2014-04-16 17:45:04 +0000 |
commit | 57f45392e2439a9251d1a267ccf0a62c0bf36c0d (patch) | |
tree | cb1f03f4b8e0e372d349d148c8abfb4e4f3f9c60 /lib/IR/Core.cpp | |
parent | 8cafc53ee45880107c8a2a3b0e3f23e830e0ffaf (diff) | |
download | llvm-57f45392e2439a9251d1a267ccf0a62c0bf36c0d.tar.gz llvm-57f45392e2439a9251d1a267ccf0a62c0bf36c0d.tar.bz2 llvm-57f45392e2439a9251d1a267ccf0a62c0bf36c0d.tar.xz |
Added new functionality to LLVM C API to use DiagnosticInfo to handle errors
Patch by: Darren Powell
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/Core.cpp')
-rw-r--r-- | lib/IR/Core.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index a9cef5c69f..81aa402b30 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -17,6 +17,8 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" @@ -76,6 +78,14 @@ LLVMContextRef LLVMGetGlobalContext() { return wrap(&getGlobalContext()); } +void LLVMContextSetDiagnosticHandler(LLVMContextRef C, + LLVMDiagnosticHandler Handler, + void *DiagnosticContext) { + unwrap(C)->setDiagnosticHandler( + LLVM_EXTENSION reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(Handler), + DiagnosticContext); +} + void LLVMContextDispose(LLVMContextRef C) { delete unwrap(C); } @@ -89,6 +99,40 @@ unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) { return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen); } +char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) { + std::string MsgStorage; + raw_string_ostream Stream(MsgStorage); + DiagnosticPrinterRawOStream DP(Stream); + + unwrap(DI)->print(DP); + Stream.flush(); + + return LLVMCreateMessage(MsgStorage.c_str()); +} + +LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){ + LLVMDiagnosticSeverity severity; + + switch(unwrap(DI)->getSeverity()) { + default: + severity = LLVMDSError; + break; + case DS_Warning: + severity = LLVMDSWarning; + break; + case DS_Remark: + severity = LLVMDSRemark; + break; + case DS_Note: + severity = LLVMDSNote; + break; + } + + return severity; +} + + + /*===-- Operations on modules ---------------------------------------------===*/ |