Skip to content

Commit 9820abf

Browse files
committed
rustc: Thread a diagnostic::emitter through driver
1 parent e78b104 commit 9820abf

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/comp/driver/driver.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,16 @@ fn get_arch(triple: str) -> option<session::arch> {
316316
} else { none };
317317
}
318318

319-
fn build_target_config(sopts: @session::options) -> @session::config {
319+
fn build_target_config(sopts: @session::options,
320+
demitter: diagnostic::emitter) -> @session::config {
320321
let os = alt get_os(sopts.target_triple) {
321322
some(os) { os }
322-
none. { early_error("Unknown operating system!") }
323+
none. { early_error(demitter, "Unknown operating system!") }
323324
};
324325
let arch = alt get_arch(sopts.target_triple) {
325326
some(arch) { arch }
326-
none. { early_error("Unknown architecture! " + sopts.target_triple) }
327+
none. { early_error(demitter,
328+
"Unknown architecture! " + sopts.target_triple) }
327329
};
328330
let (int_type, uint_type, float_type) = alt arch {
329331
session::arch_x86. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
@@ -353,8 +355,8 @@ fn host_triple() -> str {
353355
ret ht != "" ? ht : fail "rustc built without CFG_HOST_TRIPLE";
354356
}
355357

356-
fn build_session_options(match: getopts::match)
357-
-> @session::options {
358+
fn build_session_options(match: getopts::match,
359+
demitter: diagnostic::emitter) -> @session::options {
358360
let crate_type = if opt_present(match, "lib") {
359361
session::lib_crate
360362
} else if opt_present(match, "bin") {
@@ -398,7 +400,7 @@ fn build_session_options(match: getopts::match)
398400
let opt_level: uint =
399401
if opt_present(match, "O") {
400402
if opt_present(match, "opt-level") {
401-
early_error("-O and --opt-level both provided");
403+
early_error(demitter, "-O and --opt-level both provided");
402404
}
403405
2u
404406
} else if opt_present(match, "opt-level") {
@@ -408,7 +410,7 @@ fn build_session_options(match: getopts::match)
408410
"2" { 2u }
409411
"3" { 3u }
410412
_ {
411-
early_error("optimization level needs " +
413+
early_error(demitter, "optimization level needs " +
412414
"to be between 0-3")
413415
}
414416
}
@@ -450,8 +452,9 @@ fn build_session_options(match: getopts::match)
450452
ret sopts;
451453
}
452454

453-
fn build_session(sopts: @session::options, input: str) -> session::session {
454-
let target_cfg = build_target_config(sopts);
455+
fn build_session(sopts: @session::options, input: str,
456+
demitter: diagnostic::emitter) -> session::session {
457+
let target_cfg = build_target_config(sopts, demitter);
455458
let cstore = cstore::mk_cstore();
456459
let filesearch = filesearch::mk_filesearch(
457460
sopts.maybe_sysroot,
@@ -590,8 +593,8 @@ fn build_output_filenames(ifile: str,
590593
obj_filename: obj_path};
591594
}
592595

593-
fn early_error(msg: str) -> ! {
594-
diagnostic::emit_diagnostic(none, msg, diagnostic::fatal);
596+
fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
597+
emitter(none, msg, diagnostic::fatal);
595598
fail;
596599
}
597600

src/comp/driver/rustc.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import io::writer_util;
99
import option::{some, none};
1010
import getopts::{opt_present};
1111
import rustc::driver::driver::*;
12+
import rustc::syntax::codemap;
13+
import rustc::driver::diagnostic;
1214

1315
fn version(argv0: str) {
1416
let vers = "unknown version";
@@ -68,11 +70,16 @@ fn main(args: [str]) {
6870

6971
if vec::len(args) == 0u { usage(binary); ret; }
7072

73+
let demitter = fn@(cmsp: option<(codemap::codemap, codemap::span)>,
74+
msg: str, lvl: diagnostic::level) {
75+
diagnostic::emit_diagnostic(cmsp, msg, lvl);
76+
};
77+
7178
let match =
7279
alt getopts::getopts(args, opts()) {
7380
ok(m) { m }
7481
err(f) {
75-
early_error(getopts::fail_str(f))
82+
early_error(demitter, getopts::fail_str(f))
7683
}
7784
};
7885
if opt_present(match, "h") || opt_present(match, "help") {
@@ -84,13 +91,13 @@ fn main(args: [str]) {
8491
ret;
8592
}
8693
let ifile = alt vec::len(match.free) {
87-
0u { early_error("No input filename given.") }
94+
0u { early_error(demitter, "No input filename given.") }
8895
1u { match.free[0] }
89-
_ { early_error("Multiple input filenames provided.") }
96+
_ { early_error(demitter, "Multiple input filenames provided.") }
9097
};
9198

92-
let sopts = build_session_options(match);
93-
let sess = build_session(sopts, ifile);
99+
let sopts = build_session_options(match, demitter);
100+
let sess = build_session(sopts, ifile, demitter);
94101
let odir = getopts::opt_maybe_str(match, "out-dir");
95102
let ofile = getopts::opt_maybe_str(match, "o");
96103
let cfg = build_configuration(sess, binary, ifile);

0 commit comments

Comments
 (0)