logs: replace every fmt::print with a lg call instead (#1368)

Favors the `lg` namespace over `fmt` directly, as this will output the
logs to a file / has log levels.

I also made assertion errors go to a file, this unfortunately means
importing `lg` and hence `fmt` which was attempted to be avoided before.
But I'm not sure how else to do this aspect without re-inventing the
file logging.

We have a lot of commented out prints as well that we should probably
cleanup at some point / switch them to trace level and default to `info`
level.

I noticed the pattern of disabling debug logs behind some boolean,
something to consider cleaning up in the future -- if our logs were more
structured (knowing where they are coming from) then a lot this
boilerplate could be eliminated.

Closes #1358
This commit is contained in:
Tyler Wilding
2022-10-01 11:58:36 -04:00
committed by GitHub
parent 4e48ba21c1
commit 4d751af38e
120 changed files with 990 additions and 893 deletions
+24 -23
View File
@@ -3,6 +3,7 @@
#include "GenericElementMatcher.h"
#include "common/goos/PrettyPrinter.h"
#include "common/log/log.h"
#include "common/type_system/state.h"
#include "common/util/Assert.h"
#include "common/util/BitUtils.h"
@@ -402,7 +403,7 @@ void pop_helper(const std::vector<RegisterAccess>& vars,
submit_regs.push_back(var.reg());
} else {
// auto var_id = env.get_program_var_id(var);
// fmt::print(
// lg::print(
// "Unsafe to pop {}: used {} times, def {} times, expected use {} ({} {} rd:
// {}) ({} "
// "{})\n",
@@ -413,7 +414,7 @@ void pop_helper(const std::vector<RegisterAccess>& vars,
// if (var.to_string(env) == "a3-0") {
// for (auto& use : use_def.uses) {
// if (!use.disabled) {
// fmt::print(" at instruction {}\n", use.op_id);
// lg::print(" at instruction {}\n", use.op_id);
// }
// }
// }
@@ -1231,7 +1232,7 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env,
}
}
}
// fmt::print("here {} {} {}\n", rd_in.base_type.print(), rd.success,
// lg::print("here {} {} {}\n", rd_in.base_type.print(), rd.success,
// rd.has_variable_token());
if (idx_of_success >= 0) {
@@ -1261,7 +1262,7 @@ void SimpleExpressionElement::update_from_stack_add_i(const Env& env,
return;
} else {
// TODO - output error to IR
lg::error("Bad {} at OP: {}\n", args.at(0)->to_string(env), m_my_idx);
lg::error("Bad {} at OP: {}", args.at(0)->to_string(env), m_my_idx);
throw std::runtime_error("Failed to match product_with_constant inline array access 2.");
}
}
@@ -1525,7 +1526,7 @@ void SimpleExpressionElement::update_from_stack_pcypld(const Env& env,
result->push_back(as_mod);
return;
} else {
fmt::print("pcpyud rewrite form fail: {} {}\n", base_form.print(), a1_form.print());
lg::warn("pcpyud rewrite form fail: {} {}", base_form.print(), a1_form.print());
}
}
auto new_form = pool.alloc_element<GenericElement>(
@@ -1995,7 +1996,7 @@ void SimpleExpressionElement::update_from_stack_logor_or_logand(const Env& env,
auto repopped = stack.pop_reg(var_b, {}, env, true, stack.size() - 1);
if (!repopped) {
fmt::print("repop failed.\n{}\n", stack.print(env));
lg::warn("repop failed.\n{}", stack.print(env));
repopped = var_to_form(var_b, pool);
}
@@ -2592,7 +2593,7 @@ void SetFormFormElement::push_to_stack(const Env& env, FormPool& pool, FormStack
m_src = value;
}
} else if (src_as_bf_set) {
fmt::print("invalid bf set: {}\n", src_as_bf_set->to_string(env));
lg::warn("invalid bf set: {}", src_as_bf_set->to_string(env));
}
// setting a bitfield to zero is wonky.
@@ -3014,12 +3015,12 @@ Form* get_set_next_state(FormElement* set_elt, const Env& env) {
Matcher::deref(Matcher::any_reg(0), false, {DerefTokenMatcher::string("next-state")});
auto mr = match(dst_matcher, dst);
if (!mr.matched) {
fmt::print("failed to match dst {}\n", dst->to_string(env));
lg::error("failed to match dst {}", dst->to_string(env));
return nullptr;
}
if (mr.maps.regs.at(0)->reg() != Register(Reg::GPR, Reg::S6)) {
fmt::print("failed to match pp reg, got {}\n", mr.maps.regs.at(0)->reg().to_string());
lg::error("failed to match pp reg, got {}", mr.maps.regs.at(0)->reg().to_string());
return nullptr;
}
@@ -3236,11 +3237,11 @@ void FunctionCallElement::update_from_stack(const Env& env,
}
if (should_use_virtual) {
// fmt::print("STACK\n{}\n\n", stack.print(env));
// lg::print("STACK\n{}\n\n", stack.print(env));
auto pop = pop_to_forms({*arg0_mr.maps.regs.at(0)}, env, pool, stack, allow_side_effects,
{}, {2})
.at(0);
// fmt::print("GOT: {}\n", pop->to_string(env));
// lg::print("GOT: {}\n", pop->to_string(env));
arg_forms.at(0) = pop;
auto head = mr.maps.forms.at(1);
@@ -3855,7 +3856,7 @@ Form* try_rewrite_as_process_to_ppointer(CondNoElseElement* value,
return nullptr;
}
// fmt::print("Matched condition {} in {}\n", condition_var.to_string(env),
// lg::print("Matched condition {} in {}\n", condition_var.to_string(env),
// value->to_string(env));
auto* menv = const_cast<Env*>(&env);
@@ -3909,7 +3910,7 @@ Form* try_rewrite_as_pppointer_to_process(CondNoElseElement* value,
return nullptr;
}
// fmt::print("Matched condition {} in {}\n", condition_var.to_string(env),
// lg::print("Matched condition {} in {}\n", condition_var.to_string(env),
// value->to_string(env));
auto* menv = const_cast<Env*>(&env);
@@ -4045,7 +4046,7 @@ void CondNoElseElement::push_to_stack(const Env& env, FormPool& pool, FormStack&
stack.push_value_to_reg(write_as_value, as_ja_group, true,
env.get_variable_type(final_destination, false));
} else {
// fmt::print("func {} final destination {} type {}\n", env.func->name(),
// lg::print("func {} final destination {} type {}\n", env.func->name(),
// final_destination.to_string(env),
// env.get_variable_type(final_destination, false).print());
stack.push_value_to_reg(write_as_value, pool.alloc_single_form(nullptr, this), true,
@@ -4213,24 +4214,24 @@ void CondWithElseElement::push_to_stack(const Env& env, FormPool& pool, FormStac
// (set! x (if y z (expr))) and z requires a cast, but the move from z to x is
// eliminated by GOAL's register allocator.
// fmt::print("func: {}\n", env.func->name());
// lg::print("func: {}\n", env.func->name());
//
// fmt::print("checking:\n");
// lg::print("checking:\n");
// for (auto& t : source_types) {
// fmt::print(" {}\n", t.print());
// lg::print(" {}\n", t.print());
// }
auto expected_type = env.get_variable_type(*last_var, true);
// fmt::print("The expected type is {}\n", expected_type.print());
// lg::print("The expected type is {}\n", expected_type.print());
auto result_type =
source_types.empty() ? expected_type : env.dts->ts.lowest_common_ancestor(source_types);
// fmt::print("but we actually got {}\n", result_type.print());
// lg::print("but we actually got {}\n", result_type.print());
Form* result_value = pool.alloc_single_form(nullptr, this);
if (!env.dts->ts.tc(expected_type, result_type)) {
result_value = pool.form<CastElement>(expected_type, result_value);
}
// fmt::print("{}\n", result_value->to_string(env));
// lg::print("{}\n", result_value->to_string(env));
stack.push_value_to_reg(*last_var, result_value, true,
env.get_variable_type(*last_var, false));
@@ -5323,7 +5324,7 @@ void AsmBranchElement::push_to_stack(const Env& env, FormPool& pool, FormStack&
auto op = pool.alloc_element<TranslatedAsmBranch>(
branch_condition, m_branch_delay, m_branch_op->label_id(), m_branch_op->is_likely());
// fmt::print("rewrote as {}\n", op->to_string(env));
// lg::print("rewrote as {}\n", op->to_string(env));
stack.push_form_element(op, true);
}
@@ -5381,7 +5382,7 @@ void BranchElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta
ASSERT(!m_op->likely());
auto op = pool.alloc_element<TranslatedAsmBranch>(branch_condition, branch_delay,
m_op->label_id(), m_op->likely());
// fmt::print("rewrote (non-asm) as {}\n", op->to_string(env));
// lg::print("rewrote (non-asm) as {}\n", op->to_string(env));
stack.push_form_element(op, true);
}
@@ -5502,7 +5503,7 @@ void ArrayFieldAccess::update_with_val(Form* new_val,
if (!match_result.matched) {
result->push_back(this);
return;
fmt::print("power {}\n", power_of_two);
lg::error("power {}", power_of_two);
throw std::runtime_error(
"Couldn't match ArrayFieldAccess (stride power of 2, 0 offset) values: " +
new_val->to_string(env));