2011-06-15 13:19:50 -05:00
|
|
|
|
2011-09-12 18:13:28 -05:00
|
|
|
import syntax::{ast, codemap};
|
2011-07-13 19:26:06 -05:00
|
|
|
import syntax::ast::node_id;
|
2011-07-05 04:48:19 -05:00
|
|
|
import codemap::span;
|
2011-12-07 14:06:12 -06:00
|
|
|
import syntax::ast::{int_ty, uint_ty, float_ty};
|
2012-04-18 01:34:48 -05:00
|
|
|
import syntax::parse::parse_sess;
|
2012-05-29 22:38:46 -05:00
|
|
|
import metadata::filesearch;
|
2011-10-12 14:29:08 -05:00
|
|
|
import back::target_strs;
|
2012-05-09 00:25:22 -05:00
|
|
|
import back::link;
|
2012-01-19 02:50:51 -06:00
|
|
|
import middle::lint;
|
2010-09-01 15:24:14 -05:00
|
|
|
|
2012-06-04 18:07:54 -05:00
|
|
|
|
2012-01-19 19:56:05 -06:00
|
|
|
enum os { os_win32, os_macos, os_linux, os_freebsd, }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-01-19 19:56:05 -06:00
|
|
|
enum arch { arch_x86, arch_x86_64, arch_arm, }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-01-19 19:56:05 -06:00
|
|
|
enum crate_type { bin_crate, lib_crate, unknown_crate, }
|
2011-12-08 22:08:00 -06:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
type config =
|
2011-07-27 07:19:39 -05:00
|
|
|
{os: os,
|
|
|
|
arch: arch,
|
2011-10-12 14:29:08 -05:00
|
|
|
target_strs: target_strs::t,
|
2011-12-07 14:06:12 -06:00
|
|
|
int_type: int_ty,
|
|
|
|
uint_type: uint_ty,
|
|
|
|
float_type: float_ty};
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-05-17 23:53:49 -05:00
|
|
|
const ppregions: uint = 1u;
|
|
|
|
const time_passes: uint = 2u;
|
|
|
|
const count_llvm_insns: uint = 4u;
|
|
|
|
const time_llvm_passes: uint = 8u;
|
2012-07-05 14:59:03 -05:00
|
|
|
const trans_stats: uint = 16u;
|
2012-05-17 23:53:49 -05:00
|
|
|
const no_asm_comments: uint = 32u;
|
|
|
|
const no_verify: uint = 64u;
|
2012-05-18 21:02:39 -05:00
|
|
|
const trace: uint = 128u;
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2377): This exists to transition to a Rust crate runtime
|
2012-06-19 14:36:24 -05:00
|
|
|
// It should be removed
|
|
|
|
const no_rt: uint = 256u;
|
2012-07-10 19:33:16 -05:00
|
|
|
const coherence: uint = 512u;
|
2012-07-05 14:59:03 -05:00
|
|
|
const borrowck_stats: uint = 1024u;
|
2012-07-06 17:03:18 -05:00
|
|
|
const borrowck_note_pure: uint = 2048;
|
2012-07-11 12:28:30 -05:00
|
|
|
const borrowck_note_loan: uint = 4096;
|
2012-05-17 23:53:49 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
|
|
|
|
~[(~"ppregions", ~"prettyprint regions with \
|
2012-05-17 23:53:49 -05:00
|
|
|
internal repr details", ppregions),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"time-passes", ~"measure time of each rustc pass", time_passes),
|
|
|
|
(~"count-llvm-insns", ~"count where LLVM \
|
2012-05-17 23:53:49 -05:00
|
|
|
instrs originate", count_llvm_insns),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"time-llvm-passes", ~"measure time of each LLVM pass",
|
|
|
|
time_llvm_passes),
|
|
|
|
(~"trans-stats", ~"gather trans statistics", trans_stats),
|
|
|
|
(~"no-asm-comments", ~"omit comments when using -S", no_asm_comments),
|
|
|
|
(~"no-verify", ~"skip LLVM verification", no_verify),
|
|
|
|
(~"trace", ~"emit trace logs", trace),
|
|
|
|
(~"no-rt", ~"do not link to the runtime", no_rt),
|
|
|
|
(~"coherence", ~"perform coherence checking", coherence),
|
|
|
|
(~"borrowck-stats", ~"gather borrowck statistics", borrowck_stats),
|
|
|
|
(~"borrowck-note-pure", ~"note where purity is req'd",
|
2012-07-11 12:28:30 -05:00
|
|
|
borrowck_note_pure),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"borrowck-note-loan", ~"note where loans are req'd",
|
2012-07-11 12:28:30 -05:00
|
|
|
borrowck_note_loan)
|
2012-06-29 18:26:56 -05:00
|
|
|
]
|
2012-05-17 23:53:49 -05:00
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
type options =
|
2011-07-27 07:19:39 -05:00
|
|
|
// The crate config requested for the session, which may be combined
|
|
|
|
// with additional crate configurations during the compile process
|
2011-12-08 22:08:00 -06:00
|
|
|
{crate_type: crate_type,
|
2011-07-27 07:19:39 -05:00
|
|
|
static: bool,
|
|
|
|
optimize: uint,
|
|
|
|
debuginfo: bool,
|
2011-12-14 14:47:05 -06:00
|
|
|
extra_debuginfo: bool,
|
2012-06-29 18:26:56 -05:00
|
|
|
lint_opts: ~[(lint::lint, lint::level)],
|
2011-07-27 07:19:39 -05:00
|
|
|
save_temps: bool,
|
|
|
|
output_type: back::link::output_type,
|
2012-07-14 00:57:48 -05:00
|
|
|
addl_lib_search_paths: ~[~str],
|
|
|
|
maybe_sysroot: option<~str>,
|
|
|
|
target_triple: ~str,
|
2011-07-27 07:19:39 -05:00
|
|
|
cfg: ast::crate_cfg,
|
|
|
|
test: bool,
|
2011-07-30 20:17:35 -05:00
|
|
|
parse_only: bool,
|
2011-08-11 00:12:42 -05:00
|
|
|
no_trans: bool,
|
2012-05-17 23:53:49 -05:00
|
|
|
debugging_opts: uint,
|
2012-05-14 10:22:51 -05:00
|
|
|
};
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type crate_metadata = {name: ~str, data: ~[u8]};
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
type session = @{targ_cfg: @config,
|
|
|
|
opts: @options,
|
|
|
|
cstore: metadata::cstore::cstore,
|
|
|
|
parse_sess: parse_sess,
|
|
|
|
codemap: codemap::codemap,
|
|
|
|
// For a library crate, this is always none
|
2012-03-26 20:35:18 -05:00
|
|
|
mut main_fn: option<(node_id, codemap::span)>,
|
2012-01-24 23:42:54 -06:00
|
|
|
span_diagnostic: diagnostic::span_handler,
|
2012-01-12 10:59:49 -06:00
|
|
|
filesearch: filesearch::filesearch,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut building_library: bool,
|
2012-07-14 00:57:48 -05:00
|
|
|
working_dir: ~str,
|
2012-06-04 18:07:54 -05:00
|
|
|
warning_settings: lint::warning_settings};
|
2011-03-25 12:42:57 -05:00
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
impl session for session {
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_fatal(sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_fatal(sp, msg)
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn fatal(msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().fatal(msg)
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_err(sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_err(sp, msg)
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn err(msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().err(msg)
|
2012-01-13 19:08:47 -06:00
|
|
|
}
|
|
|
|
fn has_errors() -> bool {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().has_errors()
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
|
|
|
fn abort_if_errors() {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().abort_if_errors()
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_warn(sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_warn(sp, msg)
|
2012-01-12 10:59:49 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn warn(msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().warn(msg)
|
2011-08-27 16:57:47 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_note(sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_note(sp, msg)
|
2012-01-12 10:59:49 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn note(msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().note(msg)
|
2011-08-27 16:57:47 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_bug(sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_bug(sp, msg)
|
2011-05-17 16:12:49 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn bug(msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().bug(msg)
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn span_unimpl(sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_unimpl(sp, msg)
|
2012-01-13 19:08:47 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn unimpl(msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().unimpl(msg)
|
2011-03-18 14:30:44 -05:00
|
|
|
}
|
2012-06-04 18:07:54 -05:00
|
|
|
fn span_lint_level(level: lint::level,
|
2012-07-14 00:57:48 -05:00
|
|
|
sp: span, msg: ~str) {
|
2012-06-04 18:07:54 -05:00
|
|
|
alt level {
|
|
|
|
lint::ignore { }
|
|
|
|
lint::warn { self.span_warn(sp, msg); }
|
|
|
|
lint::error { self.span_err(sp, msg); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn span_lint(lint_mode: lint::lint,
|
|
|
|
expr_id: ast::node_id, item_id: ast::node_id,
|
2012-07-14 00:57:48 -05:00
|
|
|
span: span, msg: ~str) {
|
2012-06-04 18:07:54 -05:00
|
|
|
let level = lint::get_warning_settings_level(
|
|
|
|
self.warning_settings, lint_mode, expr_id, item_id);
|
|
|
|
self.span_lint_level(level, span, msg);
|
|
|
|
}
|
2011-07-06 17:22:23 -05:00
|
|
|
fn next_node_id() -> ast::node_id {
|
2012-04-18 01:34:48 -05:00
|
|
|
ret syntax::parse::next_node_id(self.parse_sess);
|
2011-12-19 02:42:58 -06:00
|
|
|
}
|
2012-03-22 19:39:45 -05:00
|
|
|
fn diagnostic() -> diagnostic::span_handler {
|
|
|
|
self.span_diagnostic
|
|
|
|
}
|
2012-05-17 23:53:49 -05:00
|
|
|
fn debugging_opt(opt: uint) -> bool {
|
|
|
|
(self.opts.debugging_opts & opt) != 0u
|
|
|
|
}
|
|
|
|
fn ppregions() -> bool { self.debugging_opt(ppregions) }
|
|
|
|
fn time_passes() -> bool { self.debugging_opt(time_passes) }
|
|
|
|
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) }
|
|
|
|
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
|
2012-07-05 14:59:03 -05:00
|
|
|
fn trans_stats() -> bool { self.debugging_opt(trans_stats) }
|
2012-05-17 23:53:49 -05:00
|
|
|
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
|
|
|
|
fn no_verify() -> bool { self.debugging_opt(no_verify) }
|
2012-05-18 21:02:39 -05:00
|
|
|
fn trace() -> bool { self.debugging_opt(trace) }
|
2012-07-10 19:33:16 -05:00
|
|
|
fn coherence() -> bool { self.debugging_opt(coherence) }
|
2012-07-05 14:59:03 -05:00
|
|
|
fn borrowck_stats() -> bool { self.debugging_opt(borrowck_stats) }
|
2012-07-06 17:03:18 -05:00
|
|
|
fn borrowck_note_pure() -> bool { self.debugging_opt(borrowck_note_pure) }
|
2012-07-11 12:28:30 -05:00
|
|
|
fn borrowck_note_loan() -> bool { self.debugging_opt(borrowck_note_loan) }
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2011-12-08 23:05:44 -06:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Some reasonable defaults
|
2012-05-09 00:25:22 -05:00
|
|
|
fn basic_options() -> @options {
|
|
|
|
@{
|
|
|
|
crate_type: session::lib_crate,
|
|
|
|
static: false,
|
|
|
|
optimize: 0u,
|
|
|
|
debuginfo: false,
|
|
|
|
extra_debuginfo: false,
|
2012-06-29 18:26:56 -05:00
|
|
|
lint_opts: ~[],
|
2012-05-09 00:25:22 -05:00
|
|
|
save_temps: false,
|
|
|
|
output_type: link::output_type_exe,
|
2012-06-29 18:26:56 -05:00
|
|
|
addl_lib_search_paths: ~[],
|
2012-05-09 00:25:22 -05:00
|
|
|
maybe_sysroot: none,
|
|
|
|
target_triple: driver::host_triple(),
|
2012-06-29 18:26:56 -05:00
|
|
|
cfg: ~[],
|
2012-05-09 00:25:22 -05:00
|
|
|
test: false,
|
|
|
|
parse_only: false,
|
|
|
|
no_trans: false,
|
2012-06-08 09:46:14 -05:00
|
|
|
debugging_opts: 0u
|
2012-05-09 00:25:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:19:00 -05:00
|
|
|
// Seems out of place, but it uses session, so I'm putting it here
|
2012-07-14 00:57:48 -05:00
|
|
|
fn expect<T: copy>(sess: session, opt: option<T>, msg: fn() -> ~str) -> T {
|
2012-05-22 16:55:39 -05:00
|
|
|
diagnostic::expect(sess.diagnostic(), opt, msg)
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
|
2012-01-17 16:37:39 -06:00
|
|
|
fn building_library(req_crate_type: crate_type, crate: @ast::crate,
|
|
|
|
testing: bool) -> bool {
|
2011-12-08 23:05:44 -06:00
|
|
|
alt req_crate_type {
|
2012-01-19 00:37:22 -06:00
|
|
|
bin_crate { false }
|
|
|
|
lib_crate { true }
|
|
|
|
unknown_crate {
|
2012-01-17 16:37:39 -06:00
|
|
|
if testing {
|
|
|
|
false
|
|
|
|
} else {
|
2012-04-15 03:07:47 -05:00
|
|
|
alt syntax::attr::first_attr_value_str_by_name(
|
2012-01-17 16:37:39 -06:00
|
|
|
crate.node.attrs,
|
2012-07-14 00:57:48 -05:00
|
|
|
~"crate_type") {
|
|
|
|
option::some(@~"lib") { true }
|
2012-01-17 16:37:39 -06:00
|
|
|
_ { false }
|
|
|
|
}
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 19:16:26 -05:00
|
|
|
fn sess_os_to_meta_os(os: os) -> metadata::loader::os {
|
|
|
|
import metadata::loader;
|
|
|
|
|
|
|
|
alt os {
|
|
|
|
os_win32 { loader::os_win32 }
|
|
|
|
os_linux { loader::os_linux }
|
|
|
|
os_macos { loader::os_macos }
|
|
|
|
os_freebsd { loader::os_freebsd }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 23:05:44 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
import syntax::ast_util;
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn make_crate_type_attr(t: ~str) -> ast::attribute {
|
2011-12-08 23:05:44 -06:00
|
|
|
ast_util::respan(ast_util::dummy_sp(), {
|
|
|
|
style: ast::attr_outer,
|
|
|
|
value: ast_util::respan(ast_util::dummy_sp(),
|
|
|
|
ast::meta_name_value(
|
2012-07-14 00:57:48 -05:00
|
|
|
@~"crate_type",
|
2011-12-08 23:05:44 -06:00
|
|
|
ast_util::respan(ast_util::dummy_sp(),
|
2012-06-30 05:54:54 -05:00
|
|
|
ast::lit_str(@t)))),
|
|
|
|
is_sugared_doc: false
|
2011-12-08 23:05:44 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut attrs = ~[];
|
2012-07-14 00:57:48 -05:00
|
|
|
if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; }
|
|
|
|
if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; }
|
2011-12-08 23:05:44 -06:00
|
|
|
@ast_util::respan(ast_util::dummy_sp(), {
|
2012-06-29 18:26:56 -05:00
|
|
|
directives: ~[],
|
|
|
|
module: {view_items: ~[], items: ~[]},
|
2011-12-08 23:05:44 -06:00
|
|
|
attrs: attrs,
|
2012-06-29 18:26:56 -05:00
|
|
|
config: ~[]
|
2011-12-08 23:05:44 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_crate_type_attr_results_in_bin_output() {
|
|
|
|
let crate = make_crate(true, false);
|
2012-01-17 16:37:39 -06:00
|
|
|
assert !building_library(unknown_crate, crate, false);
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lib_crate_type_attr_results_in_lib_output() {
|
|
|
|
let crate = make_crate(false, true);
|
2012-01-17 16:37:39 -06:00
|
|
|
assert building_library(unknown_crate, crate, false);
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_option_overrides_lib_crate_type() {
|
|
|
|
let crate = make_crate(false, true);
|
2012-01-17 16:37:39 -06:00
|
|
|
assert !building_library(bin_crate, crate, false);
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lib_option_overrides_bin_crate_type() {
|
|
|
|
let crate = make_crate(true, false);
|
2012-01-17 16:37:39 -06:00
|
|
|
assert building_library(lib_crate, crate, false);
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_crate_type_is_default() {
|
|
|
|
let crate = make_crate(false, false);
|
2012-01-17 16:37:39 -06:00
|
|
|
assert !building_library(unknown_crate, crate, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_option_overrides_lib_crate_type() {
|
|
|
|
let crate = make_crate(false, true);
|
|
|
|
assert !building_library(unknown_crate, crate, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_option_does_not_override_requested_lib_type() {
|
|
|
|
let crate = make_crate(false, false);
|
|
|
|
assert building_library(lib_crate, crate, true);
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 15:24:14 -05:00
|
|
|
// Local Variables:
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|