8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- pub use self :: Input :: * ;
12
-
13
11
use back:: link;
14
12
use back:: write;
15
13
use session:: Session ;
16
- use session:: config;
14
+ use session:: config:: { mod , Input , OutputFilenames } ;
17
15
use lint;
18
- use llvm:: { ContextRef , ModuleRef } ;
19
- use metadata:: common:: LinkMeta ;
20
16
use metadata:: creader;
21
17
use middle:: { stability, ty, reachable} ;
22
18
use middle:: dependency_format;
@@ -28,7 +24,6 @@ use rustc::typeck;
28
24
use trans;
29
25
30
26
use util:: common:: time;
31
- use util:: nodemap:: { NodeSet } ;
32
27
33
28
use serialize:: { json, Encodable } ;
34
29
@@ -114,36 +109,19 @@ pub fn anon_src() -> String {
114
109
pub fn source_name ( input : & Input ) -> String {
115
110
match * input {
116
111
// 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 ( )
135
114
}
136
115
}
137
116
138
-
139
117
pub fn phase_1_parse_input ( sess : & Session , cfg : ast:: CrateConfig , input : & Input )
140
118
-> ast:: Crate {
141
119
let krate = time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
142
120
match * input {
143
- FileInput ( ref file) => {
121
+ Input :: File ( ref file) => {
144
122
parse:: parse_crate_from_file ( & ( * file) , cfg. clone ( ) , & sess. parse_sess )
145
123
}
146
- StrInput ( ref src) => {
124
+ Input :: Str ( ref src) => {
147
125
parse:: parse_crate_from_source_str ( anon_src ( ) . to_string ( ) ,
148
126
src. to_string ( ) ,
149
127
cfg. clone ( ) ,
@@ -343,23 +321,13 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
343
321
map
344
322
}
345
323
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
-
356
324
/// Run the resolution, typechecking, region checking and other
357
325
/// miscellaneous analysis passes on the crate. Return various
358
326
/// structures carrying the results of the analysis.
359
327
pub fn phase_3_run_analysis_passes < ' tcx > ( sess : Session ,
360
328
ast_map : ast_map:: Map < ' tcx > ,
361
329
type_arena : & ' tcx TypedArena < ty:: TyS < ' tcx > > ,
362
- name : String ) -> CrateAnalysis < ' tcx > {
330
+ name : String ) -> ty :: CrateAnalysis < ' tcx > {
363
331
let time_passes = sess. time_passes ( ) ;
364
332
let krate = ast_map. krate ( ) ;
365
333
@@ -474,7 +442,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
474
442
time ( time_passes, "lint checking" , ( ) , |_|
475
443
lint:: check_crate ( & ty_cx, & exported_items) ) ;
476
444
477
- CrateAnalysis {
445
+ ty :: CrateAnalysis {
478
446
exp_map2 : exp_map2,
479
447
ty_cx : ty_cx,
480
448
exported_items : exported_items,
@@ -486,7 +454,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
486
454
487
455
pub fn phase_save_analysis ( sess : & Session ,
488
456
krate : & ast:: Crate ,
489
- analysis : & CrateAnalysis ,
457
+ analysis : & ty :: CrateAnalysis ,
490
458
odir : & Option < Path > ) {
491
459
if ( sess. opts . debugging_opts & config:: SAVE_ANALYSIS ) == 0 {
492
460
return ;
@@ -495,39 +463,24 @@ pub fn phase_save_analysis(sess: &Session,
495
463
save:: process_crate ( sess, krate, analysis, odir) ) ;
496
464
}
497
465
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
-
513
466
/// Run the translation phase to LLVM, after which the AST and analysis can
514
467
/// 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 ) {
517
470
let time_passes = analysis. ty_cx . sess . time_passes ( ) ;
518
471
519
472
time ( time_passes, "resolving dependency formats" , ( ) , |_|
520
473
dependency_format:: calculate ( & analysis. ty_cx ) ) ;
521
474
522
475
// Option dance to work around the lack of stack once closures.
523
476
time ( time_passes, "translation" , analysis, |analysis|
524
- trans:: base :: trans_crate ( analysis) )
477
+ trans:: trans_crate ( analysis) )
525
478
}
526
479
527
480
/// Run LLVM itself, producing a bitcode file, assembly file or object file
528
481
/// as a side effect.
529
482
pub fn phase_5_run_llvm_passes ( sess : & Session ,
530
- trans : & CrateTranslation ,
483
+ trans : & trans :: CrateTranslation ,
531
484
outputs : & OutputFilenames ) {
532
485
if sess. opts . cg . no_integrated_as {
533
486
let output_type = config:: OutputTypeAssembly ;
@@ -555,7 +508,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
555
508
/// Run the linker on any artifacts that resulted from the LLVM run.
556
509
/// This should produce either a finished executable or library.
557
510
pub fn phase_6_link_output ( sess : & Session ,
558
- trans : & CrateTranslation ,
511
+ trans : & trans :: CrateTranslation ,
559
512
outputs : & OutputFilenames ) {
560
513
let old_path = os:: getenv ( "PATH" ) . unwrap_or_else ( ||String :: new ( ) ) ;
561
514
let mut new_path = sess. host_filesearch ( ) . get_tools_search_paths ( ) ;
@@ -640,8 +593,8 @@ fn write_out_deps(sess: &Session,
640
593
// Use default filename: crate source filename with extension replaced
641
594
// by ".d"
642
595
( true , None ) => match * input {
643
- FileInput ( ..) => outputs. with_extension ( "d" ) ,
644
- StrInput ( ..) => {
596
+ Input :: File ( ..) => outputs. with_extension ( "d" ) ,
597
+ Input :: Str ( ..) => {
645
598
sess. warn ( "can not write --dep-info without a filename \
646
599
when compiling stdin.") ;
647
600
return
@@ -752,43 +705,6 @@ pub fn collect_crate_metadata(session: &Session,
752
705
session. opts . cg . metadata . clone ( )
753
706
}
754
707
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
-
792
708
pub fn build_output_filenames ( input : & Input ,
793
709
odir : & Option < Path > ,
794
710
ofile : & Option < Path > ,
0 commit comments