2021-02-25 09:51:28 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2021-02-25 09:51:28 -05:00
|
|
|
#include "common/goos/Object.h"
|
|
|
|
#include "common/type_system/TypeSpec.h"
|
|
|
|
#include "common/type_system/TypeSystem.h"
|
2022-10-09 12:53:44 -04:00
|
|
|
#include "common/versions.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
|
|
|
#include "decompiler/Disasm/DecompilerLabel.h"
|
|
|
|
#include "decompiler/IR2/LabelDB.h"
|
|
|
|
#include "decompiler/ObjectFile/LinkedWord.h"
|
2021-02-27 14:40:18 -05:00
|
|
|
#include "decompiler/config.h"
|
|
|
|
#include "decompiler/util/DecompilerTypeSystem.h"
|
2021-02-25 09:51:28 -05:00
|
|
|
|
|
|
|
namespace decompiler {
|
2021-07-01 21:38:19 -04:00
|
|
|
class LinkedObjectFile;
|
2021-02-25 09:51:28 -05:00
|
|
|
std::optional<TypeSpec> get_type_of_label(const DecompilerLabel& label,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words);
|
|
|
|
|
|
|
|
goos::Object decompile_string_at_label(const DecompilerLabel& label,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words);
|
|
|
|
goos::Object decompile_at_label(const TypeSpec& type,
|
|
|
|
const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-07-01 21:38:19 -04:00
|
|
|
const TypeSystem& ts,
|
2022-09-27 19:44:20 -04:00
|
|
|
const LinkedObjectFile* file,
|
2022-10-09 12:53:44 -04:00
|
|
|
GameVersion version,
|
2022-09-27 19:44:20 -04:00
|
|
|
bool in_static_pair = false);
|
2021-08-29 11:13:06 -04:00
|
|
|
goos::Object decompile_at_label_with_hint(const LabelInfo& hint,
|
2021-02-27 14:40:18 -05:00
|
|
|
const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-07-01 21:38:19 -04:00
|
|
|
DecompilerTypeSystem& dts,
|
2022-10-09 12:53:44 -04:00
|
|
|
const LinkedObjectFile* file,
|
|
|
|
GameVersion version);
|
2021-02-25 09:51:28 -05:00
|
|
|
goos::Object decompile_at_label_guess_type(const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-07-01 21:38:19 -04:00
|
|
|
const TypeSystem& ts,
|
2022-10-09 12:53:44 -04:00
|
|
|
const LinkedObjectFile* file,
|
|
|
|
GameVersion version);
|
2021-02-25 09:51:28 -05:00
|
|
|
goos::Object decompile_structure(const TypeSpec& actual_type,
|
|
|
|
const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-07-01 21:38:19 -04:00
|
|
|
const TypeSystem& ts,
|
2021-09-26 11:41:58 -04:00
|
|
|
const LinkedObjectFile* file,
|
2022-10-09 12:53:44 -04:00
|
|
|
bool use_fancy_macros,
|
|
|
|
GameVersion version);
|
2021-02-25 09:51:28 -05:00
|
|
|
goos::Object decompile_pair(const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-05-12 21:57:19 -04:00
|
|
|
const TypeSystem& ts,
|
2021-07-01 21:38:19 -04:00
|
|
|
bool add_quote,
|
2022-10-09 12:53:44 -04:00
|
|
|
const LinkedObjectFile* file,
|
|
|
|
GameVersion version);
|
2021-02-25 09:51:28 -05:00
|
|
|
goos::Object decompile_boxed_array(const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
2021-07-01 21:38:19 -04:00
|
|
|
const TypeSystem& ts,
|
2021-07-03 16:18:41 -04:00
|
|
|
const LinkedObjectFile* file,
|
2022-10-09 12:53:44 -04:00
|
|
|
const std::optional<TypeSpec>& content_type_override,
|
|
|
|
GameVersion version);
|
2021-02-25 09:51:28 -05:00
|
|
|
goos::Object decompile_value(const TypeSpec& type,
|
|
|
|
const std::vector<u8>& bytes,
|
|
|
|
const TypeSystem& ts);
|
2021-02-27 14:40:18 -05:00
|
|
|
goos::Object decompile_value_array(const TypeSpec& elt_type,
|
|
|
|
const Type* elt_type_info,
|
|
|
|
int length,
|
|
|
|
int stride,
|
|
|
|
int offset,
|
|
|
|
const std::vector<LinkedWord>& obj_words,
|
|
|
|
const TypeSystem& ts);
|
2021-04-17 18:35:50 -04:00
|
|
|
goos::Object decompile_bitfield(const TypeSpec& type,
|
|
|
|
const BitFieldType* type_info,
|
|
|
|
const DecompilerLabel& label,
|
|
|
|
const std::vector<DecompilerLabel>& labels,
|
|
|
|
const std::vector<std::vector<LinkedWord>>& words,
|
|
|
|
const TypeSystem& ts);
|
|
|
|
|
|
|
|
struct BitFieldConstantDef {
|
|
|
|
bool is_signed = false;
|
|
|
|
u64 value = -1;
|
2021-04-26 21:40:08 -04:00
|
|
|
std::optional<std::string> enum_constant;
|
2021-04-17 18:35:50 -04:00
|
|
|
std::string field_name;
|
2021-07-26 20:02:16 -04:00
|
|
|
|
|
|
|
struct NestedField {
|
|
|
|
TypeSpec field_type;
|
|
|
|
std::vector<BitFieldConstantDef> fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::optional<NestedField> nested_field;
|
2021-04-17 18:35:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T extract_bitfield(T input, int start_bit, int size) {
|
|
|
|
int end_bit = start_bit + size;
|
|
|
|
T left_shifted = input << (64 - end_bit);
|
|
|
|
return left_shifted >> (64 - size);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& type,
|
|
|
|
const TypeSystem& ts,
|
|
|
|
u64 value);
|
|
|
|
|
2021-06-16 21:11:21 -04:00
|
|
|
std::optional<std::vector<BitFieldConstantDef>> try_decompile_bitfield_from_int(
|
|
|
|
const TypeSpec& type,
|
|
|
|
const TypeSystem& ts,
|
|
|
|
u64 value,
|
2021-08-31 11:05:03 -04:00
|
|
|
bool require_success,
|
|
|
|
std::optional<int> offset);
|
2021-06-16 21:11:21 -04:00
|
|
|
|
2021-04-22 19:08:58 -04:00
|
|
|
std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
|
|
|
|
const TypeSystem& ts,
|
|
|
|
u64 value);
|
2021-04-23 20:29:15 -04:00
|
|
|
std::string decompile_int_enum_from_int(const TypeSpec& type, const TypeSystem& ts, u64 value);
|
2021-09-26 11:41:58 -04:00
|
|
|
goos::Object bitfield_defs_print(const TypeSpec& type,
|
|
|
|
const std::vector<BitFieldConstantDef>& defs);
|
2021-02-25 09:51:28 -05:00
|
|
|
} // namespace decompiler
|