Skip to content

Commit 37023ab

Browse files
committed
---
yaml --- r: 2741 b: refs/heads/master c: 1081d0a h: refs/heads/master i: 2739: 671093f v: v3
1 parent b15965b commit 37023ab

File tree

2 files changed

+64
-47
lines changed

2 files changed

+64
-47
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: 837dff9226a5c6cf5d0626e2c53f3a0bf637a072
2+
refs/heads/master: 1081d0aee9fc0b942a90cff5b88c08f17454f763

trunk/src/comp/driver/rustc.rs

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ fn default_environment(session::session sess,
5656
}
5757

5858
fn parse_input(session::session sess,
59-
parser::parser p,
60-
str input) -> @ast::crate {
59+
parser::parser p,
60+
str input) -> @ast::crate {
6161
if (str::ends_with(input, ".rc")) {
6262
ret parser::parse_crate_from_crate_file(p);
6363
} else if (str::ends_with(input, ".rs")) {
@@ -207,8 +207,7 @@ fn get_default_sysroot(str binary) -> str {
207207
ret dirname;
208208
}
209209

210-
fn main(vec[str] args) {
211-
210+
fn build_target_config() -> @session::config {
212211
let str triple =
213212
std::str::rustrt::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple());
214213

@@ -219,45 +218,12 @@ fn main(vec[str] args) {
219218
uint_type = common::ty_u32,
220219
float_type = common::ty_f64);
221220

222-
auto opts = [optflag("h"), optflag("help"),
223-
optflag("v"), optflag("version"),
224-
optflag("glue"), optflag("emit-llvm"),
225-
optflag("pretty"), optflag("typed-pretty"),
226-
optflag("ls"), optflag("parse-only"),
227-
optflag("O"), optopt("OptLevel"),
228-
optflag("shared"), optmulti("L"),
229-
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
230-
optflag("save-temps"), optopt("sysroot"),
231-
optflag("stats"),
232-
optflag("time-passes"), optflag("time-llvm-passes"),
233-
optflag("no-typestate"), optflag("noverify")];
234-
auto binary = vec::shift[str](args);
235-
auto match;
236-
alt (getopts::getopts(args, opts)) {
237-
case (getopts::failure(?f)) {
238-
log_err #fmt("error: %s", getopts::fail_str(f));
239-
fail;
240-
}
241-
case (getopts::success(?m)) { match = m; }
242-
}
243-
if (opt_present(match, "h") ||
244-
opt_present(match, "help")) {
245-
usage(binary);
246-
ret;
247-
}
248-
249-
if (opt_present(match, "v") ||
250-
opt_present(match, "version")) {
251-
version(binary);
252-
ret;
253-
}
221+
ret target_cfg;
222+
}
254223

255-
auto pretty = opt_present(match, "pretty");
256-
auto typed_pretty = opt_present(match, "typed-pretty");
257-
auto ls = opt_present(match, "ls");
258-
auto glue = opt_present(match, "glue");
224+
fn build_session_options(str binary, getopts::match match)
225+
-> @session::options {
259226
auto shared = opt_present(match, "shared");
260-
auto output_file = getopts::opt_maybe_str(match, "o");
261227
auto library_search_paths = getopts::opt_strs(match, "L");
262228

263229
auto output_type = link::output_type_exe;
@@ -331,15 +297,63 @@ fn main(vec[str] args) {
331297
library_search_paths = library_search_paths,
332298
sysroot = sysroot);
333299

300+
ret sopts;
301+
}
302+
303+
fn build_session(@session::options sopts) -> session::session {
304+
auto target_cfg = build_target_config();
334305
auto crate_cache = common::new_int_hash[session::crate_metadata]();
335306
auto target_crate_num = 0;
336307
let vec[@ast::meta_item] md = [];
337308
auto sess =
338309
session::session(target_crate_num, target_cfg, sopts,
339-
crate_cache, md, front::codemap::new_codemap());
310+
crate_cache, md, front::codemap::new_codemap());
311+
ret sess;
312+
}
313+
314+
fn main(vec[str] args) {
315+
316+
auto opts = [optflag("h"), optflag("help"),
317+
optflag("v"), optflag("version"),
318+
optflag("glue"), optflag("emit-llvm"),
319+
optflag("pretty"), optflag("typed-pretty"),
320+
optflag("ls"), optflag("parse-only"),
321+
optflag("O"), optopt("OptLevel"),
322+
optflag("shared"), optmulti("L"),
323+
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
324+
optflag("save-temps"), optopt("sysroot"),
325+
optflag("stats"),
326+
optflag("time-passes"), optflag("time-llvm-passes"),
327+
optflag("no-typestate"), optflag("noverify")];
328+
329+
auto binary = vec::shift[str](args);
330+
auto match = alt (getopts::getopts(args, opts)) {
331+
case (getopts::success(?m)) { m }
332+
case (getopts::failure(?f)) {
333+
log_err #fmt("error: %s", getopts::fail_str(f));
334+
fail
335+
}
336+
};
337+
338+
if (opt_present(match, "h") ||
339+
opt_present(match, "help")) {
340+
usage(binary);
341+
ret;
342+
}
343+
344+
if (opt_present(match, "v") ||
345+
opt_present(match, "version")) {
346+
version(binary);
347+
ret;
348+
}
349+
350+
auto sopts = build_session_options(binary, match);
351+
auto sess = build_session(sopts);
340352

341353
auto n_inputs = vec::len[str](match.free);
342354

355+
auto output_file = getopts::opt_maybe_str(match, "o");
356+
auto glue = opt_present(match, "glue");
343357
if (glue) {
344358
if (n_inputs > 0u) {
345359
sess.err("No input files allowed with --glue.");
@@ -357,7 +371,10 @@ fn main(vec[str] args) {
357371

358372
auto ifile = match.free.(0);
359373
let str saved_out_filename = "";
360-
auto env = default_environment(sess, args.(0), ifile);
374+
auto env = default_environment(sess, binary, ifile);
375+
auto pretty = opt_present(match, "pretty");
376+
auto typed_pretty = opt_present(match, "typed-pretty");
377+
auto ls = opt_present(match, "ls");
361378
if (pretty || typed_pretty) {
362379
pretty_print_input(sess, env, ifile, typed_pretty);
363380
} else if (ls) {
@@ -368,7 +385,7 @@ fn main(vec[str] args) {
368385
let vec[str] parts = str::split(ifile, '.' as u8);
369386
vec::pop[str](parts);
370387
saved_out_filename = parts.(0);
371-
alt (output_type) {
388+
alt (sopts.output_type) {
372389
case (link::output_type_none) { parts += ["pp"]; }
373390
case (link::output_type_bitcode) { parts += ["bc"]; }
374391
case (link::output_type_assembly) { parts += ["s"]; }
@@ -389,7 +406,7 @@ fn main(vec[str] args) {
389406

390407
// If the user wants an exe generated we need to invoke
391408
// gcc to link the object file with some libs
392-
if (output_type == link::output_type_exe) {
409+
if (sopts.output_type == link::output_type_exe) {
393410

394411
//FIXME: Should we make the 'stage3's variable here?
395412
let str glu = "stage3/glue.o";
@@ -438,7 +455,7 @@ fn main(vec[str] args) {
438455
}
439456

440457
// Remove the temporary object file if we aren't saving temps
441-
if (!save_temps) {
458+
if (!sopts.save_temps) {
442459
run::run_program("rm", [saved_out_filename + ".o"]);
443460
}
444461
}

0 commit comments

Comments
 (0)