2011-03-25 16:32:39 -05:00
|
|
|
import front.ast;
|
2011-04-08 11:44:20 -05:00
|
|
|
import front.codemap;
|
2010-09-01 15:24:14 -05:00
|
|
|
import util.common.span;
|
2010-11-22 18:27:00 -06:00
|
|
|
import util.common.ty_mach;
|
2011-05-06 15:13:13 -05:00
|
|
|
import std.UInt;
|
2011-04-28 12:50:54 -05:00
|
|
|
import std.Term;
|
2011-05-06 15:13:13 -05:00
|
|
|
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,
|
|
|
|
bool time_passes,
|
2011-05-10 18:10:08 -05:00
|
|
|
bool time_llvm_passes,
|
2011-05-05 12:48:02 -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-04-28 12:50: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);
|
2011-05-06 15:13:13 -05:00
|
|
|
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
|
|
|
|
|
|
|
if (Term.color_supported()) {
|
2011-05-06 15:13:13 -05:00
|
|
|
Term.fg(IO.stdout().get_buf_writer(), color);
|
2011-04-28 16:59:16 -05:00
|
|
|
}
|
|
|
|
|
2011-05-06 15:13:13 -05:00
|
|
|
IO.stdout().write_str(#fmt("%s:", kind));
|
2011-04-28 16:59:16 -05:00
|
|
|
|
|
|
|
if (Term.color_supported()) {
|
2011-05-06 15:13:13 -05:00
|
|
|
Term.reset(IO.stdout().get_buf_writer());
|
2011-04-28 16:59:16 -05:00
|
|
|
}
|
|
|
|
|
2011-05-06 15:13:13 -05:00
|
|
|
IO.stdout().write_str(#fmt(" %s\n", msg));
|
2011-04-28 12:50:54 -05:00
|
|
|
}
|
|
|
|
|
2011-05-04 18:53:42 -05:00
|
|
|
state obj session(ast.crate_num cnum,
|
|
|
|
@config targ_cfg, @options opts,
|
2011-05-06 15:13:13 -05:00
|
|
|
Map.hashmap[int, crate_metadata] crates,
|
2011-04-18 02:22:23 -05:00
|
|
|
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-03-25 16:32:39 -05:00
|
|
|
fn get_targ_crate_num() -> ast.crate_num {
|
|
|
|
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-04-18 02:22:23 -05:00
|
|
|
fn add_metadata(vec[@ast.meta_item] data) {
|
|
|
|
metadata = metadata + data;
|
|
|
|
}
|
|
|
|
fn get_metadata() -> vec[@ast.meta_item] {
|
|
|
|
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
|
|
|
|
|
|
|
fn get_codemap() -> codemap.codemap {
|
|
|
|
ret cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lookup_pos(uint pos) -> codemap.loc {
|
|
|
|
ret codemap.lookup_pos(cm, pos);
|
|
|
|
}
|
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:
|