2011-06-15 13:19:50 -05:00
|
|
|
|
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;
|
2011-06-07 19:54:22 -05:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2010-09-01 15:24:14 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
tag os { os_win32; os_macos; os_linux; }
|
|
|
|
|
|
|
|
tag arch { arch_x86; arch_x64; arch_arm; }
|
|
|
|
|
|
|
|
type config =
|
|
|
|
rec(os os,
|
|
|
|
arch arch,
|
|
|
|
ty_mach int_type,
|
|
|
|
ty_mach uint_type,
|
|
|
|
ty_mach float_type);
|
|
|
|
|
|
|
|
type options =
|
|
|
|
rec(bool shared,
|
|
|
|
uint optimize,
|
|
|
|
bool debuginfo,
|
|
|
|
bool verify,
|
|
|
|
bool run_typestate,
|
|
|
|
bool save_temps,
|
|
|
|
bool stats,
|
|
|
|
bool time_passes,
|
|
|
|
bool time_llvm_passes,
|
|
|
|
back::link::output_type output_type,
|
|
|
|
vec[str] library_search_paths,
|
|
|
|
str sysroot);
|
|
|
|
|
|
|
|
type crate_metadata = rec(str name, vec[u8] data);
|
2011-03-25 12:42:57 -05:00
|
|
|
|
2011-05-26 17:58:30 -05:00
|
|
|
fn span_to_str(span sp, codemap::codemap cm) -> str {
|
2011-05-12 10:24:54 -05:00
|
|
|
auto lo = codemap::lookup_pos(cm, sp.lo);
|
|
|
|
auto hi = codemap::lookup_pos(cm, sp.hi);
|
2011-06-15 13:19:50 -05:00
|
|
|
ret #fmt("%s:%u:%u:%u:%u", lo.filename, lo.line, lo.col, hi.line, hi.col);
|
2011-05-26 17:58:30 -05:00
|
|
|
}
|
|
|
|
|
2011-06-07 19:54:22 -05:00
|
|
|
fn emit_diagnostic(option::t[span] sp, str msg, str kind, u8 color,
|
2011-05-26 17:58:30 -05:00
|
|
|
codemap::codemap cm) {
|
2011-06-07 19:54:22 -05:00
|
|
|
auto ss = "<input>:0:0:0:0";
|
|
|
|
alt (sp) {
|
2011-06-15 13:19:50 -05:00
|
|
|
case (some(?ssp)) { ss = span_to_str(ssp, cm); }
|
|
|
|
case (none) { }
|
2011-06-07 19:54:22 -05:00
|
|
|
}
|
|
|
|
io::stdout().write_str(ss + ": ");
|
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));
|
|
|
|
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-06-15 13:19:50 -05:00
|
|
|
obj session(ast::crate_num cnum,
|
|
|
|
@config targ_cfg,
|
|
|
|
@options opts,
|
|
|
|
map::hashmap[int, crate_metadata] crates,
|
2011-06-19 05:24:42 -05:00
|
|
|
codemap::codemap cm) {
|
2011-06-15 13:19:50 -05:00
|
|
|
fn get_targ_cfg() -> @config { ret targ_cfg; }
|
|
|
|
fn get_opts() -> @options { ret opts; }
|
|
|
|
fn get_targ_crate_num() -> ast::crate_num { ret cnum; }
|
2011-06-19 00:41:20 -05:00
|
|
|
fn span_fatal(span sp, str msg) -> ! {
|
2011-04-28 12:50:54 -05:00
|
|
|
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-07 19:54:22 -05:00
|
|
|
emit_diagnostic(some(sp), msg, "error", 9u8, cm);
|
2010-09-01 15:24:14 -05:00
|
|
|
fail;
|
|
|
|
}
|
2011-06-19 00:41:20 -05:00
|
|
|
fn fatal(str msg) -> ! {
|
2011-06-07 19:54:22 -05:00
|
|
|
emit_diagnostic(none[span], msg, "error", 9u8, cm);
|
2010-09-01 15:24:14 -05:00
|
|
|
fail;
|
|
|
|
}
|
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.
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-07 19:54:22 -05:00
|
|
|
emit_diagnostic(some(sp), msg, "warning", 11u8, cm);
|
|
|
|
}
|
|
|
|
fn warn(str msg) {
|
|
|
|
emit_diagnostic(none[span], msg, "warning", 11u8, cm);
|
2011-03-18 15:44:13 -05:00
|
|
|
}
|
2011-05-17 16:12:49 -05:00
|
|
|
fn span_note(span sp, str msg) {
|
|
|
|
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-07 19:54:22 -05:00
|
|
|
emit_diagnostic(some(sp), msg, "note", 10u8, cm);
|
|
|
|
}
|
|
|
|
fn span_bug(span sp, str msg) -> ! {
|
2011-06-19 00:41:20 -05:00
|
|
|
self.span_fatal(sp, #fmt("internal compiler error %s", msg));
|
2011-05-17 16:12:49 -05:00
|
|
|
}
|
2011-05-20 19:36:33 -05:00
|
|
|
fn bug(str msg) -> ! {
|
2011-06-19 00:41:20 -05:00
|
|
|
self.fatal(#fmt("internal compiler error %s", msg));
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2011-05-20 19:36:33 -05:00
|
|
|
fn span_unimpl(span sp, str msg) -> ! {
|
2011-06-07 19:54:22 -05:00
|
|
|
self.span_bug(sp, "unimplemented " + msg);
|
2011-03-18 14:30:44 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
fn unimpl(str msg) -> ! { self.bug("unimplemented " + msg); }
|
|
|
|
fn get_external_crate(int num) -> crate_metadata { ret crates.get(num); }
|
2011-03-25 12:42:57 -05:00
|
|
|
fn set_external_crate(int num, &crate_metadata metadata) {
|
|
|
|
crates.insert(num, metadata);
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
fn has_external_crate(int num) -> bool { ret crates.contains_key(num); }
|
|
|
|
fn get_codemap() -> codemap::codemap { 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
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
fn span_str(span sp) -> str { ret span_to_str(sp, self.get_codemap()); }
|
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:
|