self.straightline(expr, pred, [r, l])
}
- ast::ExprLog(l, r) |
ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r])
self.straightline(expr, pred, [e])
}
+ ast::ExprLogLevel |
ast::ExprMac(*) |
ast::ExprInlineAsm(*) |
ast::ExprSelf |
join_bits(&self.dfcx.oper, temp, in_out);
}
- ast::ExprLog(l, r) |
ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) => {
self.walk_exprs([l, r], in_out, loop_scopes);
}
+ ast::ExprLogLevel |
ast::ExprLit(*) |
ast::ExprPath(*) |
ast::ExprSelf => {
StrEqFnLangItem, // 19
UniqStrEqFnLangItem, // 20
- LogTypeFnLangItem, // 21
FailFnLangItem, // 22
FailBoundsCheckFnLangItem, // 23
ExchangeMallocFnLangItem, // 24
pub fn uniq_str_eq_fn(&self) -> Option<DefId> {
self.items[UniqStrEqFnLangItem as uint]
}
- pub fn log_type_fn(&self) -> Option<DefId> {
- self.items[LogTypeFnLangItem as uint]
- }
pub fn fail_fn(&self) -> Option<DefId> {
self.items[FailFnLangItem as uint]
}
item_refs.insert(@"str_eq", StrEqFnLangItem as uint);
item_refs.insert(@"uniq_str_eq", UniqStrEqFnLangItem as uint);
- item_refs.insert(@"log_type", LogTypeFnLangItem as uint);
item_refs.insert(@"fail_", FailFnLangItem as uint);
item_refs.insert(@"fail_bounds_check",
FailBoundsCheckFnLangItem as uint);
// otherwise, live nodes are not required:
ExprIndex(*) | ExprField(*) | ExprVstore(*) | ExprVec(*) |
- ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLog(*) |
+ ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLogLevel |
ExprBinary(*) | ExprAddrOf(*) |
ExprDoBody(*) | ExprCast(*) | ExprUnary(*) | ExprBreak(_) |
ExprAgain(_) | ExprLit(_) | ExprRet(*) | ExprBlock(*) |
self.propagate_through_expr(l, ln)
}
- ExprLog(l, r) |
ExprIndex(_, l, r) |
ExprBinary(_, _, l, r) => {
self.propagate_through_exprs([l, r], succ)
}
}
+ ExprLogLevel |
ExprLit(*) => {
succ
}
// no correctness conditions related to liveness
ExprCall(*) | ExprMethodCall(*) | ExprIf(*) | ExprMatch(*) |
ExprWhile(*) | ExprLoop(*) | ExprIndex(*) | ExprField(*) |
- ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLog(*) |
+ ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLogLevel |
ExprBinary(*) | ExprDoBody(*) |
ExprCast(*) | ExprUnary(*) | ExprRet(*) | ExprBreak(*) |
ExprAgain(*) | ExprLit(_) | ExprBlock(*) |
ast::ExprDoBody(*) | ast::ExprUnary(*) |
ast::ExprMethodCall(*) | ast::ExprCast(*) | ast::ExprVstore(*) |
ast::ExprVec(*) | ast::ExprTup(*) | ast::ExprIf(*) |
- ast::ExprLog(*) | ast::ExprBinary(*) | ast::ExprWhile(*) |
+ ast::ExprLogLevel | ast::ExprBinary(*) | ast::ExprWhile(*) |
ast::ExprBlock(*) | ast::ExprLoop(*) | ast::ExprMatch(*) |
ast::ExprLit(*) | ast::ExprBreak(*) | ast::ExprMac(*) |
ast::ExprAgain(*) | ast::ExprStruct(*) | ast::ExprRepeat(*) |
self.use_expr(base, Read, visitor);
}
+ ExprLogLevel |
ExprInlineAsm(*) |
ExprBreak(*) |
ExprAgain(*) |
self.consume_block(blk, visitor);
}
- ExprLog(a_expr, b_expr) => {
- self.consume_expr(a_expr, visitor);
- self.use_expr(b_expr, Read, visitor);
- }
-
ExprWhile(cond_expr, ref blk) => {
self.consume_expr(cond_expr, visitor);
self.consume_block(blk, visitor);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::c_str::ToCStr;
-
-use back::link;
-use lib;
use lib::llvm::*;
use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
-use middle::lang_items::LogTypeFnLangItem;
use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::callee;
use syntax::ast;
use syntax::ast::Ident;
-use syntax::ast_map::path_mod;
use syntax::ast_util;
use syntax::codemap::Span;
return next_bcx;
}
-pub fn trans_log(log_ex: &ast::Expr,
- lvl: @ast::Expr,
- bcx: @mut Block,
- e: @ast::Expr) -> @mut Block {
- let _icx = push_ctxt("trans_log");
- let ccx = bcx.ccx();
- let mut bcx = bcx;
- if ty::type_is_bot(expr_ty(bcx, lvl)) {
- return expr::trans_into(bcx, lvl, expr::Ignore);
- }
-
- let (modpath, modname) = {
- let path = &mut bcx.fcx.path;
- let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
- for e in path.iter() {
- match *e {
- path_mod(_) => { modpath.push(*e) }
- _ => {}
- }
- }
- let modname = path_str(ccx.sess, modpath);
- (modpath, modname)
- };
-
- let global = if ccx.module_data.contains_key(&modname) {
- ccx.module_data.get_copy(&modname)
- } else {
- let s = link::mangle_internal_name_by_path_and_seq(
- ccx, modpath, "loglevel");
- let global;
- unsafe {
- global = do s.with_c_str |buf| {
- llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
- };
- llvm::LLVMSetGlobalConstant(global, False);
- llvm::LLVMSetInitializer(global, C_null(Type::i32()));
- lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
- }
- ccx.module_data.insert(modname, global);
- global
- };
- let current_level = Load(bcx, global);
- let level = unpack_result!(bcx, {
- do with_scope_result(bcx, lvl.info(), "level") |bcx| {
- expr::trans_to_datum(bcx, lvl).to_result()
- }
- });
-
- let llenabled = ICmp(bcx, lib::llvm::IntUGE, current_level, level);
- do with_cond(bcx, llenabled) |bcx| {
- do with_scope(bcx, log_ex.info(), "log") |bcx| {
- let mut bcx = bcx;
-
- // Translate the value to be logged
- let val_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, e));
-
- // Call the polymorphic log function
- let val = val_datum.to_ref_llval(bcx);
- let did = langcall(bcx, Some(e.span), "", LogTypeFnLangItem);
- let bcx = callee::trans_lang_call_with_type_params(
- bcx, did, [level, val], [val_datum.ty], expr::Ignore);
- bcx
- }
- }
-}
-
pub fn trans_break_cont(bcx: @mut Block,
opt_label: Option<Ident>,
to_end: bool)
scope_map.insert(exp.id, scope_stack.last().scope_metadata);
match exp.node {
+ ast::ExprLogLevel |
ast::ExprSelf |
ast::ExprLit(_) |
ast::ExprBreak(_) |
}
ast::ExprAssign(@ref sub_exp1, @ref sub_exp2) |
- ast::ExprLog(@ref sub_exp1, @ref sub_exp2) |
ast::ExprRepeat(@ref sub_exp1, @ref sub_exp2, _) => {
walk_expr(cx, sub_exp1, scope_stack, scope_map);
walk_expr(cx, sub_exp2, scope_stack, scope_map);
use back::abi;
-use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage};
+use back::link;
+use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage, False};
use lib;
use metadata::csearch;
use middle::trans::_match;
use std::vec;
use syntax::print::pprust::{expr_to_str};
use syntax::ast;
+use syntax::ast_map::path_mod;
use syntax::codemap;
// Destinations
ast::ExprParen(e) => {
return trans_rvalue_datum_unadjusted(bcx, e);
}
+ ast::ExprLogLevel => {
+ return trans_log_level(bcx);
+ }
_ => {
bcx.tcx().sess.span_bug(
expr.span,
ast::ExprRet(ex) => {
return controlflow::trans_ret(bcx, ex);
}
- ast::ExprLog(lvl, a) => {
- return controlflow::trans_log(expr, lvl, bcx, a);
- }
ast::ExprWhile(cond, ref body) => {
return controlflow::trans_while(bcx, cond, body);
}
fn shorten(x: &str) -> @str {
(if x.char_len() > 60 {x.slice_chars(0, 60)} else {x}).to_managed()
}
+
+pub fn trans_log_level(bcx: @mut Block) -> DatumBlock {
+ let _icx = push_ctxt("trans_log_level");
+ let ccx = bcx.ccx();
+
+ let (modpath, modname) = {
+ let path = &mut bcx.fcx.path;
+ let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
+ for e in path.iter() {
+ match *e {
+ path_mod(_) => { modpath.push(*e) }
+ _ => {}
+ }
+ }
+ let modname = path_str(ccx.sess, modpath);
+ (modpath, modname)
+ };
+
+ let global = if ccx.module_data.contains_key(&modname) {
+ ccx.module_data.get_copy(&modname)
+ } else {
+ let s = link::mangle_internal_name_by_path_and_seq(
+ ccx, modpath, "loglevel");
+ let global;
+ unsafe {
+ global = do s.with_c_str |buf| {
+ llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
+ };
+ llvm::LLVMSetGlobalConstant(global, False);
+ llvm::LLVMSetInitializer(global, C_null(Type::i32()));
+ lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
+ }
+ ccx.module_data.insert(modname, global);
+ global
+ };
+
+ return immediate_rvalue_bcx(bcx, Load(bcx, global), ty::mk_u32());
+}
let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id);
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
}
- ExprLog(_, val) => {
- node_type_needs(cx, use_tydesc, val.id);
- }
ExprCall(f, _, _) => {
let r = ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id));
for a in r.iter() {
ExprMatch(*) | ExprBlock(_) | ExprIf(*) | ExprWhile(*) |
ExprBreak(_) | ExprAgain(_) | ExprUnary(*) | ExprLit(_) |
ExprMac(_) | ExprAddrOf(*) | ExprRet(_) | ExprLoop(*) |
- ExprDoBody(_) => (),
+ ExprDoBody(_) | ExprLogLevel => (),
ExprForLoop(*) => fail!("non-desugared expr_for_loop")
}
ast::ExprBreak(*) |
ast::ExprAgain(*) |
ast::ExprRet(*) |
- ast::ExprLog(*) |
ast::ExprWhile(*) |
ast::ExprLoop(*) |
ast::ExprAssign(*) |
ast::ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
+ ast::ExprLogLevel |
ast::ExprLit(_) | // Note: lit_str is carved out above
ast::ExprUnary(*) |
ast::ExprAddrOf(*) |
}
fcx.write_bot(id);
}
- ast::ExprLog(lv, e) => {
- check_expr_has_type(fcx, lv,
- ty::mk_mach_uint(ast::ty_u32));
-
- // Note: this does not always execute, so do not propagate bot:
- check_expr(fcx, e);
- if ty::type_is_error(fcx.expr_ty(e)) {
- fcx.write_error(id);
- }
- else {
- fcx.write_nil(id);
- }
+ ast::ExprLogLevel => {
+ fcx.write_ty(id, ty::mk_u32())
}
ast::ExprParen(a) => {
check_expr_with_opt_hint(fcx, a, expected);
ast::ExprBreak(*) |
ast::ExprAgain(*) |
ast::ExprRet(*) |
- ast::ExprLog(*) |
+ ast::ExprLogLevel |
ast::ExprWhile(*) |
ast::ExprLoop(*) |
ast::ExprAssign(*) |
rt::logging::console_off();
}
-#[cfg(not(test))]
+#[cfg(not(test), stage0)]
#[lang="log_type"]
#[allow(missing_doc)]
pub fn log_type<T>(_level: u32, object: &T) {
}
}
}
+
+// XXX: This will change soon to not require an allocation. This is an unstable
+// api which should not be used outside of the macros in ext/expand.
+#[doc(hidden)]
+pub fn log(_level: u32, msg: ~str) {
+ newsched_log_str(msg);
+}
pub use option;
pub use kinds;
pub use local_data;
+ pub use logging;
pub use sys;
pub use unstable;
pub use str;
ExprBreak(Option<Ident>),
ExprAgain(Option<Ident>),
ExprRet(Option<@Expr>),
- ExprLog(@Expr, @Expr),
+
+ /// Gets the log level for the enclosing module
+ ExprLogLevel,
ExprInlineAsm(inline_asm),
macro_rules! ignore (($($x:tt)*) => (()))
- macro_rules! error (
- ($arg:expr) => (
- __log(1u32, fmt!( \"%?\", $arg ))
- );
- ($( $arg:expr ),+) => (
- __log(1u32, fmt!( $($arg),+ ))
- )
- )
-
- macro_rules! warn (
- ($arg:expr) => (
- __log(2u32, fmt!( \"%?\", $arg ))
- );
- ($( $arg:expr ),+) => (
- __log(2u32, fmt!( $($arg),+ ))
- )
- )
-
- macro_rules! info (
- ($arg:expr) => (
- __log(3u32, fmt!( \"%?\", $arg ))
- );
- ($( $arg:expr ),+) => (
- __log(3u32, fmt!( $($arg),+ ))
- )
- )
-
- macro_rules! debug (
- ($arg:expr) => (
- if cfg!(debug) { __log(4u32, fmt!( \"%?\", $arg )) }
- );
- ($( $arg:expr ),+) => (
- if cfg!(debug) { __log(4u32, fmt!( $($arg),+ )) }
- )
- )
-
- macro_rules! error2 (
- ($($arg:tt)*) => ( __log(1u32, format!($($arg)*)))
- )
-
- macro_rules! warn2 (
- ($($arg:tt)*) => ( __log(2u32, format!($($arg)*)))
- )
-
- macro_rules! info2 (
- ($($arg:tt)*) => ( __log(3u32, format!($($arg)*)))
+ macro_rules! log(
+ ($lvl:expr, $arg:expr) => ({
+ let lvl = $lvl;
+ if lvl <= __log_level() {
+ ::std::logging::log(lvl, fmt!(\"%?\", $arg))
+ }
+ });
+ ($lvl:expr, $($arg:expr),+) => ({
+ let lvl = $lvl;
+ if lvl <= __log_level() {
+ ::std::logging::log(lvl, fmt!($($arg),+))
+ }
+ })
)
+ macro_rules! error( ($($arg:tt)+) => (log!(1u32, $($arg)+)) )
+ macro_rules! warn ( ($($arg:tt)+) => (log!(2u32, $($arg)+)) )
+ macro_rules! info ( ($($arg:tt)+) => (log!(3u32, $($arg)+)) )
+ macro_rules! debug( ($($arg:tt)+) => (
+ if cfg!(debug) { log!(4u32, $($arg)+) }
+ ))
- macro_rules! debug2 (
- ($($arg:tt)*) => (
- if cfg!(debug) { __log(4u32, format!($($arg)*)) }
- )
+ macro_rules! log2(
+ ($lvl:expr, $($arg:tt)+) => ({
+ let lvl = $lvl;
+ if lvl <= __log_level() {
+ ::std::logging::log(lvl, format!($($arg)+))
+ }
+ })
)
+ macro_rules! error2( ($($arg:tt)+) => (log2!(1u32, $($arg)+)) )
+ macro_rules! warn2 ( ($($arg:tt)+) => (log2!(2u32, $($arg)+)) )
+ macro_rules! info2 ( ($($arg:tt)+) => (log2!(3u32, $($arg)+)) )
+ macro_rules! debug2( ($($arg:tt)+) => (
+ if cfg!(debug) { log2!(4u32, $($arg)+) }
+ ))
macro_rules! fail(
() => (
// allocation but should rather delegate to an invocation of
// write! instead of format!
macro_rules! print (
- ($($arg:tt)+) => ( ::std::io::print(format!($($arg)+)))
+ ($($arg:tt)+) => (::std::io::print(format!($($arg)+)))
)
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
// allocation but should rather delegate to an io::Writer
macro_rules! println (
- ($($arg:tt)+) => ({ print!($($arg)+); ::std::io::println(\"\"); })
+ ($($arg:tt)+) => (::std::io::println(format!($($arg)+)))
)
// NOTE: use this after a snapshot lands to abstract the details
ExprRet(ref e) => {
ExprRet(e.map_move(|x| fld.fold_expr(x)))
}
- ExprLog(lv, e) => {
- ExprLog(
- fld.fold_expr(lv),
- fld.fold_expr(e)
- )
- }
+ ExprLogLevel => ExprLogLevel,
ExprInlineAsm(ref a) => {
ExprInlineAsm(inline_asm {
inputs: a.inputs.map(|&(c, input)| (c, fld.fold_expr(input))),
ExprBreak(_) => (),
ExprAgain(_) => (),
ExprRet(eo) => visit_expr_opt(eo, (e.clone(), v)),
- ExprLog(lv, x) => {
- (v.visit_expr)(lv, (e.clone(), v));
- (v.visit_expr)(x, (e.clone(), v));
- }
+ ExprLogLevel => (),
ExprMac(ref mac) => visit_mac(mac, (e.clone(), v)),
ExprParen(x) => (v.visit_expr)(x, (e.clone(), v)),
ExprInlineAsm(ref a) => {
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock};
use ast::{ExprBreak, ExprCall, ExprCast, ExprDoBody};
use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex};
-use ast::{ExprLit, ExprLog, ExprLoop, ExprMac};
+use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac};
use ast::{ExprMethodCall, ExprParen, ExprPath, ExprRepeat};
use ast::{ExprRet, ExprSelf, ExprStruct, ExprTup, ExprUnary};
use ast::{ExprVec, ExprVstore, ExprVstoreMutBox};
}
}
hi = self.last_span.hi;
- } else if self.eat_keyword(keywords::__Log) {
- // LOG expression
+ } else if self.eat_keyword(keywords::__LogLevel) {
+ // LOG LEVEL expression
self.expect(&token::LPAREN);
- let lvl = self.parse_expr();
- self.expect(&token::COMMA);
- let e = self.parse_expr();
- ex = ExprLog(lvl, e);
+ ex = ExprLogLevel;
hi = self.span.hi;
self.expect(&token::RPAREN);
} else if self.eat_keyword(keywords::Return) {
"if", // 42
"impl", // 43
"let", // 44
- "__log", // 45
+ "__log_level", // 45
"loop", // 46
"match", // 47
"mod", // 48
Impl,
In,
Let,
- __Log,
+ __LogLevel,
Loop,
Match,
Mod,
Impl => Ident { name: 43, ctxt: 0 },
In => Ident { name: 63, ctxt: 0 },
Let => Ident { name: 44, ctxt: 0 },
- __Log => Ident { name: 45, ctxt: 0 },
+ __LogLevel => Ident { name: 45, ctxt: 0 },
Loop => Ident { name: 46, ctxt: 0 },
Match => Ident { name: 47, ctxt: 0 },
Mod => Ident { name: 48, ctxt: 0 },
_ => ()
}
}
- ast::ExprLog(lexp, expr) => {
- word(s.s, "__log");
+ ast::ExprLogLevel => {
+ word(s.s, "__log_level");
popen(s);
- print_expr(s, lexp);
- word(s.s, ",");
- space_if_not_bol(s);
- print_expr(s, expr);
pclose(s);
}
ast::ExprInlineAsm(ref a) => {
ExprRet(optional_expression) => {
walk_expr_opt(visitor, optional_expression, env.clone())
}
- ExprLog(level, subexpression) => {
- visitor.visit_expr(level, env.clone());
- visitor.visit_expr(subexpression, env.clone());
- }
+ ExprLogLevel => {}
ExprMac(ref macro) => walk_mac(visitor, macro, env.clone()),
ExprParen(subexpression) => {
visitor.visit_expr(subexpression, env.clone())