@@ -78,50 +78,39 @@ fn time[T](bool do_it, str what, fn()->T thunk) -> T {
78
78
}
79
79
80
80
fn compile_input ( session . session sess,
81
- eval . env env,
82
- str input , str output ,
83
- bool shared ,
84
- bool optimize ,
85
- bool debuginfo ,
86
- bool verify ,
87
- bool save_temps ,
88
- trans. output_type ot ,
89
- bool time_passes ,
90
- bool run_typestate ,
91
- vec[ str] library_search_paths ) {
81
+ eval . env env,
82
+ str input , str output ) {
83
+ auto time_passes = sess. get_opts ( ) . time_passes ;
92
84
auto def = tup ( 0 , 0 ) ;
93
85
auto p = parser. new_parser ( sess, env, def, input, 0 u) ;
94
86
auto crate = time[ @ast. crate ] ( time_passes, "parsing" ,
95
- bind parse_input ( sess, p, input) ) ;
96
- if ( ot == trans. output_type_none ) { ret; }
87
+ bind parse_input ( sess, p, input) ) ;
88
+ if ( sess . get_opts ( ) . output_type == trans. output_type_none ) { ret; }
97
89
98
90
crate = time[ @ast. crate ] ( time_passes, "external crate reading" ,
99
- bind creader. read_crates ( sess, crate , library_search_paths ) ) ;
91
+ bind creader. read_crates ( sess, crate ) ) ;
100
92
crate = time[ @ast. crate ] ( time_passes, "resolution" ,
101
- bind resolve. resolve_crate ( sess, crate ) ) ;
93
+ bind resolve. resolve_crate ( sess, crate ) ) ;
102
94
time[ ( ) ] ( time_passes, "capture checking" ,
103
- bind capture. check_for_captures ( sess, crate ) ) ;
95
+ bind capture. check_for_captures ( sess, crate ) ) ;
104
96
105
97
auto ty_cx = ty. mk_ctxt ( sess) ;
106
98
auto typeck_result =
107
99
time[ typeck. typecheck_result ] ( time_passes, "typechecking" ,
108
- bind typeck. check_crate ( ty_cx, crate ) ) ;
100
+ bind typeck. check_crate ( ty_cx, crate ) ) ;
109
101
crate = typeck_result. _0 ;
110
102
auto type_cache = typeck_result. _1 ;
111
103
112
- if ( run_typestate) {
104
+ if ( sess . get_opts ( ) . run_typestate ) {
113
105
crate = time[ @ast. crate ] ( time_passes, "typestate checking" ,
114
106
bind typestate_check. check_crate ( crate ) ) ;
115
107
}
116
108
117
109
auto llmod = time[ llvm. ModuleRef ] ( time_passes, "translation" ,
118
- bind trans. trans_crate ( sess, crate , ty_cx, type_cache, output,
119
- debuginfo, shared) ) ;
110
+ bind trans. trans_crate ( sess, crate , ty_cx, type_cache, output) ) ;
120
111
121
112
time[ ( ) ] ( time_passes, "LLVM passes" ,
122
- bind trans. run_passes ( llmod, optimize, debuginfo,
123
- verify, save_temps, output,
124
- ot) ) ;
113
+ bind trans. run_passes ( sess, llmod, output) ) ;
125
114
}
126
115
127
116
fn pretty_print_input ( session . session sess,
@@ -133,7 +122,7 @@ fn pretty_print_input(session.session sess,
133
122
pretty. pprust . print_file ( crate . node. module , input, std. io . stdout ( ) ) ;
134
123
}
135
124
136
- fn usage ( session . session sess , str argv0 ) {
125
+ fn usage ( str argv0 ) {
137
126
io. stdout ( ) . write_str ( #fmt ( "usage: %s [options] <input>\n " , argv0) + "
138
127
options:
139
128
@@ -166,17 +155,12 @@ fn get_os() -> session.os {
166
155
fn main ( vec[ str] args ) {
167
156
168
157
// FIXME: don't hard-wire this.
169
- auto target_cfg = rec ( os = get_os ( ) ,
170
- arch = session. arch_x86 ,
171
- int_type = common. ty_i32 ,
172
- uint_type = common. ty_u32 ,
173
- float_type = common. ty_f64 ) ;
174
-
175
- auto crate_cache = common. new_int_hash [ session. crate_metadata ] ( ) ;
176
- auto target_crate_num = 0 ;
177
- let vec[ @ast. meta_item] md = vec ( ) ;
178
- auto sess = session. session ( target_crate_num, target_cfg, crate_cache,
179
- md, front. codemap . new_codemap ( ) ) ;
158
+ let @session. config target_cfg =
159
+ @rec ( os = get_os ( ) ,
160
+ arch = session. arch_x86 ,
161
+ int_type = common. ty_i32 ,
162
+ uint_type = common. ty_u32 ,
163
+ float_type = common. ty_f64 ) ;
180
164
181
165
auto opts = vec ( optflag ( "h" ) , optflag ( "glue" ) ,
182
166
optflag ( "pretty" ) , optflag ( "ls" ) , optflag ( "parse-only" ) ,
@@ -187,11 +171,14 @@ fn main(vec[str] args) {
187
171
auto binary = _vec. shift [ str] ( args) ;
188
172
auto match;
189
173
alt ( GetOpts . getopts ( args, opts) ) {
190
- case ( GetOpts . failure ( ?f) ) { sess. err ( GetOpts . fail_str ( f) ) ; fail; }
174
+ case ( GetOpts . failure ( ?f) ) {
175
+ log_err #fmt( "error: %s" , GetOpts . fail_str ( f) ) ;
176
+ fail;
177
+ }
191
178
case ( GetOpts . success ( ?m) ) { match = m; }
192
179
}
193
180
if ( opt_present ( match , "h" ) ) {
194
- usage ( sess , binary) ;
181
+ usage ( binary) ;
195
182
ret;
196
183
}
197
184
@@ -201,13 +188,13 @@ fn main(vec[str] args) {
201
188
auto shared = opt_present ( match , "shared" ) ;
202
189
auto output_file = GetOpts . opt_maybe_str ( match , "o" ) ;
203
190
auto library_search_paths = GetOpts . opt_strs ( match , "L" ) ;
204
- auto ot = trans. output_type_bitcode ;
191
+ auto output_type = trans. output_type_bitcode ;
205
192
if ( opt_present ( match , "parse-only" ) ) {
206
- ot = trans. output_type_none ;
193
+ output_type = trans. output_type_none ;
207
194
} else if ( opt_present ( match , "S" ) ) {
208
- ot = trans. output_type_assembly ;
195
+ output_type = trans. output_type_assembly ;
209
196
} else if ( opt_present ( match , "c" ) ) {
210
- ot = trans. output_type_object ;
197
+ output_type = trans. output_type_object ;
211
198
}
212
199
auto verify = !opt_present ( match , "noverify" ) ;
213
200
auto save_temps = opt_present ( match , "save-temps" ) ;
@@ -216,14 +203,33 @@ fn main(vec[str] args) {
216
203
auto debuginfo = opt_present ( match , "g" ) ;
217
204
auto time_passes = opt_present ( match , "time-passes" ) ;
218
205
auto run_typestate = !opt_present ( match , "no-typestate" ) ;
206
+
207
+ let @session. options sopts =
208
+ @rec ( shared = shared,
209
+ optimize = optimize,
210
+ debuginfo = debuginfo,
211
+ verify = verify,
212
+ run_typestate = run_typestate,
213
+ save_temps = save_temps,
214
+ time_passes = time_passes,
215
+ output_type = output_type,
216
+ library_search_paths = library_search_paths) ;
217
+
218
+ auto crate_cache = common. new_int_hash [ session. crate_metadata ] ( ) ;
219
+ auto target_crate_num = 0 ;
220
+ let vec[ @ast. meta_item] md = vec ( ) ;
221
+ auto sess =
222
+ session. session ( target_crate_num, target_cfg, sopts,
223
+ crate_cache, md, front. codemap . new_codemap ( ) ) ;
224
+
219
225
auto n_inputs = _vec. len [ str] ( match . free) ;
220
226
221
227
if ( glue) {
222
228
if ( n_inputs > 0 u) {
223
229
sess. err ( "No input files allowed with --glue." ) ;
224
230
}
225
231
auto out = option. from_maybe [ str] ( "glue.bc" , output_file) ;
226
- middle. trans . make_common_glue ( out , optimize , verify , save_temps , ot ) ;
232
+ middle. trans . make_common_glue ( sess , out ) ;
227
233
ret;
228
234
}
229
235
@@ -244,18 +250,21 @@ fn main(vec[str] args) {
244
250
case ( none[ str] ) {
245
251
let vec[ str] parts = _str. split ( ifile, '.' as u8 ) ;
246
252
_vec. pop [ str] ( parts) ;
247
- parts += vec ( "bc" ) ;
253
+ alt ( output_type) {
254
+ case ( trans. output_type_none )
255
+ { parts += vec ( "pp" ) ; }
256
+ case ( trans. output_type_bitcode )
257
+ { parts += vec ( "bc" ) ; }
258
+ case ( trans. output_type_assembly )
259
+ { parts += vec ( "s" ) ; }
260
+ case ( trans. output_type_object )
261
+ { parts += vec ( "o" ) ; }
262
+ }
248
263
auto ofile = _str. connect ( parts, "." ) ;
249
- compile_input ( sess, env, ifile, ofile, shared,
250
- optimize, debuginfo, verify,
251
- save_temps, ot, time_passes,
252
- run_typestate, library_search_paths) ;
264
+ compile_input ( sess, env, ifile, ofile) ;
253
265
}
254
266
case ( some[ str] ( ?ofile) ) {
255
- compile_input ( sess, env, ifile, ofile, shared,
256
- optimize, debuginfo, verify,
257
- save_temps, ot, time_passes,
258
- run_typestate, library_search_paths) ;
267
+ compile_input ( sess, env, ifile, ofile) ;
259
268
}
260
269
}
261
270
}
0 commit comments