2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
// -*- rust -*-
|
2011-09-12 18:13:28 -05:00
|
|
|
import metadata::{creader, cstore};
|
2011-11-10 10:41:42 -06:00
|
|
|
import syntax::parse::{parser};
|
2011-09-12 18:13:28 -05:00
|
|
|
import syntax::{ast, codemap};
|
2011-06-30 19:29:54 -05:00
|
|
|
import front::attr;
|
2011-11-17 09:42:17 -06:00
|
|
|
import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
|
|
|
|
last_use};
|
2011-09-12 18:13:28 -05:00
|
|
|
import syntax::print::{pp, pprust};
|
2011-11-10 10:41:42 -06:00
|
|
|
import util::{ppaux, filesearch};
|
2011-05-13 15:47:37 -05:00
|
|
|
import back::link;
|
2011-12-13 18:25:51 -06:00
|
|
|
import core::{option, str, vec, int, result};
|
|
|
|
import std::{fs, io, getopts};
|
|
|
|
import option::{some, none};
|
|
|
|
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
|
2011-10-13 14:23:50 -05:00
|
|
|
import back::{x86, x86_64};
|
2011-05-12 10:24:54 -05:00
|
|
|
|
2011-08-26 17:11:06 -05:00
|
|
|
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }
|
2011-03-01 17:57:55 -06:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn default_configuration(sess: session::session, argv0: str, input: str) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
ast::crate_cfg {
|
|
|
|
let libc =
|
|
|
|
alt sess.get_targ_cfg().os {
|
2011-09-02 17:34:58 -05:00
|
|
|
session::os_win32. { "msvcrt.dll" }
|
|
|
|
session::os_macos. { "libc.dylib" }
|
|
|
|
session::os_linux. { "libc.so.6" }
|
|
|
|
_ { "libc.so" }
|
2011-06-15 13:19:50 -05:00
|
|
|
};
|
2011-06-30 19:29:54 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let mk = attr::mk_name_value_item_str;
|
2011-06-30 19:29:54 -05:00
|
|
|
|
2011-11-15 18:33:07 -06:00
|
|
|
let arch = alt sess.get_targ_cfg().arch {
|
|
|
|
session::arch_x86. { "x86" }
|
|
|
|
session::arch_x86_64. { "x86_64" }
|
|
|
|
session::arch_arm. { "arm" }
|
|
|
|
};
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
ret [ // Target bindings.
|
2011-09-21 10:46:18 -05:00
|
|
|
mk("target_os", std::os::target_os()),
|
2011-11-15 18:33:07 -06:00
|
|
|
mk("target_arch", arch),
|
2011-09-02 17:34:58 -05:00
|
|
|
mk("target_libc", libc),
|
2011-08-19 17:16:48 -05:00
|
|
|
// Build bindings.
|
2011-09-21 10:46:18 -05:00
|
|
|
mk("build_compiler", argv0),
|
|
|
|
mk("build_input", input)];
|
2011-03-01 17:57:55 -06:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn build_configuration(sess: session::session, argv0: str, input: str) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
ast::crate_cfg {
|
2011-07-01 17:30:25 -05:00
|
|
|
// Combine the configuration requested by the session (command line) with
|
2011-07-13 20:13:19 -05:00
|
|
|
// some default and generated configuration items
|
2011-07-27 07:19:39 -05:00
|
|
|
let default_cfg = default_configuration(sess, argv0, input);
|
|
|
|
let user_cfg = sess.get_opts().cfg;
|
2011-07-27 07:48:34 -05:00
|
|
|
// If the user wants a test runner, then add the test cfg
|
|
|
|
let gen_cfg =
|
2011-07-27 07:19:39 -05:00
|
|
|
{
|
2011-09-02 17:34:58 -05:00
|
|
|
if sess.get_opts().test && !attr::contains_name(user_cfg, "test")
|
|
|
|
{
|
|
|
|
[attr::mk_word_item("test")]
|
2011-08-19 17:16:48 -05:00
|
|
|
} else { [] }
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-07-13 20:13:19 -05:00
|
|
|
ret user_cfg + gen_cfg + default_cfg;
|
2011-07-01 17:30:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
|
2011-07-01 17:30:25 -05:00
|
|
|
// FIXME: It would be nice to use the parser to parse all varieties of
|
|
|
|
// meta_item here. At the moment we just support the meta_word variant.
|
2011-08-19 17:16:48 -05:00
|
|
|
let words = [];
|
2011-09-02 17:34:58 -05:00
|
|
|
for s: str in cfgspecs { words += [attr::mk_word_item(s)]; }
|
2011-07-05 19:57:34 -05:00
|
|
|
ret words;
|
2011-07-01 17:30:25 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn input_is_stdin(filename: str) -> bool { filename == "-" }
|
2011-07-30 17:50:16 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_input(sess: session::session, cfg: ast::crate_cfg, input: str) ->
|
2011-09-02 17:34:58 -05:00
|
|
|
@ast::crate {
|
2011-07-30 17:50:16 -05:00
|
|
|
if !input_is_stdin(input) {
|
2011-09-02 17:34:58 -05:00
|
|
|
parser::parse_crate_from_file(input, cfg, sess.get_parse_sess())
|
2011-08-19 17:16:48 -05:00
|
|
|
} else { parse_input_src(sess, cfg, input).crate }
|
2011-07-30 17:50:16 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str)
|
2011-09-02 17:34:58 -05:00
|
|
|
-> {crate: @ast::crate, src: str} {
|
2011-10-28 23:19:59 -05:00
|
|
|
let srcbytes = if infile != "-" {
|
|
|
|
alt io::file_reader(infile) {
|
|
|
|
result::ok(reader) { reader }
|
|
|
|
result::err(e) {
|
|
|
|
sess.fatal(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
io::stdin()
|
|
|
|
}.read_whole_stream();
|
2011-09-01 19:27:58 -05:00
|
|
|
let src = str::unsafe_from_bytes(srcbytes);
|
2011-08-19 17:16:48 -05:00
|
|
|
let crate =
|
2011-09-02 17:34:58 -05:00
|
|
|
parser::parse_crate_from_source_str(infile, src, cfg,
|
|
|
|
sess.get_parse_sess());
|
2011-07-30 17:50:16 -05:00
|
|
|
ret {crate: crate, src: src};
|
2011-01-03 22:41:11 -06:00
|
|
|
}
|
|
|
|
|
2011-10-25 08:56:55 -05:00
|
|
|
fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
|
2011-07-27 07:19:39 -05:00
|
|
|
if !do_it { ret thunk(); }
|
2011-07-22 05:03:10 -05:00
|
|
|
let start = std::time::precise_time_s();
|
2011-07-27 07:19:39 -05:00
|
|
|
let rv = thunk();
|
2011-07-22 05:03:10 -05:00
|
|
|
let end = std::time::precise_time_s();
|
2011-09-01 20:49:10 -05:00
|
|
|
log_err #fmt["time: %s took %s s", what,
|
2011-12-13 18:25:51 -06:00
|
|
|
float::to_str(end - start, 3u)];
|
2011-04-29 13:55:20 -05:00
|
|
|
ret rv;
|
|
|
|
}
|
|
|
|
|
2011-12-06 16:39:58 -06:00
|
|
|
fn inject_libcore_reference(sess: session::session,
|
|
|
|
crate: @ast::crate) -> @ast::crate {
|
|
|
|
|
|
|
|
fn spanned<copy T>(x: T) -> @ast::spanned<T> {
|
|
|
|
ret @{node: x,
|
|
|
|
span: {lo: 0u, hi: 0u,
|
|
|
|
expanded_from: codemap::os_none}};
|
|
|
|
}
|
|
|
|
|
|
|
|
let n1 = sess.next_node_id();
|
|
|
|
let n2 = sess.next_node_id();
|
|
|
|
|
|
|
|
let vi1 = spanned(ast::view_item_use("core", [], n1));
|
|
|
|
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
|
|
|
|
|
2011-12-07 15:29:04 -06:00
|
|
|
let vis = [vi1, vi2] + crate.node.module.view_items;
|
2011-12-06 16:39:58 -06:00
|
|
|
|
2011-12-07 15:29:04 -06:00
|
|
|
ret @{node: {module: { view_items: vis with crate.node.module }
|
|
|
|
with crate.node} with *crate }
|
2011-12-06 16:39:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
2011-12-15 15:52:33 -06:00
|
|
|
outdir: option::t<str>, output: option::t<str>) {
|
2011-12-08 22:33:31 -06:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let time_passes = sess.get_opts().time_passes;
|
|
|
|
let crate =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
|
2011-07-30 20:17:35 -05:00
|
|
|
if sess.get_opts().parse_only { ret; }
|
2011-12-08 22:33:31 -06:00
|
|
|
|
2011-12-08 23:31:50 -06:00
|
|
|
sess.set_building_library(crate);
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
crate =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "configuration",
|
2011-07-27 07:19:39 -05:00
|
|
|
bind front::config::strip_unconfigured_items(crate));
|
|
|
|
if sess.get_opts().test {
|
|
|
|
crate =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "building test harness",
|
2011-10-11 19:50:54 -05:00
|
|
|
bind front::test::modify_for_testing(sess, crate));
|
2011-07-06 16:29:50 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
crate =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "expansion",
|
2011-07-27 07:19:39 -05:00
|
|
|
bind syntax::ext::expand::expand_crate(sess, crate));
|
2011-07-06 17:22:23 -05:00
|
|
|
|
2011-12-06 16:39:58 -06:00
|
|
|
if sess.get_opts().libcore {
|
|
|
|
crate = inject_libcore_reference(sess, crate);
|
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let ast_map =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "ast indexing",
|
2011-07-27 07:19:39 -05:00
|
|
|
bind middle::ast_map::map_crate(*crate));
|
2011-10-06 05:50:47 -05:00
|
|
|
time(time_passes, "external crate/lib resolution",
|
|
|
|
bind creader::read_crates(sess, *crate));
|
2011-12-13 06:19:56 -06:00
|
|
|
let {def_map, ext_map, exp_map, impl_map} =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "resolution",
|
2011-06-20 02:59:16 -05:00
|
|
|
bind resolve::resolve_crate(sess, ast_map, crate));
|
2011-07-27 07:19:39 -05:00
|
|
|
let freevars =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "freevar finding",
|
2011-09-01 07:35:00 -05:00
|
|
|
bind freevars::annotate_freevars(def_map, crate));
|
2011-12-02 06:42:51 -06:00
|
|
|
time(time_passes, "const checking",
|
|
|
|
bind middle::check_const::check_crate(sess, crate));
|
2011-08-18 19:59:17 -05:00
|
|
|
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, ast_map, freevars);
|
2011-12-14 07:38:25 -06:00
|
|
|
let method_map = time(time_passes, "typechecking",
|
|
|
|
bind typeck::check_crate(ty_cx, impl_map, crate));
|
2011-11-21 03:56:00 -06:00
|
|
|
time(time_passes, "block-use checking",
|
|
|
|
bind middle::block_use::check_crate(ty_cx, crate));
|
2011-10-13 14:25:57 -05:00
|
|
|
time(time_passes, "function usage",
|
|
|
|
bind fn_usage::check_crate_fn_usage(ty_cx, crate));
|
2011-10-06 05:50:47 -05:00
|
|
|
time(time_passes, "alt checking",
|
2011-08-19 07:34:45 -05:00
|
|
|
bind middle::check_alt::check_crate(ty_cx, crate));
|
2011-11-13 15:47:11 -06:00
|
|
|
time(time_passes, "typestate checking",
|
|
|
|
bind middle::tstate::ck::check_crate(ty_cx, crate));
|
2011-09-02 17:34:58 -05:00
|
|
|
let mut_map =
|
|
|
|
time(time_passes, "mutability checking",
|
|
|
|
bind middle::mut::check_crate(ty_cx, crate));
|
2011-11-21 02:25:42 -06:00
|
|
|
let (copy_map, ref_map) =
|
2011-09-12 04:27:30 -05:00
|
|
|
time(time_passes, "alias checking",
|
|
|
|
bind middle::alias::check_crate(ty_cx, crate));
|
2011-11-21 02:25:42 -06:00
|
|
|
let last_uses = time(time_passes, "last use finding",
|
|
|
|
bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx));
|
2011-11-17 09:42:17 -06:00
|
|
|
time(time_passes, "kind checking",
|
2011-12-14 07:38:25 -06:00
|
|
|
bind kind::check_crate(ty_cx, method_map, last_uses, crate));
|
2011-07-30 20:17:35 -05:00
|
|
|
if sess.get_opts().no_trans { ret; }
|
2011-12-08 22:33:31 -06:00
|
|
|
|
2011-12-15 15:52:33 -06:00
|
|
|
let outputs = build_output_filenames(input, outdir, output, sess);
|
2011-12-08 22:33:31 -06:00
|
|
|
|
2011-12-02 10:51:59 -06:00
|
|
|
let (llmod, link_meta) =
|
2011-09-02 17:34:58 -05:00
|
|
|
time(time_passes, "translation",
|
2011-12-08 22:33:31 -06:00
|
|
|
bind trans::trans_crate(sess, crate, ty_cx,
|
2011-12-15 04:42:27 -06:00
|
|
|
outputs.obj_filename, exp_map, ast_map,
|
2011-12-14 07:38:25 -06:00
|
|
|
mut_map, copy_map, last_uses,
|
|
|
|
method_map));
|
2011-10-06 05:50:47 -05:00
|
|
|
time(time_passes, "LLVM passes",
|
2011-12-08 22:33:31 -06:00
|
|
|
bind link::write::run_passes(sess, llmod, outputs.obj_filename));
|
|
|
|
|
|
|
|
let stop_after_codegen =
|
|
|
|
sess.get_opts().output_type != link::output_type_exe ||
|
|
|
|
sess.get_opts().static && sess.building_library();
|
|
|
|
|
|
|
|
if stop_after_codegen { ret; }
|
|
|
|
|
|
|
|
time(time_passes, "Linking",
|
|
|
|
bind link::link_binary(sess, outputs.obj_filename,
|
2011-12-02 10:51:59 -06:00
|
|
|
outputs.out_filename, link_meta));
|
2010-10-22 13:47:28 -05:00
|
|
|
}
|
2010-07-13 16:26:59 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
|
|
|
ppm: pp_mode) {
|
|
|
|
fn ann_paren_for_expr(node: pprust::ann_node) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
|
2011-07-05 03:38:35 -05:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt node {
|
|
|
|
pprust::node_expr(s, expr) {
|
|
|
|
pp::space(s.s);
|
2011-09-02 17:34:58 -05:00
|
|
|
pp::word(s.s, "as");
|
2011-07-27 07:19:39 -05:00
|
|
|
pp::space(s.s);
|
2011-09-02 17:34:58 -05:00
|
|
|
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
|
2011-07-27 07:19:39 -05:00
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
|
|
|
_ { }
|
2011-07-05 03:38:35 -05:00
|
|
|
}
|
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn ann_identified_post(node: pprust::ann_node) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt node {
|
|
|
|
pprust::node_item(s, item) {
|
|
|
|
pp::space(s.s);
|
2011-09-02 17:34:58 -05:00
|
|
|
pprust::synth_comment(s, int::to_str(item.id, 10u));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
pprust::node_block(s, blk) {
|
|
|
|
pp::space(s.s);
|
2011-09-02 17:34:58 -05:00
|
|
|
pprust::synth_comment(s,
|
|
|
|
"block " + int::to_str(blk.node.id, 10u));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
pprust::node_expr(s, expr) {
|
|
|
|
pp::space(s.s);
|
2011-09-02 17:34:58 -05:00
|
|
|
pprust::synth_comment(s, int::to_str(expr.id, 10u));
|
2011-07-27 07:19:39 -05:00
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
|
|
|
_ { }
|
2011-07-05 03:38:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-30 17:50:16 -05:00
|
|
|
// Because the pretty printer needs to make a pass over the source
|
|
|
|
// to collect comments and literals, and we need to support reading
|
|
|
|
// from stdin, we're going to just suck the source into a string
|
|
|
|
// so both the parser and pretty-printer can use it.
|
|
|
|
let crate_src = parse_input_src(sess, cfg, input);
|
|
|
|
let crate = crate_src.crate;
|
|
|
|
let src = crate_src.src;
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let ann;
|
|
|
|
alt ppm {
|
2011-08-26 17:11:06 -05:00
|
|
|
ppm_expanded. {
|
|
|
|
crate = syntax::ext::expand::expand_crate(sess, crate);
|
|
|
|
ann = pprust::no_ann();
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
ppm_typed. {
|
2011-08-26 17:11:06 -05:00
|
|
|
crate = syntax::ext::expand::expand_crate(sess, crate);
|
2011-07-27 07:19:39 -05:00
|
|
|
let amap = middle::ast_map::map_crate(*crate);
|
2011-12-13 06:19:56 -06:00
|
|
|
let {def_map, ext_map, impl_map, _} =
|
2011-08-19 17:16:48 -05:00
|
|
|
resolve::resolve_crate(sess, amap, crate);
|
2011-09-01 07:35:00 -05:00
|
|
|
let freevars = freevars::annotate_freevars(def_map, crate);
|
2011-08-18 19:59:17 -05:00
|
|
|
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, amap, freevars);
|
2011-12-13 06:19:56 -06:00
|
|
|
typeck::check_crate(ty_cx, impl_map, crate);
|
2011-07-27 07:19:39 -05:00
|
|
|
ann = {pre: ann_paren_for_expr, post: bind ann_typed_post(ty_cx, _)};
|
|
|
|
}
|
|
|
|
ppm_identified. {
|
|
|
|
ann = {pre: ann_paren_for_expr, post: ann_identified_post};
|
|
|
|
}
|
|
|
|
ppm_normal. { ann = pprust::no_ann(); }
|
2011-05-17 19:42:23 -05:00
|
|
|
}
|
2011-09-02 17:34:58 -05:00
|
|
|
pprust::print_crate(sess.get_codemap(), crate, input,
|
|
|
|
io::string_reader(src), io::stdout(), ann);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn version(argv0: str) {
|
2011-09-02 17:34:58 -05:00
|
|
|
let vers = "unknown version";
|
2011-09-01 19:37:20 -05:00
|
|
|
let env_vers = #env["CFG_VERSION"];
|
2011-09-01 19:27:58 -05:00
|
|
|
if str::byte_len(env_vers) != 0u { vers = env_vers; }
|
2011-09-02 17:34:58 -05:00
|
|
|
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
|
2011-09-21 10:46:18 -05:00
|
|
|
io::stdout().write_str(#fmt["host: %s\n", host_triple()]);
|
2011-05-05 14:03:23 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn usage(argv0: str) {
|
2011-09-02 17:34:58 -05:00
|
|
|
io::stdout().write_str(#fmt["usage: %s [options] <input>\n", argv0] +
|
|
|
|
"
|
2011-04-19 05:02:06 -05:00
|
|
|
options:
|
|
|
|
|
2011-05-05 14:03:23 -05:00
|
|
|
-h --help display this message
|
|
|
|
-v --version print version info and exit
|
|
|
|
|
2011-04-19 05:02:06 -05:00
|
|
|
-o <filename> write output to <filename>
|
2011-12-15 15:52:33 -06:00
|
|
|
--out-dir <dir> write output to compiler-chosen filename in <dir>
|
2011-07-07 13:42:18 -05:00
|
|
|
--lib compile a library crate
|
2011-12-08 22:08:00 -06:00
|
|
|
--bin compile an executable crate (default)
|
2011-07-07 13:42:18 -05:00
|
|
|
--static use or produce static libraries
|
2011-12-06 16:39:58 -06:00
|
|
|
--no-core omit the 'core' library (used and imported by default)
|
2011-06-01 20:31:31 -05:00
|
|
|
--pretty [type] pretty-print the input instead of compiling
|
2011-04-26 13:32:08 -05:00
|
|
|
--ls list the symbols defined by a crate file
|
2011-04-19 05:02:06 -05:00
|
|
|
-L <path> add a directory to the library search path
|
2011-12-06 15:02:59 -06:00
|
|
|
--no-verify suppress LLVM verification step (slight speedup)
|
2011-04-26 13:32:08 -05:00
|
|
|
--parse-only parse only; do not compile, assemble, or link
|
2011-07-30 20:17:35 -05:00
|
|
|
--no-trans run all passes except translation; no output
|
2011-05-04 17:36:42 -05:00
|
|
|
-g produce debug info
|
2011-10-28 14:51:46 -05:00
|
|
|
--opt-level <lvl> optimize with possible levels 0-3
|
2011-10-28 14:49:19 -05:00
|
|
|
-O equivalent to --opt-level=2
|
2011-04-25 16:08:12 -05:00
|
|
|
-S compile only; do not assemble or link
|
2011-11-14 16:03:20 -06:00
|
|
|
--no-asm-comments do not add comments into the assembly source
|
2011-04-25 16:08:12 -05:00
|
|
|
-c compile and assemble, but do not link
|
2011-05-16 13:14:24 -05:00
|
|
|
--emit-llvm produce an LLVM bitcode file
|
2011-04-26 13:32:08 -05:00
|
|
|
--save-temps write intermediate files in addition to normal output
|
2011-05-12 17:42:12 -05:00
|
|
|
--stats gather and report various compilation statistics
|
2011-10-28 14:51:46 -05:00
|
|
|
--cfg <cfgspec> configure the compilation environment
|
2011-04-29 13:55:20 -05:00
|
|
|
--time-passes time the individual phases of the compiler
|
2011-05-10 18:10:08 -05:00
|
|
|
--time-llvm-passes time the individual phases of the LLVM backend
|
2011-11-16 20:35:30 -06:00
|
|
|
--sysroot <path> override the system root
|
2011-09-21 10:46:18 -05:00
|
|
|
--target <triple> target to compile for (default: host triple)
|
2011-07-15 13:38:16 -05:00
|
|
|
--test build test harness
|
2011-08-11 00:12:42 -05:00
|
|
|
--gc garbage collect shared data (experimental/temporary)
|
2011-09-30 20:20:28 -05:00
|
|
|
--stack-growth perform stack checks (experimental)
|
2011-11-16 22:23:43 -06:00
|
|
|
--warn-unused-imports
|
|
|
|
warn about unnecessary imports
|
2011-07-15 13:38:16 -05:00
|
|
|
|
2011-08-28 02:24:28 -05:00
|
|
|
");
|
2010-10-22 13:47:28 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn get_os(triple: str) -> session::os {
|
2011-09-02 17:34:58 -05:00
|
|
|
ret if str::find(triple, "win32") >= 0 ||
|
|
|
|
str::find(triple, "mingw32") >= 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
session::os_win32
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::find(triple, "darwin") >= 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
session::os_macos
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::find(triple, "linux") >= 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
session::os_linux
|
2011-10-28 13:57:01 -05:00
|
|
|
} else { early_error("Unknown operating system!") };
|
2011-05-06 08:59:33 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn get_arch(triple: str) -> session::arch {
|
2011-09-02 17:34:58 -05:00
|
|
|
ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
|
|
|
|
str::find(triple, "i586") >= 0 ||
|
|
|
|
str::find(triple, "i686") >= 0 ||
|
|
|
|
str::find(triple, "i786") >= 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
session::arch_x86
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::find(triple, "x86_64") >= 0 {
|
2011-10-13 14:23:50 -05:00
|
|
|
session::arch_x86_64
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::find(triple, "arm") >= 0 ||
|
|
|
|
str::find(triple, "xscale") >= 0 {
|
2011-06-15 13:19:50 -05:00
|
|
|
session::arch_arm
|
2011-10-28 13:57:01 -05:00
|
|
|
} else { early_error("Unknown architecture! " + triple) };
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
|
|
|
|
2011-09-21 10:46:18 -05:00
|
|
|
fn build_target_config(sopts: @session::options) -> @session::config {
|
2011-10-12 14:29:08 -05:00
|
|
|
let os = get_os(sopts.target_triple);
|
|
|
|
let arch = get_arch(sopts.target_triple);
|
|
|
|
let (int_type, uint_type, float_type) = alt arch {
|
|
|
|
session::arch_x86. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
|
2011-10-13 14:23:50 -05:00
|
|
|
session::arch_x86_64. {(ast::ty_i64, ast::ty_u64, ast::ty_f64)}
|
2011-10-12 14:29:08 -05:00
|
|
|
session::arch_arm. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
|
|
|
|
};
|
|
|
|
let target_strs = alt arch {
|
|
|
|
session::arch_x86. {x86::get_target_strs(os)}
|
2011-10-13 14:23:50 -05:00
|
|
|
session::arch_x86_64. {x86_64::get_target_strs(os)}
|
2011-10-12 14:29:08 -05:00
|
|
|
session::arch_arm. {x86::get_target_strs(os)}
|
|
|
|
};
|
2011-07-27 07:19:39 -05:00
|
|
|
let target_cfg: @session::config =
|
2011-10-12 14:29:08 -05:00
|
|
|
@{os: os, arch: arch, target_strs: target_strs, int_type: int_type,
|
|
|
|
uint_type: uint_type, float_type: float_type};
|
2011-05-22 15:41:32 -05:00
|
|
|
ret target_cfg;
|
|
|
|
}
|
2011-05-05 14:03:23 -05:00
|
|
|
|
2011-09-21 10:46:18 -05:00
|
|
|
fn host_triple() -> str {
|
2011-09-29 13:31:28 -05:00
|
|
|
// Get the host triple out of the build environment. This ensures that our
|
|
|
|
// idea of the host triple is the same as for the set of libraries we've
|
|
|
|
// actually built. We can't just take LLVM's host triple because they
|
|
|
|
// normalize all ix86 architectures to i386.
|
|
|
|
// FIXME: Instead of grabbing the host triple we really should be
|
|
|
|
// grabbing (at compile time) the target triple that this rustc is
|
|
|
|
// built with and calling that (at runtime) the host triple.
|
|
|
|
let ht = #env("CFG_HOST_TRIPLE");
|
|
|
|
ret ht != "" ? ht : fail "rustc built without CFG_HOST_TRIPLE";
|
2011-09-21 10:46:18 -05:00
|
|
|
}
|
|
|
|
|
2011-10-03 14:46:22 -05:00
|
|
|
fn build_session_options(match: getopts::match)
|
2011-09-12 04:27:30 -05:00
|
|
|
-> @session::options {
|
2011-12-08 22:08:00 -06:00
|
|
|
let crate_type = if opt_present(match, "lib") {
|
|
|
|
session::lib_crate
|
|
|
|
} else if opt_present(match, "bin") {
|
|
|
|
session::bin_crate
|
|
|
|
} else {
|
|
|
|
session::unknown_crate
|
|
|
|
};
|
2011-09-02 17:34:58 -05:00
|
|
|
let static = opt_present(match, "static");
|
2011-07-14 19:26:10 -05:00
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
let parse_only = opt_present(match, "parse-only");
|
|
|
|
let no_trans = opt_present(match, "no-trans");
|
2011-07-30 20:17:35 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let output_type =
|
2011-07-30 20:17:35 -05:00
|
|
|
if parse_only || no_trans {
|
2011-06-15 13:19:50 -05:00
|
|
|
link::output_type_none
|
2011-11-07 07:32:13 -06:00
|
|
|
} else if opt_present(match, "S") && opt_present(match, "emit-llvm") {
|
|
|
|
link::output_type_llvm_assembly
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if opt_present(match, "S") {
|
2011-06-15 13:19:50 -05:00
|
|
|
link::output_type_assembly
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if opt_present(match, "c") {
|
2011-06-15 13:19:50 -05:00
|
|
|
link::output_type_object
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if opt_present(match, "emit-llvm") {
|
2011-06-15 13:19:50 -05:00
|
|
|
link::output_type_bitcode
|
|
|
|
} else { link::output_type_exe };
|
2011-12-06 16:39:58 -06:00
|
|
|
let libcore = !opt_present(match, "no-core");
|
2011-12-06 15:02:59 -06:00
|
|
|
let verify = !opt_present(match, "no-verify");
|
2011-09-02 17:34:58 -05:00
|
|
|
let save_temps = opt_present(match, "save-temps");
|
|
|
|
let debuginfo = opt_present(match, "g");
|
|
|
|
let stats = opt_present(match, "stats");
|
|
|
|
let time_passes = opt_present(match, "time-passes");
|
|
|
|
let time_llvm_passes = opt_present(match, "time-llvm-passes");
|
|
|
|
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
|
2011-09-21 10:46:18 -05:00
|
|
|
let target_opt = getopts::opt_maybe_str(match, "target");
|
2011-11-14 16:03:20 -06:00
|
|
|
let no_asm_comments = getopts::opt_present(match, "no-asm-comments");
|
2011-11-14 21:37:20 -06:00
|
|
|
alt output_type {
|
|
|
|
// unless we're emitting huamn-readable assembly, omit comments.
|
2011-11-14 16:03:20 -06:00
|
|
|
link::output_type_llvm_assembly. | link::output_type_assembly. {}
|
|
|
|
_ { no_asm_comments = true; }
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
let opt_level: uint =
|
2011-09-02 17:34:58 -05:00
|
|
|
if opt_present(match, "O") {
|
2011-10-28 14:49:19 -05:00
|
|
|
if opt_present(match, "opt-level") {
|
|
|
|
early_error("-O and --opt-level both provided");
|
2011-05-19 14:46:10 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
2u
|
2011-10-28 14:49:19 -05:00
|
|
|
} else if opt_present(match, "opt-level") {
|
|
|
|
alt getopts::opt_str(match, "opt-level") {
|
2011-09-02 17:34:58 -05:00
|
|
|
"0" { 0u }
|
|
|
|
"1" { 1u }
|
|
|
|
"2" { 2u }
|
|
|
|
"3" { 3u }
|
2011-07-27 07:19:39 -05:00
|
|
|
_ {
|
2011-10-28 13:57:01 -05:00
|
|
|
early_error("optimization level needs " +
|
|
|
|
"to be between 0-3")
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
} else { 0u };
|
2011-09-21 10:46:18 -05:00
|
|
|
let target =
|
|
|
|
alt target_opt {
|
|
|
|
none. { host_triple() }
|
|
|
|
some(s) { s }
|
|
|
|
};
|
|
|
|
|
2011-10-03 14:46:22 -05:00
|
|
|
let addl_lib_search_paths = getopts::opt_strs(match, "L");
|
2011-09-02 17:34:58 -05:00
|
|
|
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
|
|
|
|
let test = opt_present(match, "test");
|
|
|
|
let do_gc = opt_present(match, "gc");
|
2011-09-30 20:20:28 -05:00
|
|
|
let stack_growth = opt_present(match, "stack-growth");
|
2011-11-16 22:23:43 -06:00
|
|
|
let warn_unused_imports = opt_present(match, "warn-unused-imports");
|
2011-07-27 07:19:39 -05:00
|
|
|
let sopts: @session::options =
|
2011-12-08 22:08:00 -06:00
|
|
|
@{crate_type: crate_type,
|
2011-07-27 07:19:39 -05:00
|
|
|
static: static,
|
2011-12-06 16:39:58 -06:00
|
|
|
libcore: libcore,
|
2011-07-27 07:19:39 -05:00
|
|
|
optimize: opt_level,
|
|
|
|
debuginfo: debuginfo,
|
|
|
|
verify: verify,
|
|
|
|
save_temps: save_temps,
|
|
|
|
stats: stats,
|
|
|
|
time_passes: time_passes,
|
|
|
|
time_llvm_passes: time_llvm_passes,
|
|
|
|
output_type: output_type,
|
2011-10-03 14:46:22 -05:00
|
|
|
addl_lib_search_paths: addl_lib_search_paths,
|
|
|
|
maybe_sysroot: sysroot_opt,
|
2011-09-21 10:46:18 -05:00
|
|
|
target_triple: target,
|
2011-07-27 07:19:39 -05:00
|
|
|
cfg: cfg,
|
|
|
|
test: test,
|
2011-07-30 20:17:35 -05:00
|
|
|
parse_only: parse_only,
|
2011-08-11 00:12:42 -05:00
|
|
|
no_trans: no_trans,
|
2011-09-30 20:20:28 -05:00
|
|
|
do_gc: do_gc,
|
2011-11-14 16:03:20 -06:00
|
|
|
stack_growth: stack_growth,
|
2011-11-16 22:23:43 -06:00
|
|
|
no_asm_comments: no_asm_comments,
|
|
|
|
warn_unused_imports: warn_unused_imports};
|
2011-05-22 15:41:32 -05:00
|
|
|
ret sopts;
|
|
|
|
}
|
|
|
|
|
2011-10-04 16:14:36 -05:00
|
|
|
fn build_session(sopts: @session::options) -> session::session {
|
2011-09-21 10:46:18 -05:00
|
|
|
let target_cfg = build_target_config(sopts);
|
2011-07-27 07:19:39 -05:00
|
|
|
let cstore = cstore::mk_cstore();
|
2011-10-03 14:46:22 -05:00
|
|
|
let filesearch = filesearch::mk_filesearch(
|
|
|
|
sopts.maybe_sysroot,
|
|
|
|
sopts.target_triple,
|
|
|
|
sopts.addl_lib_search_paths);
|
2011-07-07 20:25:56 -05:00
|
|
|
ret session::session(target_cfg, sopts, cstore,
|
2011-07-27 07:19:39 -05:00
|
|
|
@{cm: codemap::new_codemap(), mutable next_id: 0},
|
2011-12-08 23:31:50 -06:00
|
|
|
none, 0u, filesearch, false);
|
2011-05-22 15:41:32 -05:00
|
|
|
}
|
|
|
|
|
2011-10-10 06:54:03 -05:00
|
|
|
fn parse_pretty(sess: session::session, &&name: str) -> pp_mode {
|
2011-09-02 17:34:58 -05:00
|
|
|
if str::eq(name, "normal") {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret ppm_normal;
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::eq(name, "expanded") {
|
2011-08-26 17:11:06 -05:00
|
|
|
ret ppm_expanded;
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::eq(name, "typed") {
|
2011-06-15 13:19:50 -05:00
|
|
|
ret ppm_typed;
|
2011-09-02 17:34:58 -05:00
|
|
|
} else if str::eq(name, "identified") { ret ppm_identified; }
|
|
|
|
sess.fatal("argument to `pretty` must be one of `normal`, `typed`, or " +
|
|
|
|
"`identified`");
|
2011-06-01 20:31:31 -05:00
|
|
|
}
|
|
|
|
|
2011-08-11 17:50:27 -05:00
|
|
|
fn opts() -> [getopts::opt] {
|
2011-09-02 17:34:58 -05:00
|
|
|
ret [optflag("h"), optflag("help"), optflag("v"), optflag("version"),
|
2011-09-28 17:26:11 -05:00
|
|
|
optflag("emit-llvm"), optflagopt("pretty"),
|
2011-09-02 17:34:58 -05:00
|
|
|
optflag("ls"), optflag("parse-only"), optflag("no-trans"),
|
2011-10-28 14:49:19 -05:00
|
|
|
optflag("O"), optopt("opt-level"), optmulti("L"), optflag("S"),
|
2011-12-15 15:52:33 -06:00
|
|
|
optopt("o"), optopt("out-dir"),
|
|
|
|
optflag("c"), optflag("g"), optflag("save-temps"),
|
2011-09-21 10:46:18 -05:00
|
|
|
optopt("sysroot"), optopt("target"), optflag("stats"),
|
|
|
|
optflag("time-passes"), optflag("time-llvm-passes"),
|
2011-12-06 15:02:59 -06:00
|
|
|
optflag("no-verify"),
|
2011-09-21 10:46:18 -05:00
|
|
|
optmulti("cfg"), optflag("test"),
|
2011-12-06 16:39:58 -06:00
|
|
|
optflag("no-core"),
|
2011-12-08 22:08:00 -06:00
|
|
|
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
|
2011-11-16 23:42:22 -06:00
|
|
|
optflag("stack-growth"),
|
2011-11-16 22:23:43 -06:00
|
|
|
optflag("no-asm-comments"),
|
|
|
|
optflag("warn-unused-imports")];
|
2011-07-13 20:13:19 -05:00
|
|
|
}
|
|
|
|
|
2011-12-15 15:52:33 -06:00
|
|
|
fn build_output_filenames(ifile: str,
|
|
|
|
odir: option::t<str>,
|
|
|
|
ofile: option::t<str>,
|
2011-12-08 22:08:00 -06:00
|
|
|
sess: session::session)
|
2011-10-28 02:53:57 -05:00
|
|
|
-> @{out_filename: str, obj_filename:str} {
|
2011-12-15 15:52:33 -06:00
|
|
|
let obj_path = "";
|
|
|
|
let out_path: str = "";
|
2011-12-08 22:08:00 -06:00
|
|
|
let sopts = sess.get_opts();
|
2011-10-28 02:53:57 -05:00
|
|
|
let stop_after_codegen =
|
|
|
|
sopts.output_type != link::output_type_exe ||
|
2011-12-08 22:08:00 -06:00
|
|
|
sopts.static && sess.building_library();
|
2011-12-15 15:52:33 -06:00
|
|
|
|
|
|
|
|
|
|
|
let obj_suffix =
|
|
|
|
alt sopts.output_type {
|
|
|
|
link::output_type_none. { "none" }
|
|
|
|
link::output_type_bitcode. { "bc" }
|
|
|
|
link::output_type_assembly. { "s" }
|
|
|
|
link::output_type_llvm_assembly. { "ll" }
|
|
|
|
// Object and exe output both use the '.o' extension here
|
|
|
|
link::output_type_object. | link::output_type_exe. {
|
|
|
|
"o"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-28 02:53:57 -05:00
|
|
|
alt ofile {
|
|
|
|
none. {
|
|
|
|
// "-" as input file will cause the parser to read from stdin so we
|
|
|
|
// have to make up a name
|
|
|
|
// We want to toss everything after the final '.'
|
2011-12-15 15:52:33 -06:00
|
|
|
let dirname = alt odir {
|
|
|
|
some(d) { d }
|
|
|
|
none. {
|
|
|
|
if input_is_stdin(ifile) {
|
|
|
|
std::os::getcwd()
|
|
|
|
} else {
|
|
|
|
fs::dirname(ifile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let (base_path, _) = if !input_is_stdin(ifile) {
|
|
|
|
fs::splitext(ifile)
|
|
|
|
} else {
|
|
|
|
(fs::connect(dirname, "rust_out"), "")
|
|
|
|
};
|
|
|
|
|
2011-10-28 02:53:57 -05:00
|
|
|
|
2011-12-08 22:08:00 -06:00
|
|
|
if sess.building_library() {
|
2011-12-15 15:52:33 -06:00
|
|
|
let basename = fs::basename(base_path);
|
2011-12-15 13:33:57 -06:00
|
|
|
let dylibname = std::os::dylib_filename(basename);
|
2011-12-15 15:52:33 -06:00
|
|
|
out_path = fs::connect(dirname, dylibname);
|
|
|
|
obj_path = fs::connect(dirname, basename + "." + obj_path);
|
2011-10-28 02:53:57 -05:00
|
|
|
} else {
|
2011-12-15 15:52:33 -06:00
|
|
|
out_path = base_path;
|
|
|
|
obj_path = base_path + "." + obj_suffix;
|
2011-10-28 02:53:57 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-15 15:52:33 -06:00
|
|
|
|
2011-10-28 02:53:57 -05:00
|
|
|
some(out_file) {
|
2011-12-15 15:52:33 -06:00
|
|
|
out_path = out_file;
|
|
|
|
obj_path = if stop_after_codegen {
|
|
|
|
out_file
|
|
|
|
} else {
|
|
|
|
let (base, _) = fs::splitext(out_file);
|
|
|
|
let modified = base + "." + obj_suffix;
|
|
|
|
modified
|
|
|
|
};
|
|
|
|
|
|
|
|
if sess.building_library() {
|
|
|
|
// FIXME: We might want to warn here; we're actually not going to
|
|
|
|
// respect the user's choice of library name when it comes time to
|
|
|
|
// link, we'll be linking to lib<basename>-<hash>-<version>.so no
|
|
|
|
// matter what.
|
|
|
|
}
|
|
|
|
|
|
|
|
if odir != none {
|
|
|
|
sess.warn("Ignoring --out-dir flag due to -o flag.");
|
|
|
|
}
|
2011-10-28 02:53:57 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-15 15:52:33 -06:00
|
|
|
ret @{out_filename: out_path,
|
|
|
|
obj_filename: obj_path};
|
2011-10-28 02:53:57 -05:00
|
|
|
}
|
|
|
|
|
2011-10-28 13:57:01 -05:00
|
|
|
fn early_error(msg: str) -> ! {
|
|
|
|
codemap::print_diagnostic("", codemap::error, msg);
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
fn main(args: [str]) {
|
2011-11-03 04:57:54 -05:00
|
|
|
let args = args, binary = vec::shift(args);
|
2011-07-27 07:19:39 -05:00
|
|
|
let match =
|
2011-08-27 19:46:13 -05:00
|
|
|
alt getopts::getopts(args, opts()) {
|
2011-07-27 07:19:39 -05:00
|
|
|
getopts::success(m) { m }
|
|
|
|
getopts::failure(f) {
|
2011-10-28 13:57:01 -05:00
|
|
|
early_error(getopts::fail_str(f))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
};
|
2011-09-02 17:34:58 -05:00
|
|
|
if opt_present(match, "h") || opt_present(match, "help") {
|
2011-05-22 15:41:32 -05:00
|
|
|
usage(binary);
|
|
|
|
ret;
|
|
|
|
}
|
2011-09-02 17:34:58 -05:00
|
|
|
if opt_present(match, "v") || opt_present(match, "version") {
|
2011-05-22 15:41:32 -05:00
|
|
|
version(binary);
|
|
|
|
ret;
|
|
|
|
}
|
2011-10-28 13:57:01 -05:00
|
|
|
let ifile = alt vec::len(match.free) {
|
|
|
|
0u { early_error("No input filename given.") }
|
|
|
|
1u { match.free[0] }
|
|
|
|
_ { early_error("Multiple input filenames provided.") }
|
|
|
|
};
|
|
|
|
|
2011-10-03 14:46:22 -05:00
|
|
|
let sopts = build_session_options(match);
|
2011-10-04 16:14:36 -05:00
|
|
|
let sess = build_session(sopts);
|
2011-12-15 15:52:33 -06:00
|
|
|
let odir = getopts::opt_maybe_str(match, "out-dir");
|
2011-10-28 13:17:07 -05:00
|
|
|
let ofile = getopts::opt_maybe_str(match, "o");
|
2011-09-02 17:34:58 -05:00
|
|
|
let cfg = build_configuration(sess, binary, ifile);
|
2011-07-27 07:19:39 -05:00
|
|
|
let pretty =
|
2011-09-02 17:34:58 -05:00
|
|
|
option::map::<str,
|
2011-08-13 02:09:25 -05:00
|
|
|
pp_mode>(bind parse_pretty(sess, _),
|
2011-09-02 17:34:58 -05:00
|
|
|
getopts::opt_default(match, "pretty",
|
|
|
|
"normal"));
|
2011-07-27 07:19:39 -05:00
|
|
|
alt pretty {
|
2011-09-02 17:34:58 -05:00
|
|
|
some::<pp_mode>(ppm) { pretty_print_input(sess, cfg, ifile, ppm); ret; }
|
2011-08-13 02:09:25 -05:00
|
|
|
none::<pp_mode>. {/* continue */ }
|
2011-06-01 20:31:31 -05:00
|
|
|
}
|
2011-09-02 17:34:58 -05:00
|
|
|
let ls = opt_present(match, "ls");
|
2011-10-12 14:29:08 -05:00
|
|
|
if ls {
|
|
|
|
metadata::creader::list_file_metadata(sess, ifile, io::stdout());
|
|
|
|
ret;
|
|
|
|
}
|
2011-07-08 14:03:48 -05:00
|
|
|
|
2011-12-15 15:52:33 -06:00
|
|
|
compile_input(sess, cfg, ifile, odir, ofile);
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
2011-07-13 20:13:19 -05:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
|
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let match =
|
2011-09-02 17:34:58 -05:00
|
|
|
alt getopts::getopts(["--test"], opts()) {
|
2011-07-27 07:19:39 -05:00
|
|
|
getopts::success(m) { m }
|
|
|
|
};
|
2011-10-03 15:13:21 -05:00
|
|
|
let sessopts = build_session_options(match);
|
2011-10-04 16:14:36 -05:00
|
|
|
let sess = build_session(sessopts);
|
2011-09-02 17:34:58 -05:00
|
|
|
let cfg = build_configuration(sess, "whatever", "whatever");
|
|
|
|
assert (attr::contains_name(cfg, "test"));
|
2011-07-13 20:13:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the user supplies --test and --cfg test, don't implicitly add
|
|
|
|
// another --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let match =
|
2011-09-02 17:34:58 -05:00
|
|
|
alt getopts::getopts(["--test", "--cfg=test"], opts()) {
|
2011-07-27 07:19:39 -05:00
|
|
|
getopts::success(m) { m }
|
|
|
|
};
|
2011-10-03 15:13:21 -05:00
|
|
|
let sessopts = build_session_options(match);
|
2011-10-04 16:14:36 -05:00
|
|
|
let sess = build_session(sessopts);
|
2011-09-02 17:34:58 -05:00
|
|
|
let cfg = build_configuration(sess, "whatever", "whatever");
|
|
|
|
let test_items = attr::find_meta_items_by_name(cfg, "test");
|
2011-08-15 18:38:23 -05:00
|
|
|
assert (vec::len(test_items) == 1u);
|
2011-07-13 20:13:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-12 12:29:23 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|