#include <llvm/Linker.h>
#else
#include <llvm/Linker/Linker.h>
+#include <llvm/IR/DiagnosticInfo.h>
+#include <llvm/IR/DiagnosticPrinter.h>
#endif
#if HAVE_LLVM < 0x0303
#include <llvm/DerivedTypes.h>
return m;
}
+#if HAVE_LLVM >= 0x0305
+
+ void
+ diagnostic_handler(const llvm::DiagnosticInfo &di, void *data) {
+ if (di.getSeverity() == llvm::DS_Error) {
+ std::string message = *(compat::string*)data;
+ llvm::raw_string_ostream stream(message);
+ llvm::DiagnosticPrinterRawOStream dp(stream);
+ di.print(dp);
+ stream.flush();
+ *(compat::string*)data = message;
+
+ throw build_error();
+ }
+ }
+
+#endif
+
void
init_targets() {
static bool targets_initialized = false;
llvm::LLVMContext llvm_ctx;
unsigned optimization_level;
+#if HAVE_LLVM >= 0x0305
+ llvm_ctx.setDiagnosticHandler(diagnostic_handler, &r_log);
+#endif
+
// The input file name must have the .cl extension in order for the
// CompilerInvocation class to recognize it as an OpenCL source file.
llvm::Module *mod = compile_llvm(llvm_ctx, source, "input.cl", triple,
// LLVM 3.6 and newer, the user takes ownership of the module.
delete mod;
#endif
+
return m;
}