@@ -37,12 +37,12 @@ fn default_environment(session::session sess,
37
37
str argv0 ,
38
38
str input ) -> eval:: env {
39
39
40
- auto libc = "libc.so" ;
41
- alt ( sess . get_targ_cfg ( ) . os ) {
42
- case ( session:: os_win32 ) { libc = "msvcrt.dll" ; }
43
- case ( session:: os_macos ) { libc = "libc.dylib" ; }
44
- case ( session :: os_linux ) { libc = "libc.so.6" ; }
45
- }
40
+ auto libc = alt ( sess . get_targ_cfg ( ) . os ) {
41
+ case ( session :: os_win32 ) { "msvcrt.dll" }
42
+ case ( session:: os_macos ) { "libc.dylib" }
43
+ case ( session:: os_linux ) { "libc.so.6" }
44
+ case ( _ ) { "libc.so" }
45
+ } ;
46
46
47
47
ret [ // Target bindings.
48
48
tup ( "target_os" , eval:: val_str ( std:: os:: target_os ( ) ) ) ,
@@ -58,13 +58,14 @@ fn default_environment(session::session sess,
58
58
fn parse_input ( session:: session sess,
59
59
parser:: parser p,
60
60
str input ) -> @ast:: crate {
61
- if ( str:: ends_with ( input, ".rc" ) ) {
62
- ret parser:: parse_crate_from_crate_file ( p) ;
61
+ ret if ( str:: ends_with ( input, ".rc" ) ) {
62
+ parser:: parse_crate_from_crate_file ( p)
63
63
} else if ( str:: ends_with ( input, ".rs" ) ) {
64
- ret parser:: parse_crate_from_source_file ( p) ;
65
- }
66
- sess. err ( "unknown input file type: " + input) ;
67
- fail;
64
+ parser:: parse_crate_from_source_file ( p)
65
+ } else {
66
+ sess. err ( "unknown input file type: " + input) ;
67
+ fail
68
+ } ;
68
69
}
69
70
70
71
fn time[ T ] ( bool do_it, str what, fn ( ) ->T thunk) -> T {
@@ -174,31 +175,36 @@ options:
174
175
}
175
176
176
177
fn get_os ( str triple ) -> session:: os {
177
- if ( str:: find ( triple, "win32" ) >= 0 ||
178
- str:: find ( triple, "mingw32" ) >= 0 ) {
179
- ret session:: os_win32;
180
- } else if ( str:: find ( triple, "darwin" ) >= 0 ) { ret session:: os_macos; }
181
- else if ( str:: find ( triple, "linux" ) >= 0 ) { ret session:: os_linux; }
182
- else { log_err "Unknown operating system!" ; fail; }
178
+ ret if ( str:: find ( triple, "win32" ) >= 0 ||
179
+ str:: find ( triple, "mingw32" ) >= 0 ) {
180
+ session:: os_win32
181
+ } else if ( str:: find ( triple, "darwin" ) >= 0 ) {
182
+ session:: os_macos
183
+ } else if ( str:: find ( triple, "linux" ) >= 0 ) {
184
+ session:: os_linux
185
+ } else {
186
+ log_err "Unknown operating system!" ;
187
+ fail
188
+ } ;
183
189
}
184
190
185
191
fn get_arch ( str triple ) -> session:: arch {
186
- if ( str:: find ( triple, "i386" ) >= 0 ||
187
- str:: find ( triple, "i486" ) >= 0 ||
188
- str:: find ( triple, "i586" ) >= 0 ||
189
- str:: find ( triple, "i686" ) >= 0 ||
190
- str:: find ( triple, "i786" ) >= 0 ) {
191
- ret session:: arch_x86;
192
+ ret if ( str:: find ( triple, "i386" ) >= 0 ||
193
+ str:: find ( triple, "i486" ) >= 0 ||
194
+ str:: find ( triple, "i586" ) >= 0 ||
195
+ str:: find ( triple, "i686" ) >= 0 ||
196
+ str:: find ( triple, "i786" ) >= 0 ) {
197
+ session:: arch_x86
192
198
} else if ( str:: find ( triple, "x86_64" ) >= 0 ) {
193
- ret session:: arch_x64;
199
+ session:: arch_x64
194
200
} else if ( str:: find ( triple, "arm" ) >= 0 ||
195
201
str:: find ( triple, "xscale" ) >= 0 ) {
196
- ret session:: arch_arm;
202
+ session:: arch_arm
197
203
}
198
204
else {
199
205
log_err ( "Unknown architecture! " + triple) ;
200
- fail;
201
- }
206
+ fail
207
+ } ;
202
208
}
203
209
204
210
fn get_default_sysroot ( str binary ) -> str {
@@ -226,16 +232,17 @@ fn build_session_options(str binary, getopts::match match)
226
232
auto shared = opt_present ( match , "shared" ) ;
227
233
auto library_search_paths = getopts:: opt_strs ( match , "L" ) ;
228
234
229
- auto output_type = link:: output_type_exe;
230
- if ( opt_present ( match , "parse-only" ) ) {
231
- output_type = link:: output_type_none;
235
+ auto output_type = if ( opt_present ( match , "parse-only" ) ) {
236
+ link:: output_type_none
232
237
} else if ( opt_present ( match , "S" ) ) {
233
- output_type = link:: output_type_assembly;
238
+ link:: output_type_assembly
234
239
} else if ( opt_present ( match , "c" ) ) {
235
- output_type = link:: output_type_object;
240
+ link:: output_type_object
236
241
} else if ( opt_present ( match , "emit-llvm" ) ) {
237
- output_type = link:: output_type_bitcode;
238
- }
242
+ link:: output_type_bitcode
243
+ } else {
244
+ link:: output_type_exe
245
+ } ;
239
246
240
247
auto verify = !opt_present ( match , "noverify" ) ;
241
248
auto save_temps = opt_present( match , "save-temps" ) ;
@@ -246,46 +253,35 @@ fn build_session_options(str binary, getopts::match match)
246
253
auto run_typestate = !opt_present( match , "no-typestate" ) ;
247
254
auto sysroot_opt = getopts:: opt_maybe_str( match , "sysroot" ) ;
248
255
249
- let uint optLevel = 0 u;
250
- if ( opt_present ( match , "O" ) ) {
251
- optLevel = 2 u;
256
+ let uint opt_level = if ( opt_present( match , "O" ) ) {
252
257
if ( opt_present( match, "OptLevel" ) ) {
253
258
log_err "error: -O and --OptLevel both provided" ;
254
259
fail;
255
260
}
256
- }
257
-
258
- if ( opt_present ( match , "OptLevel" ) ) {
259
- auto opt = getopts:: opt_maybe_str ( match , "OptLevel" ) ;
260
- alt ( opt) {
261
- case ( some[ str] ( ?s) ) {
262
- alt ( s) {
263
- case ( "0" ) { optLevel = 0 u; }
264
- case ( "1" ) { optLevel = 1 u; }
265
- case ( "2" ) { optLevel = 2 u; }
266
- case ( "3" ) { optLevel = 3 u; }
267
- case ( _) {
268
- log_err "error: optimization level needs to be between 0-3" ;
269
- fail;
270
- }
271
- }
272
- }
273
- case ( none[ str] ) {
274
- log_err "error: expected optimization level after --OptLevel=" ;
275
- fail;
261
+ 2 u
262
+ } else if ( opt_present ( match , "OptLevel" ) ) {
263
+ alt ( getopts:: opt_str( match, "OptLevel" ) ) {
264
+ case ( "0" ) { 0 u }
265
+ case ( "1" ) { 1 u }
266
+ case ( "2" ) { 2 u }
267
+ case ( "3" ) { 3 u }
268
+ case ( _) {
269
+ log_err "error: optimization level needs to be between 0-3" ;
270
+ fail
276
271
}
277
272
}
278
- }
273
+ } else {
274
+ 0 u
275
+ } ;
279
276
280
- auto sysroot;
281
- alt ( sysroot_opt) {
282
- case ( none[ str] ) { sysroot = get_default_sysroot ( binary) ; }
283
- case ( some[ str] ( ?s) ) { sysroot = s; }
284
- }
277
+ auto sysroot = alt ( sysroot_opt) {
278
+ case ( none[ str] ) { get_default_sysroot ( binary) }
279
+ case ( some[ str] ( ?s) ) { s }
280
+ } ;
285
281
286
282
let @session:: options sopts =
287
283
@rec ( shared = shared,
288
- optimize = optLevel ,
284
+ optimize = opt_level ,
289
285
debuginfo = debuginfo,
290
286
verify = verify,
291
287
run_typestate = run_typestate,
0 commit comments