8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ #![ cfg_attr( not( feature="llvm" ) , allow( dead_code) ) ]
12
+
11
13
use rustc:: hir:: { self , map as hir_map} ;
12
14
use rustc:: hir:: lowering:: lower_crate;
13
15
use rustc:: ich:: Fingerprint ;
@@ -19,8 +21,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
19
21
use rustc:: session:: search_paths:: PathKind ;
20
22
use rustc:: lint;
21
23
use rustc:: middle:: { self , stability, reachable} ;
22
- #[ cfg( feature="llvm" ) ]
23
- use rustc:: middle:: dependency_format;
24
24
use rustc:: middle:: privacy:: AccessLevels ;
25
25
use rustc:: mir:: transform:: { MIR_CONST , MIR_VALIDATED , MIR_OPTIMIZED , Passes } ;
26
26
use rustc:: ty:: { self , TyCtxt , Resolutions , GlobalArenas } ;
@@ -33,9 +33,7 @@ use rustc_incremental::{self, IncrementalHashesMap};
33
33
use rustc_resolve:: { MakeGlobMap , Resolver } ;
34
34
use rustc_metadata:: creader:: CrateLoader ;
35
35
use 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;
39
37
use rustc_trans as trans;
40
38
use rustc_typeck as typeck;
41
39
use rustc_privacy;
@@ -73,8 +71,6 @@ pub fn compile_input(sess: &Session,
73
71
output : & Option < PathBuf > ,
74
72
addl_plugins : Option < Vec < String > > ,
75
73
control : & CompileController ) -> CompileResult {
76
- use rustc_trans:: back:: write:: OngoingCrateTranslation ;
77
-
78
74
macro_rules! controller_entry_point {
79
75
( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
80
76
let state = & mut $make_state;
@@ -91,10 +87,27 @@ pub fn compile_input(sess: &Session,
91
87
} }
92
88
}
93
89
90
+ if cfg ! ( not( feature="llvm" ) ) {
91
+ use rustc:: session:: config:: CrateType ;
92
+ if !sess. opts . debugging_opts . no_trans && sess. opts . output_types . should_trans ( ) {
93
+ sess. err ( "LLVM is not supported by this rustc. Please use -Z no-trans to compile" )
94
+ }
95
+
96
+ if sess. opts . crate_types . iter ( ) . all ( |& t|{
97
+ t != CrateType :: CrateTypeRlib && t != CrateType :: CrateTypeExecutable
98
+ } ) {
99
+ sess. err (
100
+ "LLVM is not supported by this rustc, so non rlib libraries are not supported"
101
+ ) ;
102
+ }
103
+
104
+ sess. abort_if_errors ( ) ;
105
+ }
106
+
94
107
// We need nested scopes here, because the intermediate results can keep
95
108
// large chunks of memory alive and we want to free them as soon as
96
109
// possible to keep the peak memory usage low
97
- let ( outputs, trans) : ( OutputFilenames , OngoingCrateTranslation ) = {
110
+ let ( outputs, trans) : ( OutputFilenames , write :: OngoingCrateTranslation ) = {
98
111
let krate = match phase_1_parse_input ( control, sess, input) {
99
112
Ok ( krate) => krate,
100
113
Err ( mut parse_error) => {
@@ -214,7 +227,6 @@ pub fn compile_input(sess: &Session,
214
227
tcx. print_debug_stats ( ) ;
215
228
}
216
229
217
- #[ cfg( feature="llvm" ) ]
218
230
let trans = phase_4_translate_to_llvm ( tcx, analysis, incremental_hashes_map,
219
231
& outputs) ;
220
232
@@ -230,24 +242,14 @@ pub fn compile_input(sess: &Session,
230
242
}
231
243
}
232
244
233
- #[ cfg( not( feature="llvm" ) ) ]
234
- {
235
- let _ = incremental_hashes_map;
236
- sess. err ( & format ! ( "LLVM is not supported by this rustc" ) ) ;
237
- sess. abort_if_errors ( ) ;
238
- unreachable ! ( ) ;
239
- }
240
-
241
- #[ cfg( feature="llvm" ) ]
242
245
Ok ( ( outputs, trans) )
243
246
} ) ??
244
247
} ;
245
248
246
249
#[ cfg( not( feature="llvm" ) ) ]
247
250
{
248
- let _ = outputs;
249
- let _ = trans;
250
- unreachable ! ( ) ;
251
+ let ( _, _) = ( outputs, trans) ;
252
+ sess. fatal ( "LLVM is not supported by this rustc" ) ;
251
253
}
252
254
253
255
#[ cfg( feature="llvm" ) ]
@@ -504,7 +506,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
504
506
}
505
507
}
506
508
507
- #[ cfg( feature="llvm" ) ]
508
509
fn state_after_llvm ( input : & ' a Input ,
509
510
session : & ' tcx Session ,
510
511
out_dir : & ' a Option < PathBuf > ,
@@ -518,7 +519,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
518
519
}
519
520
}
520
521
521
- #[ cfg( feature="llvm" ) ]
522
522
fn state_when_compilation_done ( input : & ' a Input ,
523
523
session : & ' tcx Session ,
524
524
out_dir : & ' a Option < PathBuf > ,
@@ -1095,7 +1095,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
1095
1095
1096
1096
/// Run the translation phase to LLVM, after which the AST and analysis can
1097
1097
/// be discarded.
1098
- #[ cfg( feature="llvm" ) ]
1099
1098
pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1100
1099
analysis : ty:: CrateAnalysis ,
1101
1100
incremental_hashes_map : IncrementalHashesMap ,
@@ -1105,7 +1104,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1105
1104
1106
1105
time ( time_passes,
1107
1106
"resolving dependency formats" ,
1108
- || dependency_format:: calculate ( tcx) ) ;
1107
+ || :: rustc :: middle :: dependency_format:: calculate ( tcx) ) ;
1109
1108
1110
1109
let translation =
1111
1110
time ( time_passes,
@@ -1140,9 +1139,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
1140
1139
pub fn phase_6_link_output ( sess : & Session ,
1141
1140
trans : & trans:: CrateTranslation ,
1142
1141
outputs : & OutputFilenames ) {
1143
- time ( sess. time_passes ( ) ,
1144
- "linking" ,
1145
- || 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
+ } ) ;
1146
1145
}
1147
1146
1148
1147
fn escape_dep_filename ( filename : & str ) -> String {
0 commit comments