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;
|
2010-09-01 15:24:14 -05:00
|
|
|
import std._uint;
|
2011-03-25 12:42:57 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
type cfg = rec(os os,
|
|
|
|
arch arch,
|
|
|
|
ty_mach int_type,
|
|
|
|
ty_mach uint_type,
|
|
|
|
ty_mach float_type);
|
|
|
|
|
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-18 02:22:23 -05:00
|
|
|
state obj session(ast.crate_num cnum, cfg targ,
|
|
|
|
map.hashmap[int, crate_metadata] crates,
|
|
|
|
mutable vec[@ast.meta_item] metadata,
|
|
|
|
codemap.codemap cm) {
|
2010-11-22 18:27:00 -06:00
|
|
|
|
|
|
|
fn get_targ_cfg() -> cfg {
|
|
|
|
ret targ;
|
|
|
|
}
|
|
|
|
|
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-08 11:44:20 -05:00
|
|
|
auto lo = codemap.lookup_pos(cm, sp.lo);
|
|
|
|
auto hi = codemap.lookup_pos(cm, sp.hi);
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("%s:%u:%u:%u:%u: error: %s",
|
|
|
|
lo.filename,
|
|
|
|
lo.line, lo.col,
|
|
|
|
hi.line, hi.col,
|
|
|
|
msg);
|
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-08 11:44:20 -05:00
|
|
|
auto lo = codemap.lookup_pos(cm, sp.lo);
|
|
|
|
auto hi = codemap.lookup_pos(cm, sp.hi);
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("%s:%u:%u:%u:%u: warning: %s",
|
|
|
|
lo.filename,
|
|
|
|
lo.line, lo.col,
|
|
|
|
hi.line, hi.col,
|
|
|
|
msg);
|
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-08 11:44:20 -05:00
|
|
|
auto lo = codemap.lookup_pos(cm, sp.lo);
|
|
|
|
auto hi = codemap.lookup_pos(cm, sp.hi);
|
2011-04-19 05:02:06 -05:00
|
|
|
log_err #fmt("%s:%u:%u:%u:%u: error: unimplemented %s",
|
|
|
|
lo.filename,
|
|
|
|
lo.line, lo.col,
|
|
|
|
hi.line, hi.col,
|
|
|
|
msg);
|
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:
|