From 57f45392e2439a9251d1a267ccf0a62c0bf36c0d Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Wed, 16 Apr 2014 17:45:04 +0000 Subject: 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 --- lib/IR/Core.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib/IR/Core.cpp') 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(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 ---------------------------------------------===*/ -- cgit v1.2.3