Switch log_expr to carrying a full expr:u32 for level. Add log_full variant that parses that expr, prepare for snapshot.

This commit is contained in:
Graydon Hoare 2011-12-21 14:31:31 -08:00
parent 66856a39b3
commit 8d9e7deab5
9 changed files with 59 additions and 29 deletions

View File

@ -3622,7 +3622,7 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
assert dest == ignore;
ret trans_fail_expr(bcx, some(e.span), expr);
}
ast::expr_log(lvl, a) {
ast::expr_log(_, lvl, a) {
assert dest == ignore;
ret trans_log(lvl, bcx, a);
}
@ -3768,7 +3768,7 @@ fn load_if_immediate(cx: @block_ctxt, v: ValueRef, t: ty::t) -> ValueRef {
ret v;
}
fn trans_log(lvl: int, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
fn trans_log(lvl: @ast::expr, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
let ccx = bcx_ccx(cx);
let lcx = cx.fcx.lcx;
let modname = str::connect(lcx.module_path, "::");
@ -3778,20 +3778,26 @@ fn trans_log(lvl: int, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
let s = link::mangle_internal_name_by_path_and_seq(
lcx.ccx, lcx.module_path, "loglevel");
let global = str::as_buf(s, {|buf|
llvm::LLVMAddGlobal(lcx.ccx.llmod, ccx.int_type, buf)
llvm::LLVMAddGlobal(lcx.ccx.llmod, T_i32(), buf)
});
llvm::LLVMSetGlobalConstant(global, False);
llvm::LLVMSetInitializer(global, C_null(ccx.int_type));
llvm::LLVMSetInitializer(global, C_null(T_i32()));
llvm::LLVMSetLinkage(global,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
lcx.ccx.module_data.insert(modname, global);
global
};
let level_cx = new_scope_block_ctxt(cx, "level");
let log_cx = new_scope_block_ctxt(cx, "log");
let after_cx = new_sub_block_ctxt(cx, "after");
let load = Load(cx, global);
let test = ICmp(cx, lib::llvm::LLVMIntSGE, load, C_int(ccx, lvl));
CondBr(cx, test, log_cx.llbb, after_cx.llbb);
Br(cx, level_cx.llbb);
let level_res = trans_temp_expr(level_cx, lvl);
let test = ICmp(level_res.bcx, lib::llvm::LLVMIntUGE,
load, level_res.val);
CondBr(level_res.bcx, test, log_cx.llbb, after_cx.llbb);
let sub = trans_temp_expr(log_cx, e);
let e_ty = ty::expr_ty(bcx_tcx(cx), e);
let log_bcx = sub.bcx;
@ -3807,14 +3813,12 @@ fn trans_log(lvl: int, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
let llvalptr = r.val;
let llval_i8 = PointerCast(log_bcx, llvalptr, T_ptr(T_i8()));
// FIXME lvl should not be int, but actually u32,
// and the upcall should take a u32, not an i32
Call(log_bcx, ccx.upcalls.log_type,
[lltydesc, llval_i8, C_i32(lvl as i32)]);
[lltydesc, llval_i8, level_res.val]);
log_bcx = trans_block_cleanups(log_bcx, log_cx);
Br(log_bcx, after_cx.llbb);
ret after_cx;
ret trans_block_cleanups(after_cx, level_cx);
}
fn trans_check_expr(cx: @block_ctxt, e: @ast::expr, s: str) -> @block_ctxt {

View File

@ -344,9 +344,8 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
clear_pp(rslt);
handle_var(fcx, rslt, e.id, path_to_ident(fcx.ccx.tcx, p));
}
expr_log(_, arg) {
find_pre_post_expr(fcx, arg);
copy_pre_post(fcx.ccx, e.id, arg);
expr_log(_, lvl, arg) {
find_pre_post_exprs(fcx, [lvl, arg], e.id);
}
expr_fn(f, cap_clause) {
find_pre_post_expr_fn_upvars(fcx, e);

View File

@ -366,8 +366,8 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
return_val);
}
expr_path(_) { ret pure_exp(fcx.ccx, e.id, pres); }
expr_log(_, ex) {
ret find_pre_post_state_sub(fcx, pres, ex, e.id, none);
expr_log(_, lvl, ex) {
ret find_pre_post_state_two(fcx, pres, lvl, ex, e.id, oper_pure);
}
expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
expr_lit(l) { ret pure_exp(fcx.ccx, e.id, pres); }

View File

@ -1868,8 +1868,9 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
bot = true;
write::nil_ty(tcx, id);
}
ast::expr_log(l, e) {
bot = check_expr(fcx, e);
ast::expr_log(_, lv, e) {
bot = check_expr_with(fcx, lv, ty::mk_mach_uint(tcx, ast::ty_u32));
bot |= check_expr(fcx, e);
write::nil_ty(tcx, id);
}
ast::expr_check(_, e) {

View File

@ -247,7 +247,7 @@ fn proto_kind(p: proto) -> kind {
expr_cont;
expr_ret(option::t<@expr>);
expr_be(@expr);
expr_log(int, @expr);
expr_log(int, @expr, @expr);
/* just an assert, no significance to typestate */
expr_assert(@expr);

View File

@ -424,7 +424,8 @@ fn fold_anon_obj_field_(aof: anon_obj_field, fld: ast_fold) ->
expr_cont. { e }
expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) }
expr_be(e) { expr_be(fld.fold_expr(e)) }
expr_log(lv, e) { expr_log(lv, fld.fold_expr(e)) }
expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv),
fld.fold_expr(e)) }
expr_assert(e) { expr_assert(fld.fold_expr(e)) }
expr_check(m, e) { expr_check(m, fld.fold_expr(e)) }
expr_if_check(cond, tr, fl) {

View File

@ -165,7 +165,8 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
"cont", "ret", "be", "fail", "type", "resource", "check",
"assert", "claim", "native", "fn", "lambda", "pure",
"unsafe", "block", "import", "export", "let", "const",
"log", "log_err", "tag", "obj", "copy", "sendfn", "impl"] {
"log", "log_err", "log_full",
"tag", "obj", "copy", "sendfn", "impl"] {
words.insert(word, ());
}
words
@ -758,6 +759,15 @@ fn is_bar(t: token::token) -> bool {
alt t { token::BINOP(token::OR.) | token::OROR. { true } _ { false } }
}
fn mk_lit_u32(p: parser, i: u32) -> @ast::expr {
let span = p.get_span();
let lv_lit = @{node: ast::lit_uint(i as u64, ast::ty_u32),
span: span};
ret @{id: p.get_id(), node: ast::expr_lit(lv_lit), span: span};
}
fn parse_bottom_expr(p: parser) -> @ast::expr {
let lo = p.get_lo_pos();
let hi = p.get_hi_pos();
@ -899,13 +909,18 @@ fn parse_expr_opt(p: parser) -> option::t<@ast::expr> {
hi = e.span.hi;
ex = ast::expr_fail(some(e));
} else { ex = ast::expr_fail(none); }
} else if eat_word(p, "log_full") {
let e = parse_expr(p);
let lvl = parse_expr(p);
ex = ast::expr_log(2, lvl, e);
hi = e.span.hi;
} else if eat_word(p, "log") {
let e = parse_expr(p);
ex = ast::expr_log(1, e);
ex = ast::expr_log(1, mk_lit_u32(p, 1u32), e);
hi = e.span.hi;
} else if eat_word(p, "log_err") {
let e = parse_expr(p);
ex = ast::expr_log(0, e);
ex = ast::expr_log(0, mk_lit_u32(p, 0u32), e);
hi = e.span.hi;
} else if eat_word(p, "assert") {
let e = parse_expr(p);

View File

@ -913,9 +913,16 @@ fn print_opt(s: ps, expr: option::t<@ast::expr>) {
}
}
ast::expr_be(result) { word_nbsp(s, "be"); print_expr(s, result); }
ast::expr_log(lvl, expr) {
alt lvl { 1 { word_nbsp(s, "log"); } 0 { word_nbsp(s, "log_err"); } }
print_expr(s, expr);
ast::expr_log(lvl, lexp, expr) {
alt lvl {
1 { word_nbsp(s, "log"); print_expr(s, expr); }
0 { word_nbsp(s, "log_err"); print_expr(s, expr); }
2 {
word_nbsp(s, "log_full");
word(s.s, " ");
print_expr(s, lexp);
}
}
}
ast::expr_check(m, expr) {
alt m {
@ -990,7 +997,7 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
ast::expr_ternary(_, _, _) | ast::expr_move(_, _) |
ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) |
ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
ast::expr_log(_, _) | ast::expr_assert(_) |
ast::expr_log(_, _, _) | ast::expr_assert(_) |
ast::expr_check(_, _) { true }
_ { false }
};
@ -1305,7 +1312,7 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
ast::expr_be(_) { true }
ast::expr_assert(_) { true }
ast::expr_check(_, _) { true }
ast::expr_log(_, _) { true }
ast::expr_log(_, _, _) { true }
_ { false }
}
}
@ -1644,7 +1651,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) |
ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) |
ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
ast::expr_log(_, sub) | ast::expr_assert(sub) |
ast::expr_log(_, _, sub) | ast::expr_assert(sub) |
ast::expr_check(_, sub) { ends_in_lit_int(sub) }
ast::expr_fail(osub) | ast::expr_ret(osub) {
alt osub {

View File

@ -333,7 +333,10 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
expr_cont. { }
expr_ret(eo) { visit_expr_opt(eo, e, v); }
expr_be(x) { v.visit_expr(x, e, v); }
expr_log(_, x) { v.visit_expr(x, e, v); }
expr_log(_, lv, x) {
v.visit_expr(lv, e, v);
v.visit_expr(x, e, v);
}
expr_check(_, x) { v.visit_expr(x, e, v); }
expr_assert(x) { v.visit_expr(x, e, v); }
expr_anon_obj(anon_obj) {