mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 14:13:45 -04:00
im bored.
This commit is contained in:
+11
-12
@@ -248,7 +248,7 @@ Arguments Interpreter::get_args(const Object& form, const Object& rest, const Ar
|
||||
// loop over forms in list
|
||||
Object current = rest;
|
||||
while (!current.is_empty_list()) {
|
||||
auto arg = current.as_pair()->car;
|
||||
const auto& arg = current.as_pair()->car;
|
||||
|
||||
// did we get a ":keyword"
|
||||
if (arg.is_symbol() && arg.as_symbol()->name.at(0) == ':') {
|
||||
@@ -344,7 +344,7 @@ ArgumentSpec Interpreter::parse_arg_spec(const Object& form, Object& rest) {
|
||||
|
||||
Object current = rest;
|
||||
while (!current.is_empty_list()) {
|
||||
auto arg = current.as_pair()->car;
|
||||
const auto& arg = current.as_pair()->car;
|
||||
if (!arg.is_symbol()) {
|
||||
throw_eval_error(form, "args must be symbols");
|
||||
}
|
||||
@@ -355,7 +355,7 @@ ArgumentSpec Interpreter::parse_arg_spec(const Object& form, Object& rest) {
|
||||
if (!current.is_pair()) {
|
||||
throw_eval_error(form, "rest arg must have a name");
|
||||
}
|
||||
auto rest_name = current.as_pair()->car;
|
||||
const auto& rest_name = current.as_pair()->car;
|
||||
if (!rest_name.is_symbol()) {
|
||||
throw_eval_error(form, "rest name must be a symbol");
|
||||
}
|
||||
@@ -368,23 +368,22 @@ ArgumentSpec Interpreter::parse_arg_spec(const Object& form, Object& rest) {
|
||||
} else if (arg.as_symbol()->name == "&key") {
|
||||
// special case for &key
|
||||
current = current.as_pair()->cdr;
|
||||
auto key_arg = current.as_pair()->car;
|
||||
const auto& key_arg = current.as_pair()->car;
|
||||
if (key_arg.is_symbol()) {
|
||||
// form is &key name
|
||||
auto key_arg_name = key_arg.as_symbol()->name;
|
||||
const auto& key_arg_name = key_arg.as_symbol()->name;
|
||||
if (spec.named.find(key_arg_name) != spec.named.end()) {
|
||||
throw_eval_error(form, "key argument " + key_arg_name + " multiply defined");
|
||||
}
|
||||
spec.named[key_arg_name] = NamedArg();
|
||||
} else if (key_arg.is_pair()) {
|
||||
// form is &key (name default-value)
|
||||
auto key_iter = key_arg;
|
||||
auto kn = key_iter.as_pair()->car;
|
||||
key_iter = key_iter.as_pair()->cdr;
|
||||
const auto& kn = key_arg.as_pair()->car;
|
||||
const auto& key_iter = key_arg.as_pair()->cdr;
|
||||
if (!kn.is_symbol()) {
|
||||
throw_eval_error(form, "key argument must have a symbol as a name");
|
||||
}
|
||||
auto key_arg_name = kn.as_symbol()->name;
|
||||
const auto& key_arg_name = kn.as_symbol()->name;
|
||||
if (spec.named.find(key_arg_name) != spec.named.end()) {
|
||||
throw_eval_error(form, "key argument " + key_arg_name + " multiply defined");
|
||||
}
|
||||
@@ -667,7 +666,7 @@ Object Interpreter::eval_set(const Object& form,
|
||||
const std::shared_ptr<EnvironmentObject>& env) {
|
||||
auto args = get_args(form, rest, make_varargs());
|
||||
vararg_check(form, args, {ObjectType::SYMBOL, {}}, {});
|
||||
auto to_define = args.unnamed.at(0);
|
||||
const auto& to_define = args.unnamed.at(0);
|
||||
Object to_set = eval_with_rewind(args.unnamed.at(1), env);
|
||||
|
||||
std::shared_ptr<EnvironmentObject> search_env = env;
|
||||
@@ -1555,8 +1554,8 @@ Object Interpreter::eval_format(const Object& form,
|
||||
throw_eval_error(form, "format must get at least two arguments");
|
||||
}
|
||||
|
||||
auto dest = args.unnamed.at(0);
|
||||
auto format_str = args.unnamed.at(1);
|
||||
const auto& dest = args.unnamed.at(0);
|
||||
const auto& format_str = args.unnamed.at(1);
|
||||
if (!format_str.is_string()) {
|
||||
throw_eval_error(form, "format string must be a string");
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ bool get_va(const goos::Object& rest, std::string* err_string, goos::Arguments*
|
||||
// loop over forms in list
|
||||
goos::Object current = rest;
|
||||
while (!current.is_empty_list()) {
|
||||
auto arg = current.as_pair()->car;
|
||||
const auto& arg = current.as_pair()->car;
|
||||
|
||||
// did we get a ":keyword"
|
||||
if (arg.is_symbol() && arg.as_symbol()->name.at(0) == ':') {
|
||||
|
||||
@@ -64,7 +64,7 @@ goos::Object build_list(const std::vector<goos::Object>& objects) {
|
||||
// build a list out of an array of forms
|
||||
goos::Object build_list(const goos::Object* objects, int count) {
|
||||
ASSERT(count);
|
||||
auto car = objects[0];
|
||||
auto& car = objects[0];
|
||||
goos::Object cdr;
|
||||
if (count - 1) {
|
||||
cdr = build_list(objects + 1, count - 1);
|
||||
|
||||
@@ -577,7 +577,7 @@ Object Reader::read_list(TextStream& ts, bool expect_close_paren) {
|
||||
if (objects.size() < 2) {
|
||||
throw_reader_error(ts, "A list with a dot must have at least one thing before the dot", -1);
|
||||
}
|
||||
auto back = objects.back();
|
||||
auto& back = objects.back();
|
||||
objects.pop_back();
|
||||
auto rv = build_list(objects);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
/*!
|
||||
* Convert from a pixel location in a texture (x, y, texture buffer width) to VRAM address (byte).
|
||||
* Uses the PSMCT32 format.
|
||||
@@ -218,4 +220,4 @@ inline u32 rgba16_to_rgba32(u32 in) {
|
||||
// texture format enums
|
||||
enum class PSM { PSMCT16 = 0x02, PSMT8 = 0x13, PSMT4 = 0x14 };
|
||||
// clut format enums
|
||||
enum class CPSM { PSMCT32 = 0x0, PSMCT16 = 0x02 };
|
||||
enum class CPSM { PSMCT32 = 0x0, PSMCT16 = 0x02 };
|
||||
|
||||
@@ -133,7 +133,7 @@ void try_reverse_lookup_array_like(const FieldReverseLookupInput& input,
|
||||
bool is_integer = ts.tc(TypeSpec("integer"), input.base_type.get_single_arg());
|
||||
bool is_basic = ts.tc(TypeSpec("basic"), input.base_type.get_single_arg());
|
||||
ASSERT(di.mem_deref); // it's accessing a pointer.
|
||||
auto elt_type = di.result_type;
|
||||
const auto& elt_type = di.result_type;
|
||||
|
||||
if (input.stride) {
|
||||
// variable access to the array.
|
||||
|
||||
@@ -37,8 +37,8 @@ std::string deftype_parent_list(const goos::Object& list) {
|
||||
throw std::runtime_error("invalid parent list in deftype: " + list.print());
|
||||
}
|
||||
|
||||
auto parent = list.as_pair()->car;
|
||||
auto rest = list.as_pair()->cdr;
|
||||
const auto& parent = list.as_pair()->car;
|
||||
const auto& rest = list.as_pair()->cdr;
|
||||
if (!rest.is_empty_list()) {
|
||||
throw std::runtime_error("invalid parent list in deftype - can only have one parent");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
struct DgoDescription {
|
||||
std::string dgo_name;
|
||||
|
||||
@@ -1491,15 +1491,15 @@ void AsmBranchOp::update_register_info() {
|
||||
if (m_branch_delay) {
|
||||
m_branch_delay->update_register_info();
|
||||
|
||||
for (auto x : m_branch_delay->read_regs()) {
|
||||
for (auto& x : m_branch_delay->read_regs()) {
|
||||
m_read_regs.push_back(x);
|
||||
}
|
||||
|
||||
for (auto x : m_branch_delay->write_regs()) {
|
||||
for (auto& x : m_branch_delay->write_regs()) {
|
||||
m_write_regs.push_back(x);
|
||||
}
|
||||
|
||||
for (auto x : m_branch_delay->clobber_regs()) {
|
||||
for (auto& x : m_branch_delay->clobber_regs()) {
|
||||
m_clobber_regs.push_back(x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ FormElement* SetVarOp::get_as_form(FormPool& pool, const Env& env) const {
|
||||
}
|
||||
} else {
|
||||
// access a field
|
||||
auto arg0_type = env.get_types_before_op(m_my_idx).get(m_src.get_arg(0).var().reg());
|
||||
auto& arg0_type = env.get_types_before_op(m_my_idx).get(m_src.get_arg(0).var().reg());
|
||||
if (arg0_type.kind == TP_Type::Kind::TYPESPEC) {
|
||||
FieldReverseLookupInput rd_in;
|
||||
rd_in.deref = std::nullopt;
|
||||
@@ -451,7 +451,7 @@ FormElement* StoreOp::get_as_form(FormPool& pool, const Env& env) const {
|
||||
}
|
||||
|
||||
if (m_value.is_var()) {
|
||||
auto input_var_type = env.get_types_before_op(m_my_idx).get(m_value.var().reg());
|
||||
auto& input_var_type = env.get_types_before_op(m_my_idx).get(m_value.var().reg());
|
||||
if (env.dts->ts.tc(TypeSpec("uinteger"), input_var_type.typespec())) {
|
||||
cast_type.insert(cast_type.begin(), 'u');
|
||||
}
|
||||
@@ -481,10 +481,10 @@ FormElement* make_label_load(int label_idx,
|
||||
FormPool& pool,
|
||||
int load_size,
|
||||
LoadVarOp::Kind load_kind) {
|
||||
auto label = env.file->labels.at(label_idx);
|
||||
auto label_name = label.name;
|
||||
const auto& label = env.file->labels.at(label_idx);
|
||||
const auto& label_name = label.name;
|
||||
// auto hint = env.label_types().find(label_name);
|
||||
auto hint = env.file->label_db->lookup(label_idx);
|
||||
auto& hint = env.file->label_db->lookup(label_idx);
|
||||
|
||||
if (!hint.known) {
|
||||
throw std::runtime_error(fmt::format("Label {} was unknown in AtomicOpForm.", hint.name));
|
||||
@@ -498,7 +498,7 @@ FormElement* make_label_load(int label_idx,
|
||||
if ((load_kind == LoadVarOp::Kind::FLOAT || load_kind == LoadVarOp::Kind::SIGNED) &&
|
||||
load_size == 4 && hint.result_type == TypeSpec("float")) {
|
||||
ASSERT((label.offset % 4) == 0);
|
||||
auto word = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4);
|
||||
const auto& word = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4);
|
||||
ASSERT(word.kind() == LinkedWord::PLAIN_DATA);
|
||||
float value;
|
||||
memcpy(&value, &word.data, 4);
|
||||
@@ -506,8 +506,8 @@ FormElement* make_label_load(int label_idx,
|
||||
} else if (hint.result_type == TypeSpec("uint64") && load_kind != LoadVarOp::Kind::FLOAT &&
|
||||
load_size == 8) {
|
||||
ASSERT((label.offset % 8) == 0);
|
||||
auto word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4);
|
||||
auto word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4));
|
||||
const auto& word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4);
|
||||
const auto& word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4));
|
||||
ASSERT(word0.kind() == LinkedWord::PLAIN_DATA);
|
||||
ASSERT(word1.kind() == LinkedWord::PLAIN_DATA);
|
||||
u64 value;
|
||||
|
||||
@@ -119,7 +119,7 @@ TP_Type SimpleAtom::get_type(const TypeState& input,
|
||||
if (hint.result_type.base_type() == "string") {
|
||||
// we special case strings because the type pass will constant propagate them as needed to
|
||||
// figure out the argument count for calls for format.
|
||||
auto label = env.file->labels.at(m_int);
|
||||
const auto& label = env.file->labels.at(m_int);
|
||||
return TP_Type::make_from_string(env.file->get_goal_string_by_label(label));
|
||||
}
|
||||
if (hint.is_value) {
|
||||
@@ -715,8 +715,8 @@ TypeState IR2_BranchDelay::propagate_types(const TypeState& input,
|
||||
// at the input value. If it's a uint/int based type, we just return uint/int (not the type)
|
||||
// this will kill any weird stuff like product, etc.
|
||||
// if it's not an integer type, it's currently an error.
|
||||
auto dst = m_var[0]->reg();
|
||||
auto src = m_var[1]->reg();
|
||||
const auto& dst = m_var[0]->reg();
|
||||
const auto& src = m_var[1]->reg();
|
||||
if (tc(dts, TypeSpec("uint"), output.get(src))) {
|
||||
output.get(dst) = TP_Type::make_from_ts("uint");
|
||||
} else if (tc(dts, TypeSpec("int"), output.get(src))) {
|
||||
@@ -764,7 +764,7 @@ TypeState AtomicOp::propagate_types(const TypeState& input,
|
||||
// do op-specific type propagation
|
||||
TypeState result = propagate_types_internal(input, env, dts);
|
||||
// clobber
|
||||
for (auto reg : m_clobber_regs) {
|
||||
for (const auto& reg : m_clobber_regs) {
|
||||
result.get(reg) = TP_Type::make_uninitialized();
|
||||
}
|
||||
return result;
|
||||
@@ -913,7 +913,7 @@ TP_Type LoadVarOp::get_src_type(const TypeState& input,
|
||||
}
|
||||
|
||||
// todo labeldb
|
||||
auto label_name = env.file->labels.at(src.label()).name;
|
||||
const auto& label_name = env.file->labels.at(src.label()).name;
|
||||
const auto& hint = env.file->label_db->lookup(label_name);
|
||||
if (!hint.known) {
|
||||
throw std::runtime_error(
|
||||
@@ -1198,7 +1198,7 @@ TypeState CallOp::propagate_types_internal(const TypeState& input,
|
||||
Reg::T0, Reg::T1, Reg::T2, Reg::T3};
|
||||
TypeState end_types = input;
|
||||
|
||||
auto in_tp = input.get(Register(Reg::GPR, Reg::T9));
|
||||
auto& in_tp = input.get(Register(Reg::GPR, Reg::T9));
|
||||
if (in_tp.kind == TP_Type::Kind::OBJECT_NEW_METHOD &&
|
||||
!dts.type_prop_settings.current_method_type.empty()) {
|
||||
// calling object new method. Set the result to a new object of our type
|
||||
@@ -1248,8 +1248,8 @@ TypeState CallOp::propagate_types_internal(const TypeState& input,
|
||||
|
||||
if (in_tp.kind == TP_Type::Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION ||
|
||||
in_tp.kind == TP_Type::Kind::SET_TO_RUN_FUNCTION) {
|
||||
auto func_to_run_type = input.get(Register(Reg::GPR, arg_regs[1]));
|
||||
auto func_to_run_ts = func_to_run_type.typespec();
|
||||
auto& func_to_run_type = input.get(Register(Reg::GPR, arg_regs[1]));
|
||||
const auto& func_to_run_ts = func_to_run_type.typespec();
|
||||
if (func_to_run_ts.base_type() != "function" || func_to_run_ts.arg_count() == 0 ||
|
||||
func_to_run_ts.arg_count() > 7) {
|
||||
throw std::runtime_error(
|
||||
@@ -1280,7 +1280,7 @@ TypeState CallOp::propagate_types_internal(const TypeState& input,
|
||||
if (in_type.arg_count() == 2 && in_type.get_arg(0) == TypeSpec("_varargs_")) {
|
||||
// we're calling a varags function, which is format. We can determine the argument count
|
||||
// by looking at the format string, if we can get it.
|
||||
auto arg_type = input.get(Register(Reg::GPR, Reg::A1));
|
||||
auto& arg_type = input.get(Register(Reg::GPR, Reg::A1));
|
||||
auto can_determine_argc = arg_type.can_be_format_string();
|
||||
auto dynamic_string = false;
|
||||
if (!can_determine_argc && arg_type.typespec() == TypeSpec("string")) {
|
||||
@@ -1396,7 +1396,7 @@ TypeState AsmBranchOp::propagate_types_internal(const TypeState& input,
|
||||
}
|
||||
// for now, just make everything uint
|
||||
TypeState output = input;
|
||||
for (auto x : m_write_regs) {
|
||||
for (const auto& x : m_write_regs) {
|
||||
if (x.allowed_local_gpr()) {
|
||||
output.get(x) = TP_Type::make_from_ts("uint");
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ std::string Env::print_local_var_types(const Form* top_level_form) const {
|
||||
ASSERT(has_local_vars());
|
||||
auto var_info = extract_visible_variables(top_level_form);
|
||||
std::vector<std::string> entries;
|
||||
for (auto x : var_info) {
|
||||
for (const auto& x : var_info) {
|
||||
entries.push_back(fmt::format("{}: {}", x.name(), x.type.typespec().print()));
|
||||
}
|
||||
|
||||
|
||||
@@ -286,9 +286,9 @@ FormElement* last_two_in_and_to_handle_get_proc(Form* first,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto in1 = *first_result.maps.regs.at(reg_input_1);
|
||||
auto in2 = *second_result.maps.regs.at(reg_input_2);
|
||||
auto in3 = *second_result.maps.regs.at(reg_input_3);
|
||||
const auto& in1 = *first_result.maps.regs.at(reg_input_1);
|
||||
const auto& in2 = *second_result.maps.regs.at(reg_input_2);
|
||||
const auto& in3 = *second_result.maps.regs.at(reg_input_3);
|
||||
|
||||
auto in_name = in1.to_string(env);
|
||||
if (in_name != in2.to_string(env)) {
|
||||
@@ -352,4 +352,4 @@ FormElement* last_two_in_and_to_handle_get_proc(Form* first,
|
||||
repopped);
|
||||
}
|
||||
}
|
||||
} // namespace decompiler
|
||||
} // namespace decompiler
|
||||
|
||||
+16
-16
@@ -529,11 +529,11 @@ void AtomicOpElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
}
|
||||
|
||||
void AtomicOpElement::get_modified_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
@@ -573,11 +573,11 @@ void AsmBranchElement::collect_vars(RegAccessSet& vars, bool recursive) const {
|
||||
|
||||
void AsmBranchElement::get_modified_regs(RegSet& regs) const {
|
||||
m_branch_delay->get_modified_regs(regs);
|
||||
for (auto r : m_branch_op->write_regs()) {
|
||||
for (auto& r : m_branch_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_branch_op->clobber_regs()) {
|
||||
for (auto& r : m_branch_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
@@ -708,11 +708,11 @@ void AsmOpElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
}
|
||||
|
||||
void AsmOpElement::get_modified_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
@@ -738,19 +738,19 @@ void OpenGoalAsmOpElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
}
|
||||
|
||||
void OpenGoalAsmOpElement::collect_vf_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->read_regs()) {
|
||||
for (auto& r : m_op->read_regs()) {
|
||||
if (r.is_vu_float()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
if (r.is_vu_float()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
if (r.is_vu_float()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
@@ -758,11 +758,11 @@ void OpenGoalAsmOpElement::collect_vf_regs(RegSet& regs) const {
|
||||
}
|
||||
|
||||
void OpenGoalAsmOpElement::get_modified_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
@@ -813,7 +813,7 @@ void ConditionElement::invert() {
|
||||
}
|
||||
|
||||
void ConditionElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
for (auto src : m_src) {
|
||||
for (auto& src : m_src) {
|
||||
if (src.has_value() && src->is_var()) {
|
||||
vars.insert(src->var());
|
||||
}
|
||||
@@ -845,11 +845,11 @@ void FunctionCallElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
}
|
||||
|
||||
void FunctionCallElement::get_modified_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
@@ -875,11 +875,11 @@ void BranchElement::collect_vars(RegAccessSet& vars, bool) const {
|
||||
}
|
||||
|
||||
void BranchElement::get_modified_regs(RegSet& regs) const {
|
||||
for (auto r : m_op->write_regs()) {
|
||||
for (auto& r : m_op->write_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
|
||||
for (auto r : m_op->clobber_regs()) {
|
||||
for (auto& r : m_op->clobber_regs()) {
|
||||
regs.insert(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ void SimpleExpressionElement::update_from_stack_identity(const Env& env,
|
||||
result->push_back(x);
|
||||
}
|
||||
} else if (arg.is_static_addr()) {
|
||||
auto& lab = env.file->labels.at(arg.label());
|
||||
const auto& lab = env.file->labels.at(arg.label());
|
||||
if (env.file->is_string(lab.target_segment, lab.offset)) {
|
||||
auto str = env.file->get_goal_string(lab.target_segment, lab.offset / 4 - 1, false);
|
||||
result->push_back(pool.alloc_element<StringConstantElement>(str));
|
||||
|
||||
@@ -118,7 +118,7 @@ Form* FormStack::pop_reg(const RegisterAccess& var,
|
||||
|
||||
namespace {
|
||||
bool nonempty_intersection(const RegSet& a, const RegSet& b) {
|
||||
for (auto x : a) {
|
||||
for (auto& x : a) {
|
||||
if (b.find(x) != b.end()) {
|
||||
return true;
|
||||
}
|
||||
@@ -233,7 +233,7 @@ bool is_op_in_place(SetVarElement* elt,
|
||||
auto matcher = Matcher::op(GenericOpMatcher::fixed(op), {Matcher::any_reg(0), Matcher::any(1)});
|
||||
auto result = match(matcher, elt->src());
|
||||
if (result.matched) {
|
||||
auto first = result.maps.regs.at(0);
|
||||
const auto& first = result.maps.regs.at(0);
|
||||
ASSERT(first.has_value());
|
||||
|
||||
if (first->reg() != elt->dst().reg()) {
|
||||
|
||||
@@ -198,7 +198,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_var()) {
|
||||
got = true;
|
||||
result = atom.var();
|
||||
@@ -230,7 +230,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_label()) {
|
||||
got = true;
|
||||
result = atom.label();
|
||||
@@ -341,7 +341,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_int()) {
|
||||
if (!m_int_match.has_value()) {
|
||||
return true;
|
||||
@@ -366,7 +366,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_int()) {
|
||||
if (m_int_out_id != -1) {
|
||||
maps_out->ints[m_int_out_id] = atom.get_int();
|
||||
@@ -391,7 +391,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_ptr()) {
|
||||
if (m_string_out_id != -1) {
|
||||
maps_out->strings[m_string_out_id] = atom.get_str();
|
||||
@@ -415,7 +415,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_val()) {
|
||||
if (m_string_out_id != -1) {
|
||||
maps_out->strings[m_string_out_id] = atom.get_str();
|
||||
@@ -436,7 +436,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_val()) {
|
||||
return atom.get_str() == m_str;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ std::vector<goos::Object> OpenGOALAsm::get_args(const std::vector<DecompilerLabe
|
||||
|
||||
bool got_fsf = false;
|
||||
for (int i = 0; i < m_instr.n_src; i++) {
|
||||
auto v = m_src.at(i);
|
||||
const auto& v = m_src.at(i);
|
||||
InstructionAtom atom = m_instr.get_src(i);
|
||||
|
||||
if (v.has_value()) {
|
||||
|
||||
@@ -79,9 +79,8 @@ std::string ObjectFileData::to_unique_name() const {
|
||||
std::string result = record.name + "-";
|
||||
auto dgo_names_sorted = dgo_names;
|
||||
std::sort(dgo_names_sorted.begin(), dgo_names_sorted.end());
|
||||
for (auto x : dgo_names_sorted) {
|
||||
x = strip_dgo_extension(x);
|
||||
result += x + "-";
|
||||
for (const auto& x : dgo_names_sorted) {
|
||||
result += strip_dgo_extension(x) + "-";
|
||||
}
|
||||
result.pop_back();
|
||||
return result;
|
||||
|
||||
@@ -446,9 +446,9 @@ void ObjectFileDB::ir2_register_usage_pass(int seg, ObjectFileData& data) {
|
||||
if (!func.suspected_asm && func.ir2.atomic_ops_succeeded) {
|
||||
func.ir2.env.set_reg_use(analyze_ir2_register_usage(func));
|
||||
|
||||
auto block_0_start = func.ir2.env.reg_use().block.at(0).input;
|
||||
const auto& block_0_start = func.ir2.env.reg_use().block.at(0).input;
|
||||
std::vector<Register> dep_regs;
|
||||
for (auto x : block_0_start) {
|
||||
for (const auto& x : block_0_start) {
|
||||
dep_regs.push_back(x);
|
||||
}
|
||||
|
||||
@@ -873,7 +873,7 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function&
|
||||
// print linked strings
|
||||
for (int iidx = 0; iidx < instr.n_src; iidx++) {
|
||||
if (instr.get_src(iidx).is_label()) {
|
||||
auto lab = data.linked_data.labels.at(instr.get_src(iidx).get_label());
|
||||
const auto& lab = data.linked_data.labels.at(instr.get_src(iidx).get_label());
|
||||
if (data.linked_data.is_string(lab.target_segment, lab.offset)) {
|
||||
append_commented(
|
||||
line, printed_comment,
|
||||
@@ -997,7 +997,7 @@ std::string ObjectFileDB::ir2_final_out(ObjectFileData& data,
|
||||
result += ";;-*-Lisp-*-\n";
|
||||
result += "(in-package goal)\n\n";
|
||||
ASSERT(data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).size() == 1);
|
||||
auto top_level = data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).at(0);
|
||||
const auto& top_level = data.linked_data.functions_by_seg.at(TOP_LEVEL_SEGMENT).at(0);
|
||||
result += write_from_top_level(top_level, dts, data.linked_data, skip_functions);
|
||||
result += "\n\n";
|
||||
return result;
|
||||
|
||||
@@ -245,9 +245,9 @@ bool delay_slot_sets_false(BranchElement* branch, SetVarOp& delay) {
|
||||
|
||||
if (branch->op()->condition().kind() == IR2_Condition::Kind::FALSE) {
|
||||
if (delay.src().is_identity() && delay.src().get_arg(0).is_var()) {
|
||||
auto src_var = delay.src().get_arg(0).var();
|
||||
auto& src_var = delay.src().get_arg(0).var();
|
||||
auto& cond = branch->op()->condition();
|
||||
auto cond_reg = cond.src(0).var().reg();
|
||||
auto& cond_reg = cond.src(0).var().reg();
|
||||
return cond_reg == src_var.reg();
|
||||
}
|
||||
}
|
||||
@@ -286,9 +286,9 @@ bool delay_slot_sets_truthy(BranchElement* branch, SetVarOp& delay) {
|
||||
|
||||
if (branch->op()->condition().kind() == IR2_Condition::Kind::TRUTHY) {
|
||||
if (delay.src().is_identity() && delay.src().get_arg(0).is_var()) {
|
||||
auto src_var = delay.src().get_arg(0).var();
|
||||
auto& src_var = delay.src().get_arg(0).var();
|
||||
auto& cond = branch->op()->condition();
|
||||
auto cond_reg = cond.src(0).var().reg();
|
||||
auto& cond_reg = cond.src(0).var().reg();
|
||||
return cond_reg == src_var.reg();
|
||||
}
|
||||
}
|
||||
@@ -351,7 +351,7 @@ bool try_clean_up_sc_as_and(FormPool& pool, Function& func, ShortCircuitElement*
|
||||
|
||||
auto branch_id = branch.first->op()->op_id();
|
||||
auto& branch_info = func.ir2.env.reg_use().op.at(branch_id);
|
||||
for (auto x : delay_info.consumes) {
|
||||
for (const auto& x : delay_info.consumes) {
|
||||
branch_info.consumes.insert(x);
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement*
|
||||
// cheat for the old method
|
||||
auto branch_id = branch.first->op()->op_id();
|
||||
auto& branch_info = func.ir2.env.reg_use().op.at(branch_id);
|
||||
for (auto x : delay_info.consumes) {
|
||||
for (const auto& x : delay_info.consumes) {
|
||||
branch_info.consumes.insert(x);
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ void convert_cond_no_else_to_compare(FormPool& pool,
|
||||
ASSERT(condition.first);
|
||||
auto body = dynamic_cast<SetVarElement*>(cne->entries.front().body->try_as_single_element());
|
||||
ASSERT(body);
|
||||
auto dst = body->dst();
|
||||
auto& dst = body->dst();
|
||||
auto src_atom = get_atom_src(body->src());
|
||||
ASSERT(src_atom);
|
||||
ASSERT(src_atom->is_sym_val());
|
||||
@@ -829,7 +829,7 @@ bool is_op_3(FormElement* ir,
|
||||
}
|
||||
|
||||
// destination should be a register
|
||||
auto dest = set->dst();
|
||||
auto& dest = set->dst();
|
||||
if (dst != dest.reg()) {
|
||||
return false;
|
||||
}
|
||||
@@ -843,8 +843,8 @@ bool is_op_3(FormElement* ir,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto arg0 = math->expr().get_arg(0);
|
||||
auto arg1 = math->expr().get_arg(1);
|
||||
auto& arg0 = math->expr().get_arg(0);
|
||||
auto& arg1 = math->expr().get_arg(1);
|
||||
|
||||
if (!arg0.is_var() || src0 != arg0.var().reg() || !arg1.is_var() || src1 != arg1.var().reg()) {
|
||||
return false;
|
||||
@@ -880,12 +880,12 @@ bool is_op_3(AtomicOp* op,
|
||||
}
|
||||
|
||||
// destination should be a register
|
||||
auto dest = set->dst();
|
||||
auto& dest = set->dst();
|
||||
if (dst != dest.reg()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto math = set->src();
|
||||
auto& math = set->src();
|
||||
if (kind != math.kind()) {
|
||||
return false;
|
||||
}
|
||||
@@ -894,8 +894,8 @@ bool is_op_3(AtomicOp* op,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto arg0 = math.get_arg(0);
|
||||
auto arg1 = math.get_arg(1);
|
||||
auto& arg0 = math.get_arg(0);
|
||||
auto& arg1 = math.get_arg(1);
|
||||
|
||||
if (!arg0.is_var() || src0 != arg0.var().reg() || !arg1.is_var() || src1 != arg1.var().reg()) {
|
||||
return false;
|
||||
@@ -929,17 +929,17 @@ bool is_op_2(AtomicOp* op,
|
||||
}
|
||||
|
||||
// destination should be a register
|
||||
auto dest = set->dst();
|
||||
auto& dest = set->dst();
|
||||
if (dst != dest.reg()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto math = set->src();
|
||||
auto& math = set->src();
|
||||
if (kind != math.kind()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto arg = math.get_arg(0);
|
||||
auto& arg = math.get_arg(0);
|
||||
|
||||
if (!arg.is_var() || src0 != arg.var().reg()) {
|
||||
return false;
|
||||
@@ -970,7 +970,7 @@ bool is_op_2(FormElement* ir,
|
||||
}
|
||||
|
||||
// destination should be a register
|
||||
auto dest = set->dst();
|
||||
auto& dest = set->dst();
|
||||
if (dst != dest.reg()) {
|
||||
return false;
|
||||
}
|
||||
@@ -980,7 +980,7 @@ bool is_op_2(FormElement* ir,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto arg = math->expr().get_arg(0);
|
||||
auto& arg = math->expr().get_arg(0);
|
||||
|
||||
if (!arg.is_var() || src0 != arg.var().reg()) {
|
||||
return false;
|
||||
@@ -1038,8 +1038,8 @@ Form* try_sc_as_abs(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto input = branch->op()->condition().src(0);
|
||||
auto output = delay->dst();
|
||||
auto& input = branch->op()->condition().src(0);
|
||||
auto& output = delay->dst();
|
||||
|
||||
ASSERT(input.is_var());
|
||||
ASSERT(input.var().reg() == delay->src().get_arg(0).var().reg());
|
||||
@@ -1112,11 +1112,11 @@ Form* try_sc_as_ash(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
dsrav a0, a0, a1 ; a0 is both input and output here
|
||||
*/
|
||||
|
||||
auto sa_in = branch->op()->condition().src(0);
|
||||
auto& sa_in = branch->op()->condition().src(0);
|
||||
ASSERT(sa_in.is_var());
|
||||
auto result = delay->dst();
|
||||
auto value_in = delay->src().get_arg(0).var();
|
||||
auto sa_in2 = delay->src().get_arg(1).var();
|
||||
auto& result = delay->dst();
|
||||
auto& value_in = delay->src().get_arg(0).var();
|
||||
auto& sa_in2 = delay->src().get_arg(1).var();
|
||||
ASSERT(sa_in.var().reg() == sa_in2.reg());
|
||||
|
||||
auto dsubu_candidate = b1_ptr->at(0);
|
||||
@@ -1146,7 +1146,7 @@ Form* try_sc_as_ash(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
|
||||
RegisterAccess dest_ir = result;
|
||||
SimpleAtom shift_ir = branch->op()->condition().src(0);
|
||||
auto value_ir =
|
||||
auto& value_ir =
|
||||
dynamic_cast<const SimpleExpressionElement*>(dsrav_set->src()->try_as_single_element())
|
||||
->expr()
|
||||
.get_arg(0);
|
||||
@@ -1177,7 +1177,7 @@ Form* try_sc_as_ash(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
|
||||
// fix up the other ones:
|
||||
f.ir2.env.disable_use(branch->op()->condition().src(0).var()); // bgezl X, L
|
||||
auto dsubu_var = dynamic_cast<SimpleExpressionElement*>(dsubu_set->src()->try_as_single_element())
|
||||
auto& dsubu_var = dynamic_cast<SimpleExpressionElement*>(dsubu_set->src()->try_as_single_element())
|
||||
->expr()
|
||||
.get_arg(0)
|
||||
.var();
|
||||
@@ -1258,14 +1258,14 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto temp_reg0 = set_shift->dst();
|
||||
auto& temp_reg0 = set_shift->dst();
|
||||
|
||||
auto shift = dynamic_cast<SimpleExpressionElement*>(set_shift->src()->try_as_single_element());
|
||||
if (!shift || shift->expr().kind() != SimpleExpression::Kind::LEFT_SHIFT) {
|
||||
return nullptr;
|
||||
}
|
||||
auto src_reg = shift->expr().get_arg(0).var();
|
||||
auto sa = shift->expr().get_arg(1);
|
||||
auto& src_reg = shift->expr().get_arg(0).var();
|
||||
auto& sa = shift->expr().get_arg(1);
|
||||
if (!sa.is_int() || sa.get_int() != 61) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1280,9 +1280,9 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
!first_branch->op()->likely()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto temp_reg = first_branch->op()->condition().src(0).var();
|
||||
auto& temp_reg = first_branch->op()->condition().src(0).var();
|
||||
ASSERT(temp_reg.reg() == temp_reg0.reg());
|
||||
auto dst_reg = b0_delay_op.dst();
|
||||
auto& dst_reg = b0_delay_op.dst();
|
||||
|
||||
auto b1_delay_op = get_delay_op(f, b1_d);
|
||||
if (!second_branch || !is_set_symbol_value(b1_delay_op, "pair") ||
|
||||
@@ -1292,12 +1292,12 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
}
|
||||
|
||||
// check we agree on destination register.
|
||||
auto dst_reg2 = b1_delay_op.dst();
|
||||
auto& dst_reg2 = b1_delay_op.dst();
|
||||
ASSERT(dst_reg2.reg() == dst_reg.reg());
|
||||
|
||||
// else case is a lwu to grab the type from a basic
|
||||
ASSERT(else_case);
|
||||
auto dst_reg3 = else_case->dst();
|
||||
auto& dst_reg3 = else_case->dst();
|
||||
ASSERT(dst_reg3.reg() == dst_reg.reg());
|
||||
auto load_op = dynamic_cast<LoadSourceElement*>(else_case->src()->try_as_single_element());
|
||||
if (!load_op || load_op->kind() != LoadVarOp::Kind::UNSIGNED || load_op->size() != 4) {
|
||||
@@ -1308,8 +1308,8 @@ Form* try_sc_as_type_of(FormPool& pool, Function& f, const ShortCircuit* vtx) {
|
||||
if (!load_loc || load_loc->expr().kind() != SimpleExpression::Kind::ADD) {
|
||||
return nullptr;
|
||||
}
|
||||
auto src_reg3 = load_loc->expr().get_arg(0);
|
||||
auto offset = load_loc->expr().get_arg(1);
|
||||
auto& src_reg3 = load_loc->expr().get_arg(0);
|
||||
auto& offset = load_loc->expr().get_arg(1);
|
||||
if (!src_reg3.is_var() || !offset.is_int()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ bool convert_to_expressions(
|
||||
f.guessed_name.kind == FunctionName::FunctionKind::V_STATE) {
|
||||
f.ir2.env.set_remap_for_function(f.type);
|
||||
} else if (f.guessed_name.kind == FunctionName::FunctionKind::METHOD) {
|
||||
auto method_type =
|
||||
const auto& method_type =
|
||||
dts.ts.lookup_method(f.guessed_name.type_name, f.guessed_name.method_id).type;
|
||||
if (f.guessed_name.method_id == GOAL_NEW_METHOD) {
|
||||
f.ir2.env.set_remap_for_new_method(method_type);
|
||||
|
||||
@@ -132,7 +132,7 @@ FormElement* rewrite_as_dotimes(LetElement* in, const Env& env, FormPool& pool)
|
||||
}
|
||||
|
||||
// check the lt operation:
|
||||
auto lt_var = mr.maps.regs.at(0);
|
||||
const auto& lt_var = mr.maps.regs.at(0);
|
||||
ASSERT(lt_var);
|
||||
if (env.get_variable_name(*lt_var) != var) {
|
||||
return nullptr; // wrong variable checked
|
||||
@@ -154,7 +154,7 @@ FormElement* rewrite_as_dotimes(LetElement* in, const Env& env, FormPool& pool)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto inc_var = int_mr.maps.regs.at(0);
|
||||
const auto& inc_var = int_mr.maps.regs.at(0);
|
||||
ASSERT(inc_var);
|
||||
if (env.get_variable_name(*inc_var) != var) {
|
||||
return nullptr; // wrong variable incremented
|
||||
@@ -216,7 +216,7 @@ FormElement* rewrite_as_send_event(LetElement* in, const Env& env, FormPool& poo
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto from_var = *from_mr.maps.regs.at(1);
|
||||
const auto& from_var = *from_mr.maps.regs.at(1);
|
||||
if (from_var.reg() != Register(Reg::GPR, Reg::S6)) {
|
||||
// fmt::print(" fail: from3\n");
|
||||
return nullptr;
|
||||
@@ -359,7 +359,7 @@ FormElement* rewrite_as_countdown(LetElement* in, const Env& env, FormPool& pool
|
||||
}
|
||||
|
||||
// check the zero operation:
|
||||
auto lt_var = mr.maps.regs.at(0);
|
||||
const auto& lt_var = mr.maps.regs.at(0);
|
||||
ASSERT(lt_var);
|
||||
if (env.get_variable_name(*lt_var) != idx_var) {
|
||||
return nullptr; // wrong variable checked
|
||||
@@ -381,7 +381,7 @@ FormElement* rewrite_as_countdown(LetElement* in, const Env& env, FormPool& pool
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto inc_var = int_mr.maps.regs.at(0);
|
||||
const auto& inc_var = int_mr.maps.regs.at(0);
|
||||
ASSERT(inc_var);
|
||||
if (env.get_variable_name(*inc_var) != idx_var) {
|
||||
return nullptr; // wrong variable incremented
|
||||
@@ -502,7 +502,7 @@ FormElement* rewrite_empty_let(LetElement* in, const Env&, FormPool&) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto reg = in->entries().at(0).dest.reg();
|
||||
const auto& reg = in->entries().at(0).dest.reg();
|
||||
if (reg.get_kind() == Reg::GPR && !reg.allowed_local_gpr()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -870,7 +870,7 @@ FormElement* rewrite_multi_let_as_vector_dot(LetElement* in, const Env& env, For
|
||||
if (!mr.matched) {
|
||||
return nullptr;
|
||||
}
|
||||
auto this_var = mr.maps.regs.at(0);
|
||||
const auto& this_var = mr.maps.regs.at(0);
|
||||
ASSERT(this_var.has_value());
|
||||
if (in_vars[in_var].has_value()) {
|
||||
// seen it before
|
||||
@@ -1089,7 +1089,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l
|
||||
|
||||
RegAccessSet ras;
|
||||
first_form_as_set->src()->collect_vars(ras, true);
|
||||
for (auto ra : ras) {
|
||||
for (const auto& ra : ras) {
|
||||
if (ra.reg() == first_form_as_set->dst().reg()) {
|
||||
if (env.get_variable_name(ra) == env.get_variable_name(first_form_as_set->dst())) {
|
||||
allowed = false;
|
||||
@@ -1243,7 +1243,7 @@ LetStats insert_lets(const Function& func, Env& env, FormPool& pool, Form* top_l
|
||||
RegAccessSet used;
|
||||
e.src->collect_vars(used, true);
|
||||
std::unordered_set<std::string> used_by_name;
|
||||
for (auto used_var : used) {
|
||||
for (const auto& used_var : used) {
|
||||
used_by_name.insert(env.get_variable_name(used_var));
|
||||
}
|
||||
for (auto& old_entry : as_let->entries()) {
|
||||
|
||||
@@ -18,8 +18,8 @@ void phase1(const FunctionAtomicOps& ops, int block_id, RegUsageInfo* out) {
|
||||
|
||||
for (int i = end_op; i-- > start_op;) {
|
||||
const auto& instr = ops.ops.at(i);
|
||||
auto read = instr->read_regs();
|
||||
auto write = instr->write_regs();
|
||||
auto& read = instr->read_regs();
|
||||
auto& write = instr->write_regs();
|
||||
|
||||
auto& lv = out->op.at(i).live;
|
||||
auto& dd = out->op.at(i).dead;
|
||||
@@ -77,13 +77,13 @@ bool phase2(const std::vector<BasicBlock>& blocks, int block_id, RegUsageInfo* i
|
||||
if (s == -1) {
|
||||
continue;
|
||||
}
|
||||
for (auto in : info->block.at(s).input) {
|
||||
for (const auto& in : info->block.at(s).input) {
|
||||
out.insert(in);
|
||||
}
|
||||
}
|
||||
|
||||
RegSet in = block_info.use;
|
||||
for (auto x : out) {
|
||||
for (const auto& x : out) {
|
||||
if (!in_set(block_info.defs, x)) {
|
||||
in.insert(x);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ void phase3(const FunctionAtomicOps& ops,
|
||||
if (s == -1) {
|
||||
continue;
|
||||
}
|
||||
for (auto i : info->block.at(s).input) {
|
||||
for (const auto& i : info->block.at(s).input) {
|
||||
live_local.insert(i);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void phase3(const FunctionAtomicOps& ops,
|
||||
auto& dd = info->op.at(i).dead;
|
||||
|
||||
RegSet new_live = lv;
|
||||
for (auto x : live_local) {
|
||||
for (const auto& x : live_local) {
|
||||
if (!in_set(dd, x)) {
|
||||
new_live.insert(x);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ RegUsageInfo analyze_ir2_register_usage(const Function& function) {
|
||||
auto& first_op_live_out = result.op.at(0).live;
|
||||
RegSet first_op_live_in;
|
||||
first_op_live_in.insert(first_op_live_out.begin(), first_op_live_out.end());
|
||||
for (auto reg : ops->ops.at(0)->write_regs()) {
|
||||
for (auto& reg : ops->ops.at(0)->write_regs()) {
|
||||
first_op_live_in.erase(reg);
|
||||
}
|
||||
first_op_live_in.insert(ops->ops.at(0)->read_regs().begin(), ops->ops.at(0)->read_regs().end());
|
||||
@@ -195,13 +195,13 @@ RegUsageInfo analyze_ir2_register_usage(const Function& function) {
|
||||
auto& op_info = result.op.at(i);
|
||||
|
||||
// look at each register we read from:
|
||||
for (auto reg : op->read_regs()) {
|
||||
for (auto& reg : op->read_regs()) {
|
||||
if (op_info.live.find(reg) == op_info.live.end()) {
|
||||
// not live out, this means we must consume it.
|
||||
op_info.consumes.insert(reg);
|
||||
} else {
|
||||
// the register has a live value, but is it a new value?
|
||||
for (auto wr : op->write_regs()) {
|
||||
for (const auto& wr : op->write_regs()) {
|
||||
if (wr == reg) {
|
||||
op_info.consumes.insert(reg);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ RegUsageInfo analyze_ir2_register_usage(const Function& function) {
|
||||
}
|
||||
|
||||
// also useful to know, written and unused.
|
||||
for (auto reg : op->write_regs()) {
|
||||
for (auto& reg : op->write_regs()) {
|
||||
if (op_info.live.find(reg) == op_info.live.end()) {
|
||||
// fmt::print("op {} wau {}\n", op->to_string(function.ir2.env), reg.to_string());
|
||||
op_info.written_and_unused.insert(reg);
|
||||
@@ -222,4 +222,4 @@ RegUsageInfo analyze_ir2_register_usage(const Function& function) {
|
||||
ASSERT(result.op.size() == ops->ops.size());
|
||||
return result;
|
||||
}
|
||||
} // namespace decompiler
|
||||
} // namespace decompiler
|
||||
|
||||
@@ -22,7 +22,7 @@ bool try_convert_lambda(const Function& parent_function,
|
||||
bool defstate_behavior) {
|
||||
auto atom = form_as_atom(f);
|
||||
if (atom && atom->is_static_addr()) {
|
||||
auto lab = parent_function.ir2.env.file->labels.at(atom->label());
|
||||
const auto& lab = parent_function.ir2.env.file->labels.at(atom->label());
|
||||
auto& env = parent_function.ir2.env;
|
||||
const auto& info = parent_function.ir2.env.file->label_db->lookup(lab.name);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace decompiler {
|
||||
|
||||
@@ -955,7 +955,7 @@ void PrototypeBucketTie::read_from_file(TypedRef ref,
|
||||
auto data_array = get_field_ref(ref, "color-index-qwc", dts);
|
||||
for (u32 i = 0; i < num_color_qwcs; i++) {
|
||||
int byte_offset = data_array.byte_offset + i;
|
||||
auto word = data_array.data->words_by_seg.at(data_array.seg).at(byte_offset / 4);
|
||||
auto& word = data_array.data->words_by_seg.at(data_array.seg).at(byte_offset / 4);
|
||||
color_index_qwc.push_back(word.get_byte(byte_offset % 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ DecompilerTypeSystem::DecompilerTypeSystem() {
|
||||
namespace {
|
||||
// some utilities for parsing the type def file
|
||||
|
||||
goos::Object& car(goos::Object& pair) {
|
||||
goos::Object& car(const goos::Object& pair) {
|
||||
if (pair.is_pair()) {
|
||||
return pair.as_pair()->car;
|
||||
} else {
|
||||
@@ -22,7 +22,7 @@ goos::Object& car(goos::Object& pair) {
|
||||
}
|
||||
}
|
||||
|
||||
goos::Object& cdr(goos::Object& pair) {
|
||||
goos::Object& cdr(const goos::Object& pair) {
|
||||
if (pair.is_pair()) {
|
||||
return pair.as_pair()->cdr;
|
||||
} else {
|
||||
@@ -52,9 +52,9 @@ void DecompilerTypeSystem::parse_type_defs(const std::vector<std::string>& file_
|
||||
try {
|
||||
if (car(o).as_symbol()->name == "define-extern") {
|
||||
auto* rest = &cdr(o);
|
||||
auto sym_name = car(*rest);
|
||||
const auto& sym_name = car(*rest);
|
||||
rest = &cdr(*rest);
|
||||
auto sym_type = car(*rest);
|
||||
const auto& sym_type = car(*rest);
|
||||
if (!cdr(*rest).is_empty_list()) {
|
||||
throw std::runtime_error("malformed define-extern");
|
||||
}
|
||||
@@ -72,9 +72,9 @@ void DecompilerTypeSystem::parse_type_defs(const std::vector<std::string>& file_
|
||||
|
||||
} else if (car(o).as_symbol()->name == "declare-type") {
|
||||
auto* rest = &cdr(o);
|
||||
auto type_name = car(*rest);
|
||||
const auto& type_name = car(*rest);
|
||||
rest = &cdr(*rest);
|
||||
auto type_kind = car(*rest);
|
||||
const auto& type_kind = car(*rest);
|
||||
if (!cdr(*rest).is_empty_list()) {
|
||||
throw std::runtime_error("malformed declare-type");
|
||||
}
|
||||
@@ -95,7 +95,7 @@ void DecompilerTypeSystem::parse_type_defs(const std::vector<std::string>& file_
|
||||
|
||||
TypeSpec DecompilerTypeSystem::parse_type_spec(const std::string& str) const {
|
||||
auto read = m_reader.read_from_string(str);
|
||||
auto data = cdr(read);
|
||||
const auto& data = cdr(read);
|
||||
return parse_typespec(&ts, car(data));
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ goos::Object decomp_ref_to_integer_array_guess_size(
|
||||
// the input is the location of the data field.
|
||||
// we expect that to be a label:
|
||||
ASSERT((field_location % 4) == 0);
|
||||
auto pointer_to_data = words.at(field_location / 4);
|
||||
auto& pointer_to_data = words.at(field_location / 4);
|
||||
ASSERT(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
|
||||
// the data shouldn't have any labels in the middle of it, so we can find the end of the array
|
||||
@@ -426,7 +426,7 @@ goos::Object decomp_ref_to_inline_array_guess_size(
|
||||
// the input is the location of the data field.
|
||||
// we expect that to be a label:
|
||||
ASSERT((field_location % 4) == 0);
|
||||
auto pointer_to_data = words.at(field_location / 4);
|
||||
auto& pointer_to_data = words.at(field_location / 4);
|
||||
ASSERT(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
|
||||
// the data shouldn't have any labels in the middle of it, so we can find the end of the array
|
||||
@@ -1368,10 +1368,10 @@ goos::Object decompile_pair(const DecompilerLabel& label,
|
||||
|
||||
if ((to_print.offset % 8) == 2) {
|
||||
// continue
|
||||
auto car_word = words.at(to_print.target_segment).at((to_print.offset - 2) / 4);
|
||||
auto& car_word = words.at(to_print.target_segment).at((to_print.offset - 2) / 4);
|
||||
list_tokens.push_back(decompile_pair_elt(car_word, labels, words, ts, file));
|
||||
|
||||
auto cdr_word = words.at(to_print.target_segment).at((to_print.offset + 2) / 4);
|
||||
auto& cdr_word = words.at(to_print.target_segment).at((to_print.offset + 2) / 4);
|
||||
// if empty
|
||||
if (cdr_word.kind() == LinkedWord::EMPTY_PTR) {
|
||||
if (add_quote) {
|
||||
@@ -1388,8 +1388,7 @@ goos::Object decompile_pair(const DecompilerLabel& label,
|
||||
// invalid.
|
||||
lg::error(
|
||||
"There is an improper list. This is probably okay, but should be checked manually "
|
||||
"because we "
|
||||
"could not find a test case yet.");
|
||||
"because we could not find a test case yet.");
|
||||
list_tokens.push_back(pretty_print::to_symbol("."));
|
||||
list_tokens.push_back(decompile_pair_elt(cdr_word, labels, words, ts, file));
|
||||
if (add_quote) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
void kmemcard_init_globals();
|
||||
|
||||
constexpr s32 SAVE_SIZE = 691; // likely different by versions! 692 on PAL/JPN
|
||||
constexpr s32 SAVE_SIZE = 691; // likely different between versions! 692 on PAL/JPN
|
||||
constexpr s32 BANK_SIZE = 0x10000;
|
||||
|
||||
// each card can be in one of these states:
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "SystemThread.h"
|
||||
#include "common/log/log.h"
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ Compiler::Compiler(const std::string& user_profile, std::unique_ptr<ReplWrapper>
|
||||
ReplStatus Compiler::execute_repl(bool auto_listen, bool auto_debug) {
|
||||
// init repl
|
||||
m_repl->print_welcome_message();
|
||||
auto examples = m_repl->examples;
|
||||
auto regex_colors = m_repl->regex_colors;
|
||||
const auto& examples = m_repl->examples;
|
||||
const auto& regex_colors = m_repl->regex_colors;
|
||||
m_repl->init_default_settings();
|
||||
using namespace std::placeholders;
|
||||
m_repl->get_repl().set_completion_callback(
|
||||
|
||||
@@ -14,7 +14,7 @@ Register get_reg(const RegVal* rv, const AllocationResult& allocs, emitter::IR_R
|
||||
if (rv->ireg().id < int(range.size())) {
|
||||
auto& lr = range.at(rv->ireg().id);
|
||||
if (lr.has_info_at(irec.ir_id)) {
|
||||
auto ass_reg = range.at(rv->ireg().id).get(irec.ir_id);
|
||||
auto& ass_reg = range.at(rv->ireg().id).get(irec.ir_id);
|
||||
if (ass_reg.kind == Assignment::Kind::REGISTER) {
|
||||
ASSERT(ass_reg.reg == reg);
|
||||
} else {
|
||||
@@ -412,7 +412,7 @@ RegAllocInstr IR_FunctionCall::to_rai() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < emitter::RegisterInfo::N_REGS; i++) {
|
||||
auto info = emitter::gRegInfo.get_info(i);
|
||||
auto& info = emitter::gRegInfo.get_info(i);
|
||||
if (info.temp()) {
|
||||
rai.clobber.emplace_back(i);
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ goos::Object Compiler::unquote(const goos::Object& o) {
|
||||
*/
|
||||
bool Compiler::is_quoted_sym(const goos::Object& o) {
|
||||
if (o.is_pair()) {
|
||||
auto car = pair_car(o);
|
||||
auto cdr = pair_cdr(o);
|
||||
auto& car = pair_car(o);
|
||||
auto& cdr = pair_cdr(o);
|
||||
if (car.is_symbol() && car.as_symbol()->name == "quote") {
|
||||
if (cdr.is_pair()) {
|
||||
auto thing = pair_car(cdr);
|
||||
auto& thing = pair_car(cdr);
|
||||
if (thing.is_symbol()) {
|
||||
if (pair_cdr(cdr).is_empty_list()) {
|
||||
return true;
|
||||
|
||||
@@ -31,7 +31,7 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
|
||||
throw_compiler_error(form, "Must have an rlet body.");
|
||||
}
|
||||
|
||||
auto defs = args.unnamed.front();
|
||||
const auto& defs = args.unnamed.front();
|
||||
|
||||
auto fenv = env->function_env();
|
||||
auto lenv = fenv->alloc_env<LexicalEnv>(env);
|
||||
@@ -49,7 +49,7 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
|
||||
{"class", {false, goos::ObjectType::SYMBOL}}});
|
||||
|
||||
// get the name of the new place
|
||||
auto new_place_name = def_args.unnamed.at(0);
|
||||
const auto& new_place_name = def_args.unnamed.at(0);
|
||||
|
||||
// get the type of the new place
|
||||
TypeSpec ts = m_ts.make_typespec("object");
|
||||
@@ -126,7 +126,7 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
|
||||
lenv->emit_ir<IR_ValueReset>(form, reset_regs);
|
||||
}
|
||||
|
||||
for (auto c : constraints) {
|
||||
for (const auto& c : constraints) {
|
||||
fenv->constrain(c);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ Val* Compiler::compile_asm_load_sym(const goos::Object& form, const goos::Object
|
||||
if (sym_kv == m_symbol_types.end()) {
|
||||
throw_compiler_error(form, "Cannot find a symbol named {}.", sym_name);
|
||||
}
|
||||
auto ts = sym_kv->second;
|
||||
const auto& ts = sym_kv->second;
|
||||
bool sext = m_ts.lookup_type(ts)->get_load_signed();
|
||||
if (args.has_named("sext")) {
|
||||
sext = get_true_or_false(form, args.named.at("sext"));
|
||||
|
||||
@@ -297,8 +297,8 @@ Val* Compiler::compile(const goos::Object& code, Env* env) {
|
||||
*/
|
||||
Val* Compiler::compile_pair(const goos::Object& code, Env* env) {
|
||||
auto pair = code.as_pair();
|
||||
auto head = pair->car;
|
||||
auto rest = pair->cdr;
|
||||
const auto& head = pair->car;
|
||||
const auto& rest = pair->cdr;
|
||||
|
||||
if (head.is_symbol()) {
|
||||
auto head_sym = head.as_symbol();
|
||||
@@ -379,7 +379,7 @@ Val* Compiler::compile_get_symbol_value(const goos::Object& form,
|
||||
form, "The symbol {} was looked up as a global variable, but it does not exist.", name);
|
||||
}
|
||||
|
||||
auto ts = existing_symbol->second;
|
||||
const auto& ts = existing_symbol->second;
|
||||
auto sext = m_ts.lookup_type(ts)->get_load_signed();
|
||||
auto fe = env->function_env();
|
||||
auto sym = fe->alloc_val<SymbolVal>(name, m_ts.make_typespec("symbol"));
|
||||
|
||||
@@ -40,7 +40,7 @@ Val* Compiler::compile_begin(const goos::Object& form, const goos::Object& rest,
|
||||
*/
|
||||
Val* Compiler::compile_block(const goos::Object& form, const goos::Object& _rest, Env* env) {
|
||||
auto rest = &_rest;
|
||||
auto name = pair_car(*rest);
|
||||
auto& name = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
|
||||
if (!rest->is_pair()) {
|
||||
@@ -112,7 +112,7 @@ Val* Compiler::compile_return_from(const goos::Object& form, const goos::Object&
|
||||
const Object* rest = &_rest;
|
||||
auto block_name = symbol_string(pair_car(*rest));
|
||||
rest = &pair_cdr(*rest);
|
||||
auto value_expression = pair_car(*rest);
|
||||
auto& value_expression = pair_car(*rest);
|
||||
expect_empty_list(pair_cdr(*rest));
|
||||
|
||||
// evaluate expression to return
|
||||
@@ -193,4 +193,4 @@ Val* Compiler::compile_nop(const goos::Object& form, const goos::Object& rest, E
|
||||
va_check(form, args, {}, {});
|
||||
env->emit_ir<IR_Nop>(form);
|
||||
return get_none();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,13 +374,13 @@ Val* Compiler::compile_build_dgo(const goos::Object& form, const goos::Object& r
|
||||
(void)env;
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {goos::ObjectType::STRING}, {});
|
||||
auto dgo_desc = pair_cdr(m_goos.reader.read_from_file({args.unnamed.at(0).as_string()->data}));
|
||||
auto& dgo_desc = pair_cdr(m_goos.reader.read_from_file({args.unnamed.at(0).as_string()->data}));
|
||||
|
||||
for_each_in_list(dgo_desc, [&](const goos::Object& dgo) {
|
||||
DgoDescription desc;
|
||||
auto first = pair_car(dgo);
|
||||
auto& first = pair_car(dgo);
|
||||
desc.dgo_name = as_string(first);
|
||||
auto dgo_rest = pair_cdr(dgo);
|
||||
auto& dgo_rest = pair_cdr(dgo);
|
||||
|
||||
for_each_in_list(dgo_rest, [&](const goos::Object& entry) {
|
||||
auto e_arg = get_va(dgo, entry);
|
||||
|
||||
@@ -210,8 +210,8 @@ Compiler::ConstPropResult Compiler::constant_propagation_dispatch(const goos::Ob
|
||||
|
||||
case goos::ObjectType::PAIR: {
|
||||
auto pair = expanded.as_pair();
|
||||
auto head = pair->car;
|
||||
auto rest = pair->cdr;
|
||||
const auto& head = pair->car;
|
||||
const auto& rest = pair->cdr;
|
||||
|
||||
// in theory you could write code like:
|
||||
// ((#if PC_PORT foo bar) ...)
|
||||
@@ -247,7 +247,7 @@ Compiler::ConstPropResult Compiler::constant_propagation_dispatch(const goos::Ob
|
||||
s64 Compiler::get_constant_integer_or_error(const goos::Object& in, Env* env) {
|
||||
auto prop = try_constant_propagation(in, env);
|
||||
if (prop.value.is_pair()) {
|
||||
auto head = prop.value.as_pair()->car;
|
||||
const auto& head = prop.value.as_pair()->car;
|
||||
if (head.is_symbol()) {
|
||||
auto head_sym = head.as_symbol();
|
||||
auto enum_type = m_ts.try_enum_lookup(head_sym->name);
|
||||
@@ -279,7 +279,7 @@ ValOrConstInt Compiler::get_constant_integer_or_variable(const goos::Object& in,
|
||||
auto prop = try_constant_propagation(in, env);
|
||||
|
||||
if (prop.value.is_pair()) {
|
||||
auto head = prop.value.as_pair()->car;
|
||||
const auto& head = prop.value.as_pair()->car;
|
||||
if (head.is_symbol()) {
|
||||
auto head_sym = head.as_symbol();
|
||||
auto enum_type = m_ts.try_enum_lookup(head_sym->name);
|
||||
@@ -316,4 +316,4 @@ ValOrConstFloat Compiler::get_constant_float_or_variable(const goos::Object& in,
|
||||
return ValOrConstFloat(compile_no_const_prop(prop.value, env));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +41,15 @@ Condition Compiler::compile_condition(const goos::Object& condition, Env* env, b
|
||||
|
||||
// possibly a form with an optimizable condition?
|
||||
if (condition.is_pair()) {
|
||||
auto first = pair_car(condition);
|
||||
auto rest = pair_cdr(condition);
|
||||
auto& first = pair_car(condition);
|
||||
auto& rest = pair_cdr(condition);
|
||||
|
||||
if (first.is_symbol()) {
|
||||
auto fas = first.as_symbol();
|
||||
|
||||
// if there's a not, we can just try again to get an optimization with the invert flipped.
|
||||
if (fas->name == "not") {
|
||||
auto arg = pair_car(rest);
|
||||
auto& arg = pair_car(rest);
|
||||
if (!pair_cdr(rest).is_empty_list()) {
|
||||
throw_compiler_error(condition, "A condition with \"not\" can have only one argument");
|
||||
}
|
||||
@@ -153,7 +153,7 @@ Val* Compiler::compile_condition_as_bool(const goos::Object& form,
|
||||
Val* Compiler::compile_when_goto(const goos::Object& form, const goos::Object& _rest, Env* env) {
|
||||
(void)form;
|
||||
auto* rest = &_rest;
|
||||
auto condition_code = pair_car(*rest);
|
||||
auto& condition_code = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
|
||||
auto label = symbol_string(pair_car(*rest));
|
||||
@@ -186,8 +186,8 @@ Val* Compiler::compile_cond(const goos::Object& form, const goos::Object& rest,
|
||||
std::vector<TypeSpec> case_result_types;
|
||||
|
||||
for_each_in_list(rest, [&](const goos::Object& o) {
|
||||
auto test = pair_car(o);
|
||||
auto clauses = pair_cdr(o);
|
||||
auto& test = pair_car(o);
|
||||
auto& clauses = pair_cdr(o);
|
||||
|
||||
if (got_else) {
|
||||
throw_compiler_error(form, "Cond from cannot have any cases after else.");
|
||||
|
||||
@@ -9,8 +9,8 @@ u32 Compiler::parse_address_spec(const goos::Object& form) {
|
||||
}
|
||||
|
||||
if (form.is_pair()) {
|
||||
auto first = form.as_pair()->car;
|
||||
auto rest = form.as_pair()->cdr;
|
||||
const auto& first = form.as_pair()->car;
|
||||
const auto& rest = form.as_pair()->cdr;
|
||||
if (first.is_symbol() && symbol_string(first) == "sym") {
|
||||
if (rest.is_pair() && rest.as_pair()->car.is_symbol()) {
|
||||
u32 addr = m_debugger.get_symbol_address(symbol_string(rest.as_pair()->car));
|
||||
@@ -156,7 +156,7 @@ Val* Compiler::compile_dump_all(const goos::Object& form, const goos::Object& re
|
||||
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {{goos::ObjectType::STRING}}, {});
|
||||
auto dest_file = args.unnamed.at(0).as_string()->data;
|
||||
const auto& dest_file = args.unnamed.at(0).as_string()->data;
|
||||
auto buffer = new u8[EE_MAIN_MEM_SIZE];
|
||||
memset(buffer, 0, EE_MAIN_MEM_SIZE);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace {
|
||||
const goos::Object& get_lambda_body(const goos::Object& def) {
|
||||
auto* iter = &def;
|
||||
while (true) {
|
||||
auto car = iter->as_pair()->car;
|
||||
const auto& car = iter->as_pair()->car;
|
||||
if (car.is_symbol() && car.as_symbol()->name.at(0) == ':') {
|
||||
iter = &iter->as_pair()->cdr;
|
||||
iter = &iter->as_pair()->cdr;
|
||||
@@ -319,7 +319,7 @@ Val* Compiler::compile_function_or_method_call(const goos::Object& form, Env* en
|
||||
auto fe = env->function_env();
|
||||
|
||||
auto args = get_va(form, form);
|
||||
auto uneval_head = args.unnamed.at(0);
|
||||
const auto& uneval_head = args.unnamed.at(0);
|
||||
Val* head = get_none();
|
||||
|
||||
// determine if this call should be automatically inlined.
|
||||
@@ -451,7 +451,7 @@ Val* Compiler::compile_function_or_method_call(const goos::Object& form, Env* en
|
||||
for (uint32_t i = 0; i < eval_args.size(); i++) {
|
||||
// note, inlined functions will get a more specific type if possible
|
||||
// todo, is this right?
|
||||
auto type = eval_args.at(i)->type();
|
||||
const auto& type = eval_args.at(i)->type();
|
||||
auto copy = env->make_ireg(type, m_ts.lookup_type(type)->get_preferred_reg_class());
|
||||
env->emit_ir<IR_RegSet>(form, copy, eval_args.at(i));
|
||||
copy->mark_as_settable();
|
||||
@@ -618,7 +618,7 @@ Val* Compiler::compile_real_function_call(const goos::Object& form,
|
||||
std::vector<RegVal*> arg_outs;
|
||||
for (int i = 0; i < (int)args.size(); i++) {
|
||||
const auto& arg = args.at(i);
|
||||
auto reg = cc.arg_regs.at(i);
|
||||
const auto& reg = cc.arg_regs.at(i);
|
||||
arg_outs.push_back(
|
||||
env->make_ireg(arg->type(), reg.is_xmm() ? RegClass::INT_128 : RegClass::GPR_64));
|
||||
arg_outs.back()->mark_as_settable();
|
||||
@@ -657,7 +657,7 @@ Val* Compiler::compile_declare(const goos::Object& form, const goos::Object& res
|
||||
throw_compiler_error(o, "Invalid declare specification.");
|
||||
}
|
||||
|
||||
auto first = o.as_pair()->car;
|
||||
const auto& first = o.as_pair()->car;
|
||||
auto rrest = &o.as_pair()->cdr;
|
||||
|
||||
if (!first.is_symbol()) {
|
||||
@@ -719,7 +719,7 @@ Val* Compiler::compile_declare_file(const goos::Object& /*form*/,
|
||||
throw_compiler_error(o, "Invalid declare-file specification.");
|
||||
}
|
||||
|
||||
auto first = o.as_pair()->car;
|
||||
const auto& first = o.as_pair()->car;
|
||||
auto rrest = &o.as_pair()->cdr;
|
||||
|
||||
if (!first.is_symbol()) {
|
||||
@@ -740,4 +740,4 @@ Val* Compiler::compile_declare_file(const goos::Object& /*form*/,
|
||||
});
|
||||
|
||||
return get_none();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ Val* Compiler::compile_gscond(const goos::Object& form, const goos::Object& rest
|
||||
Val* Compiler::compile_quote(const goos::Object& form, const goos::Object& rest, Env* env) {
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {{}}, {});
|
||||
auto thing = args.unnamed.at(0);
|
||||
const auto& thing = args.unnamed.at(0);
|
||||
switch (thing.type) {
|
||||
case goos::ObjectType::SYMBOL:
|
||||
return compile_get_sym_obj(thing.as_symbol()->name, env);
|
||||
@@ -164,7 +164,7 @@ Val* Compiler::compile_define_constant(const goos::Object& form,
|
||||
|
||||
auto sym = pair_car(*rest).as_symbol();
|
||||
rest = &pair_cdr(*rest);
|
||||
auto value = pair_car(*rest);
|
||||
const auto& value = pair_car(*rest);
|
||||
|
||||
rest = &rest->as_pair()->cdr;
|
||||
if (!rest->is_empty_list()) {
|
||||
@@ -218,8 +218,8 @@ Val* Compiler::compile_defconstant(const goos::Object& form, const goos::Object&
|
||||
* Compile an "mlet" scoped constant/symbol macro form
|
||||
*/
|
||||
Val* Compiler::compile_mlet(const goos::Object& form, const goos::Object& rest, Env* env) {
|
||||
auto defs = pair_car(rest);
|
||||
auto body = pair_cdr(rest);
|
||||
const auto& defs = pair_car(rest);
|
||||
const auto& body = pair_cdr(rest);
|
||||
|
||||
auto fenv = env->function_env();
|
||||
auto menv = fenv->alloc_env<SymbolMacroEnv>(env);
|
||||
@@ -245,8 +245,8 @@ bool Compiler::expand_macro_once(const goos::Object& src, goos::Object* out, Env
|
||||
return false;
|
||||
}
|
||||
|
||||
auto first = src.as_pair()->car;
|
||||
auto rest = src.as_pair()->cdr;
|
||||
const auto& first = src.as_pair()->car;
|
||||
const auto& rest = src.as_pair()->cdr;
|
||||
if (!first.is_symbol()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ bool Compiler::is_singed_integer_or_binteger(const TypeSpec& ts) {
|
||||
|
||||
Val* Compiler::number_to_integer(const goos::Object& form, Val* in, Env* env) {
|
||||
(void)env;
|
||||
auto ts = in->type();
|
||||
const auto& ts = in->type();
|
||||
if (is_binteger(ts)) {
|
||||
throw_compiler_error(form, "Cannot convert {} (a binteger) to an integer yet.", in->print());
|
||||
} else if (is_float(ts)) {
|
||||
@@ -57,7 +57,7 @@ Val* Compiler::number_to_integer(const goos::Object& form, Val* in, Env* env) {
|
||||
|
||||
Val* Compiler::number_to_binteger(const goos::Object& form, Val* in, Env* env) {
|
||||
(void)env;
|
||||
auto ts = in->type();
|
||||
const auto& ts = in->type();
|
||||
if (is_binteger(ts)) {
|
||||
return in;
|
||||
} else if (is_float(ts)) {
|
||||
@@ -77,7 +77,7 @@ Val* Compiler::number_to_binteger(const goos::Object& form, Val* in, Env* env) {
|
||||
|
||||
Val* Compiler::number_to_float(const goos::Object& form, Val* in, Env* env) {
|
||||
(void)env;
|
||||
auto ts = in->type();
|
||||
const auto& ts = in->type();
|
||||
if (is_binteger(ts)) {
|
||||
throw_compiler_error(form, "Cannot convert {} (a binteger) to an float yet.", in->print());
|
||||
} else if (is_float(ts)) {
|
||||
@@ -114,7 +114,7 @@ Val* Compiler::compile_add(const goos::Object& form, const goos::Object& rest, E
|
||||
|
||||
// look at the first value to determine the math mode
|
||||
auto first_val = compile_error_guard(args.unnamed.at(0), env);
|
||||
auto first_type = first_val->type();
|
||||
const auto& first_type = first_val->type();
|
||||
auto math_type = get_math_mode(first_type);
|
||||
switch (math_type) {
|
||||
case MATH_INT:
|
||||
@@ -161,7 +161,7 @@ Val* Compiler::compile_mul(const goos::Object& form, const goos::Object& rest, E
|
||||
|
||||
// look at the first value to determine the math mode
|
||||
auto first_val = compile_error_guard(args.unnamed.at(0), env);
|
||||
auto first_type = first_val->type();
|
||||
const auto& first_type = first_val->type();
|
||||
auto math_type = get_math_mode(first_type);
|
||||
switch (math_type) {
|
||||
case MATH_INT: {
|
||||
@@ -277,7 +277,7 @@ Val* Compiler::compile_imul64(const goos::Object& form, const goos::Object& rest
|
||||
|
||||
// look at the first value to determine the math mode
|
||||
auto first_val = compile_error_guard(args.unnamed.at(0), env);
|
||||
auto first_type = first_val->type();
|
||||
const auto& first_type = first_val->type();
|
||||
auto math_type = get_math_mode(first_type);
|
||||
switch (math_type) {
|
||||
case MATH_INT: {
|
||||
@@ -311,7 +311,7 @@ Val* Compiler::compile_sub(const goos::Object& form, const goos::Object& rest, E
|
||||
}
|
||||
|
||||
auto first_val = compile_error_guard(args.unnamed.at(0), env);
|
||||
auto first_type = first_val->type();
|
||||
const auto& first_type = first_val->type();
|
||||
auto math_type = get_math_mode(first_type);
|
||||
switch (math_type) {
|
||||
case MATH_INT:
|
||||
@@ -434,7 +434,7 @@ Val* Compiler::compile_div(const goos::Object& form, const goos::Object& rest, E
|
||||
}
|
||||
|
||||
auto first_val = compile_error_guard(args.unnamed.at(0), env);
|
||||
auto first_type = first_val->type();
|
||||
const auto& first_type = first_val->type();
|
||||
auto math_type = get_math_mode(first_type);
|
||||
switch (math_type) {
|
||||
case MATH_INT: {
|
||||
|
||||
@@ -12,8 +12,9 @@ void Compiler::compile_state_handler_set(StructureType* state_type_info,
|
||||
Env* env,
|
||||
Val*& code_val,
|
||||
Val*& enter_val) {
|
||||
// do not set state handler field if handler is #f, that's already the value in the static data
|
||||
// but what if it's ACTUALLY setting it to #f??? see crate-buzzer wait
|
||||
// do not set state handler field if handler is *no-state*
|
||||
// we don't use #f here because you might want to actually set the state to #f
|
||||
// (see crate-buzzer wait)
|
||||
auto& arg = args.named.at(name);
|
||||
if (!(arg.is_symbol() && arg.as_symbol()->name == "*no-state*")) {
|
||||
auto field = get_field_of_structure(state_type_info, state_object, name, env);
|
||||
|
||||
@@ -32,8 +32,7 @@ void Compiler::compile_static_structure_inline(const goos::Object& form,
|
||||
auto field_name_def = symbol_string(pair_car(*field_defs));
|
||||
field_defs = &pair_cdr(*field_defs);
|
||||
|
||||
auto field_value = pair_car(*field_defs);
|
||||
field_value = expand_macro_completely(field_value, env);
|
||||
auto field_value = expand_macro_completely(pair_car(*field_defs), env);
|
||||
field_defs = &pair_cdr(*field_defs);
|
||||
|
||||
if (field_name_def.at(0) != ':') {
|
||||
@@ -331,7 +330,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form,
|
||||
auto field_name_def = symbol_string(pair_car(*field_defs));
|
||||
field_defs = &pair_cdr(*field_defs);
|
||||
|
||||
auto field_value = pair_car(*field_defs);
|
||||
const auto& field_value = pair_car(*field_defs);
|
||||
field_defs = &pair_cdr(*field_defs);
|
||||
|
||||
if (field_name_def.at(0) != ':') {
|
||||
@@ -353,7 +352,7 @@ Val* Compiler::compile_bitfield_definition(const goos::Object& form,
|
||||
if (!got_constant && is_bitfield(field_info.result_type) && !allow_dynamic_construction) {
|
||||
auto static_result = compile_static(field_value, env);
|
||||
if (static_result.is_constant_data()) {
|
||||
auto constant_data = static_result.constant();
|
||||
const auto& constant_data = static_result.constant();
|
||||
if (constant_data.size() == 8) {
|
||||
typecheck(field_value, field_info.result_type, static_result.typespec(),
|
||||
"Type of static constant");
|
||||
@@ -695,11 +694,11 @@ StaticResult Compiler::compile_static(const goos::Object& form_before_macro, Env
|
||||
fie->add_static(std::move(obj));
|
||||
return result;
|
||||
} else if (form.is_pair()) {
|
||||
auto first = form.as_pair()->car;
|
||||
auto rest = form.as_pair()->cdr;
|
||||
const auto& first = form.as_pair()->car;
|
||||
const auto& rest = form.as_pair()->cdr;
|
||||
if (first.is_symbol() && first.as_symbol()->name == "quote") {
|
||||
if (rest.is_pair()) {
|
||||
auto second = rest.as_pair()->car;
|
||||
const auto& second = rest.as_pair()->car;
|
||||
if (!rest.as_pair()->cdr.is_empty_list()) {
|
||||
throw_compiler_error(form, "The form {} is an invalid quoted form.", form.print());
|
||||
}
|
||||
@@ -784,7 +783,7 @@ StaticResult Compiler::compile_static(const goos::Object& form_before_macro, Env
|
||||
va_check(form, args, {goos::ObjectType::SYMBOL},
|
||||
{{{"method-count", {false, goos::ObjectType::INTEGER}}}});
|
||||
|
||||
auto type_name = args.unnamed.at(0).as_symbol()->name;
|
||||
const auto& type_name = args.unnamed.at(0).as_symbol()->name;
|
||||
|
||||
std::optional<int> expected_method_count = m_ts.try_get_type_method_count(type_name);
|
||||
int method_count = -1;
|
||||
|
||||
@@ -639,10 +639,8 @@ Val* Compiler::get_field_of_structure(const StructureType* type,
|
||||
result = fe->alloc_val<MemoryDerefVal>(di.result_type, loc, MemLoadInfo(di));
|
||||
result->mark_as_settable();
|
||||
} else {
|
||||
auto type_for_offset = field.type;
|
||||
if (field.type.base_type() == "inline-array") {
|
||||
type_for_offset = field.type.get_single_arg();
|
||||
}
|
||||
const auto& type_for_offset =
|
||||
field.type.base_type() == "inline-array" ? field.type.get_single_arg() : field.type;
|
||||
auto field_type_info = m_ts.lookup_type(type_for_offset);
|
||||
result = fe->alloc_val<MemoryOffsetConstantVal>(
|
||||
field.type, object, field.field.offset() + offset + field_type_info->get_offset());
|
||||
@@ -708,7 +706,7 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest
|
||||
|
||||
// compound, is field access/nested access
|
||||
while (!rest->is_empty_list()) {
|
||||
auto field_obj = pair_car(*rest);
|
||||
auto& field_obj = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
auto type_info = m_ts.lookup_type_allow_partial_def(result->type());
|
||||
|
||||
@@ -773,7 +771,6 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest
|
||||
result->type().print());
|
||||
}
|
||||
auto di = m_ts.get_deref_info(result->type());
|
||||
auto base_type = di.result_type;
|
||||
ASSERT(di.can_deref);
|
||||
if (has_constant_idx) {
|
||||
result = fe->alloc_val<MemoryOffsetConstantVal>(di.result_type, result,
|
||||
@@ -790,7 +787,6 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest
|
||||
result->type().print());
|
||||
}
|
||||
auto di = m_ts.get_deref_info(result->type());
|
||||
auto base_type = di.result_type;
|
||||
ASSERT(di.mem_deref);
|
||||
ASSERT(di.can_deref);
|
||||
Val* loc = nullptr;
|
||||
@@ -815,7 +811,7 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest
|
||||
// figure out how to access this...
|
||||
auto di = m_ts.get_deref_info(loc_type);
|
||||
// and the result
|
||||
auto base_type = di.result_type;
|
||||
const auto& base_type = di.result_type;
|
||||
ASSERT(base_type == result->type().get_single_arg());
|
||||
ASSERT(di.mem_deref);
|
||||
ASSERT(di.can_deref);
|
||||
@@ -972,7 +968,7 @@ Val* Compiler::compile_heap_new(const goos::Object& form,
|
||||
auto elt_type = quoted_sym_as_string(pair_car(*rest));
|
||||
rest = &pair_cdr(*rest);
|
||||
|
||||
auto count_obj = pair_car(*rest);
|
||||
auto& count_obj = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
// try to get the size as a compile time constant.
|
||||
auto cv = get_constant_integer_or_variable(count_obj, env);
|
||||
@@ -1104,7 +1100,7 @@ Val* Compiler::compile_stack_new(const goos::Object& form,
|
||||
auto elt_type = quoted_sym_as_string(pair_car(*rest));
|
||||
rest = &pair_cdr(*rest);
|
||||
|
||||
auto count_obj = pair_car(*rest);
|
||||
auto& count_obj = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
// try to get the size as a compile time constant.
|
||||
int64_t constant_count = get_constant_integer_or_error(count_obj, env);
|
||||
@@ -1201,7 +1197,7 @@ Val* Compiler::compile_new(const goos::Object& form, const goos::Object& _rest,
|
||||
auto allocation = quoted_sym_as_string(pair_car(_rest));
|
||||
auto rest = &pair_cdr(_rest);
|
||||
|
||||
auto type = pair_car(*rest);
|
||||
auto& type = pair_car(*rest);
|
||||
rest = &pair_cdr(*rest);
|
||||
|
||||
if (allocation == "global" || allocation == "debug" || allocation == "process" ||
|
||||
@@ -1255,7 +1251,7 @@ Val* Compiler::compile_method_of_type(const goos::Object& form,
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {{}, {goos::ObjectType::SYMBOL}}, {});
|
||||
|
||||
auto arg = args.unnamed.at(0);
|
||||
const auto& arg = args.unnamed.at(0);
|
||||
auto method_name = symbol_string(args.unnamed.at(1));
|
||||
|
||||
// in order to do proper method lookup, we peek at the symbol that the user provided and see if
|
||||
@@ -1289,7 +1285,7 @@ Val* Compiler::compile_method_of_object(const goos::Object& form,
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {{}, {goos::ObjectType::SYMBOL}}, {});
|
||||
|
||||
auto arg = args.unnamed.at(0);
|
||||
const auto& arg = args.unnamed.at(0);
|
||||
auto method_name = symbol_string(args.unnamed.at(1));
|
||||
|
||||
auto obj = compile_error_guard(arg, env)->to_gpr(form, env);
|
||||
@@ -1406,7 +1402,7 @@ int Compiler::get_size_for_size_of(const goos::Object& form, const goos::Object&
|
||||
auto args = get_va(form, rest);
|
||||
va_check(form, args, {goos::ObjectType::SYMBOL}, {});
|
||||
|
||||
auto type_to_look_for = args.unnamed.at(0).as_symbol()->name;
|
||||
const auto& type_to_look_for = args.unnamed.at(0).as_symbol()->name;
|
||||
|
||||
if (!m_ts.fully_defined_type_exists(type_to_look_for)) {
|
||||
throw_compiler_error(
|
||||
|
||||
@@ -263,7 +263,7 @@ bool can_var_be_assigned(int var,
|
||||
|
||||
// can clobber on the last one or first one - check that we don't interfere with a clobber
|
||||
for (int instr = lr.min + 1; instr <= lr.max - 1; instr++) {
|
||||
for (auto clobber : in.instructions.at(instr).clobber) {
|
||||
for (auto& clobber : in.instructions.at(instr).clobber) {
|
||||
if (ass.occupies_reg(clobber)) {
|
||||
if (debug_trace >= 1) {
|
||||
printf("at idx %d clobber\n", instr);
|
||||
@@ -275,7 +275,7 @@ bool can_var_be_assigned(int var,
|
||||
}
|
||||
|
||||
for (int instr = lr.min; instr <= lr.max; instr++) {
|
||||
for (auto exclusive : in.instructions.at(instr).exclude) {
|
||||
for (auto& exclusive : in.instructions.at(instr).exclude) {
|
||||
if (ass.occupies_reg(exclusive)) {
|
||||
if (debug_trace >= 1) {
|
||||
printf("at idx %d exclusive conflict\n", instr);
|
||||
@@ -352,7 +352,7 @@ bool assignment_ok_at(int var,
|
||||
|
||||
// check we aren't violating a clobber
|
||||
if (idx != lr.min && idx != lr.max) {
|
||||
for (auto clobber : in.instructions.at(idx).clobber) {
|
||||
for (auto& clobber : in.instructions.at(idx).clobber) {
|
||||
if (ass.occupies_reg(clobber)) {
|
||||
if (debug_trace >= 2) {
|
||||
printf("at idx %d clobber\n", idx);
|
||||
@@ -363,7 +363,7 @@ bool assignment_ok_at(int var,
|
||||
}
|
||||
}
|
||||
|
||||
for (auto exclusive : in.instructions.at(idx).exclude) {
|
||||
for (auto& exclusive : in.instructions.at(idx).exclude) {
|
||||
if (ass.occupies_reg(exclusive)) {
|
||||
if (debug_trace >= 2) {
|
||||
printf("at idx %d exclusive conflict\n", idx);
|
||||
@@ -548,9 +548,9 @@ bool try_spill_coloring(int var, RegAllocCache* cache, const AllocationInput& in
|
||||
|
||||
// hint didn't work
|
||||
// auto reg_order = get_default_reg_alloc_order();
|
||||
auto reg_order = get_default_alloc_order_for_var_spill(var, cache);
|
||||
auto& reg_order = get_default_alloc_order_for_var_spill(var, cache);
|
||||
if (spill_assignment.reg == -1) {
|
||||
for (auto reg : reg_order) {
|
||||
for (auto& reg : reg_order) {
|
||||
Assignment ass;
|
||||
ass.kind = Assignment::Kind::REGISTER;
|
||||
ass.reg = reg;
|
||||
@@ -625,7 +625,7 @@ bool do_allocation_for_var(int var,
|
||||
}
|
||||
}
|
||||
|
||||
auto reg_order = get_default_alloc_order_for_var(var, cache, false);
|
||||
auto& reg_order = get_default_alloc_order_for_var(var, cache, false);
|
||||
auto& all_reg_order = get_default_alloc_order_for_var(var, cache, true);
|
||||
|
||||
// todo, try other regs..
|
||||
@@ -650,7 +650,7 @@ bool do_allocation_for_var(int var,
|
||||
|
||||
// auto reg_order = get_default_reg_alloc_order();
|
||||
|
||||
for (auto reg : reg_order) {
|
||||
for (auto& reg : reg_order) {
|
||||
if (colored)
|
||||
break;
|
||||
Assignment ass;
|
||||
@@ -812,7 +812,7 @@ AllocationResult allocate_registers(const AllocationInput& input) {
|
||||
result.stack_slots_for_vars = input.stack_slots_for_stack_vars;
|
||||
|
||||
// check for use of saved registers
|
||||
for (auto sr : emitter::gRegInfo.get_all_saved()) {
|
||||
for (auto& sr : emitter::gRegInfo.get_all_saved()) {
|
||||
bool uses_sr = false;
|
||||
for (auto& lr : cache.live_ranges) {
|
||||
for (int instr_idx = lr.min; instr_idx <= lr.max; instr_idx++) {
|
||||
|
||||
@@ -390,7 +390,7 @@ std::vector<VarAssignment> initialize_unassigned(const std::vector<Range<s32>>&
|
||||
result.reserve(input.max_vars);
|
||||
ASSERT(input.max_vars == (int)live_ranges.size());
|
||||
int var_idx = 0;
|
||||
for (auto lr : live_ranges) {
|
||||
for (auto& lr : live_ranges) {
|
||||
result.emplace_back(lr.first(), lr.last(), var_idx++);
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ loop_top:
|
||||
}
|
||||
}
|
||||
|
||||
for (auto reg : order) {
|
||||
for (auto& reg : order) {
|
||||
if (check_register_assign_at(input, *cache, var_idx, instr_idx, reg)) {
|
||||
var.set_stack_slot_reg(reg, instr_idx);
|
||||
bonus.reg = reg;
|
||||
@@ -1165,7 +1165,7 @@ AllocationResult allocate_registers_v2(const AllocationInput& input) {
|
||||
result.stack_slots_for_vars = input.stack_slots_for_stack_vars;
|
||||
|
||||
// check for use of saved registers
|
||||
for (auto sr : emitter::gRegInfo.get_all_saved()) {
|
||||
for (auto& sr : emitter::gRegInfo.get_all_saved()) {
|
||||
bool uses_sr = false;
|
||||
for (auto& lr : cache.vars) {
|
||||
for (int instr_idx = lr.first_live(); instr_idx <= lr.last_live(); instr_idx++) {
|
||||
@@ -1209,4 +1209,4 @@ AllocationResult allocate_registers_v2(const AllocationInput& input) {
|
||||
result.num_spills = cache.stats.num_spill_ops;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,11 +293,11 @@ void FormRegressionTest::test_final_function(
|
||||
settings.do_expressions = true;
|
||||
auto test = make_function(code, ts, settings);
|
||||
ASSERT_TRUE(test);
|
||||
auto expected_form =
|
||||
auto& expected_form =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(expected, false).as_pair()->car;
|
||||
ASSERT_TRUE(test->func.ir2.top_form);
|
||||
auto final = final_defun_out(test->func, test->func.ir2.env, *dts);
|
||||
auto actual_form =
|
||||
auto& actual_form =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(final, false).as_pair()->car;
|
||||
if (expected_form != actual_form) {
|
||||
printf("Got:\n%s\n\nExpected\n%s\n", pretty_print::to_string(actual_form).c_str(),
|
||||
|
||||
@@ -21,9 +21,9 @@ class DataDecompTest : public ::testing::Test {
|
||||
static void TearDownTestCase() { dts.reset(); }
|
||||
|
||||
void check_forms_equal(const std::string& actual, const std::string& expected) {
|
||||
auto expected_form =
|
||||
auto& expected_form =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(expected, false).as_pair()->car;
|
||||
auto actual_form =
|
||||
auto& actual_form =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(actual, false).as_pair()->car;
|
||||
if (expected_form != actual_form) {
|
||||
printf("Got:\n%s\n\nExpected\n%s\n", pretty_print::to_string(actual_form).c_str(),
|
||||
@@ -405,4 +405,4 @@ TEST_F(DataDecompTest, ReverseArtExt) {
|
||||
input.offset = 108;
|
||||
result = dts->ts.reverse_field_multi_lookup(input);
|
||||
EXPECT_EQ(result.results.at(0).tokens.at(2).print(), "type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,14 +348,14 @@ TEST_F(WithGameTests, DebuggerMemoryMap) {
|
||||
// we should have gkernel main segment
|
||||
listener::MemoryMapEntry gk_main;
|
||||
EXPECT_TRUE(mem_map.lookup("gkernel", MAIN_SEGMENT, &gk_main));
|
||||
auto lookup_2 = mem_map.lookup(gk_main.start_addr + 12);
|
||||
auto& lookup_2 = mem_map.lookup(gk_main.start_addr + 12);
|
||||
EXPECT_TRUE(lookup_2.obj_name == "gkernel");
|
||||
EXPECT_FALSE(lookup_2.empty);
|
||||
EXPECT_EQ(lookup_2.seg_id, MAIN_SEGMENT);
|
||||
}
|
||||
|
||||
TEST_F(WithGameTests, DebuggerDisassemble) {
|
||||
auto di = shared_compiler->compiler.get_debugger().get_debug_info_for_object("gcommon");
|
||||
auto& di = shared_compiler->compiler.get_debugger().get_debug_info_for_object("gcommon");
|
||||
bool fail = false;
|
||||
auto result = di.disassemble_all_functions(&fail, &shared_compiler->compiler.get_goos().reader);
|
||||
// printf("Got\n%s\n", result.c_str());
|
||||
|
||||
+23
-23
@@ -9,7 +9,7 @@ using namespace goos;
|
||||
|
||||
namespace {
|
||||
Object read(const std::string& str) {
|
||||
auto body = pretty_print::get_pretty_printer_reader().read_from_string(str).as_pair()->cdr;
|
||||
auto& body = pretty_print::get_pretty_printer_reader().read_from_string(str).as_pair()->cdr;
|
||||
EXPECT_TRUE(body.as_pair()->cdr.is_empty_list());
|
||||
return body.as_pair()->car;
|
||||
}
|
||||
@@ -38,11 +38,11 @@ TEST(PrettyPrinter, ReadAgain) {
|
||||
{"goal_src", "kernel", "gcommon.gc"});
|
||||
// pretty print it
|
||||
auto printed_gcommon = pretty_print::to_string(gcommon_code);
|
||||
auto gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto& gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto printed_gcommon2 = pretty_print::to_string_v1(gcommon_code);
|
||||
EXPECT_TRUE(gcommon_code == gcommon_code2);
|
||||
}
|
||||
@@ -54,11 +54,11 @@ TEST(PrettyPrinter, ReadAgainVeryShortLines) {
|
||||
// pretty print it but with a very short line length. This looks terrible but will hopefully
|
||||
// hit many of the cases for line breaking.
|
||||
auto printed_gcommon = pretty_print::to_string(gcommon_code, 80);
|
||||
auto gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto& gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto printed_gcommon2 = pretty_print::to_string_v1(gcommon_code);
|
||||
EXPECT_TRUE(gcommon_code == gcommon_code2);
|
||||
}
|
||||
@@ -71,11 +71,11 @@ TEST(PrettyPrinter, DefunNoArgs) {
|
||||
" (the-as symbol #f)\n"
|
||||
" )";
|
||||
|
||||
auto obj = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(code)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto& obj = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(code)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto printed = pretty_print::to_string_v1(obj, 80);
|
||||
|
||||
EXPECT_EQ(printed,
|
||||
@@ -93,17 +93,17 @@ TEST(PrettyPrinter2, Debugging) {
|
||||
{"goal_src", "kernel", "gcommon.gc"});
|
||||
// pretty print it
|
||||
auto printed_gcommon = pretty_print::to_string(gcommon_code);
|
||||
auto gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto& gcommon_code2 = pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(printed_gcommon)
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
EXPECT_TRUE(gcommon_code == gcommon_code2);
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string pretty_print_v2(const std::string& str, int line_length = 110) {
|
||||
auto obj =
|
||||
auto& obj =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(str).as_pair()->cdr.as_pair()->car;
|
||||
return pretty_print::to_string(obj, line_length);
|
||||
}
|
||||
@@ -316,4 +316,4 @@ TEST(PrettyPrint2, AnotherBug) {
|
||||
" (t9-2 vector-xz-normalize!)\n"
|
||||
" )\n"
|
||||
" )");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,10 +345,10 @@ TEST(GoosReader, FromFile) {
|
||||
TEST(GoosReader, TextDb) {
|
||||
// very specific to this particular test file, but whatever.
|
||||
Reader reader;
|
||||
auto result = reader.read_from_file({"test", "test_data", "test_reader_file0.gc"})
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
auto& result = reader.read_from_file({"test", "test_data", "test_reader_file0.gc"})
|
||||
.as_pair()
|
||||
->cdr.as_pair()
|
||||
->car;
|
||||
std::string expected = "test/test_data/test_reader_file0.gc:5\n(1 2 3 4)\n ^\n";
|
||||
EXPECT_EQ(expected, reader.db.get_info_for(result));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user