rust/src/comp/driver/session.rs

129 lines
4.1 KiB
Rust
Raw Normal View History

2011-09-12 18:13:28 -05:00
import syntax::{ast, codemap};
import syntax::ast::node_id;
import codemap::span;
import syntax::ast::{int_ty, uint_ty, float_ty};
2011-11-10 10:41:42 -06:00
import std::{option};
2011-09-12 18:13:28 -05:00
import std::option::{some, none};
import syntax::parse::parser::parse_sess;
import util::filesearch;
import back::target_strs;
tag os { os_win32; os_macos; os_linux; }
tag arch { arch_x86; arch_x86_64; arch_arm; }
tag crate_type { bin_crate; lib_crate; unknown_crate; }
type config =
2011-07-27 07:19:39 -05:00
{os: os,
arch: arch,
target_strs: target_strs::t,
int_type: int_ty,
uint_type: uint_ty,
float_type: float_ty};
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
{crate_type: crate_type,
2011-07-27 07:19:39 -05:00
static: bool,
libcore: bool,
2011-07-27 07:19:39 -05:00
optimize: uint,
debuginfo: bool,
verify: bool,
save_temps: bool,
stats: bool,
time_passes: bool,
time_llvm_passes: bool,
output_type: back::link::output_type,
addl_lib_search_paths: [str],
maybe_sysroot: option::t<str>,
target_triple: str,
2011-07-27 07:19:39 -05:00
cfg: ast::crate_cfg,
test: bool,
parse_only: bool,
no_trans: bool,
do_gc: bool,
2011-11-14 16:03:20 -06:00
stack_growth: bool,
no_asm_comments: bool,
warn_unused_imports: bool};
2011-09-02 17:34:58 -05:00
type crate_metadata = {name: str, data: [u8]};
2011-07-27 07:19:39 -05:00
obj session(targ_cfg: @config,
opts: @options,
cstore: metadata::cstore::cstore,
parse_sess: parse_sess,
2011-03-25 12:42:57 -05:00
// For a library crate, this is always none
mutable main_fn: option::t<node_id>,
mutable err_count: uint,
filesearch: filesearch::filesearch) {
fn get_targ_cfg() -> @config { ret targ_cfg; }
fn get_opts() -> @options { ret opts; }
fn get_cstore() -> metadata::cstore::cstore { cstore }
fn span_fatal(sp: span, msg: str) -> ! {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_error(some(sp), msg, parse_sess.cm);
fail;
}
fn fatal(msg: str) -> ! {
codemap::emit_error(none, msg, parse_sess.cm);
fail;
}
fn span_err(sp: span, msg: str) {
codemap::emit_error(some(sp), msg, parse_sess.cm);
err_count += 1u;
}
fn err(msg: str) {
codemap::emit_error(none, msg, parse_sess.cm);
err_count += 1u;
}
fn has_errors() -> bool { err_count > 0u }
fn abort_if_errors() {
2011-09-02 17:34:58 -05:00
if err_count > 0u { self.fatal("aborting due to previous errors"); }
}
fn span_warn(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_warning(some(sp), msg, parse_sess.cm);
}
fn warn(msg: str) { codemap::emit_warning(none, msg, parse_sess.cm); }
fn span_note(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_note(some(sp), msg, parse_sess.cm);
}
fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); }
fn span_bug(sp: span, msg: str) -> ! {
2011-09-02 17:34:58 -05:00
self.span_fatal(sp, #fmt["internal compiler error %s", msg]);
}
fn bug(msg: str) -> ! {
2011-09-02 17:34:58 -05:00
self.fatal(#fmt["internal compiler error %s", msg]);
}
fn span_unimpl(sp: span, msg: str) -> ! {
2011-09-02 17:34:58 -05:00
self.span_bug(sp, "unimplemented " + msg);
}
fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
fn get_codemap() -> codemap::codemap { ret parse_sess.cm; }
2011-07-27 07:19:39 -05:00
fn lookup_pos(pos: uint) -> codemap::loc {
ret codemap::lookup_char_pos(parse_sess.cm, pos);
}
fn get_parse_sess() -> parse_sess { ret parse_sess; }
fn next_node_id() -> ast::node_id {
ret syntax::parse::parser::next_node_id(parse_sess);
}
2011-09-02 17:34:58 -05:00
fn span_str(sp: span) -> str {
ret codemap::span_to_str(sp, self.get_codemap());
}
2011-07-27 07:19:39 -05:00
fn set_main_id(d: node_id) { main_fn = some(d); }
fn get_main_id() -> option::t<node_id> { main_fn }
fn filesearch() -> filesearch::filesearch { filesearch }
fn building_library() -> bool { opts.crate_type == lib_crate }
}
// Local Variables:
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End: