Skip to content

Commit e78b104

Browse files
committed
rustc: Pull some uses of early_error up into build_target_config
1 parent 876e9fd commit e78b104

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/comp/driver/driver.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,36 +289,42 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
289289
io::string_reader(src), io::stdout(), ann);
290290
}
291291

292-
fn get_os(triple: str) -> session::os {
292+
fn get_os(triple: str) -> option<session::os> {
293293
ret if str::find(triple, "win32") >= 0 ||
294294
str::find(triple, "mingw32") >= 0 {
295-
session::os_win32
295+
some(session::os_win32)
296296
} else if str::find(triple, "darwin") >= 0 {
297-
session::os_macos
297+
some(session::os_macos)
298298
} else if str::find(triple, "linux") >= 0 {
299-
session::os_linux
299+
some(session::os_linux)
300300
} else if str::find(triple, "freebsd") >= 0 {
301-
session::os_freebsd
302-
} else { early_error("Unknown operating system!") };
301+
some(session::os_freebsd)
302+
} else { none };
303303
}
304304

305-
fn get_arch(triple: str) -> session::arch {
305+
fn get_arch(triple: str) -> option<session::arch> {
306306
ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
307307
str::find(triple, "i586") >= 0 ||
308308
str::find(triple, "i686") >= 0 ||
309309
str::find(triple, "i786") >= 0 {
310-
session::arch_x86
310+
some(session::arch_x86)
311311
} else if str::find(triple, "x86_64") >= 0 {
312-
session::arch_x86_64
312+
some(session::arch_x86_64)
313313
} else if str::find(triple, "arm") >= 0 ||
314314
str::find(triple, "xscale") >= 0 {
315-
session::arch_arm
316-
} else { early_error("Unknown architecture! " + triple) };
315+
some(session::arch_arm)
316+
} else { none };
317317
}
318318

319319
fn build_target_config(sopts: @session::options) -> @session::config {
320-
let os = get_os(sopts.target_triple);
321-
let arch = get_arch(sopts.target_triple);
320+
let os = alt get_os(sopts.target_triple) {
321+
some(os) { os }
322+
none. { early_error("Unknown operating system!") }
323+
};
324+
let arch = alt get_arch(sopts.target_triple) {
325+
some(arch) { arch }
326+
none. { early_error("Unknown architecture! " + sopts.target_triple) }
327+
};
322328
let (int_type, uint_type, float_type) = alt arch {
323329
session::arch_x86. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
324330
session::arch_x86_64. {(ast::ty_i64, ast::ty_u64, ast::ty_f64)}

0 commit comments

Comments
 (0)