mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 22:22:21 -04:00
[decompiler] Several small fixes (#775)
* fix assorted bugs * stricter return types * only look for functions in code files
This commit is contained in:
@@ -1255,11 +1255,22 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
|
||||
return type_info->entries().at(a) < type_info->entries().at(b);
|
||||
});
|
||||
|
||||
for (auto& field_name : bit_sorted_names) {
|
||||
u64 mask = ((u64)1) << type_info->entries().at(field_name);
|
||||
for (auto& kv : type_info->entries()) {
|
||||
u64 mask = ((u64)1) << kv.second;
|
||||
if (value & mask) {
|
||||
reconstructed |= mask;
|
||||
result.push_back(field_name);
|
||||
result.push_back(kv.first);
|
||||
}
|
||||
}
|
||||
|
||||
int bit_count = 0;
|
||||
{
|
||||
u64 x = value;
|
||||
while (x) {
|
||||
if (x & 1) {
|
||||
bit_count++;
|
||||
}
|
||||
x >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1270,10 +1281,18 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
|
||||
type.print(), value, reconstructed));
|
||||
}
|
||||
|
||||
// unordered map will give us these fields in a weird order, let's order them explicitly.
|
||||
std::sort(result.begin(), result.end(), [&](const std::string& a, const std::string& b) {
|
||||
return type_info->entries().at(a) < type_info->entries().at(b);
|
||||
});
|
||||
if (bit_count == (int)result.size()) {
|
||||
// unordered map will give us these fields in a weird order, let's order them explicitly.
|
||||
// because we have exactly one name per bit, we can just order them in bit order.
|
||||
std::sort(result.begin(), result.end(), [&](const std::string& a, const std::string& b) {
|
||||
return type_info->entries().at(a) < type_info->entries().at(b);
|
||||
});
|
||||
} else {
|
||||
// we have multiple. Just sort alphabetically and complain.
|
||||
lg::warn("Enum type {} has multiple entries with the same value.", type_info->get_name());
|
||||
std::sort(result.begin(), result.end());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user