mirror of
https://github.com/open-goal/jak-project
synced 2026-09-07 19:40:48 -04:00
update readme and fix unused function issue (#821)
This commit is contained in:
@@ -288,7 +288,8 @@ bool is_gpr_2_imm_int(const Instruction& instr,
|
||||
MatchParam<Register> src,
|
||||
MatchParam<int32_t> imm) {
|
||||
return kind == instr.kind && dst == instr.get_dst(0).get_reg() &&
|
||||
src == instr.get_src(0).get_reg() && imm == instr.get_src(1).get_imm();
|
||||
src == instr.get_src(0).get_reg() && instr.get_src(1).is_imm() &&
|
||||
imm == instr.get_src(1).get_imm();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -102,6 +102,15 @@ int LabelDB::get_index_by_offset(int seg, int offset) const {
|
||||
return m_labels_by_offset_into_seg.at(seg).at(offset);
|
||||
}
|
||||
|
||||
std::optional<int> LabelDB::try_get_index_by_offset(int seg, int offset) const {
|
||||
auto it = m_labels_by_offset_into_seg.at(seg).find(offset);
|
||||
if (it == m_labels_by_offset_into_seg.at(seg).end()) {
|
||||
return {};
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
int LabelDB::get_index_by_name(const std::string& name) const {
|
||||
return m_labels_by_name.at(name);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ class LabelDB {
|
||||
const LabelInfo& lookup(int idx) const;
|
||||
const LabelInfo& lookup(const std::string& name) const;
|
||||
int get_index_by_offset(int seg, int offset) const;
|
||||
std::optional<int> try_get_index_by_offset(int seg, int offset) const;
|
||||
int get_index_by_name(const std::string& name) const;
|
||||
|
||||
LabelInfo set_and_get_previous(int idx,
|
||||
|
||||
@@ -639,7 +639,14 @@ void ObjectFileDB::ir2_insert_lets(int seg) {
|
||||
for_each_function_in_seg(seg, [&](Function& func, ObjectFileData&) {
|
||||
if (func.ir2.expressions_succeeded) {
|
||||
attempted++;
|
||||
combined_stats += insert_lets(func, func.ir2.env, *func.ir2.form_pool, func.ir2.top_form);
|
||||
try {
|
||||
combined_stats += insert_lets(func, func.ir2.env, *func.ir2.form_pool, func.ir2.top_form);
|
||||
} catch (const std::exception& e) {
|
||||
func.warnings.general_warning(
|
||||
fmt::format("Error while inserting lets: {}\n Make sure that the return type is not "
|
||||
"none if something is actually returned.",
|
||||
e.what()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -53,12 +53,17 @@ void find_functions(LabelDB* db, LinkedObjectFile* file) {
|
||||
// first, the label for the start of the function
|
||||
// + 4 bytes for the type tag.
|
||||
int offset_of_function = func.start_word * 4 + 4;
|
||||
int idx_of_label = db->get_index_by_offset(seg, offset_of_function);
|
||||
auto old = db->set_and_get_previous(idx_of_label, func.type, false, {});
|
||||
if (old.known) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"There is a config entry for label {}, but it's a function. Remove the config.",
|
||||
old.name));
|
||||
auto idx_of_label = db->try_get_index_by_offset(seg, offset_of_function);
|
||||
if (!idx_of_label) {
|
||||
func.warnings.general_warning("Could not find any references to this function: {}",
|
||||
func.guessed_name.to_string());
|
||||
} else {
|
||||
auto old = db->set_and_get_previous(*idx_of_label, func.type, false, {});
|
||||
if (old.known) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"There is a config entry for label {}, but it's a function. Remove the config.",
|
||||
old.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +78,9 @@ void find_boxed(LabelDB* db, LinkedObjectFile* file) {
|
||||
if ((lab.offset & 7) == BASIC_OFFSET) {
|
||||
// it's a basic! probably.
|
||||
const auto& word = file->words_by_seg.at(lab.target_segment).at((lab.offset - 4) / 4);
|
||||
if (word.kind == LinkedWord::TYPE_PTR) {
|
||||
// the snowball-bank is a weird basic with no fields other than the built-in type.
|
||||
// so it can actually share a label with something else.
|
||||
if (word.kind == LinkedWord::TYPE_PTR && word.symbol_name != "snowball-bank") {
|
||||
TypeSpec basic_type(word.symbol_name);
|
||||
const auto& existing = db->lookup(lab.name);
|
||||
if (existing.known) {
|
||||
|
||||
@@ -351,7 +351,12 @@ goos::Object decomp_ref_to_inline_array_guess_size(
|
||||
const auto& start_label = labels.at(pointer_to_data.label_id);
|
||||
int end_label_idx =
|
||||
index_of_closest_following_label_in_segment(start_label.offset, my_seg, labels);
|
||||
assert(end_label_idx >= 0);
|
||||
|
||||
if (end_label_idx < 0) {
|
||||
throw std::runtime_error(
|
||||
"Failed to find label: likely just an unimplemented case for when the data is the last "
|
||||
"thing in the file.");
|
||||
}
|
||||
const auto& end_label = labels.at(end_label_idx);
|
||||
// fmt::print("Data is from {} to {}\n", start_label.name, end_label.name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user