2011-05-12 10:24:54 -05:00
|
|
|
import front::ast;
|
|
|
|
import front::codemap;
|
|
|
|
import util::common::span;
|
|
|
|
import util::common::ty_mach;
|
2011-05-17 13:41:41 -05:00
|
|
|
import std::uint;
|
2011-05-12 10:24:54 -05:00
|
|
|
import std::term;
|
|
|
|
import std::io;
|
|
|
|
import std::map;
|
2010-09-01 15:24:14 -05:00
|
|
|
|
2010-11-22 18:27:00 -06:00
|
|
|
tag os {
|
|
|
|
os_win32;
|
|
|
|
os_macos;
|
|
|
|
os_linux;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag arch {
|
|
|
|
arch_x86;
|
|
|
|
arch_x64;
|
|
|
|
arch_arm;
|
|
|
|
}
|
|
|
|
|
2011-05-04 18:53:42 -05:00
|
|
|
type config = rec(os os,
|
|
|
|
arch arch,
|
|
|
|
ty_mach int_type,
|
|
|
|
ty_mach uint_type,
|
|
|
|
ty_mach float_type);
|
|
|
|
|
|
|
|
type options = rec(bool shared,
|
|
|
|
bool optimize,
|
|
|
|
bool debuginfo,
|
|
|
|
bool verify,
|
|
|
|
bool run_typestate,
|
|
|
|
bool save_temps,
|
2011-05-12 17:42:12 -05:00
|
|
|
bool stats,
|
2011-05-04 18:53:42 -05:00
|
|
|
bool time_passes,
|
2011-05-10 18:10:08 -05:00
|
|
|
bool time_llvm_passes,
|
2011-05-13 15:47:37 -05:00
|
|
|
back::link::output_type output_type,
|
2011-05-04 21:27:54 -05:00
|
|
|
vec[str] library_search_paths,
|
|
|
|
str sysroot);
|
2010-11-22 18:27:00 -06:00
|
|
|
|
2011-04-18 02:22:23 -05:00
|
|
|
type crate_metadata = rec(str name,
|
|
|
|
vec[u8] data);
|
2011-03-25 12:42:57 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn emit_diagnostic(span sp, str msg, str kind, u8 color,
|
|
|
|
codemap::codemap cm) {
|
|
|
|
auto lo = codemap::lookup_pos(cm, sp.lo);
|
|
|
|
auto hi = codemap::lookup_pos(cm, sp.hi);
|
|
|
|
io::stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line,
|
2011-04-28 12:50:54 -05:00
|
|
|
lo.col, hi.line, hi.col));
|
2011-04-28 16:59:16 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
if (term::color_supported()) {
|
|
|
|
term::fg(io::stdout().get_buf_writer(), color);
|
2011-04-28 16:59:16 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
io::stdout().write_str(#fmt("%s:", kind));
|
2011-04-28 16:59:16 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
if (term::color_supported()) {
|
|
|
|
term::reset(io::stdout().get_buf_writer());
|
2011-04-28 16:59:16 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
io::stdout().write_str(#fmt(" %s\n", msg));
|
2011-04-28 12:50:54 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
state obj session(ast::crate_num cnum,
|
2011-05-04 18:53:42 -05:00
|
|
|
@config targ_cfg, @options opts,
|
2011-05-12 10:24:54 -05:00
|
|
|
map::hashmap[int, crate_metadata] crates,
|
|
|
|
mutable vec[@ast::meta_item] metadata,
|
|
|
|
codemap::codemap cm) {
|
2010-11-22 18:27:00 -06:00
|
|
|
|
2011-05-04 18:53:42 -05:00
|
|
|
fn get_targ_cfg() -> @config {
|
|
|
|
ret targ_cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_opts() -> @options {
|
|
|
|
ret opts;
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn get_targ_crate_num() -> ast::crate_num {
|
2011-03-25 16:32:39 -05:00
|
|
|
ret cnum;
|
|
|
|
}
|
|
|
|
|
2010-09-23 15:15:51 -05:00
|
|
|
fn span_err(span sp, str msg) {
|
2011-04-28 12:50:54 -05:00
|
|
|
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
|
|
|
emit_diagnostic(sp, msg, "error", 9u8, cm);
|
2010-09-01 15:24:14 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2010-09-23 15:15:51 -05:00
|
|
|
fn err(str msg) {
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("error: %s", msg);
|
2010-09-01 15:24:14 -05:00
|
|
|
fail;
|
|
|
|
}
|
2010-09-23 15:15:51 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn add_metadata(vec[@ast::meta_item] data) {
|
2011-04-18 02:22:23 -05:00
|
|
|
metadata = metadata + data;
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
fn get_metadata() -> vec[@ast::meta_item] {
|
2011-04-18 02:22:23 -05:00
|
|
|
ret metadata;
|
|
|
|
}
|
|
|
|
|
2011-03-18 15:44:13 -05:00
|
|
|
fn span_warn(span sp, str msg) {
|
2011-04-28 12:50:54 -05:00
|
|
|
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
|
|
|
emit_diagnostic(sp, msg, "warning", 11u8, cm);
|
2011-03-18 15:44:13 -05:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:27:00 -06:00
|
|
|
fn bug(str msg) {
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("error: internal compiler error %s", msg);
|
2010-11-22 18:27:00 -06:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-03-18 14:30:44 -05:00
|
|
|
fn span_unimpl(span sp, str msg) {
|
2011-04-28 12:50:54 -05:00
|
|
|
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
|
|
|
emit_diagnostic(sp, "internal compiler error: unimplemented " + msg,
|
|
|
|
"error", 9u8, cm);
|
2011-03-18 14:30:44 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2010-09-23 15:15:51 -05:00
|
|
|
fn unimpl(str msg) {
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("error: unimplemented %s", msg);
|
2010-09-23 15:15:51 -05:00
|
|
|
fail;
|
|
|
|
}
|
2011-03-25 12:42:57 -05:00
|
|
|
|
|
|
|
fn get_external_crate(int num) -> crate_metadata {
|
|
|
|
ret crates.get(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_external_crate(int num, &crate_metadata metadata) {
|
|
|
|
crates.insert(num, metadata);
|
|
|
|
}
|
2011-03-25 13:10:50 -05:00
|
|
|
|
|
|
|
fn has_external_crate(int num) -> bool {
|
|
|
|
ret crates.contains_key(num);
|
|
|
|
}
|
2011-04-08 11:44:20 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn get_codemap() -> codemap::codemap {
|
2011-04-08 11:44:20 -05:00
|
|
|
ret cm;
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn lookup_pos(uint pos) -> codemap::loc {
|
|
|
|
ret codemap::lookup_pos(cm, pos);
|
2011-04-08 11:44:20 -05: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
|
2011-03-25 17:07:27 -05:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2010-09-01 15:24:14 -05:00
|
|
|
// End:
|