rustc: Thread a diagnostic::emitter through driver
This commit is contained in:
parent
e78b1040e7
commit
9820abfcc7
2 changed files with 26 additions and 16 deletions
|
|
@ -316,14 +316,16 @@ fn get_arch(triple: str) -> option<session::arch> {
|
|||
} else { none };
|
||||
}
|
||||
|
||||
fn build_target_config(sopts: @session::options) -> @session::config {
|
||||
fn build_target_config(sopts: @session::options,
|
||||
demitter: diagnostic::emitter) -> @session::config {
|
||||
let os = alt get_os(sopts.target_triple) {
|
||||
some(os) { os }
|
||||
none. { early_error("Unknown operating system!") }
|
||||
none. { early_error(demitter, "Unknown operating system!") }
|
||||
};
|
||||
let arch = alt get_arch(sopts.target_triple) {
|
||||
some(arch) { arch }
|
||||
none. { early_error("Unknown architecture! " + sopts.target_triple) }
|
||||
none. { early_error(demitter,
|
||||
"Unknown architecture! " + sopts.target_triple) }
|
||||
};
|
||||
let (int_type, uint_type, float_type) = alt arch {
|
||||
session::arch_x86. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
|
||||
|
|
@ -353,8 +355,8 @@ fn host_triple() -> str {
|
|||
ret ht != "" ? ht : fail "rustc built without CFG_HOST_TRIPLE";
|
||||
}
|
||||
|
||||
fn build_session_options(match: getopts::match)
|
||||
-> @session::options {
|
||||
fn build_session_options(match: getopts::match,
|
||||
demitter: diagnostic::emitter) -> @session::options {
|
||||
let crate_type = if opt_present(match, "lib") {
|
||||
session::lib_crate
|
||||
} else if opt_present(match, "bin") {
|
||||
|
|
@ -398,7 +400,7 @@ fn build_session_options(match: getopts::match)
|
|||
let opt_level: uint =
|
||||
if opt_present(match, "O") {
|
||||
if opt_present(match, "opt-level") {
|
||||
early_error("-O and --opt-level both provided");
|
||||
early_error(demitter, "-O and --opt-level both provided");
|
||||
}
|
||||
2u
|
||||
} else if opt_present(match, "opt-level") {
|
||||
|
|
@ -408,7 +410,7 @@ fn build_session_options(match: getopts::match)
|
|||
"2" { 2u }
|
||||
"3" { 3u }
|
||||
_ {
|
||||
early_error("optimization level needs " +
|
||||
early_error(demitter, "optimization level needs " +
|
||||
"to be between 0-3")
|
||||
}
|
||||
}
|
||||
|
|
@ -450,8 +452,9 @@ fn build_session_options(match: getopts::match)
|
|||
ret sopts;
|
||||
}
|
||||
|
||||
fn build_session(sopts: @session::options, input: str) -> session::session {
|
||||
let target_cfg = build_target_config(sopts);
|
||||
fn build_session(sopts: @session::options, input: str,
|
||||
demitter: diagnostic::emitter) -> session::session {
|
||||
let target_cfg = build_target_config(sopts, demitter);
|
||||
let cstore = cstore::mk_cstore();
|
||||
let filesearch = filesearch::mk_filesearch(
|
||||
sopts.maybe_sysroot,
|
||||
|
|
@ -590,8 +593,8 @@ fn build_output_filenames(ifile: str,
|
|||
obj_filename: obj_path};
|
||||
}
|
||||
|
||||
fn early_error(msg: str) -> ! {
|
||||
diagnostic::emit_diagnostic(none, msg, diagnostic::fatal);
|
||||
fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
|
||||
emitter(none, msg, diagnostic::fatal);
|
||||
fail;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import io::writer_util;
|
|||
import option::{some, none};
|
||||
import getopts::{opt_present};
|
||||
import rustc::driver::driver::*;
|
||||
import rustc::syntax::codemap;
|
||||
import rustc::driver::diagnostic;
|
||||
|
||||
fn version(argv0: str) {
|
||||
let vers = "unknown version";
|
||||
|
|
@ -68,11 +70,16 @@ fn main(args: [str]) {
|
|||
|
||||
if vec::len(args) == 0u { usage(binary); ret; }
|
||||
|
||||
let demitter = fn@(cmsp: option<(codemap::codemap, codemap::span)>,
|
||||
msg: str, lvl: diagnostic::level) {
|
||||
diagnostic::emit_diagnostic(cmsp, msg, lvl);
|
||||
};
|
||||
|
||||
let match =
|
||||
alt getopts::getopts(args, opts()) {
|
||||
ok(m) { m }
|
||||
err(f) {
|
||||
early_error(getopts::fail_str(f))
|
||||
early_error(demitter, getopts::fail_str(f))
|
||||
}
|
||||
};
|
||||
if opt_present(match, "h") || opt_present(match, "help") {
|
||||
|
|
@ -84,13 +91,13 @@ fn main(args: [str]) {
|
|||
ret;
|
||||
}
|
||||
let ifile = alt vec::len(match.free) {
|
||||
0u { early_error("No input filename given.") }
|
||||
0u { early_error(demitter, "No input filename given.") }
|
||||
1u { match.free[0] }
|
||||
_ { early_error("Multiple input filenames provided.") }
|
||||
_ { early_error(demitter, "Multiple input filenames provided.") }
|
||||
};
|
||||
|
||||
let sopts = build_session_options(match);
|
||||
let sess = build_session(sopts, ifile);
|
||||
let sopts = build_session_options(match, demitter);
|
||||
let sess = build_session(sopts, ifile, demitter);
|
||||
let odir = getopts::opt_maybe_str(match, "out-dir");
|
||||
let ofile = getopts::opt_maybe_str(match, "o");
|
||||
let cfg = build_configuration(sess, binary, ifile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue