@@ -392,14 +392,56 @@ pub fn phase_5_run_llvm_passes(sess: Session,
392
392
/// This should produce either a finished executable or library.
393
393
pub fn phase_6_link_output ( sess : Session ,
394
394
trans : & CrateTranslation ,
395
- input : & input ,
396
395
outputs : & OutputFilenames ) {
397
- let outputs = time ( sess. time_passes ( ) , "linking" , ( ) , |_|
396
+ time ( sess. time_passes ( ) , "linking" , ( ) , |_|
398
397
link:: link_binary ( sess,
399
398
trans,
400
399
& outputs. obj_filename ,
401
400
& outputs. out_filename ,
402
401
& trans. link ) ) ;
402
+ }
403
+
404
+ pub fn stop_after_phase_3 ( sess : Session ) -> bool {
405
+ if sess. opts . no_trans {
406
+ debug ! ( "invoked with --no-trans, returning early from compile_input" ) ;
407
+ return true ;
408
+ }
409
+ return false ;
410
+ }
411
+
412
+ pub fn stop_after_phase_1 ( sess : Session ) -> bool {
413
+ if sess. opts . parse_only {
414
+ debug ! ( "invoked with --parse-only, returning early from compile_input" ) ;
415
+ return true ;
416
+ }
417
+ return false ;
418
+ }
419
+
420
+ pub fn stop_after_phase_2 ( sess : Session ) -> bool {
421
+ if sess. opts . no_analysis {
422
+ debug ! ( "invoked with --no-analysis, returning early from compile_input" ) ;
423
+ return true ;
424
+ }
425
+ return false ;
426
+ }
427
+
428
+ pub fn stop_after_phase_5 ( sess : Session ) -> bool {
429
+ if sess. opts . output_type != link:: output_type_exe {
430
+ debug ! ( "not building executable, returning early from compile_input" ) ;
431
+ return true ;
432
+ }
433
+ return false ;
434
+ }
435
+
436
+ fn write_out_deps ( sess : Session , input : & input , outputs : & OutputFilenames , crate : & ast:: Crate )
437
+ {
438
+ let lm = link:: build_link_meta ( sess, crate . attrs, & outputs. obj_filename ,
439
+ & mut :: util:: sha2:: Sha256 :: new ( ) ) ;
440
+
441
+ let sess_outputs = sess. outputs . borrow ( ) ;
442
+ let out_filenames = sess_outputs. get ( ) . iter ( )
443
+ . map ( |& output| link:: filename_for_input ( & sess, output, & lm, & outputs. out_filename ) )
444
+ . to_owned_vec ( ) ;
403
445
404
446
// Write out dependency rules to the dep-info file if requested with --dep-info
405
447
let deps_filename = match sess. opts . write_dependency_info {
@@ -409,7 +451,7 @@ pub fn phase_6_link_output(sess: Session,
409
451
( true , None ) => match * input {
410
452
file_input( ref input_path) => {
411
453
let filestem = input_path. filestem ( ) . expect ( "input file must have stem" ) ;
412
- let filename = outputs [ 0 ] . dir_path ( ) . join ( filestem) . with_extension ( "d" ) ;
454
+ let filename = out_filenames [ 0 ] . dir_path ( ) . join ( filestem) . with_extension ( "d" ) ;
413
455
filename
414
456
} ,
415
457
str_input( ..) => {
@@ -419,40 +461,17 @@ pub fn phase_6_link_output(sess: Session,
419
461
} ,
420
462
_ => return ,
421
463
} ;
464
+
422
465
// Build a list of files used to compile the output and
423
466
// write Makefile-compatible dependency rules
424
467
let files: ~[ @str ] = sess. codemap . files . iter ( )
425
468
. filter_map ( |fmap| if fmap. is_real_file ( ) { Some ( fmap. name ) } else { None } )
426
469
. collect ( ) ;
427
470
let mut file = io:: File :: create ( & deps_filename) ;
428
- for output in outputs . iter ( ) {
471
+ for path in out_filenames . iter ( ) {
429
472
write ! ( & mut file as & mut Writer ,
430
- "{}: {}\n \n " , output. display( ) , files. connect( " " ) ) ;
431
- }
432
- }
433
-
434
- pub fn stop_after_phase_3 ( sess : Session ) -> bool {
435
- if sess. opts . no_trans {
436
- debug ! ( "invoked with --no-trans, returning early from compile_input" ) ;
437
- return true ;
438
- }
439
- return false ;
440
- }
441
-
442
- pub fn stop_after_phase_1 ( sess : Session ) -> bool {
443
- if sess. opts . parse_only {
444
- debug ! ( "invoked with --parse-only, returning early from compile_input" ) ;
445
- return true ;
473
+ "{}: {}\n \n " , path. display( ) , files. connect( " " ) ) ;
446
474
}
447
- return false ;
448
- }
449
-
450
- pub fn stop_after_phase_5 ( sess : Session ) -> bool {
451
- if sess. opts . output_type != link:: output_type_exe {
452
- debug ! ( "not building executable, returning early from compile_input" ) ;
453
- return true ;
454
- }
455
- return false ;
456
475
}
457
476
458
477
pub fn compile_input ( sess : Session , cfg : ast:: CrateConfig , input : & input ,
@@ -468,6 +487,11 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
468
487
} ;
469
488
let outputs = build_output_filenames ( input, outdir, output,
470
489
expanded_crate. attrs , sess) ;
490
+
491
+ write_out_deps ( sess, input, outputs, & expanded_crate) ;
492
+
493
+ if stop_after_phase_2 ( sess) { return ; }
494
+
471
495
let analysis = phase_3_run_analysis_passes ( sess, & expanded_crate) ;
472
496
if stop_after_phase_3 ( sess) { return ; }
473
497
let trans = phase_4_translate_to_llvm ( sess, expanded_crate,
@@ -476,7 +500,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
476
500
} ;
477
501
phase_5_run_llvm_passes ( sess, & trans, outputs) ;
478
502
if stop_after_phase_5 ( sess) { return ; }
479
- phase_6_link_output ( sess, & trans, input , outputs) ;
503
+ phase_6_link_output ( sess, & trans, outputs) ;
480
504
}
481
505
482
506
struct IdentifiedAnnotation {
@@ -683,6 +707,7 @@ pub fn build_session_options(binary: @str,
683
707
684
708
let parse_only = matches. opt_present ( "parse-only" ) ;
685
709
let no_trans = matches. opt_present ( "no-trans" ) ;
710
+ let no_analysis = matches. opt_present ( "no-analysis" ) ;
686
711
687
712
let lint_levels = [ lint:: allow, lint:: warn,
688
713
lint:: deny, lint:: forbid] ;
@@ -836,6 +861,7 @@ pub fn build_session_options(binary: @str,
836
861
test : test,
837
862
parse_only : parse_only,
838
863
no_trans : no_trans,
864
+ no_analysis : no_analysis,
839
865
debugging_opts : debugging_opts,
840
866
android_cross_path : android_cross_path,
841
867
write_dependency_info : write_dependency_info,
@@ -929,6 +955,9 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
929
955
optflag ( "" , "ls" , "List the symbols defined by a library crate" ) ,
930
956
optflag ( "" , "no-trans" ,
931
957
"Run all passes except translation; no output" ) ,
958
+ optflag ( "" , "no-analysis" ,
959
+ "Parse and expand the output, but run no analysis or produce \
960
+ output") ,
932
961
optflag ( "O" , "" , "Equivalent to --opt-level=2" ) ,
933
962
optopt ( "o" , "" , "Write output to <filename>" , "FILENAME" ) ,
934
963
optopt ( "" , "opt-level" ,
0 commit comments