emit_code(const ::llvm::Module &mod) {
::llvm::SmallVector<char, 1024> data;
::llvm::raw_svector_ostream os { data };
- WriteBitcodeToFile(&mod, os);
+ compat::write_bitcode_to_file(mod, os);
return { os.str().begin(), os.str().end() };
}
}
const target &target) {
std::string log;
try {
- std::unique_ptr< ::llvm::Module> cmod { CloneModule(&mod) };
+ std::unique_ptr< ::llvm::Module> cmod { compat::clone_module(mod) };
return as_string(emit_code(*cmod, target,
TargetMachine::CGFT_AssemblyFile, log));
} catch (...) {
#include "util/algorithm.hpp"
+#if HAVE_LLVM < 0x0400
+#include <llvm/Bitcode/ReaderWriter.h>
+#else
+#include <llvm/Bitcode/BitcodeReader.h>
+#include <llvm/Bitcode/BitcodeWriter.h>
+#endif
+
#include <llvm/IR/LLVMContext.h>
#include <llvm/Linker/Linker.h>
#include <llvm/Transforms/IPO.h>
+#include <llvm/Transforms/Utils/Cloning.h>
#include <llvm/Target/TargetMachine.h>
#if HAVE_LLVM >= 0x0400
#include <llvm/Support/Error.h>
ctx.setDiagnosticHandler(diagnostic_handler, data);
#endif
}
+
+ inline std::unique_ptr< ::llvm::Module>
+ clone_module(const ::llvm::Module &mod)
+ {
+#if HAVE_LLVM >= 0x0700
+ return ::llvm::CloneModule(mod);
+#else
+ return ::llvm::CloneModule(&mod);
+#endif
+ }
+
+ template<typename T> void
+ write_bitcode_to_file(const ::llvm::Module &mod, T &os)
+ {
+#if HAVE_LLVM >= 0x0700
+ ::llvm::WriteBitcodeToFile(mod, os);
+#else
+ ::llvm::WriteBitcodeToFile(&mod, os);
+#endif
+ }
}
}
}