<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Darren,<div><br></div><div>This LGTM with two comments:</div><div>- LLVMPrintDiagInfoToString should state that the string has to be freed (see inline comment).</div><div>- Should we provide an API to expose the severity as well? What would do the users of LLVMPrintDiagInfoToString if we do not?</div><div><br></div><div>Note that I’m not super familiar with the C API, so you may want to wait for another review.</div><div><br></div><div>Thanks,<br><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica;  font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">-Quentin</div>

</div>
<br><div><div>On Apr 2, 2014, at 8:32 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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 *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></blockquote><div><br></div>Add a comment here saying that the string should be freed using LLVMDisposeMessage.</div><div><br><blockquote type="cite">+ */<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 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 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>   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>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>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></div><br></div></body></html>