[decompiler] Small bitfield fixes (#599)

* fix a bunch of small bitfield related things

* fix up test

* format
This commit is contained in:
water111
2021-06-16 21:11:21 -04:00
committed by GitHub
parent b209c9e1ba
commit d26de26d21
13 changed files with 125 additions and 83 deletions
+18 -7
View File
@@ -899,9 +899,11 @@ goos::Object decompile_bitfield(const TypeSpec& type,
return bitfield_defs_print(type, defs);
}
std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value) {
std::optional<std::vector<BitFieldConstantDef>> try_decompile_bitfield_from_int(
const TypeSpec& type,
const TypeSystem& ts,
u64 value,
bool require_success) {
u64 touched_bits = 0;
std::vector<BitFieldConstantDef> result;
@@ -941,14 +943,23 @@ std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& typ
u64 untouched_but_set = value & (~touched_bits);
if (untouched_but_set) {
throw std::runtime_error(
fmt::format("Failed to decompile static bitfield of type {}. Original value is 0x{:x} but "
"we didn't touch",
type.print(), value, untouched_but_set));
if (require_success) {
throw std::runtime_error(fmt::format(
"Failed to decompile static bitfield of type {}. Original value is 0x{:x} but "
"we didn't touch",
type.print(), value, untouched_but_set));
}
return {};
}
return result;
}
std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value) {
return *try_decompile_bitfield_from_int(type, ts, value, true);
}
std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value) {