88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- pub use self :: Input :: * ;
12-
1311use back:: link;
1412use back:: write;
1513use session:: Session ;
16- use session:: config;
14+ use session:: config:: { mod , Input , OutputFilenames } ;
1715use lint;
18- use llvm:: { ContextRef , ModuleRef } ;
19- use metadata:: common:: LinkMeta ;
2016use metadata:: creader;
2117use middle:: { stability, ty, reachable} ;
2218use middle:: dependency_format;
@@ -28,7 +24,6 @@ use rustc::typeck;
2824use trans;
2925
3026use util:: common:: time;
31- use util:: nodemap:: { NodeSet } ;
3227
3328use serialize:: { json, Encodable } ;
3429
@@ -114,36 +109,19 @@ pub fn anon_src() -> String {
114109pub fn source_name ( input : & Input ) -> String {
115110 match * input {
116111 // FIXME (#9639): This needs to handle non-utf8 paths
117- FileInput ( ref ifile) => ifile. as_str ( ) . unwrap ( ) . to_string ( ) ,
118- StrInput ( _) => anon_src ( )
119- }
120- }
121-
122- pub enum Input {
123- /// Load source from file
124- FileInput ( Path ) ,
125- /// The string is the source
126- StrInput ( String )
127- }
128-
129- impl Input {
130- fn filestem ( & self ) -> String {
131- match * self {
132- FileInput ( ref ifile) => ifile. filestem_str ( ) . unwrap ( ) . to_string ( ) ,
133- StrInput ( _) => "rust_out" . to_string ( ) ,
134- }
112+ Input :: File ( ref ifile) => ifile. as_str ( ) . unwrap ( ) . to_string ( ) ,
113+ Input :: Str ( _) => anon_src ( )
135114 }
136115}
137116
138-
139117pub fn phase_1_parse_input ( sess : & Session , cfg : ast:: CrateConfig , input : & Input )
140118 -> ast:: Crate {
141119 let krate = time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
142120 match * input {
143- FileInput ( ref file) => {
121+ Input :: File ( ref file) => {
144122 parse:: parse_crate_from_file ( & ( * file) , cfg. clone ( ) , & sess. parse_sess )
145123 }
146- StrInput ( ref src) => {
124+ Input :: Str ( ref src) => {
147125 parse:: parse_crate_from_source_str ( anon_src ( ) . to_string ( ) ,
148126 src. to_string ( ) ,
149127 cfg. clone ( ) ,
@@ -343,23 +321,13 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
343321 map
344322}
345323
346- pub struct CrateAnalysis < ' tcx > {
347- pub exp_map2 : middle:: resolve:: ExportMap2 ,
348- pub exported_items : middle:: privacy:: ExportedItems ,
349- pub public_items : middle:: privacy:: PublicItems ,
350- pub ty_cx : ty:: ctxt < ' tcx > ,
351- pub reachable : NodeSet ,
352- pub name : String ,
353- }
354-
355-
356324/// Run the resolution, typechecking, region checking and other
357325/// miscellaneous analysis passes on the crate. Return various
358326/// structures carrying the results of the analysis.
359327pub fn phase_3_run_analysis_passes < ' tcx > ( sess : Session ,
360328 ast_map : ast_map:: Map < ' tcx > ,
361329 type_arena : & ' tcx TypedArena < ty:: TyS < ' tcx > > ,
362- name : String ) -> CrateAnalysis < ' tcx > {
330+ name : String ) -> ty :: CrateAnalysis < ' tcx > {
363331 let time_passes = sess. time_passes ( ) ;
364332 let krate = ast_map. krate ( ) ;
365333
@@ -474,7 +442,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
474442 time ( time_passes, "lint checking" , ( ) , |_|
475443 lint:: check_crate ( & ty_cx, & exported_items) ) ;
476444
477- CrateAnalysis {
445+ ty :: CrateAnalysis {
478446 exp_map2 : exp_map2,
479447 ty_cx : ty_cx,
480448 exported_items : exported_items,
@@ -486,7 +454,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
486454
487455pub fn phase_save_analysis ( sess : & Session ,
488456 krate : & ast:: Crate ,
489- analysis : & CrateAnalysis ,
457+ analysis : & ty :: CrateAnalysis ,
490458 odir : & Option < Path > ) {
491459 if ( sess. opts . debugging_opts & config:: SAVE_ANALYSIS ) == 0 {
492460 return ;
@@ -495,39 +463,24 @@ pub fn phase_save_analysis(sess: &Session,
495463 save:: process_crate ( sess, krate, analysis, odir) ) ;
496464}
497465
498- pub struct ModuleTranslation {
499- pub llcx : ContextRef ,
500- pub llmod : ModuleRef ,
501- }
502-
503- pub struct CrateTranslation {
504- pub modules : Vec < ModuleTranslation > ,
505- pub metadata_module : ModuleTranslation ,
506- pub link : LinkMeta ,
507- pub metadata : Vec < u8 > ,
508- pub reachable : Vec < String > ,
509- pub crate_formats : dependency_format:: Dependencies ,
510- pub no_builtins : bool ,
511- }
512-
513466/// Run the translation phase to LLVM, after which the AST and analysis can
514467/// be discarded.
515- pub fn phase_4_translate_to_llvm < ' tcx > ( analysis : CrateAnalysis < ' tcx > )
516- -> ( ty:: ctxt < ' tcx > , CrateTranslation ) {
468+ pub fn phase_4_translate_to_llvm < ' tcx > ( analysis : ty :: CrateAnalysis < ' tcx > )
469+ -> ( ty:: ctxt < ' tcx > , trans :: CrateTranslation ) {
517470 let time_passes = analysis. ty_cx . sess . time_passes ( ) ;
518471
519472 time ( time_passes, "resolving dependency formats" , ( ) , |_|
520473 dependency_format:: calculate ( & analysis. ty_cx ) ) ;
521474
522475 // Option dance to work around the lack of stack once closures.
523476 time ( time_passes, "translation" , analysis, |analysis|
524- trans:: base :: trans_crate ( analysis) )
477+ trans:: trans_crate ( analysis) )
525478}
526479
527480/// Run LLVM itself, producing a bitcode file, assembly file or object file
528481/// as a side effect.
529482pub fn phase_5_run_llvm_passes ( sess : & Session ,
530- trans : & CrateTranslation ,
483+ trans : & trans :: CrateTranslation ,
531484 outputs : & OutputFilenames ) {
532485 if sess. opts . cg . no_integrated_as {
533486 let output_type = config:: OutputTypeAssembly ;
@@ -555,7 +508,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
555508/// Run the linker on any artifacts that resulted from the LLVM run.
556509/// This should produce either a finished executable or library.
557510pub fn phase_6_link_output ( sess : & Session ,
558- trans : & CrateTranslation ,
511+ trans : & trans :: CrateTranslation ,
559512 outputs : & OutputFilenames ) {
560513 let old_path = os:: getenv ( "PATH" ) . unwrap_or_else ( ||String :: new ( ) ) ;
561514 let mut new_path = sess. host_filesearch ( ) . get_tools_search_paths ( ) ;
@@ -640,8 +593,8 @@ fn write_out_deps(sess: &Session,
640593 // Use default filename: crate source filename with extension replaced
641594 // by ".d"
642595 ( true , None ) => match * input {
643- FileInput ( ..) => outputs. with_extension ( "d" ) ,
644- StrInput ( ..) => {
596+ Input :: File ( ..) => outputs. with_extension ( "d" ) ,
597+ Input :: Str ( ..) => {
645598 sess. warn ( "can not write --dep-info without a filename \
646599 when compiling stdin.") ;
647600 return
@@ -752,43 +705,6 @@ pub fn collect_crate_metadata(session: &Session,
752705 session. opts . cg . metadata . clone ( )
753706}
754707
755- #[ deriving( Clone ) ]
756- pub struct OutputFilenames {
757- pub out_directory : Path ,
758- pub out_filestem : String ,
759- pub single_output_file : Option < Path > ,
760- extra : String ,
761- }
762-
763- impl OutputFilenames {
764- pub fn path ( & self , flavor : config:: OutputType ) -> Path {
765- match self . single_output_file {
766- Some ( ref path) => return path. clone ( ) ,
767- None => { }
768- }
769- self . temp_path ( flavor)
770- }
771-
772- pub fn temp_path ( & self , flavor : config:: OutputType ) -> Path {
773- let base = self . out_directory . join ( self . filestem ( ) ) ;
774- match flavor {
775- config:: OutputTypeBitcode => base. with_extension ( "bc" ) ,
776- config:: OutputTypeAssembly => base. with_extension ( "s" ) ,
777- config:: OutputTypeLlvmAssembly => base. with_extension ( "ll" ) ,
778- config:: OutputTypeObject => base. with_extension ( "o" ) ,
779- config:: OutputTypeExe => base,
780- }
781- }
782-
783- pub fn with_extension ( & self , extension : & str ) -> Path {
784- self . out_directory . join ( self . filestem ( ) ) . with_extension ( extension)
785- }
786-
787- fn filestem ( & self ) -> String {
788- format ! ( "{}{}" , self . out_filestem, self . extra)
789- }
790- }
791-
792708pub fn build_output_filenames ( input : & Input ,
793709 odir : & Option < Path > ,
794710 ofile : & Option < Path > ,
0 commit comments