update readme and fix unused function issue (#821)

This commit is contained in:
water111
2021-09-03 19:19:51 -04:00
committed by GitHub
parent 3d7010b05d
commit a96eb800c4
7 changed files with 108 additions and 39 deletions
+2 -1
View File
@@ -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();
}
/*!
+9
View File
@@ -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);
}
+1
View File
@@ -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,
+8 -1
View File
@@ -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()));
}
}
});
+14 -7
View File
@@ -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) {
+6 -1
View File
@@ -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);