Skip to content

Commit ac0dea8

Browse files
committed
---
yaml --- r: 2742 b: refs/heads/master c: db7611c h: refs/heads/master v: v3
1 parent 37023ab commit ac0dea8

File tree

2 files changed

+62
-66
lines changed

2 files changed

+62
-66
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1081d0aee9fc0b942a90cff5b88c08f17454f763
2+
refs/heads/master: db7611c4c9b8a0ad84d8e69930d237b74211ceb1

trunk/src/comp/driver/rustc.rs

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ fn default_environment(session::session sess,
3737
str argv0,
3838
str input) -> eval::env {
3939

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+
};
4646

4747
ret [// Target bindings.
4848
tup("target_os", eval::val_str(std::os::target_os())),
@@ -58,13 +58,14 @@ fn default_environment(session::session sess,
5858
fn parse_input(session::session sess,
5959
parser::parser p,
6060
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)
6363
} 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+
};
6869
}
6970

7071
fn time[T](bool do_it, str what, fn()->T thunk) -> T {
@@ -174,31 +175,36 @@ options:
174175
}
175176

176177
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+
};
183189
}
184190

185191
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
192198
} else if (str::find(triple, "x86_64") >= 0) {
193-
ret session::arch_x64;
199+
session::arch_x64
194200
} else if (str::find(triple, "arm") >= 0 ||
195201
str::find(triple, "xscale") >= 0 ) {
196-
ret session::arch_arm;
202+
session::arch_arm
197203
}
198204
else {
199205
log_err ("Unknown architecture! " + triple);
200-
fail;
201-
}
206+
fail
207+
};
202208
}
203209

204210
fn get_default_sysroot(str binary) -> str {
@@ -226,16 +232,17 @@ fn build_session_options(str binary, getopts::match match)
226232
auto shared = opt_present(match, "shared");
227233
auto library_search_paths = getopts::opt_strs(match, "L");
228234

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
232237
} else if (opt_present(match, "S")) {
233-
output_type = link::output_type_assembly;
238+
link::output_type_assembly
234239
} else if (opt_present(match, "c")) {
235-
output_type = link::output_type_object;
240+
link::output_type_object
236241
} 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+
};
239246

240247
auto verify = !opt_present(match, "noverify");
241248
auto save_temps = opt_present(match, "save-temps");
@@ -246,46 +253,35 @@ fn build_session_options(str binary, getopts::match match)
246253
auto run_typestate = !opt_present(match, "no-typestate");
247254
auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
248255

249-
let uint optLevel = 0u;
250-
if (opt_present(match, "O")) {
251-
optLevel = 2u;
256+
let uint opt_level = if (opt_present(match, "O")) {
252257
if (opt_present(match, "OptLevel")) {
253258
log_err "error: -O and --OptLevel both provided";
254259
fail;
255260
}
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 = 0u; }
264-
case ("1") { optLevel = 1u; }
265-
case ("2") { optLevel = 2u; }
266-
case ("3") { optLevel = 3u; }
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+
2u
262+
} else if (opt_present(match, "OptLevel")) {
263+
alt (getopts::opt_str(match, "OptLevel")) {
264+
case ("0") { 0u }
265+
case ("1") { 1u }
266+
case ("2") { 2u }
267+
case ("3") { 3u }
268+
case (_) {
269+
log_err "error: optimization level needs to be between 0-3";
270+
fail
276271
}
277272
}
278-
}
273+
} else {
274+
0u
275+
};
279276

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+
};
285281

286282
let @session::options sopts =
287283
@rec(shared = shared,
288-
optimize = optLevel,
284+
optimize = opt_level,
289285
debuginfo = debuginfo,
290286
verify = verify,
291287
run_typestate = run_typestate,

0 commit comments

Comments
 (0)