Files
jak-project/test/decompiler/FormRegressionTest.h
T
water111 814480f9e5 [Decompiler] Replace type hint system and improve variable types. (#320)
* get gkernel and gkernel-h at least somewhat working in the offline tests

* strip comments from json

* switch hints to casts. online tests passing, offline passing up to gkernel

* variable retyping is added

* fix up casts in lets

* update
2021-03-13 16:10:39 -05:00

82 lines
3.3 KiB
C++

#pragma once
#include <memory>
#include "gtest/gtest.h"
#include "decompiler/Disasm/InstructionParser.h"
#include "decompiler/util/DecompilerTypeSystem.h"
#include "decompiler/Function/Function.h"
#include "decompiler/ObjectFile/LinkedObjectFile.h"
namespace decompiler {
struct TypeCast;
}
class FormRegressionTest : public ::testing::Test {
protected:
static std::unique_ptr<decompiler::InstructionParser> parser;
static std::unique_ptr<decompiler::DecompilerTypeSystem> dts;
static void SetUpTestCase();
static void TearDownTestCase();
struct TestData {
explicit TestData(int instrs) : func(0, instrs) {}
decompiler::Function func;
decompiler::LinkedObjectFile file;
void add_string_at_label(const std::string& label_name, const std::string& data);
};
std::unique_ptr<TestData> make_function(
const std::string& code,
const TypeSpec& function_type,
bool do_expressions,
bool allow_pairs = false,
const std::string& method_name = "",
const std::vector<std::pair<std::string, std::string>>& strings = {},
const std::unordered_map<int, std::vector<decompiler::TypeCast>>& casts = {},
const std::string& var_map_json = "");
void test(const std::string& code,
const std::string& type,
const std::string& expected,
bool do_expressions,
bool allow_pairs = false,
const std::string& method_name = "",
const std::vector<std::pair<std::string, std::string>>& strings = {},
const std::unordered_map<int, std::vector<decompiler::TypeCast>>& casts = {},
const std::string& var_map_json = "");
void test_no_expr(const std::string& code,
const std::string& type,
const std::string& expected,
bool allow_pairs = false,
const std::string& method_name = "",
const std::vector<std::pair<std::string, std::string>>& strings = {},
const std::unordered_map<int, std::vector<decompiler::TypeCast>>& casts = {},
const std::string& var_map_json = "") {
test(code, type, expected, false, allow_pairs, method_name, strings, casts, var_map_json);
}
void test_with_expr(const std::string& code,
const std::string& type,
const std::string& expected,
bool allow_pairs = false,
const std::string& method_name = "",
const std::vector<std::pair<std::string, std::string>>& strings = {},
const std::unordered_map<int, std::vector<decompiler::TypeCast>>& casts = {},
const std::string& var_map_json = "") {
test(code, type, expected, true, allow_pairs, method_name, strings, casts, var_map_json);
}
void test_final_function(
const std::string& code,
const std::string& type,
const std::string& expected,
bool allow_pairs = false,
const std::vector<std::pair<std::string, std::string>>& strings = {},
const std::unordered_map<int, std::vector<decompiler::TypeCast>>& casts = {},
const std::string& var_map_json = "");
std::unordered_map<int, std::vector<decompiler::TypeCast>> parse_cast_json(const std::string& in);
};