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
-
13
11
use rustc:: dep_graph:: DepGraph ;
14
12
use rustc:: hir:: { self , map as hir_map} ;
15
13
use rustc:: hir:: lowering:: lower_crate;
@@ -34,15 +32,16 @@ use rustc_incremental;
34
32
use rustc_resolve:: { MakeGlobMap , Resolver } ;
35
33
use rustc_metadata:: creader:: CrateLoader ;
36
34
use rustc_metadata:: cstore:: { self , CStore } ;
37
- use rustc_trans:: back:: write;
38
35
use rustc_trans as trans;
36
+ use rustc_trans_utils:: trans_crate:: TransCrate ;
39
37
use rustc_typeck as typeck;
40
38
use rustc_privacy;
41
39
use rustc_plugin:: registry:: Registry ;
42
40
use rustc_plugin as plugin;
43
41
use rustc_passes:: { ast_validation, no_asm, loops, consts, static_recursion, hir_stats} ;
44
42
use rustc_const_eval:: { self , check_match} ;
45
43
use super :: Compilation ;
44
+ use :: DefaultTransCrate ;
46
45
47
46
use serialize:: json;
48
47
@@ -76,7 +75,8 @@ pub fn compile_input(sess: &Session,
76
75
output : & Option < PathBuf > ,
77
76
addl_plugins : Option < Vec < String > > ,
78
77
control : & CompileController ) -> CompileResult {
79
- use rustc_trans:: back:: write:: OngoingCrateTranslation ;
78
+ use rustc:: session:: config:: CrateType ;
79
+
80
80
macro_rules! controller_entry_point {
81
81
( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
82
82
let state = & mut $make_state;
@@ -94,17 +94,16 @@ pub fn compile_input(sess: &Session,
94
94
}
95
95
96
96
if cfg ! ( not( feature="llvm" ) ) {
97
- use rustc:: session:: config:: CrateType ;
98
- if !sess. opts . debugging_opts . no_trans && sess. opts . output_types . should_trans ( ) {
99
- sess. err ( "LLVM is not supported by this rustc. Please use -Z no-trans to compile" )
100
- }
101
-
102
- if sess. opts . crate_types . iter ( ) . all ( |& t|{
103
- t != CrateType :: CrateTypeRlib && t != CrateType :: CrateTypeExecutable
104
- } ) && !sess. opts . crate_types . is_empty ( ) {
105
- sess. err (
106
- "LLVM is not supported by this rustc, so non rlib libraries are not supported"
107
- ) ;
97
+ for cty in sess. opts . crate_types . iter ( ) {
98
+ match * cty {
99
+ CrateType :: CrateTypeRlib | CrateType :: CrateTypeDylib |
100
+ CrateType :: CrateTypeExecutable => { } ,
101
+ _ => {
102
+ sess. parse_sess . span_diagnostic . warn (
103
+ & format ! ( "LLVM unsupported, so output type {} is not supported" , cty)
104
+ ) ;
105
+ } ,
106
+ }
108
107
}
109
108
110
109
sess. abort_if_errors ( ) ;
@@ -117,7 +116,7 @@ pub fn compile_input(sess: &Session,
117
116
// We need nested scopes here, because the intermediate results can keep
118
117
// large chunks of memory alive and we want to free them as soon as
119
118
// possible to keep the peak memory usage low
120
- let ( outputs, trans, dep_graph) : ( OutputFilenames , OngoingCrateTranslation , DepGraph ) = {
119
+ let ( outputs, trans, dep_graph) = {
121
120
let krate = match phase_1_parse_input ( control, sess, input) {
122
121
Ok ( krate) => krate,
123
122
Err ( mut parse_error) => {
@@ -246,7 +245,7 @@ pub fn compile_input(sess: &Session,
246
245
tcx. print_debug_stats ( ) ;
247
246
}
248
247
249
- let trans = phase_4_translate_to_llvm ( tcx, rx) ;
248
+ let trans = phase_4_translate_to_llvm :: < DefaultTransCrate > ( tcx, rx) ;
250
249
251
250
if log_enabled ! ( :: log:: LogLevel :: Info ) {
252
251
println ! ( "Post-trans" ) ;
@@ -264,44 +263,42 @@ pub fn compile_input(sess: &Session,
264
263
} ) ??
265
264
} ;
266
265
267
- if cfg ! ( not( feature="llvm" ) ) {
268
- let ( _, _) = ( outputs, trans) ;
269
- sess. fatal ( "LLVM is not supported by this rustc" ) ;
266
+ if sess. opts . debugging_opts . print_type_sizes {
267
+ sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
270
268
}
271
269
272
- #[ cfg( feature="llvm" ) ]
273
- {
274
- if sess. opts . debugging_opts . print_type_sizes {
275
- sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
276
- }
277
-
278
- let ( phase5_result, trans) = phase_5_run_llvm_passes ( sess, & dep_graph, trans) ;
270
+ let ( phase5_result, trans) =
271
+ phase_5_run_llvm_passes :: < DefaultTransCrate > ( sess, & dep_graph, trans) ;
279
272
280
- controller_entry_point ! ( after_llvm,
281
- sess,
282
- CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
283
- phase5_result) ;
284
- phase5_result?;
273
+ controller_entry_point ! ( after_llvm,
274
+ sess,
275
+ CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
276
+ phase5_result) ;
277
+ phase5_result?;
285
278
286
- phase_6_link_output ( sess , & trans , & outputs ) ;
287
-
288
- // Now that we won't touch anything in the incremental compilation directory
289
- // any more, we can finalize it (which involves renaming it )
290
- rustc_incremental :: finalize_session_directory ( sess , trans . link . crate_hash ) ;
279
+ // Run the linker on any artifacts that resulted from the LLVM run.
280
+ // This should produce either a finished executable or library.
281
+ time ( sess . time_passes ( ) , "linking" , || {
282
+ DefaultTransCrate :: link_binary ( sess , & trans , & outputs )
283
+ } ) ;
291
284
292
- if sess. opts . debugging_opts . perf_stats {
293
- sess. print_perf_stats ( ) ;
294
- }
285
+ // Now that we won't touch anything in the incremental compilation directory
286
+ // any more, we can finalize it (which involves renaming it)
287
+ #[ cfg( feature="llvm" ) ]
288
+ rustc_incremental:: finalize_session_directory ( sess, trans. link . crate_hash ) ;
295
289
296
- controller_entry_point ! (
297
- compilation_done,
298
- sess,
299
- CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
300
- Ok ( ( ) )
301
- ) ;
290
+ if sess. opts . debugging_opts . perf_stats {
291
+ sess. print_perf_stats ( ) ;
292
+ }
302
293
294
+ controller_entry_point ! (
295
+ compilation_done,
296
+ sess,
297
+ CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
303
298
Ok ( ( ) )
304
- }
299
+ ) ;
300
+
301
+ Ok ( ( ) )
305
302
}
306
303
307
304
fn keep_hygiene_data ( sess : & Session ) -> bool {
@@ -970,7 +967,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
970
967
mir:: provide ( & mut local_providers) ;
971
968
reachable:: provide ( & mut local_providers) ;
972
969
rustc_privacy:: provide ( & mut local_providers) ;
973
- trans :: provide_local ( & mut local_providers) ;
970
+ DefaultTransCrate :: provide_local ( & mut local_providers) ;
974
971
typeck:: provide ( & mut local_providers) ;
975
972
ty:: provide ( & mut local_providers) ;
976
973
traits:: provide ( & mut local_providers) ;
@@ -982,7 +979,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
982
979
983
980
let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
984
981
cstore:: provide ( & mut extern_providers) ;
985
- trans :: provide_extern ( & mut extern_providers) ;
982
+ DefaultTransCrate :: provide_extern ( & mut extern_providers) ;
986
983
ty:: provide_extern ( & mut extern_providers) ;
987
984
traits:: provide_extern ( & mut extern_providers) ;
988
985
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
@@ -1126,9 +1123,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
1126
1123
1127
1124
/// Run the translation phase to LLVM, after which the AST and analysis can
1128
1125
/// be discarded.
1129
- pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1126
+ pub fn phase_4_translate_to_llvm < ' a , ' tcx , Trans : TransCrate > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1130
1127
rx : mpsc:: Receiver < Box < Any + Send > > )
1131
- -> write :: OngoingCrateTranslation {
1128
+ -> < Trans as TransCrate > :: OngoingCrateTranslation {
1132
1129
let time_passes = tcx. sess . time_passes ( ) ;
1133
1130
1134
1131
time ( time_passes,
@@ -1137,9 +1134,8 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1137
1134
1138
1135
let translation =
1139
1136
time ( time_passes, "translation" , move || {
1140
- trans :: trans_crate ( tcx, rx)
1137
+ Trans :: trans_crate ( tcx, rx)
1141
1138
} ) ;
1142
-
1143
1139
if tcx. sess . profile_queries ( ) {
1144
1140
profile:: dump ( "profile_queries" . to_string ( ) )
1145
1141
}
@@ -1149,15 +1145,14 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1149
1145
1150
1146
/// Run LLVM itself, producing a bitcode file, assembly file or object file
1151
1147
/// as a side effect.
1152
- #[ cfg( feature="llvm" ) ]
1153
- pub fn phase_5_run_llvm_passes ( sess : & Session ,
1148
+ pub fn phase_5_run_llvm_passes < Trans : TransCrate > ( sess : & Session ,
1154
1149
dep_graph : & DepGraph ,
1155
- trans : write :: OngoingCrateTranslation )
1156
- -> ( CompileResult , trans :: CrateTranslation ) {
1157
- let trans = trans . join ( sess, dep_graph) ;
1150
+ trans : < Trans as TransCrate > :: OngoingCrateTranslation )
1151
+ -> ( CompileResult , < Trans as TransCrate > :: TranslatedCrate ) {
1152
+ let trans = Trans :: join_trans ( trans , sess, dep_graph) ;
1158
1153
1159
1154
if sess. opts . debugging_opts . incremental_info {
1160
- write :: dump_incremental_data ( & trans) ;
1155
+ Trans :: dump_incremental_data ( & trans) ;
1161
1156
}
1162
1157
1163
1158
time ( sess. time_passes ( ) ,
@@ -1167,20 +1162,6 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
1167
1162
( sess. compile_status ( ) , trans)
1168
1163
}
1169
1164
1170
- /// Run the linker on any artifacts that resulted from the LLVM run.
1171
- /// This should produce either a finished executable or library.
1172
- #[ cfg( feature="llvm" ) ]
1173
- pub fn phase_6_link_output ( sess : & Session ,
1174
- trans : & trans:: CrateTranslation ,
1175
- outputs : & OutputFilenames ) {
1176
- time ( sess. time_passes ( ) , "linking" , || {
1177
- :: rustc_trans:: back:: link:: link_binary ( sess,
1178
- trans,
1179
- outputs,
1180
- & trans. crate_name . as_str ( ) )
1181
- } ) ;
1182
- }
1183
-
1184
1165
fn escape_dep_filename ( filename : & str ) -> String {
1185
1166
// Apparently clang and gcc *only* escape spaces:
1186
1167
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
0 commit comments