summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2014-01-15 22:04:35 +0000
committerQuentin Colombet <qcolombet@apple.com>2014-01-15 22:04:35 +0000
commit4c831d97bf065ae5d0fcba80b28e8396dfda7f39 (patch)
tree43d141a6a13492c3bd165514539826d1c2e60a14 /include
parent7fa843cfef65449f559049044762c680a857e537 (diff)
[LTO] Add a hook to map LLVM diagnostics into the clients of LTO.
Add a hook in the C API of LTO so that clients of the code generator can set their own handler for the LLVM diagnostics. The handler is defined like this: typedef void (*lto_diagnostic_handler_t)(lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt) - severity says how bad this is. - diag is a string that contains the diagnostic message. - ctxt is the registered context for this handler. This hook is more general than the lto_get_error_message, since this function keeps only the latest message and can only be queried when something went wrong (no warning for instance). <rdar://problem/15517596> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm-c/lto.h29
-rw-r--r--include/llvm/LTO/LTOCodeGenerator.h9
2 files changed, 37 insertions, 1 deletions
diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h
index 2292f470eba..483ad1a917a 100644
--- a/include/llvm-c/lto.h
+++ b/include/llvm-c/lto.h
@@ -40,7 +40,7 @@ typedef bool lto_bool_t;
* @{
*/
-#define LTO_API_VERSION 6
+#define LTO_API_VERSION 7
typedef enum {
LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
@@ -204,6 +204,33 @@ lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
extern lto_symbol_attributes
lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
+/**
+ * Diagnostic severity.
+ */
+typedef enum {
+ LTO_DS_ERROR,
+ LTO_DS_WARNING,
+ LTO_DS_NOTE
+} lto_codegen_diagnostic_severity_t;
+
+/**
+ * Diagnostic handler type.
+ * \p severity defines the severity.
+ * \p diag is the actual diagnostic.
+ * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '.
+ * \p ctxt is used to pass the context set with the diagnostic handler.
+ */
+typedef void (*lto_diagnostic_handler_t)(
+ lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt);
+
+/**
+ * Set a diagnostic handler and the related context (void *).
+ * This is more general than lto_get_error_message, as the diagnostic handler
+ * can be called at anytime within lto.
+ */
+extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
+ lto_diagnostic_handler_t,
+ void *);
/**
* Instantiates a code generator.
diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h
index defea4f7ca0..4836a51a7e7 100644
--- a/include/llvm/LTO/LTOCodeGenerator.h
+++ b/include/llvm/LTO/LTOCodeGenerator.h
@@ -46,6 +46,7 @@
namespace llvm {
class LLVMContext;
+ class DiagnosticInfo;
class GlobalValue;
class Mangler;
class MemoryBuffer;
@@ -115,6 +116,8 @@ struct LTOCodeGenerator {
bool disableGVNLoadPRE,
std::string &errMsg);
+ void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
+
bool shouldInternalize() const {
return InternalizeStrategy != LTO_INTERNALIZE_NONE;
}
@@ -139,6 +142,10 @@ private:
llvm::Mangler &Mangler);
bool determineTarget(std::string &errMsg);
+ static void DiagnosticHandler(const llvm::DiagnosticInfo &DI, void *Context);
+
+ void DiagnosticHandler2(const llvm::DiagnosticInfo &DI);
+
typedef llvm::StringMap<uint8_t> StringSet;
llvm::LLVMContext &Context;
@@ -155,6 +162,8 @@ private:
std::string MCpu;
std::string NativeObjectPath;
llvm::TargetOptions Options;
+ lto_diagnostic_handler_t DiagHandler;
+ void *DiagContext;
};
#endif // LTO_CODE_GENERATOR_H