mirror of
https://github.com/open-goal/jak-project
synced 2026-07-08 22:45:00 -04:00
[Compiler/Decompiler] Better support for Bitfield and Enum types (#374)
* compiler fixes, a decent amount of decompiler stuff is working too * more support in decompiler, fix some casts * decompile static data too
This commit is contained in:
@@ -380,9 +380,10 @@ std::vector<Form*> compact_nested_logiors(GenericElement* input, const Env&) {
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/*!
|
||||
* If this could be an integer constant, figure out what the value is.
|
||||
* TODO move this somewhere more general.
|
||||
*/
|
||||
std::optional<u64> get_goal_integer_constant(Form* in, const Env&) {
|
||||
auto as_atom = form_as_atom(in);
|
||||
@@ -405,8 +406,6 @@ std::optional<u64> get_goal_integer_constant(Form* in, const Env&) {
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BitFieldDef BitFieldDef::from_constant(const BitFieldConstantDef& constant, FormPool& pool) {
|
||||
BitFieldDef bfd;
|
||||
bfd.field_name = constant.field_name;
|
||||
@@ -474,4 +473,26 @@ Form* cast_to_bitfield(const BitFieldType* type_info,
|
||||
return pool.alloc_single_element_form<CastElement>(nullptr, typespec, in);
|
||||
}
|
||||
|
||||
Form* cast_to_bitfield_enum(const EnumType* type_info,
|
||||
const TypeSpec& typespec,
|
||||
FormPool& pool,
|
||||
const Env& env,
|
||||
Form* in) {
|
||||
auto integer = get_goal_integer_constant(strip_int_or_uint_cast(in), env);
|
||||
if (integer) {
|
||||
auto elts =
|
||||
decompile_bitfield_enum_from_int(TypeSpec(type_info->get_name()), env.dts->ts, *integer);
|
||||
auto oper = GenericOperator::make_function(
|
||||
pool.alloc_single_element_form<ConstantTokenElement>(nullptr, type_info->get_name()));
|
||||
std::vector<Form*> form_elts;
|
||||
for (auto& x : elts) {
|
||||
form_elts.push_back(pool.alloc_single_element_form<ConstantTokenElement>(nullptr, x));
|
||||
}
|
||||
return pool.alloc_single_element_form<GenericElement>(nullptr, oper, form_elts);
|
||||
} else {
|
||||
// all failed, just return whatever.
|
||||
return pool.alloc_single_element_form<CastElement>(nullptr, typespec, in);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace decompiler
|
||||
Reference in New Issue
Block a user