mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
rustc: Fall back to intrinsics.ll if we can't parse the bc
This will allow us to transition to the new bitcode format.
This commit is contained in:
parent
143f87899b
commit
9a188b2e94
@ -37,16 +37,19 @@ fn llvm_err(sess: session::session, msg: str) unsafe {
|
||||
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
|
||||
}
|
||||
|
||||
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
|
||||
fn load_intrinsics_bc(sess: session::session) -> option::t<ModuleRef> {
|
||||
let path = alt filesearch::search(
|
||||
sess.filesearch(),
|
||||
bind filesearch::pick_file("intrinsics.bc", _)) {
|
||||
option::some(path) { path }
|
||||
option::none. { sess.fatal("couldn't find intrinsics.bc") }
|
||||
option::none. {
|
||||
sess.warn("couldn't find intrinsics.bc");
|
||||
ret option::none;
|
||||
}
|
||||
};
|
||||
let membuf = str::as_buf(path, {|buf|
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
});
|
||||
if membuf as uint == 0u {
|
||||
llvm_err(sess, "installation problem: couldn't open " + path);
|
||||
fail;
|
||||
@ -54,9 +57,44 @@ fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
|
||||
let llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
|
||||
llvm::LLVMDisposeMemoryBuffer(membuf);
|
||||
if llintrinsicsmod as uint == 0u {
|
||||
llvm_err(sess, "installation problem: couldn't parse intrinsics.bc");
|
||||
sess.warn("couldn't parse intrinsics.bc");
|
||||
ret option::none;
|
||||
}
|
||||
|
||||
ret option::some(llintrinsicsmod);
|
||||
}
|
||||
|
||||
fn load_intrinsics_ll(sess: session::session) -> ModuleRef {
|
||||
let path = alt filesearch::search(
|
||||
sess.filesearch(),
|
||||
bind filesearch::pick_file("intrinsics.ll", _)) {
|
||||
option::some(path) { path }
|
||||
option::none. { sess.fatal("couldn't find intrinsics.ll") }
|
||||
};
|
||||
let llintrinsicsmod = str::as_buf(path, { |buf|
|
||||
llvm::LLVMRustParseAssemblyFile(buf)
|
||||
});
|
||||
if llintrinsicsmod as uint == 0u {
|
||||
llvm_err(sess, "couldn't parse intrinsics.ll");
|
||||
fail;
|
||||
}
|
||||
ret llintrinsicsmod;
|
||||
}
|
||||
|
||||
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
|
||||
let llintrinsicsmod = {
|
||||
alt load_intrinsics_bc(sess) {
|
||||
option::some(m) { m }
|
||||
option::none. {
|
||||
// When the bitcode format changes we can't parse a .bc
|
||||
// file produced with a newer LLVM (as happens when stage0
|
||||
// is trying to build against a new LLVM revision), in
|
||||
// that case we'll try to parse the assembly.
|
||||
sess.warn("couldn't parse intrinsics.bc, trying intrinsics.ll");
|
||||
load_intrinsics_ll(sess)
|
||||
}
|
||||
}
|
||||
};
|
||||
let linkres = llvm::LLVMLinkModules(llmod, llintrinsicsmod);
|
||||
llvm::LLVMDisposeModule(llintrinsicsmod);
|
||||
if linkres == False {
|
||||
|
@ -864,6 +864,9 @@ native mod llvm {
|
||||
/** Parses the bitcode in the given memory buffer. */
|
||||
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
|
||||
|
||||
/** Parses LLVM asm in the given file */
|
||||
fn LLVMRustParseAssemblyFile(Filename: sbuf) -> ModuleRef;
|
||||
|
||||
/** FiXME: Hacky adaptor for lack of ULongLong in FFI: */
|
||||
fn LLVMRustConstInt(IntTy: TypeRef, N_hi: uint, N_lo: uint,
|
||||
SignExtend: Bool) -> ValueRef;
|
||||
|
@ -12,9 +12,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/Assembly/PrintModulePass.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
@ -22,6 +24,7 @@
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm-c/Core.h"
|
||||
@ -109,6 +112,18 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||
delete Target;
|
||||
}
|
||||
|
||||
extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) {
|
||||
|
||||
SMDiagnostic d;
|
||||
Module *m = ParseAssemblyFile(Filename, d, getGlobalContext());
|
||||
if (m) {
|
||||
return wrap(m);
|
||||
} else {
|
||||
LLVMRustError = d.getMessage().c_str();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMModuleRef LLVMRustParseBitcode(LLVMMemoryBufferRef MemBuf) {
|
||||
LLVMModuleRef M;
|
||||
return LLVMParseBitcode(MemBuf, &M, const_cast<char **>(&LLVMRustError))
|
||||
|
@ -6,6 +6,7 @@ LLVMRustGetHostTriple
|
||||
LLVMRustConstSmallInt
|
||||
LLVMRustConstInt
|
||||
LLVMRustParseBitcode
|
||||
LLVMRustParseAssemblyFile
|
||||
LLVMRustPrintPassTimings
|
||||
LLVMRustEnableSegmentedStacks
|
||||
LLVMLinkModules
|
||||
|
Loading…
Reference in New Issue
Block a user