<div dir="ltr">Why not expose severity?  That seems like one of the more stable aspects of our diagnostics.  Besides, it's just another enum that we promise to keep stable.</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Apr 4, 2014 at 10:59 AM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'd very much prefer not to expose the severity for now. This is a<br>
fairly well thought out, but very new interface and we guarantee<br>
stability of the C interface so we'd be locking the current severity<br>
interface down.<br>
<br>
I'm not, honestly, a huge fan of opening this up to the C API in<br>
general - is there a good reason to do so?<br>
<span class="HOEnZb"><font color="#888888"><br>
-eric<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Fri, Apr 4, 2014 at 10:39 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com">qcolombet@apple.com</a>> wrote:<br>
> Hi Darren,<br>
><br>
> This LGTM with two comments:<br>
> - LLVMPrintDiagInfoToString should state that the string has to be freed<br>
> (see inline comment).<br>
> - Should we provide an API to expose the severity as well? What would do the<br>
> users of LLVMPrintDiagInfoToString if we do not?<br>
><br>
> Note that I'm not super familiar with the C API, so you may want to wait for<br>
> another review.<br>
><br>
> Thanks,<br>
> -Quentin<br>
><br>
> On Apr 2, 2014, at 8:32 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br>
><br>
> From: Darren Powell <<a href="mailto:darren.powell@amd.com">darren.powell@amd.com</a>><br>
><br>
> ---<br>
> include/llvm-c/Core.h            | 20 ++++++++++++++++++++<br>
> include/llvm/IR/DiagnosticInfo.h |  3 +++<br>
> lib/IR/Core.cpp                  | 20 ++++++++++++++++++++<br>
> 3 files changed, 43 insertions(+)<br>
><br>
> diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h<br>
> index 50c5e3a..17367ff 100644<br>
> --- a/include/llvm-c/Core.h<br>
> +++ b/include/llvm-c/Core.h<br>
> @@ -124,6 +124,12 @@ typedef struct LLVMOpaquePassRegistry<br>
> *LLVMPassRegistryRef;<br>
>  * @see llvm::Use */<br>
> typedef struct LLVMOpaqueUse *LLVMUseRef;<br>
><br>
> +<br>
> +/**<br>
> + * @see llvm::DiagnosticInfo<br>
> + */<br>
> +typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;<br>
> +<br>
> typedef enum {<br>
>     LLVMZExtAttribute       = 1<<0,<br>
>     LLVMSExtAttribute       = 1<<1,<br>
> @@ -453,6 +459,8 @@ void LLVMEnablePrettyStackTrace(void);<br>
>  * @{<br>
>  */<br>
><br>
> +typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);<br>
> +<br>
> /**<br>
>  * Create a new context.<br>
>  *<br>
> @@ -467,6 +475,13 @@ LLVMContextRef LLVMContextCreate(void);<br>
> LLVMContextRef LLVMGetGlobalContext(void);<br>
><br>
> /**<br>
> + * Set the diagnostic handler for this context.<br>
> + */<br>
> +void LLVMContextSetDiagnosticHandler(LLVMContextRef C,<br>
> +                                     LLVMDiagnosticHandler Handler,<br>
> +                                     void *DiagnosticContext);<br>
> +<br>
> +/**<br>
>  * Destroy a context instance.<br>
>  *<br>
>  * This should be called for every call to LLVMContextCreate() or memory<br>
> @@ -474,6 +489,11 @@ LLVMContextRef LLVMGetGlobalContext(void);<br>
>  */<br>
> void LLVMContextDispose(LLVMContextRef C);<br>
><br>
> +/**<br>
> + * Extract string description from DiagnosticInfo.<br>
><br>
><br>
> Add a comment here saying that the string should be freed using<br>
> LLVMDisposeMessage.<br>
><br>
> + */<br>
> +char *LLVMPrintDiagInfoToString(LLVMDiagnosticInfoRef DI);<br>
> +<br>
> unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,<br>
>                                   unsigned SLen);<br>
> unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);<br>
> diff --git a/include/llvm/IR/DiagnosticInfo.h<br>
> b/include/llvm/IR/DiagnosticInfo.h<br>
> index de2a9d8..5fd6636 100644<br>
> --- a/include/llvm/IR/DiagnosticInfo.h<br>
> +++ b/include/llvm/IR/DiagnosticInfo.h<br>
> @@ -193,6 +193,9 @@ public:<br>
>   }<br>
> };<br>
><br>
> +// Create wrappers for C Binding types (see CBindingWrapping.h).<br>
> +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)<br>
> +<br>
> } // End namespace llvm<br>
><br>
> #endif<br>
> diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp<br>
> index 4f3d8b1..e3b70c7 100644<br>
> --- a/lib/IR/Core.cpp<br>
> +++ b/lib/IR/Core.cpp<br>
> @@ -17,6 +17,8 @@<br>
> #include "llvm/IR/Attributes.h"<br>
> #include "llvm/IR/CallSite.h"<br>
> #include "llvm/IR/Constants.h"<br>
> +#include "llvm/IR/DiagnosticInfo.h"<br>
> +#include "llvm/IR/DiagnosticPrinter.h"<br>
> #include "llvm/IR/DerivedTypes.h"<br>
> #include "llvm/IR/GlobalAlias.h"<br>
> #include "llvm/IR/GlobalVariable.h"<br>
> @@ -76,6 +78,14 @@ LLVMContextRef LLVMGetGlobalContext() {<br>
>   return wrap(&getGlobalContext());<br>
> }<br>
><br>
> +void LLVMContextSetDiagnosticHandler(LLVMContextRef C,<br>
> +                                     LLVMDiagnosticHandler Handler,<br>
> +                                     void *DiagnosticContext) {<br>
> +  unwrap(C)->setDiagnosticHandler(<br>
> +      LLVM_EXTENSION<br>
> reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(Handler),<br>
> +      DiagnosticContext);<br>
> +}<br>
> +<br>
> void LLVMContextDispose(LLVMContextRef C) {<br>
>   delete unwrap(C);<br>
> }<br>
> @@ -89,6 +99,16 @@ unsigned LLVMGetMDKindID(const char* Name, unsigned SLen)<br>
> {<br>
>   return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);<br>
> }<br>
><br>
> +char *LLVMPrintDiagInfoToString(LLVMDiagnosticInfoRef DI) {<br>
> +  std::string MsgStorage;<br>
> +  raw_string_ostream Stream(MsgStorage);<br>
> +  DiagnosticPrinterRawOStream DP(Stream);<br>
> +<br>
> +  unwrap(DI)->print(DP);<br>
> +  Stream.flush();<br>
> +<br>
> +  return strdup(MsgStorage.c_str());<br>
> +}<br>
><br>
> /*===-- Operations on modules<br>
> ---------------------------------------------===*/<br>
><br>
> --<br>
> 1.8.3.2<br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>