///
#include "llvm/codegen.hpp"
+#include "llvm/compat.hpp"
#include "llvm/metadata.hpp"
#include "core/error.hpp"
#include "util/algorithm.hpp"
auto mod = ::llvm::parseBitcodeFile(::llvm::MemoryBufferRef(
as_string(m.secs[0].data), " "), ctx);
- if (::llvm::Error err = mod.takeError()) {
- std::string msg;
- ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &EIB) {
- msg = EIB.message();
- fail(r_log, error(CL_INVALID_PROGRAM), msg.c_str());
+ compat::handle_module_error(mod, [&](const std::string &s) {
+ fail(r_log, error(CL_INVALID_PROGRAM), s);
});
- }
return std::unique_ptr<::llvm::Module>(std::move(*mod));
}
#include <llvm/Linker/Linker.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Target/TargetMachine.h>
+#if HAVE_LLVM >= 0x0400
+#include <llvm/Support/Error.h>
+#else
+#include <llvm/Support/ErrorOr.h>
+#endif
#if HAVE_LLVM >= 0x0307
#include <llvm/IR/LegacyPassManager.h>
#else
const auto default_reloc_model = ::llvm::Reloc::Default;
#endif
+
+ template<typename M, typename F> void
+ handle_module_error(M &mod, const F &f) {
+#if HAVE_LLVM >= 0x0400
+ if (::llvm::Error err = mod.takeError())
+ ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &eib) {
+ f(eib.message());
+ });
+#else
+ if (!mod)
+ f(mod.getError().message());
+#endif
+ }
}
}
}