88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11+ #![ cfg_attr( not( feature="llvm" ) , allow( dead_code) ) ]
12+
1113use rustc:: hir:: { self , map as hir_map} ;
1214use rustc:: hir:: lowering:: lower_crate;
1315use rustc:: ich:: Fingerprint ;
@@ -19,8 +21,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
1921use rustc:: session:: search_paths:: PathKind ;
2022use rustc:: lint;
2123use rustc:: middle:: { self , stability, reachable} ;
22- #[ cfg( feature="llvm" ) ]
23- use rustc:: middle:: dependency_format;
2424use rustc:: middle:: privacy:: AccessLevels ;
2525use rustc:: mir:: transform:: { MIR_CONST , MIR_VALIDATED , MIR_OPTIMIZED , Passes } ;
2626use rustc:: ty:: { self , TyCtxt , Resolutions , GlobalArenas } ;
@@ -33,9 +33,7 @@ use rustc_incremental::{self, IncrementalHashesMap};
3333use rustc_resolve:: { MakeGlobMap , Resolver } ;
3434use rustc_metadata:: creader:: CrateLoader ;
3535use rustc_metadata:: cstore:: { self , CStore } ;
36- #[ cfg( feature="llvm" ) ]
37- use rustc_trans:: back:: { link, write} ;
38- #[ cfg( feature="llvm" ) ]
36+ use rustc_trans:: back:: write;
3937use rustc_trans as trans;
4038use rustc_typeck as typeck;
4139use rustc_privacy;
@@ -73,11 +71,7 @@ pub fn compile_input(sess: &Session,
7371 output : & Option < PathBuf > ,
7472 addl_plugins : Option < Vec < String > > ,
7573 control : & CompileController ) -> CompileResult {
76- #[ cfg( feature="llvm" ) ]
7774 use rustc_trans:: back:: write:: OngoingCrateTranslation ;
78- #[ cfg( not( feature="llvm" ) ) ]
79- type OngoingCrateTranslation = ( ) ;
80-
8175 macro_rules! controller_entry_point {
8276 ( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
8377 let state = & mut $make_state;
@@ -94,6 +88,23 @@ pub fn compile_input(sess: &Session,
9488 } }
9589 }
9690
91+ if cfg ! ( not( feature="llvm" ) ) {
92+ use rustc:: session:: config:: CrateType ;
93+ if !sess. opts . debugging_opts . no_trans && sess. opts . output_types . should_trans ( ) {
94+ sess. err ( "LLVM is not supported by this rustc. Please use -Z no-trans to compile" )
95+ }
96+
97+ if sess. opts . crate_types . iter ( ) . all ( |& t|{
98+ t != CrateType :: CrateTypeRlib && t != CrateType :: CrateTypeExecutable
99+ } ) && !sess. opts . crate_types . is_empty ( ) {
100+ sess. err (
101+ "LLVM is not supported by this rustc, so non rlib libraries are not supported"
102+ ) ;
103+ }
104+
105+ sess. abort_if_errors ( ) ;
106+ }
107+
97108 // We need nested scopes here, because the intermediate results can keep
98109 // large chunks of memory alive and we want to free them as soon as
99110 // possible to keep the peak memory usage low
@@ -217,7 +228,6 @@ pub fn compile_input(sess: &Session,
217228 tcx. print_debug_stats ( ) ;
218229 }
219230
220- #[ cfg( feature="llvm" ) ]
221231 let trans = phase_4_translate_to_llvm ( tcx, analysis, incremental_hashes_map,
222232 & outputs) ;
223233
@@ -233,24 +243,13 @@ pub fn compile_input(sess: &Session,
233243 }
234244 }
235245
236- #[ cfg( not( feature="llvm" ) ) ]
237- {
238- let _ = incremental_hashes_map;
239- sess. err ( & format ! ( "LLVM is not supported by this rustc" ) ) ;
240- sess. abort_if_errors ( ) ;
241- unreachable ! ( ) ;
242- }
243-
244- #[ cfg( feature="llvm" ) ]
245246 Ok ( ( outputs, trans) )
246247 } ) ??
247248 } ;
248249
249- #[ cfg( not( feature="llvm" ) ) ]
250- {
251- let _ = outputs;
252- let _ = trans;
253- unreachable ! ( ) ;
250+ if cfg ! ( not( feature="llvm" ) ) {
251+ let ( _, _) = ( outputs, trans) ;
252+ sess. fatal ( "LLVM is not supported by this rustc" ) ;
254253 }
255254
256255 #[ cfg( feature="llvm" ) ]
@@ -393,7 +392,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
393392 pub resolutions : Option < & ' a Resolutions > ,
394393 pub analysis : Option < & ' a ty:: CrateAnalysis > ,
395394 pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
396- #[ cfg( feature="llvm" ) ]
397395 pub trans : Option < & ' a trans:: CrateTranslation > ,
398396}
399397
@@ -420,7 +418,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
420418 resolutions : None ,
421419 analysis : None ,
422420 tcx : None ,
423- #[ cfg( feature="llvm" ) ]
424421 trans : None ,
425422 }
426423 }
@@ -509,7 +506,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
509506 }
510507 }
511508
512- #[ cfg( feature="llvm" ) ]
513509 fn state_after_llvm ( input : & ' a Input ,
514510 session : & ' tcx Session ,
515511 out_dir : & ' a Option < PathBuf > ,
@@ -523,7 +519,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
523519 }
524520 }
525521
526- #[ cfg( feature="llvm" ) ]
527522 fn state_when_compilation_done ( input : & ' a Input ,
528523 session : & ' tcx Session ,
529524 out_dir : & ' a Option < PathBuf > ,
@@ -942,7 +937,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
942937 mir:: provide ( & mut local_providers) ;
943938 reachable:: provide ( & mut local_providers) ;
944939 rustc_privacy:: provide ( & mut local_providers) ;
945- #[ cfg( feature="llvm" ) ]
946940 trans:: provide ( & mut local_providers) ;
947941 typeck:: provide ( & mut local_providers) ;
948942 ty:: provide ( & mut local_providers) ;
@@ -955,7 +949,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
955949
956950 let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
957951 cstore:: provide ( & mut extern_providers) ;
958- #[ cfg( feature="llvm" ) ]
959952 trans:: provide ( & mut extern_providers) ;
960953 ty:: provide_extern ( & mut extern_providers) ;
961954 traits:: provide_extern ( & mut extern_providers) ;
@@ -1102,7 +1095,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
11021095
11031096/// Run the translation phase to LLVM, after which the AST and analysis can
11041097/// be discarded.
1105- #[ cfg( feature="llvm" ) ]
11061098pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
11071099 analysis : ty:: CrateAnalysis ,
11081100 incremental_hashes_map : IncrementalHashesMap ,
@@ -1112,7 +1104,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11121104
11131105 time ( time_passes,
11141106 "resolving dependency formats" ,
1115- || dependency_format:: calculate ( tcx) ) ;
1107+ || :: rustc :: middle :: dependency_format:: calculate ( tcx) ) ;
11161108
11171109 let translation =
11181110 time ( time_passes,
@@ -1147,9 +1139,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11471139pub fn phase_6_link_output ( sess : & Session ,
11481140 trans : & trans:: CrateTranslation ,
11491141 outputs : & OutputFilenames ) {
1150- time ( sess. time_passes ( ) ,
1151- "linking" ,
1152- || link :: link_binary ( sess , trans , outputs , & trans . crate_name . as_str ( ) ) ) ;
1142+ time ( sess. time_passes ( ) , "linking" , || {
1143+ :: rustc_trans :: back :: link :: link_binary ( sess , trans , outputs , & trans . crate_name . as_str ( ) )
1144+ } ) ;
11531145}
11541146
11551147fn escape_dep_filename ( filename : & str ) -> String {
0 commit comments