rustc: Stop using shape code for logging
This commit is contained in:
parent
dbc00ced3a
commit
ac822a52be
6 changed files with 48 additions and 15 deletions
|
@ -4,13 +4,16 @@
|
|||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
export console_on, console_off;
|
||||
use cast::transmute;
|
||||
|
||||
export console_on, console_off, log_type;
|
||||
|
||||
#[nolink]
|
||||
extern mod rustrt {
|
||||
#[legacy_exports];
|
||||
fn rust_log_console_on();
|
||||
fn rust_log_console_off();
|
||||
fn rust_log_str(level: u32, string: *libc::c_char, size: libc::size_t);
|
||||
}
|
||||
|
||||
/// Turns on logging to stdout globally
|
||||
|
@ -27,4 +30,17 @@ fn console_on() {
|
|||
*/
|
||||
fn console_off() {
|
||||
rustrt::rust_log_console_off();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(notest)]
|
||||
#[lang="log_type"]
|
||||
pub fn log_type<T>(level: u32, object: &T) {
|
||||
let bytes = do io::with_bytes_writer() |writer| {
|
||||
repr::write_repr(writer, object);
|
||||
};
|
||||
unsafe {
|
||||
let len = bytes.len() as libc::size_t;
|
||||
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -952,9 +952,9 @@ rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) {
|
|||
|
||||
// Don't run on the Rust stack!
|
||||
extern "C" void
|
||||
rust_log_str(uint32_t level, const char *str) {
|
||||
rust_log_str(uint32_t level, const char *str, size_t size) {
|
||||
rust_task *task = rust_get_current_task();
|
||||
task->sched_loop->get_log().log(task, level, "%s", str);
|
||||
task->sched_loop->get_log().log(task, level, "%.*s", (int)size, str);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -46,7 +46,8 @@ struct LanguageItems {
|
|||
|
||||
mut str_eq_fn: Option<def_id>,
|
||||
mut uniq_str_eq_fn: Option<def_id>,
|
||||
mut annihilate_fn: Option<def_id>
|
||||
mut annihilate_fn: Option<def_id>,
|
||||
mut log_type_fn: Option<def_id>
|
||||
}
|
||||
|
||||
mod LanguageItems {
|
||||
|
@ -76,7 +77,8 @@ mod LanguageItems {
|
|||
|
||||
str_eq_fn: None,
|
||||
uniq_str_eq_fn: None,
|
||||
annihilate_fn: None
|
||||
annihilate_fn: None,
|
||||
log_type_fn: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +113,7 @@ fn LanguageItemCollector(crate: @crate, session: session,
|
|||
item_refs.insert(~"str_eq", &mut items.str_eq_fn);
|
||||
item_refs.insert(~"uniq_str_eq", &mut items.uniq_str_eq_fn);
|
||||
item_refs.insert(~"annihilate", &mut items.annihilate_fn);
|
||||
item_refs.insert(~"log_type", &mut items.log_type_fn);
|
||||
|
||||
LanguageItemCollector {
|
||||
crate: crate,
|
||||
|
|
|
@ -2005,12 +2005,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
|
|||
}
|
||||
Call(bcx, main_llfn, args);
|
||||
|
||||
// Call the box annihilator.
|
||||
// XXX: Crashes.
|
||||
//let did = bcx.tcx().lang_items.annihilate_fn.get();
|
||||
//let bcx = callee::trans_rtcall_or_lang_call(bcx, did, ~[],
|
||||
// expr::Ignore);
|
||||
|
||||
build_return(bcx);
|
||||
finish_fn(fcx, lltop);
|
||||
return llfdecl;
|
||||
|
|
|
@ -290,6 +290,26 @@ fn trans_rtcall_or_lang_call(bcx: block, did: ast::def_id, args: ~[ValueRef],
|
|||
ArgVals(args), dest, DontAutorefArg);
|
||||
}
|
||||
|
||||
fn trans_rtcall_or_lang_call_with_type_params(bcx: block,
|
||||
did: ast::def_id,
|
||||
args: ~[ValueRef],
|
||||
type_params: ~[ty::t],
|
||||
dest: expr::Dest) -> block {
|
||||
let fty;
|
||||
if did.crate == ast::local_crate {
|
||||
fty = ty::node_id_to_type(bcx.tcx(), did.node);
|
||||
} else {
|
||||
fty = csearch::get_type(bcx.tcx(), did).ty;
|
||||
}
|
||||
|
||||
let rty = ty::ty_fn_ret(fty);
|
||||
return callee::trans_call_inner(
|
||||
bcx, None, fty, rty,
|
||||
|bcx| trans_fn_ref_with_vtables_to_callee(bcx, did, 0, type_params,
|
||||
None),
|
||||
ArgVals(args), dest, DontAutorefArg);
|
||||
}
|
||||
|
||||
fn body_contains_ret(body: ast::blk) -> bool {
|
||||
let cx = {mut found: false};
|
||||
visit::visit_block(body, cx, visit::mk_vt(@{
|
||||
|
|
|
@ -190,12 +190,12 @@ fn trans_log(log_ex: @ast::expr,
|
|||
|
||||
// Translate the value to be logged
|
||||
let val_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, e));
|
||||
let tydesc = get_tydesc_simple(ccx, val_datum.ty);
|
||||
|
||||
// Call the polymorphic log function
|
||||
let val = val_datum.to_ref_llval(bcx);
|
||||
let val = PointerCast(bcx, val, T_ptr(T_i8()));
|
||||
Call(bcx, ccx.upcalls.log_type, [tydesc, val, level]);
|
||||
let did = bcx.tcx().lang_items.log_type_fn.get();
|
||||
let bcx = callee::trans_rtcall_or_lang_call_with_type_params(
|
||||
bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore);
|
||||
bcx
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue