2011-12-20 04:17:13 -06:00
|
|
|
// -*- rust -*-
|
2012-05-29 22:38:46 -05:00
|
|
|
import metadata::{creader, cstore, filesearch};
|
2012-07-11 17:00:40 -05:00
|
|
|
import session::{session, session_};
|
2012-04-18 01:34:48 -05:00
|
|
|
import syntax::parse;
|
2011-12-20 04:17:13 -06:00
|
|
|
import syntax::{ast, codemap};
|
2012-03-22 20:16:22 -05:00
|
|
|
import syntax::attr;
|
2012-07-17 17:23:59 -05:00
|
|
|
import middle::{trans, freevars, kind, ty, typeck, lint};
|
2011-12-20 04:17:13 -06:00
|
|
|
import syntax::print::{pp, pprust};
|
2012-05-29 22:38:46 -05:00
|
|
|
import util::ppaux;
|
2011-12-20 04:17:13 -06:00
|
|
|
import back::link;
|
|
|
|
import result::{ok, err};
|
2012-03-12 22:04:27 -05:00
|
|
|
import std::getopts;
|
2012-01-19 12:53:20 -06:00
|
|
|
import io::{reader_util, writer_util};
|
2011-12-20 04:17:13 -06:00
|
|
|
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
|
|
|
|
import back::{x86, x86_64};
|
2012-05-22 12:54:12 -05:00
|
|
|
import std::map::hashmap;
|
2012-07-25 14:06:03 -05:00
|
|
|
import lib::llvm::llvm;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-03-12 12:19:35 -05:00
|
|
|
enum pp_mode {ppm_normal, ppm_expanded, ppm_typed, ppm_identified,
|
|
|
|
ppm_expanded_identified }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* The name used for source code that doesn't originate in a file
|
|
|
|
* (e.g. source from stdin or a string)
|
|
|
|
*/
|
2012-07-14 00:57:48 -05:00
|
|
|
fn anon_src() -> ~str { ~"<anon>" }
|
2012-05-09 21:41:24 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn source_name(input: input) -> ~str {
|
2012-05-09 21:41:24 -05:00
|
|
|
alt input {
|
2012-08-03 21:59:04 -05:00
|
|
|
file_input(ifile) => ifile,
|
|
|
|
str_input(_) => anon_src()
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn default_configuration(sess: session, argv0: ~str, input: input) ->
|
2011-12-20 04:17:13 -06:00
|
|
|
ast::crate_cfg {
|
2012-01-26 03:52:08 -06:00
|
|
|
let libc = alt sess.targ_cfg.os {
|
2012-08-03 21:59:04 -05:00
|
|
|
session::os_win32 => ~"msvcrt.dll",
|
|
|
|
session::os_macos => ~"libc.dylib",
|
|
|
|
session::os_linux => ~"libc.so.6",
|
|
|
|
session::os_freebsd => ~"libc.so.7"
|
2012-04-24 04:13:25 -05:00
|
|
|
// _ { "libc.so" }
|
2012-01-26 03:52:08 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
let mk = attr::mk_name_value_item_str;
|
|
|
|
|
2012-08-02 19:15:11 -05:00
|
|
|
let (arch,wordsz) = alt sess.targ_cfg.arch {
|
2012-08-03 21:59:04 -05:00
|
|
|
session::arch_x86 => (~"x86",~"32"),
|
|
|
|
session::arch_x86_64 => (~"x86_64",~"64"),
|
|
|
|
session::arch_arm => (~"arm",~"32")
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return ~[ // Target bindings.
|
2012-06-10 02:49:59 -05:00
|
|
|
attr::mk_word_item(@os::family()),
|
2012-07-14 00:57:48 -05:00
|
|
|
mk(@~"target_os", os::sysname()),
|
|
|
|
mk(@~"target_family", os::family()),
|
|
|
|
mk(@~"target_arch", arch),
|
2012-08-02 19:15:11 -05:00
|
|
|
mk(@~"target_word_size", wordsz),
|
2012-07-14 00:57:48 -05:00
|
|
|
mk(@~"target_libc", libc),
|
2011-12-20 04:17:13 -06:00
|
|
|
// Build bindings.
|
2012-07-14 00:57:48 -05:00
|
|
|
mk(@~"build_compiler", argv0),
|
|
|
|
mk(@~"build_input", source_name(input))];
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn build_configuration(sess: session, argv0: ~str, input: input) ->
|
2011-12-20 04:17:13 -06:00
|
|
|
ast::crate_cfg {
|
|
|
|
// Combine the configuration requested by the session (command line) with
|
|
|
|
// some default and generated configuration items
|
|
|
|
let default_cfg = default_configuration(sess, argv0, input);
|
2012-01-12 10:59:49 -06:00
|
|
|
let user_cfg = sess.opts.cfg;
|
2011-12-20 04:17:13 -06:00
|
|
|
// If the user wants a test runner, then add the test cfg
|
|
|
|
let gen_cfg =
|
|
|
|
{
|
2012-07-10 17:52:05 -05:00
|
|
|
if sess.opts.test && !attr::contains_name(user_cfg, ~"test") {
|
2012-07-14 00:57:48 -05:00
|
|
|
~[attr::mk_word_item(@~"test")]
|
2012-07-10 17:52:05 -05:00
|
|
|
} else {
|
|
|
|
~[attr::mk_word_item(@~"notest")]
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return vec::append(vec::append(user_cfg, gen_cfg), default_cfg);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_cfgspecs(cfgspecs: ~[~str]) -> ast::crate_cfg {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2399): 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.
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut words = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for cfgspecs.each |s| { vec::push(words, attr::mk_word_item(@s)); }
|
2012-08-01 19:30:05 -05:00
|
|
|
return words;
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
enum input {
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Load source from file
|
2012-07-14 00:57:48 -05:00
|
|
|
file_input(~str),
|
2012-07-04 16:53:12 -05:00
|
|
|
/// The string is the source
|
2012-07-14 00:57:48 -05:00
|
|
|
str_input(~str)
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn parse_input(sess: session, cfg: ast::crate_cfg, input: input)
|
2012-01-26 03:52:08 -06:00
|
|
|
-> @ast::crate {
|
2012-05-09 21:41:24 -05:00
|
|
|
alt input {
|
2012-08-03 21:59:04 -05:00
|
|
|
file_input(file) => {
|
2012-05-09 21:41:24 -05:00
|
|
|
parse::parse_crate_from_file(file, cfg, sess.parse_sess)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
str_input(src) => {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2319): Don't really want to box the source string
|
2012-05-09 21:41:24 -05:00
|
|
|
parse::parse_crate_from_source_str(
|
|
|
|
anon_src(), @src, cfg, sess.parse_sess)
|
|
|
|
}
|
2012-01-26 03:52:08 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn time<T>(do_it: bool, what: ~str, thunk: fn() -> T) -> T {
|
2012-08-01 19:30:05 -05:00
|
|
|
if !do_it { return thunk(); }
|
2011-12-20 04:17:13 -06:00
|
|
|
let start = std::time::precise_time_s();
|
|
|
|
let rv = thunk();
|
|
|
|
let end = std::time::precise_time_s();
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_str(fmt!{"time: %3.3f s\t%s\n",
|
|
|
|
end - start, what});
|
2012-08-01 19:30:05 -05:00
|
|
|
return rv;
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
enum compile_upto {
|
2012-01-19 19:56:05 -06:00
|
|
|
cu_parse,
|
|
|
|
cu_expand,
|
|
|
|
cu_typeck,
|
|
|
|
cu_no_trans,
|
|
|
|
cu_everything,
|
2012-01-17 09:42:45 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
2012-05-09 21:41:24 -05:00
|
|
|
input: input, upto: compile_upto,
|
2012-01-31 19:05:20 -06:00
|
|
|
outputs: option<output_filenames>)
|
|
|
|
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
|
2012-05-17 23:53:49 -05:00
|
|
|
let time_passes = sess.time_passes();
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut crate = time(time_passes, ~"parsing",
|
2012-06-30 18:19:07 -05:00
|
|
|
||parse_input(sess, cfg, input) );
|
2012-08-01 19:30:05 -05:00
|
|
|
if upto == cu_parse { return {crate: crate, tcx: none}; }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-17 16:37:39 -06:00
|
|
|
sess.building_library = session::building_library(
|
|
|
|
sess.opts.crate_type, crate, sess.opts.test);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
crate = time(time_passes, ~"configuration", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
front::config::strip_unconfigured_items(crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
crate = time(time_passes, ~"maybe building test harness", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
front::test::modify_for_testing(sess, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
crate = time(time_passes, ~"expansion", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
syntax::ext::expand::expand_crate(sess.parse_sess, sess.opts.cfg,
|
|
|
|
crate));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if upto == cu_expand { return {crate: crate, tcx: none}; }
|
2012-01-26 17:20:29 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
crate = time(time_passes, ~"intrinsic injection", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
front::intrinsic_inject::inject_intrinsic(sess, crate));
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
crate = time(time_passes, ~"core injection", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
front::core_inject::maybe_inject_libcore_ref(sess, crate));
|
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
time(time_passes, ~"building lint settings table", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
lint::build_settings_crate(sess, crate));
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let ast_map = time(time_passes, ~"ast indexing", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
syntax::ast_map::map_crate(sess.diagnostic(), *crate));
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"external crate/lib resolution", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
creader::read_crates(sess.diagnostic(), *crate, sess.cstore,
|
|
|
|
sess.filesearch,
|
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os),
|
|
|
|
sess.opts.static));
|
|
|
|
|
2012-07-27 21:32:42 -05:00
|
|
|
let lang_items = time(time_passes, ~"language item collection", ||
|
2012-07-25 20:36:18 -05:00
|
|
|
middle::lang_items::collect_language_items(crate, sess));
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
let { def_map: def_map,
|
|
|
|
exp_map: exp_map,
|
|
|
|
impl_map: impl_map,
|
|
|
|
trait_map: trait_map } =
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"resolution", ||
|
2012-07-27 21:32:42 -05:00
|
|
|
middle::resolve3::resolve_crate(sess, lang_items, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let freevars = time(time_passes, ~"freevar finding", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
freevars::annotate_freevars(def_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let region_map = time(time_passes, ~"region resolution", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::region::resolve_crate(sess, def_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-31 19:35:18 -05:00
|
|
|
let rp_set = time(time_passes, ~"region parameterization inference", ||
|
2012-07-11 12:28:30 -05:00
|
|
|
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
|
|
|
|
|
|
|
|
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
|
|
|
|
region_map, rp_set);
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let (method_map, vtable_map) = time(time_passes, ~"typechecking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
typeck::check_crate(ty_cx,
|
|
|
|
impl_map,
|
2012-07-11 17:00:40 -05:00
|
|
|
trait_map,
|
2012-05-22 12:54:12 -05:00
|
|
|
crate));
|
2012-07-30 21:05:56 -05:00
|
|
|
// These next two const passes can probably be merged
|
|
|
|
time(time_passes, ~"const marking", ||
|
|
|
|
middle::const_eval::process_crate(crate, def_map, ty_cx));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"const checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::check_const::check_crate(sess, crate, ast_map, def_map,
|
|
|
|
method_map, ty_cx));
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if upto == cu_typeck { return {crate: crate, tcx: some(ty_cx)}; }
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"block-use checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::block_use::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"loop checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::check_loop::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"alt checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::check_alt::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let last_use_map = time(time_passes, ~"liveness checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
middle::liveness::check_crate(ty_cx, method_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let (root_map, mutbl_map) = time(time_passes, ~"borrow checking", ||
|
2012-06-30 18:19:07 -05:00
|
|
|
middle::borrowck::check_crate(ty_cx, method_map,
|
2012-05-22 12:54:12 -05:00
|
|
|
last_use_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"kind checking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
kind::check_crate(ty_cx, method_map, last_use_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"lint checking", || lint::check_crate(ty_cx, crate));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if upto == cu_no_trans { return {crate: crate, tcx: some(ty_cx)}; }
|
2012-01-17 09:42:45 -06:00
|
|
|
let outputs = option::get(outputs);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-14 22:32:29 -05:00
|
|
|
let maps = {mutbl_map: mutbl_map, root_map: root_map,
|
2012-06-08 09:46:14 -05:00
|
|
|
last_use_map: last_use_map,
|
2012-05-14 22:32:29 -05:00
|
|
|
impl_map: impl_map, method_map: method_map,
|
2012-06-06 16:19:52 -05:00
|
|
|
vtable_map: vtable_map};
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let (llmod, link_meta) = time(time_passes, ~"translation", ||
|
2012-06-30 18:19:07 -05:00
|
|
|
trans::base::trans_crate(sess, crate, ty_cx, outputs.obj_filename,
|
2012-05-22 12:54:12 -05:00
|
|
|
exp_map, maps));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"LLVM passes", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
link::write::run_passes(sess, llmod, outputs.obj_filename));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
let stop_after_codegen =
|
2012-01-12 10:59:49 -06:00
|
|
|
sess.opts.output_type != link::output_type_exe ||
|
|
|
|
sess.opts.static && sess.building_library;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if stop_after_codegen { return {crate: crate, tcx: some(ty_cx)}; }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
time(time_passes, ~"linking", ||
|
2012-05-22 12:54:12 -05:00
|
|
|
link::link_binary(sess, outputs.obj_filename,
|
|
|
|
outputs.out_filename, link_meta));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return {crate: crate, tcx: some(ty_cx)};
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn compile_input(sess: session, cfg: ast::crate_cfg, input: input,
|
2012-07-14 00:57:48 -05:00
|
|
|
outdir: option<~str>, output: option<~str>) {
|
2012-01-17 09:42:45 -06:00
|
|
|
|
|
|
|
let upto = if sess.opts.parse_only { cu_parse }
|
|
|
|
else if sess.opts.no_trans { cu_no_trans }
|
|
|
|
else { cu_everything };
|
|
|
|
let outputs = build_output_filenames(input, outdir, output, sess);
|
|
|
|
compile_upto(sess, cfg, input, upto, some(outputs));
|
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
|
2011-12-20 04:17:13 -06:00
|
|
|
ppm: pp_mode) {
|
|
|
|
fn ann_paren_for_expr(node: pprust::ann_node) {
|
2012-08-03 21:59:04 -05:00
|
|
|
alt node {
|
|
|
|
pprust::node_expr(s, expr) => pprust::popen(s),
|
|
|
|
_ => ()
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
|
|
|
|
alt node {
|
2012-08-03 21:59:04 -05:00
|
|
|
pprust::node_expr(s, expr) => {
|
2011-12-20 04:17:13 -06:00
|
|
|
pp::space(s.s);
|
2012-07-14 00:57:48 -05:00
|
|
|
pp::word(s.s, ~"as");
|
2011-12-20 04:17:13 -06:00
|
|
|
pp::space(s.s);
|
|
|
|
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
|
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn ann_identified_post(node: pprust::ann_node) {
|
|
|
|
alt node {
|
2012-08-03 21:59:04 -05:00
|
|
|
pprust::node_item(s, item) => {
|
2011-12-20 04:17:13 -06:00
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s, int::to_str(item.id, 10u));
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
pprust::node_block(s, blk) => {
|
2011-12-20 04:17:13 -06:00
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s,
|
2012-07-14 00:57:48 -05:00
|
|
|
~"block " + int::to_str(blk.node.id, 10u));
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
pprust::node_expr(s, expr) => {
|
2011-12-20 04:17:13 -06:00
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s, int::to_str(expr.id, 10u));
|
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
pprust::node_pat(s, pat) => {
|
2012-05-18 21:06:56 -05:00
|
|
|
pp::space(s.s);
|
2012-07-14 00:57:48 -05:00
|
|
|
pprust::synth_comment(s, ~"pat " + int::to_str(pat.id, 10u));
|
2012-05-18 21:06:56 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06: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.
|
2012-01-17 09:42:45 -06:00
|
|
|
let upto = alt ppm {
|
2012-08-03 21:59:04 -05:00
|
|
|
ppm_expanded | ppm_expanded_identified => cu_expand,
|
|
|
|
ppm_typed => cu_typeck,
|
|
|
|
_ => cu_parse
|
2012-01-17 09:42:45 -06:00
|
|
|
};
|
2012-01-26 03:52:08 -06:00
|
|
|
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-06-28 17:29:15 -05:00
|
|
|
let ann = alt ppm {
|
2012-08-03 21:59:04 -05:00
|
|
|
ppm_typed => {
|
2012-06-28 17:29:15 -05:00
|
|
|
{pre: ann_paren_for_expr,
|
2012-06-30 18:19:07 -05:00
|
|
|
post: |a| ann_typed_post(option::get(tcx), a) }
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ppm_identified | ppm_expanded_identified => {
|
2012-06-28 17:29:15 -05:00
|
|
|
{pre: ann_paren_for_expr, post: ann_identified_post}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ppm_expanded | ppm_normal => pprust::no_ann()
|
2012-06-28 17:29:15 -05:00
|
|
|
};
|
|
|
|
let is_expanded = upto != cu_parse;
|
2012-05-09 21:41:24 -05:00
|
|
|
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
|
2012-06-30 18:19:07 -05:00
|
|
|
do io::with_str_reader(*src) |rdr| {
|
2012-07-27 16:21:15 -05:00
|
|
|
pprust::print_crate(sess.codemap, sess.parse_sess.interner,
|
|
|
|
sess.span_diagnostic, crate,
|
2012-05-09 21:41:24 -05:00
|
|
|
source_name(input),
|
2012-06-28 17:29:15 -05:00
|
|
|
rdr, io::stdout(), ann, is_expanded);
|
2012-02-29 23:23:50 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn get_os(triple: ~str) -> option<session::os> {
|
2012-08-01 19:30:05 -05:00
|
|
|
if str::contains(triple, ~"win32") ||
|
2012-07-14 00:57:48 -05:00
|
|
|
str::contains(triple, ~"mingw32") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_win32)
|
2012-07-14 00:57:48 -05:00
|
|
|
} else if str::contains(triple, ~"darwin") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_macos)
|
2012-07-14 00:57:48 -05:00
|
|
|
} else if str::contains(triple, ~"linux") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_linux)
|
2012-07-14 00:57:48 -05:00
|
|
|
} else if str::contains(triple, ~"freebsd") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_freebsd)
|
2012-08-01 19:30:05 -05:00
|
|
|
} else { none }
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn get_arch(triple: ~str) -> option<session::arch> {
|
2012-08-01 19:30:05 -05:00
|
|
|
if str::contains(triple, ~"i386") ||
|
|
|
|
str::contains(triple, ~"i486") ||
|
2012-07-14 00:57:48 -05:00
|
|
|
str::contains(triple, ~"i586") ||
|
|
|
|
str::contains(triple, ~"i686") ||
|
|
|
|
str::contains(triple, ~"i786") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_x86)
|
2012-07-14 00:57:48 -05:00
|
|
|
} else if str::contains(triple, ~"x86_64") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_x86_64)
|
2012-07-14 00:57:48 -05:00
|
|
|
} else if str::contains(triple, ~"arm") ||
|
|
|
|
str::contains(triple, ~"xscale") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_arm)
|
2012-08-01 19:30:05 -05:00
|
|
|
} else { none }
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 01:18:01 -06:00
|
|
|
fn build_target_config(sopts: @session::options,
|
|
|
|
demitter: diagnostic::emitter) -> @session::config {
|
2012-01-14 01:03:37 -06:00
|
|
|
let os = alt get_os(sopts.target_triple) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(os) => os,
|
|
|
|
none => early_error(demitter, ~"unknown operating system")
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
|
|
|
let arch = alt get_arch(sopts.target_triple) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(arch) => arch,
|
|
|
|
none => early_error(demitter,
|
|
|
|
~"unknown architecture: " + sopts.target_triple)
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
let (int_type, uint_type, float_type) = alt arch {
|
2012-08-03 21:59:04 -05:00
|
|
|
session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
|
|
|
|
session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
|
|
|
|
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
let target_strs = alt arch {
|
2012-08-03 21:59:04 -05:00
|
|
|
session::arch_x86 => x86::get_target_strs(os),
|
|
|
|
session::arch_x86_64 => x86_64::get_target_strs(os),
|
|
|
|
session::arch_arm => x86::get_target_strs(os)
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
let target_cfg: @session::config =
|
|
|
|
@{os: os, arch: arch, target_strs: target_strs, int_type: int_type,
|
|
|
|
uint_type: uint_type, float_type: float_type};
|
2012-08-01 19:30:05 -05:00
|
|
|
return target_cfg;
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn host_triple() -> ~str {
|
2011-12-20 04:17:13 -06: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.
|
2012-06-21 18:44:10 -05:00
|
|
|
|
|
|
|
// FIXME (#2400): 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.
|
2012-07-30 18:01:07 -05:00
|
|
|
let ht = env!{"CFG_HOST_TRIPLE"};
|
2012-08-01 19:30:05 -05:00
|
|
|
return if ht != ~"" {
|
2012-01-29 20:33:08 -06:00
|
|
|
ht
|
|
|
|
} else {
|
2012-07-14 00:57:48 -05:00
|
|
|
fail ~"rustc built without CFG_HOST_TRIPLE"
|
2012-01-29 20:33:08 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
fn build_session_options(matches: getopts::matches,
|
2012-01-14 01:18:01 -06:00
|
|
|
demitter: diagnostic::emitter) -> @session::options {
|
2012-07-31 18:38:41 -05:00
|
|
|
let crate_type = if opt_present(matches, ~"lib") {
|
2011-12-20 04:17:13 -06:00
|
|
|
session::lib_crate
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"bin") {
|
2011-12-20 04:17:13 -06:00
|
|
|
session::bin_crate
|
|
|
|
} else {
|
|
|
|
session::unknown_crate
|
|
|
|
};
|
2012-07-31 18:38:41 -05:00
|
|
|
let static = opt_present(matches, ~"static");
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
let parse_only = opt_present(matches, ~"parse-only");
|
|
|
|
let no_trans = opt_present(matches, ~"no-trans");
|
2012-04-12 19:30:52 -05:00
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
let lint_levels = [lint::allow, lint::warn,
|
|
|
|
lint::deny, lint::forbid];
|
|
|
|
let mut lint_opts = ~[];
|
2012-04-12 19:30:52 -05:00
|
|
|
let lint_dict = lint::get_lint_dict();
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
for lint_levels.each |level| {
|
|
|
|
let level_name = lint::level_to_str(level);
|
|
|
|
let level_short = level_name.substr(0,1).to_upper();
|
2012-07-31 18:38:41 -05:00
|
|
|
let flags = vec::append(getopts::opt_strs(matches, level_short),
|
|
|
|
getopts::opt_strs(matches, level_name));
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
for flags.each |lint_name| {
|
|
|
|
let lint_name = str::replace(lint_name, ~"-", ~"_");
|
|
|
|
alt lint_dict.find(lint_name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-07-30 18:01:07 -05:00
|
|
|
early_error(demitter, fmt!{"unknown %s flag: %s",
|
|
|
|
level_name, lint_name});
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
some(lint) => {
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
vec::push(lint_opts, (lint.lint, level));
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-17 23:53:49 -05:00
|
|
|
let mut debugging_opts = 0u;
|
2012-07-31 18:38:41 -05:00
|
|
|
let debug_flags = getopts::opt_strs(matches, ~"Z");
|
2012-05-17 23:53:49 -05:00
|
|
|
let debug_map = session::debugging_opts_map();
|
2012-06-30 18:19:07 -05:00
|
|
|
for debug_flags.each |debug_flag| {
|
2012-05-17 23:53:49 -05:00
|
|
|
let mut this_bit = 0u;
|
2012-06-30 18:19:07 -05:00
|
|
|
for debug_map.each |pair| {
|
2012-05-17 23:53:49 -05:00
|
|
|
let (name, _, bit) = pair;
|
|
|
|
if name == debug_flag { this_bit = bit; break; }
|
|
|
|
}
|
|
|
|
if this_bit == 0u {
|
2012-07-30 18:01:07 -05:00
|
|
|
early_error(demitter, fmt!{"unknown debug flag: %s", debug_flag})
|
2012-05-17 23:53:49 -05:00
|
|
|
}
|
|
|
|
debugging_opts |= this_bit;
|
|
|
|
}
|
2012-07-25 14:06:03 -05:00
|
|
|
if debugging_opts & session::debug_llvm != 0 {
|
|
|
|
llvm::LLVMSetDebug(1);
|
|
|
|
}
|
2012-05-17 23:53:49 -05:00
|
|
|
|
2011-12-20 04:17:13 -06:00
|
|
|
let output_type =
|
|
|
|
if parse_only || no_trans {
|
|
|
|
link::output_type_none
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"S") &&
|
|
|
|
opt_present(matches, ~"emit-llvm") {
|
2011-12-20 04:17:13 -06:00
|
|
|
link::output_type_llvm_assembly
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"S") {
|
2011-12-20 04:17:13 -06:00
|
|
|
link::output_type_assembly
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"c") {
|
2011-12-20 04:17:13 -06:00
|
|
|
link::output_type_object
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"emit-llvm") {
|
2011-12-20 04:17:13 -06:00
|
|
|
link::output_type_bitcode
|
|
|
|
} else { link::output_type_exe };
|
2012-07-31 18:38:41 -05:00
|
|
|
let extra_debuginfo = opt_present(matches, ~"xg");
|
|
|
|
let debuginfo = opt_present(matches, ~"g") || extra_debuginfo;
|
|
|
|
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
|
|
|
|
let target_opt = getopts::opt_maybe_str(matches, ~"target");
|
|
|
|
let save_temps = getopts::opt_present(matches, ~"save-temps");
|
2011-12-20 04:17:13 -06:00
|
|
|
alt output_type {
|
|
|
|
// unless we're emitting huamn-readable assembly, omit comments.
|
2012-08-03 21:59:04 -05:00
|
|
|
link::output_type_llvm_assembly | link::output_type_assembly => (),
|
|
|
|
_ => debugging_opts |= session::no_asm_comments
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
let opt_level: uint =
|
2012-07-31 18:38:41 -05:00
|
|
|
if opt_present(matches, ~"O") {
|
|
|
|
if opt_present(matches, ~"opt-level") {
|
2012-07-14 00:57:48 -05:00
|
|
|
early_error(demitter, ~"-O and --opt-level both provided");
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
2u
|
2012-07-31 18:38:41 -05:00
|
|
|
} else if opt_present(matches, ~"opt-level") {
|
|
|
|
alt getopts::opt_str(matches, ~"opt-level") {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"0" => 0u,
|
|
|
|
~"1" => 1u,
|
|
|
|
~"2" => 2u,
|
|
|
|
~"3" => 3u,
|
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
early_error(demitter, ~"optimization level needs " +
|
|
|
|
~"to be between 0-3")
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { 0u };
|
|
|
|
let target =
|
|
|
|
alt target_opt {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => host_triple(),
|
|
|
|
some(s) => s
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L");
|
|
|
|
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"));
|
|
|
|
let test = opt_present(matches, ~"test");
|
2011-12-20 04:17:13 -06:00
|
|
|
let sopts: @session::options =
|
|
|
|
@{crate_type: crate_type,
|
|
|
|
static: static,
|
|
|
|
optimize: opt_level,
|
|
|
|
debuginfo: debuginfo,
|
|
|
|
extra_debuginfo: extra_debuginfo,
|
2012-01-19 02:50:51 -06:00
|
|
|
lint_opts: lint_opts,
|
2011-12-20 04:17:13 -06:00
|
|
|
save_temps: save_temps,
|
|
|
|
output_type: output_type,
|
|
|
|
addl_lib_search_paths: addl_lib_search_paths,
|
|
|
|
maybe_sysroot: sysroot_opt,
|
|
|
|
target_triple: target,
|
|
|
|
cfg: cfg,
|
|
|
|
test: test,
|
|
|
|
parse_only: parse_only,
|
|
|
|
no_trans: no_trans,
|
2012-06-08 09:46:14 -05:00
|
|
|
debugging_opts: debugging_opts};
|
2012-08-01 19:30:05 -05:00
|
|
|
return sopts;
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-03-21 17:56:20 -05:00
|
|
|
fn build_session(sopts: @session::options,
|
2012-01-17 09:42:45 -06:00
|
|
|
demitter: diagnostic::emitter) -> session {
|
2012-02-17 16:15:09 -06:00
|
|
|
let codemap = codemap::new_codemap();
|
|
|
|
let diagnostic_handler =
|
|
|
|
diagnostic::mk_handler(some(demitter));
|
|
|
|
let span_diagnostic_handler =
|
|
|
|
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
2012-03-21 17:56:20 -05:00
|
|
|
build_session_(sopts, codemap, demitter, span_diagnostic_handler)
|
2012-02-17 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
fn build_session_(sopts: @session::options,
|
|
|
|
cm: codemap::codemap,
|
|
|
|
demitter: diagnostic::emitter,
|
|
|
|
span_diagnostic_handler: diagnostic::span_handler)
|
|
|
|
-> session {
|
|
|
|
|
2012-01-14 01:18:01 -06:00
|
|
|
let target_cfg = build_target_config(sopts, demitter);
|
2011-12-20 04:17:13 -06:00
|
|
|
let cstore = cstore::mk_cstore();
|
|
|
|
let filesearch = filesearch::mk_filesearch(
|
|
|
|
sopts.maybe_sysroot,
|
|
|
|
sopts.target_triple,
|
|
|
|
sopts.addl_lib_search_paths);
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
let lint_settings = lint::mk_lint_settings();
|
2012-07-11 17:00:40 -05:00
|
|
|
session_(@{targ_cfg: target_cfg,
|
|
|
|
opts: sopts,
|
|
|
|
cstore: cstore,
|
|
|
|
parse_sess:
|
2012-06-06 11:50:08 -05:00
|
|
|
parse::new_parse_sess_special_handler(span_diagnostic_handler, cm),
|
2012-07-11 17:00:40 -05:00
|
|
|
codemap: cm,
|
|
|
|
// For a library crate, this is always none
|
|
|
|
mut main_fn: none,
|
|
|
|
span_diagnostic: span_diagnostic_handler,
|
|
|
|
filesearch: filesearch,
|
|
|
|
mut building_library: false,
|
|
|
|
working_dir: os::getcwd(),
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
lint_settings: lint_settings})
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_pretty(sess: session, &&name: ~str) -> pp_mode {
|
2012-08-02 17:42:56 -05:00
|
|
|
alt name {
|
|
|
|
~"normal" => ppm_normal,
|
|
|
|
~"expanded" => ppm_expanded,
|
|
|
|
~"typed" => ppm_typed,
|
|
|
|
~"expanded,identified" => ppm_expanded_identified,
|
|
|
|
~"identified" => ppm_identified,
|
|
|
|
_ => {
|
|
|
|
sess.fatal(~"argument to `pretty` must be one of `normal`, `typed`, \
|
|
|
|
or `identified`");
|
|
|
|
}
|
2012-03-12 12:19:35 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn opts() -> ~[getopts::opt] {
|
2012-08-01 19:30:05 -05:00
|
|
|
return ~[optflag(~"h"), optflag(~"help"),
|
|
|
|
optflag(~"v"), optflag(~"version"),
|
2012-07-14 00:57:48 -05:00
|
|
|
optflag(~"emit-llvm"), optflagopt(~"pretty"),
|
|
|
|
optflag(~"ls"), optflag(~"parse-only"), optflag(~"no-trans"),
|
|
|
|
optflag(~"O"), optopt(~"opt-level"), optmulti(~"L"), optflag(~"S"),
|
|
|
|
optopt(~"o"), optopt(~"out-dir"), optflag(~"xg"),
|
|
|
|
optflag(~"c"), optflag(~"g"), optflag(~"save-temps"),
|
|
|
|
optopt(~"sysroot"), optopt(~"target"),
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
optmulti(~"W"), optmulti(~"warn"),
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
optmulti(~"A"), optmulti(~"allow"),
|
|
|
|
optmulti(~"D"), optmulti(~"deny"),
|
|
|
|
optmulti(~"F"), optmulti(~"forbid"),
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
optmulti(~"Z"),
|
2012-05-17 23:53:49 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
optmulti(~"cfg"), optflag(~"test"),
|
|
|
|
optflag(~"lib"), optflag(~"bin"),
|
|
|
|
optflag(~"static"), optflag(~"gc")];
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type output_filenames = @{out_filename: ~str, obj_filename:~str};
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn build_output_filenames(input: input,
|
2012-07-14 00:57:48 -05:00
|
|
|
odir: option<~str>,
|
|
|
|
ofile: option<~str>,
|
2012-01-17 09:42:45 -06:00
|
|
|
sess: session)
|
|
|
|
-> output_filenames {
|
2012-06-14 14:40:49 -05:00
|
|
|
let obj_path;
|
|
|
|
let out_path;
|
2012-01-12 10:59:49 -06:00
|
|
|
let sopts = sess.opts;
|
2011-12-20 04:17:13 -06:00
|
|
|
let stop_after_codegen =
|
|
|
|
sopts.output_type != link::output_type_exe ||
|
2012-01-12 10:59:49 -06:00
|
|
|
sopts.static && sess.building_library;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
let obj_suffix =
|
|
|
|
alt sopts.output_type {
|
2012-08-03 21:59:04 -05:00
|
|
|
link::output_type_none => ~"none",
|
|
|
|
link::output_type_bitcode => ~"bc",
|
|
|
|
link::output_type_assembly => ~"s",
|
|
|
|
link::output_type_llvm_assembly => ~"ll",
|
2011-12-20 04:17:13 -06:00
|
|
|
// Object and exe output both use the '.o' extension here
|
2012-08-03 21:59:04 -05:00
|
|
|
link::output_type_object | link::output_type_exe => ~"o"
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
alt ofile {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2011-12-20 04:17:13 -06:00
|
|
|
// "-" 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 '.'
|
|
|
|
let dirname = alt odir {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(d) => d,
|
|
|
|
none => alt input {
|
|
|
|
str_input(_) => os::getcwd(),
|
|
|
|
file_input(ifile) => path::dirname(ifile)
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
let base_filename = alt input {
|
2012-08-03 21:59:04 -05:00
|
|
|
file_input(ifile) => {
|
2012-03-12 22:04:27 -05:00
|
|
|
let (path, _) = path::splitext(ifile);
|
|
|
|
path::basename(path)
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
str_input(_) => ~"rust_out"
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-03-12 22:04:27 -05:00
|
|
|
let base_path = path::connect(dirname, base_filename);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
if sess.building_library {
|
2012-03-12 22:04:27 -05:00
|
|
|
let basename = path::basename(base_path);
|
|
|
|
let dylibname = os::dll_filename(basename);
|
|
|
|
out_path = path::connect(dirname, dylibname);
|
2012-07-14 00:57:48 -05:00
|
|
|
obj_path = path::connect(dirname, basename + ~"." + obj_suffix);
|
2011-12-20 04:17:13 -06:00
|
|
|
} else {
|
|
|
|
out_path = base_path;
|
2012-07-14 00:57:48 -05:00
|
|
|
obj_path = base_path + ~"." + obj_suffix;
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-03 21:59:04 -05:00
|
|
|
some(out_file) => {
|
2011-12-20 04:17:13 -06:00
|
|
|
out_path = out_file;
|
|
|
|
obj_path = if stop_after_codegen {
|
|
|
|
out_file
|
|
|
|
} else {
|
2012-03-12 22:04:27 -05:00
|
|
|
let (base, _) = path::splitext(out_file);
|
2012-07-14 00:57:48 -05:00
|
|
|
let modified = base + ~"." + obj_suffix;
|
2011-12-20 04:17:13 -06:00
|
|
|
modified
|
|
|
|
};
|
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
if sess.building_library {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2401): 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.
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if odir != none {
|
2012-07-14 00:57:48 -05:00
|
|
|
sess.warn(~"ignoring --out-dir flag due to -o flag.");
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return @{out_filename: out_path,
|
2011-12-20 04:17:13 -06:00
|
|
|
obj_filename: obj_path};
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn early_error(emitter: diagnostic::emitter, msg: ~str) -> ! {
|
2012-01-14 01:18:01 -06:00
|
|
|
emitter(none, msg, diagnostic::fatal);
|
2011-12-20 04:17:13 -06:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn list_metadata(sess: session, path: ~str, out: io::writer) {
|
2012-05-22 19:16:26 -05:00
|
|
|
metadata::loader::list_file_metadata(
|
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
|
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test() {
|
2012-07-31 18:38:41 -05:00
|
|
|
let matches =
|
2012-07-14 00:57:48 -05:00
|
|
|
alt getopts::getopts(~[~"--test"], opts()) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(m) => m,
|
|
|
|
err(f) => fail ~"test_switch_implies_cfg_test: " +
|
|
|
|
getopts::fail_str(f)
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-07-31 18:38:41 -05:00
|
|
|
let sessopts = build_session_options(matches, diagnostic::emit);
|
2012-03-21 17:56:20 -05:00
|
|
|
let sess = build_session(sessopts, diagnostic::emit);
|
2012-07-14 00:57:48 -05:00
|
|
|
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
|
|
|
assert (attr::contains_name(cfg, ~"test"));
|
2011-12-20 04:17:13 -06: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() {
|
2012-07-31 18:38:41 -05:00
|
|
|
let matches =
|
2012-07-14 00:57:48 -05:00
|
|
|
alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(m) => m,
|
|
|
|
err(f) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
fail ~"test_switch_implies_cfg_test_unless_cfg_test: " +
|
|
|
|
getopts::fail_str(f);
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-07-31 18:38:41 -05:00
|
|
|
let sessopts = build_session_options(matches, diagnostic::emit);
|
2012-03-21 17:56:20 -05:00
|
|
|
let sess = build_session(sessopts, diagnostic::emit);
|
2012-07-14 00:57:48 -05:00
|
|
|
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
|
|
|
let test_items = attr::find_meta_items_by_name(cfg, ~"test");
|
2011-12-20 04:17:13 -06:00
|
|
|
assert (vec::len(test_items) == 1u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|