@@ -279,7 +279,7 @@ fn get_os(triple: str) -> session::os {
279
279
session:: os_macos
280
280
} else if str:: find ( triple, "linux" ) >= 0 {
281
281
session:: os_linux
282
- } else { log_err "Unknown operating system!" ; fail } ;
282
+ } else { early_error ( "Unknown operating system!" ) } ;
283
283
}
284
284
285
285
fn get_arch ( triple : str ) -> session:: arch {
@@ -293,7 +293,7 @@ fn get_arch(triple: str) -> session::arch {
293
293
} else if str:: find ( triple, "arm" ) >= 0 ||
294
294
str:: find ( triple, "xscale" ) >= 0 {
295
295
session:: arch_arm
296
- } else { log_err "Unknown architecture! " + triple; fail } ;
296
+ } else { early_error ( "Unknown architecture! " + triple) } ;
297
297
}
298
298
299
299
fn build_target_config ( sopts : @session:: options ) -> @session:: config {
@@ -348,8 +348,7 @@ fn build_session_options(match: getopts::match)
348
348
let opt_level: uint =
349
349
if opt_present ( match , "O" ) {
350
350
if opt_present ( match , "OptLevel" ) {
351
- log_err "error: -O and --OptLevel both provided" ;
352
- fail;
351
+ early_error ( "-O and --OptLevel both provided" ) ;
353
352
}
354
353
2 u
355
354
} else if opt_present ( match , "OptLevel" ) {
@@ -359,9 +358,8 @@ fn build_session_options(match: getopts::match)
359
358
"2" { 2 u }
360
359
"3" { 3 u }
361
360
_ {
362
- log_err "error: optimization level needs " +
363
- "to be between 0-3" ;
364
- fail
361
+ early_error( "optimization level needs " +
362
+ "to be between 0-3" )
365
363
}
366
364
}
367
365
} else { 0 u } ;
@@ -485,14 +483,18 @@ fn build_output_filenames(ifile: str, ofile: option::t<str>,
485
483
ret @{ out_filename: saved_out_filename, obj_filename: obj_filename} ;
486
484
}
487
485
486
+ fn early_error ( msg : str ) -> ! {
487
+ codemap:: print_diagnostic ( "" , codemap:: error, msg) ;
488
+ fail;
489
+ }
490
+
488
491
fn main( args : [ str ] ) {
489
492
let binary = vec:: shift ( args) ;
490
493
let match =
491
494
alt getopts:: getopts ( args, opts ( ) ) {
492
495
getopts:: success ( m) { m }
493
496
getopts:: failure ( f) {
494
- log_err #fmt[ "error: %s" , getopts:: fail_str( f) ] ;
495
- fail
497
+ early_error ( getopts:: fail_str ( f) )
496
498
}
497
499
} ;
498
500
if opt_present( match , "h" ) || opt_present( match , "help" ) {
@@ -503,16 +505,15 @@ fn main(args: [str]) {
503
505
version( binary) ;
504
506
ret;
505
507
}
508
+ let ifile = alt vec:: len( match. free) {
509
+ 0 u { early_error( "No input filename given." ) }
510
+ 1 u { match. free[ 0 ] }
511
+ _ { early_error( "Multiple input filenames provided." ) }
512
+ } ;
513
+
506
514
let sopts = build_session_options( match ) ;
507
515
let sess = build_session ( sopts) ;
508
- let n_inputs = vec:: len:: < str > ( match. free) ;
509
- if n_inputs == 0 u {
510
- sess. fatal ( "No input filename given." ) ;
511
- } else if n_inputs > 1 u {
512
- sess. fatal ( "Multiple input filenames provided." ) ;
513
- }
514
516
let ofile = getopts:: opt_maybe_str( match , "o" ) ;
515
- let ifile = match . free[ 0 ] ;
516
517
let outputs = build_output_filenames ( ifile, ofile, sopts) ;
517
518
let cfg = build_configuration ( sess, binary, ifile) ;
518
519
let pretty =
0 commit comments