mirror of
https://github.com/open-goal/jak-project
synced 2026-09-07 11:36:26 -04:00
[Decompiler - New IR] Add AtomicOp (#181)
* wip decompiler ir * add AtomicOp stuff * fix windows build and warnings * add instruction parser * include * make minilzo shared * odr fix * a * fix merge conflicts * move decompiler into namespace * update the code coverage to include the decompiler * add demo test * add register use test to example test
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "common/common_types.h"
|
||||
#include "decompiler/ObjectFile/LinkedWord.h"
|
||||
|
||||
namespace decompiler {
|
||||
class LinkedWordReader {
|
||||
public:
|
||||
explicit LinkedWordReader(const std::vector<LinkedWord>* words) : m_words(words) {}
|
||||
@@ -37,4 +38,5 @@ class LinkedWordReader {
|
||||
private:
|
||||
const std::vector<LinkedWord>* m_words = nullptr;
|
||||
u32 m_offset = 0;
|
||||
};
|
||||
};
|
||||
} // namespace decompiler
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "game/common/str_rpc_types.h"
|
||||
#include "StrFileReader.h"
|
||||
|
||||
namespace decompiler {
|
||||
StrFileReader::StrFileReader(const std::string& file_path) {
|
||||
auto data = file_util::read_binary_file(file_path);
|
||||
assert(data.size() >= SECTOR_SIZE); // must have at least the header sector
|
||||
@@ -178,4 +179,5 @@ std::string StrFileReader::get_full_name(const std::string& short_name) const {
|
||||
assert(strcmp(iso_name_1, iso_name_2) == 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} // namespace decompiler
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace decompiler {
|
||||
class StrFileReader {
|
||||
public:
|
||||
explicit StrFileReader(const std::string& file_path);
|
||||
@@ -19,3 +20,4 @@ class StrFileReader {
|
||||
private:
|
||||
std::vector<std::vector<u8>> m_chunks;
|
||||
};
|
||||
} // namespace decompiler
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "game_count.h"
|
||||
#include "LinkedWordReader.h"
|
||||
|
||||
namespace decompiler {
|
||||
GameCountResult process_game_count(ObjectFileData& data) {
|
||||
GameCountResult result;
|
||||
auto& words = data.linked_data.words_by_seg.at(0);
|
||||
@@ -37,4 +38,5 @@ std::string write_game_count(const GameCountResult& result) {
|
||||
str += fmt::format("(:unknown-1 {} :unknown-2 {})\n", result.mystery_data[0],
|
||||
result.mystery_data[1]);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
} // namespace decompiler
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace decompiler {
|
||||
struct GameCountResult {
|
||||
struct CountInfo {
|
||||
s32 money_count;
|
||||
@@ -15,4 +16,5 @@ struct GameCountResult {
|
||||
|
||||
struct ObjectFileData;
|
||||
GameCountResult process_game_count(ObjectFileData& data);
|
||||
std::string write_game_count(const GameCountResult& result);
|
||||
std::string write_game_count(const GameCountResult& result);
|
||||
} // namespace decompiler
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "decompiler/ObjectFile/ObjectFileDB.h"
|
||||
#include "common/goos/Reader.h"
|
||||
|
||||
namespace decompiler {
|
||||
namespace {
|
||||
template <typename T>
|
||||
T get_word(const LinkedWord& word) {
|
||||
@@ -17,7 +18,7 @@ T get_word(const LinkedWord& word) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Label get_label(ObjectFileData& data, const LinkedWord& word) {
|
||||
DecompilerLabel get_label(ObjectFileData& data, const LinkedWord& word) {
|
||||
assert(word.kind == LinkedWord::PTR);
|
||||
return data.linked_data.labels.at(word.label_id);
|
||||
}
|
||||
@@ -159,4 +160,5 @@ std::string write_game_text(
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} // namespace decompiler
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace decompiler {
|
||||
struct ObjectFileData;
|
||||
|
||||
struct GameTextResult {
|
||||
@@ -13,4 +14,5 @@ struct GameTextResult {
|
||||
|
||||
GameTextResult process_game_text(ObjectFileData& data);
|
||||
std::string write_game_text(
|
||||
const std::unordered_map<int, std::unordered_map<int, std::string>>& data);
|
||||
const std::unordered_map<int, std::unordered_map<int, std::string>>& data);
|
||||
} // namespace decompiler
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "decompiler/ObjectFile/ObjectFileDB.h"
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
namespace decompiler {
|
||||
namespace {
|
||||
|
||||
/*!
|
||||
@@ -314,7 +315,7 @@ struct Texture {
|
||||
u32 packed_info_words[9];
|
||||
};
|
||||
|
||||
Label name_label;
|
||||
DecompilerLabel name_label;
|
||||
std::string name;
|
||||
u32 size;
|
||||
float uv_dist;
|
||||
@@ -342,7 +343,7 @@ struct Texture {
|
||||
* Unclear what the segments really are, maybe you could split up big tpages if needed?
|
||||
*/
|
||||
struct TexturePageSegment {
|
||||
Label block_data_label;
|
||||
DecompilerLabel block_data_label;
|
||||
u32 size = 0xffffffff;
|
||||
u32 dest = 0xffffffff;
|
||||
std::string print_debug() const {
|
||||
@@ -379,10 +380,10 @@ struct FileInfo {
|
||||
* GOAL texture-page type.
|
||||
*/
|
||||
struct TexturePage {
|
||||
Label info_label;
|
||||
DecompilerLabel info_label;
|
||||
FileInfo info;
|
||||
|
||||
Label name_label;
|
||||
DecompilerLabel name_label;
|
||||
std::string name;
|
||||
|
||||
u32 id = 0xffffffff;
|
||||
@@ -392,7 +393,7 @@ struct TexturePage {
|
||||
TexturePageSegment segments[3];
|
||||
u32 pad[16] = {};
|
||||
// data...
|
||||
std::vector<Label> data;
|
||||
std::vector<DecompilerLabel> data;
|
||||
std::vector<Texture> textures;
|
||||
|
||||
std::string print_debug() const {
|
||||
@@ -423,7 +424,7 @@ struct TexturePage {
|
||||
* Convert a label to the offset (words) in the object segment.
|
||||
* If basic is set, gives you a pointer to the beginning of the memory, if the thing is a basic.
|
||||
*/
|
||||
int label_to_word_offset(Label l, bool basic) {
|
||||
int label_to_word_offset(DecompilerLabel l, bool basic) {
|
||||
assert((l.offset & 3) == 0);
|
||||
int result = l.offset / 4;
|
||||
if (basic) {
|
||||
@@ -441,7 +442,7 @@ bool is_type_tag(const LinkedWord& word, const std::string& type) {
|
||||
return word.kind == LinkedWord::TYPE_PTR && word.symbol_name == type;
|
||||
}
|
||||
|
||||
Label get_label(ObjectFileData& data, const LinkedWord& word) {
|
||||
DecompilerLabel get_label(ObjectFileData& data, const LinkedWord& word) {
|
||||
assert(word.kind == LinkedWord::PTR);
|
||||
return data.linked_data.labels.at(word.label_id);
|
||||
}
|
||||
@@ -905,3 +906,4 @@ TPageResultStats process_tpage(ObjectFileData& data) {
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
} // namespace decompiler
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace decompiler {
|
||||
struct ObjectFileData;
|
||||
|
||||
struct TPageResultStats {
|
||||
@@ -7,4 +8,5 @@ struct TPageResultStats {
|
||||
int successful_textures = 0;
|
||||
};
|
||||
|
||||
TPageResultStats process_tpage(ObjectFileData& data);
|
||||
TPageResultStats process_tpage(ObjectFileData& data);
|
||||
} // namespace decompiler
|
||||
Reference in New Issue
Block a user