2021-07-01 21:38:19 -04:00
|
|
|
#pragma once
|
2020-09-29 20:24:15 -04:00
|
|
|
|
|
|
|
#include "common/type_system/TypeSystem.h"
|
2020-11-28 15:35:38 -05:00
|
|
|
#include "decompiler/Disasm/Register.h"
|
2020-12-17 15:48:07 -05:00
|
|
|
#include "common/goos/Reader.h"
|
2020-09-29 20:24:15 -04:00
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
namespace decompiler {
|
|
|
|
class TP_Type;
|
2021-07-11 16:35:25 -04:00
|
|
|
class TypeState;
|
2020-11-27 16:38:36 -05:00
|
|
|
|
2020-09-29 20:24:15 -04:00
|
|
|
class DecompilerTypeSystem {
|
|
|
|
public:
|
|
|
|
DecompilerTypeSystem();
|
|
|
|
TypeSystem ts;
|
|
|
|
std::unordered_map<std::string, TypeSpec> symbol_types;
|
|
|
|
std::unordered_set<std::string> symbols;
|
|
|
|
std::vector<std::string> symbol_add_order;
|
2020-10-24 22:51:40 -04:00
|
|
|
std::unordered_map<std::string, u64> type_flags;
|
|
|
|
std::unordered_map<std::string, std::string> type_parents;
|
2021-07-01 21:38:19 -04:00
|
|
|
std::unordered_map<std::string, int> bad_format_strings;
|
2021-09-06 20:35:03 -04:00
|
|
|
std::unordered_map<std::string, std::vector<std::vector<int>>>
|
|
|
|
format_ops_with_dynamic_string_by_func_name;
|
2020-09-29 20:24:15 -04:00
|
|
|
|
|
|
|
void add_symbol(const std::string& name) {
|
|
|
|
if (symbols.find(name) == symbols.end()) {
|
|
|
|
symbols.insert(name);
|
|
|
|
symbol_add_order.push_back(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_symbol(const std::string& name, const std::string& base_type) {
|
|
|
|
add_symbol(name, TypeSpec(base_type));
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:27:52 -04:00
|
|
|
void add_symbol(const std::string& name, const TypeSpec& type_spec);
|
2020-09-29 20:24:15 -04:00
|
|
|
void parse_type_defs(const std::vector<std::string>& file_path);
|
2021-03-13 16:10:39 -05:00
|
|
|
TypeSpec parse_type_spec(const std::string& str) const;
|
2020-10-24 22:51:40 -04:00
|
|
|
void add_type_flags(const std::string& name, u64 flags);
|
|
|
|
void add_type_parent(const std::string& child, const std::string& parent);
|
2020-09-29 20:24:15 -04:00
|
|
|
std::string dump_symbol_types();
|
2020-10-24 22:51:40 -04:00
|
|
|
std::string lookup_parent_from_inspects(const std::string& child) const;
|
|
|
|
bool lookup_flags(const std::string& type, u64* dest) const;
|
2021-01-16 10:54:09 -05:00
|
|
|
TP_Type tp_lca(const TP_Type& existing, const TP_Type& add, bool* changed) const;
|
2020-11-27 16:38:36 -05:00
|
|
|
bool tp_lca(TypeState* combined, const TypeState& add);
|
2021-01-16 10:54:09 -05:00
|
|
|
int get_format_arg_count(const std::string& str) const;
|
|
|
|
int get_format_arg_count(const TP_Type& type) const;
|
2021-09-06 20:35:03 -04:00
|
|
|
int get_dynamic_format_arg_count(const std::string& func_name, int op_idx) const;
|
2021-03-03 20:52:25 -05:00
|
|
|
TypeSpec lookup_symbol_type(const std::string& name) const;
|
2021-07-11 18:19:41 -04:00
|
|
|
bool should_attempt_cast_simplify(const TypeSpec& expected, const TypeSpec& actual) const;
|
2021-03-03 20:52:25 -05:00
|
|
|
|
2021-03-27 15:18:59 -04:00
|
|
|
// todo - totally eliminate this.
|
2020-11-28 15:35:38 -05:00
|
|
|
struct {
|
|
|
|
std::string current_method_type;
|
2021-03-27 15:18:59 -04:00
|
|
|
void reset() { current_method_type.clear(); }
|
2020-11-28 15:35:38 -05:00
|
|
|
} type_prop_settings;
|
2020-12-17 15:48:07 -05:00
|
|
|
|
|
|
|
private:
|
2021-03-13 16:10:39 -05:00
|
|
|
mutable goos::Reader m_reader;
|
2020-09-29 20:24:15 -04:00
|
|
|
};
|
2021-01-06 20:04:15 -05:00
|
|
|
} // namespace decompiler
|