about summary refs log tree commit diff
path: root/src/comp/driver/session.rs
blob: 1f3f9baab8a90a564fe1214dcee293a1e5955315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

import syntax::{ast, codemap};
import syntax::ast::node_id;
import codemap::span;
import syntax::ast::ty_mach;
import std::{uint, map, option, str};
import std::option::{some, none};
import syntax::parse::parser::parse_sess;
import util::filesearch;

tag os { os_win32; os_macos; os_linux; }

tag arch { arch_x86; arch_x64; arch_arm; }

type config =
    {os: os,
     arch: arch,
     int_type: ty_mach,
     uint_type: ty_mach,
     float_type: ty_mach};

type options =
    // The crate config requested for the session, which may be combined
    // with additional crate configurations during the compile process
    {library: bool,
     static: bool,
     optimize: uint,
     debuginfo: bool,
     verify: bool,
     run_typestate: 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,
     cfg: ast::crate_cfg,
     test: bool,
     parse_only: bool,
     no_trans: bool,
     do_gc: bool,
     stack_growth: bool};

type crate_metadata = {name: str, data: [u8]};

obj session(targ_cfg: @config,
            opts: @options,
            cstore: metadata::cstore::cstore,
            parse_sess: parse_sess,

            // 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 abort_if_errors() {
        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) -> ! {
        self.span_fatal(sp, #fmt["internal compiler error %s", msg]);
    }
    fn bug(msg: str) -> ! {
        self.fatal(#fmt["internal compiler error %s", msg]);
    }
    fn span_unimpl(sp: span, msg: str) -> ! {
        self.span_bug(sp, "unimplemented " + msg);
    }
    fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
    fn get_codemap() -> codemap::codemap { ret parse_sess.cm; }
    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);
    }
    fn span_str(sp: span) -> str {
        ret codemap::span_to_str(sp, self.get_codemap());
    }
    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 }
}
// Local Variables:
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End: