Better error when rustc fails to write output.

This commit is contained in:
Glenn Willen 2012-07-13 17:06:30 -04:00
parent 05ff4f416b
commit 28c1f21433
3 changed files with 29 additions and 6 deletions

View file

@ -1,4 +1,4 @@
import libc::{c_int, c_uint}; import libc::{c_int, c_uint, c_char};
import driver::session; import driver::session;
import session::session; import session::session;
import lib::llvm::llvm; import lib::llvm::llvm;
@ -32,6 +32,21 @@ fn llvm_err(sess: session, msg: str) -> ! unsafe {
} else { sess.fatal(msg + ": " + str::unsafe::from_c_str(cstr)); } } else { sess.fatal(msg + ": " + str::unsafe::from_c_str(cstr)); }
} }
fn WriteOutputFile(sess:session,
PM: lib::llvm::PassManagerRef, M: ModuleRef,
Triple: *c_char,
// FIXME: When #2334 is fixed, change
// c_uint to FileType
Output: *c_char, FileType: c_uint,
OptLevel: c_int,
EnableSegmentedStacks: bool) {
let result = llvm::LLVMRustWriteOutputFile(
PM, M, Triple, Output, FileType, OptLevel, EnableSegmentedStacks);
if (!result) {
llvm_err(sess, "Could not write output");
}
}
mod write { mod write {
fn is_object_or_assembly_or_exe(ot: output_type) -> bool { fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
if ot == output_type_assembly || ot == output_type_object || if ot == output_type_assembly || ot == output_type_object ||
@ -160,7 +175,8 @@ mod write {
sess.targ_cfg.target_strs.target_triple, sess.targ_cfg.target_strs.target_triple,
|buf_t| { |buf_t| {
str::as_c_str(output, |buf_o| { str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile( WriteOutputFile(
sess,
pm.llpm, pm.llpm,
llmod, llmod,
buf_t, buf_t,
@ -181,7 +197,8 @@ mod write {
sess.targ_cfg.target_strs.target_triple, sess.targ_cfg.target_strs.target_triple,
|buf_t| { |buf_t| {
str::as_c_str(output, |buf_o| { str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile( WriteOutputFile(
sess,
pm.llpm, pm.llpm,
llmod, llmod,
buf_t, buf_t,
@ -200,7 +217,8 @@ mod write {
sess.targ_cfg.target_strs.target_triple, sess.targ_cfg.target_strs.target_triple,
|buf_t| { |buf_t| {
str::as_c_str(output, |buf_o| { str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile( WriteOutputFile(
sess,
pm.llpm, pm.llpm,
llmod, llmod,
buf_t, buf_t,

View file

@ -941,7 +941,7 @@ extern mod llvm {
// c_uint to FileType // c_uint to FileType
Output: *c_char, FileType: c_uint, Output: *c_char, FileType: c_uint,
OptLevel: c_int, OptLevel: c_int,
EnableSegmentedStacks: bool); EnableSegmentedStacks: bool) -> bool;
/** Returns a string describing the last error caused by an LLVMRust* /** Returns a string describing the last error caused by an LLVMRust*
call. */ call. */

View file

@ -75,7 +75,7 @@ extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
return true; return true;
} }
extern "C" void extern "C" bool
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
LLVMModuleRef M, LLVMModuleRef M,
const char *triple, const char *triple,
@ -107,6 +107,10 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
std::string ErrorInfo; std::string ErrorInfo;
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream OS(path, ErrorInfo,
raw_fd_ostream::F_Binary); raw_fd_ostream::F_Binary);
if (ErrorInfo != "") {
LLVMRustError = ErrorInfo.c_str();
return false;
}
formatted_raw_ostream FOS(OS); formatted_raw_ostream FOS(OS);
bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType, NoVerify); bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType, NoVerify);
@ -114,6 +118,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
(void)foo; (void)foo;
PM->run(*unwrap(M)); PM->run(*unwrap(M));
delete Target; delete Target;
return true;
} }
extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) { extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) {