Typo fixes & Windows QoL changes (#189)

* Add a Release build configuration.

* Batch file alternatives for decomp/gc/gk

For the shell-less, or people with a different Windows configuration.

* all-types.gc: Fix typo.

* gcommon.gc: Typo.

* debugger: use enum class for InstructionInfo::Kind

* decompilerIR: use enum class for IR_Store::Kind

* Update all-types.gc

* decompiler: tab to spaces

* root batch files: update directories

* Use a gitignore inside "log" folder to fix windows crashes

* Revert "Update all-types.gc"

This reverts commit 5ef179bb4e.
This commit is contained in:
ManDude 2021-01-10 15:39:32 +00:00 committed by GitHub
parent 2901f4a99e
commit e5b0541d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 386 additions and 372 deletions

3
.gitignore vendored
View File

@ -3,5 +3,4 @@ cmake-build-debug/*
.idea/*
build/*
decompiler_out/*
logs/*
log/*
logs/*

8
decomp.bat Normal file
View File

@ -0,0 +1,8 @@
@echo off
:: The caret ^ acts as a line break but does not make the next line a different command.
out\build\Release\bin\decompiler decompiler\config\jak1_ntsc_black_label.jsonc iso_data ^
decompiler_out
:: The pause command makes the batch operation halt with a "Press any key to continue..." message.
:: Useful for example if the decompiler failed and exited for whatever reason, or for verifying its
:: success.
pause

View File

@ -1,60 +1,60 @@
add_library(
decomp
SHARED
data/game_count.cpp
data/game_text.cpp
data/StrFileReader.cpp
data/tpage.cpp
data/game_count.cpp
data/game_text.cpp
data/StrFileReader.cpp
data/tpage.cpp
Disasm/Instruction.cpp
Disasm/InstructionDecode.cpp
Disasm/InstructionMatching.cpp
Disasm/InstructionParser.cpp
Disasm/InstructionMatching.cpp
Disasm/InstructionParser.cpp
Disasm/OpcodeInfo.cpp
Disasm/Register.cpp
Function/BasicBlocks.cpp
Function/CfgVtx.cpp
Function/ExpressionBuilder.cpp
Function/ExpressionStack.cpp
Function/Function.cpp
Function/RegUsage.cpp
Function/TypeAnalysis.cpp
Function/TypeInspector.cpp
Function/BasicBlocks.cpp
Function/CfgVtx.cpp
Function/ExpressionBuilder.cpp
Function/ExpressionStack.cpp
Function/Function.cpp
Function/RegUsage.cpp
Function/TypeAnalysis.cpp
Function/TypeInspector.cpp
IR/BasicOpBuilder.cpp
IR/CfgBuilder.cpp
IR/IR.cpp
IR/IR_ExpressionStack.cpp
IR/IR_TypeAnalysis.cpp
IR/BasicOpBuilder.cpp
IR/CfgBuilder.cpp
IR/IR.cpp
IR/IR_ExpressionStack.cpp
IR/IR_TypeAnalysis.cpp
IR2/AtomicOp.cpp
IR2/AtomicOpBuilder.cpp
IR2/Env.cpp
IR2/AtomicOp.cpp
IR2/AtomicOpBuilder.cpp
IR2/Env.cpp
ObjectFile/LinkedObjectFile.cpp
ObjectFile/LinkedObjectFile.cpp
ObjectFile/LinkedObjectFileCreation.cpp
ObjectFile/ObjectFileDB.cpp
ObjectFile/ObjectFileDB_IR2.cpp
ObjectFile/ObjectFileDB.cpp
ObjectFile/ObjectFileDB_IR2.cpp
util/DecompilerTypeSystem.cpp
util/TP_Type.cpp
util/TP_Type.cpp
config.cpp
config.cpp
)
target_link_libraries(decomp
minilzo
common
fmt
)
minilzo
common
fmt
)
add_executable(decompiler
main.cpp
)
target_link_libraries(decompiler
decomp
decomp
common
minilzo
fmt)

View File

@ -1009,7 +1009,7 @@ std::shared_ptr<IR_Atomic> try_sw(Instruction& instr, int idx) {
return op;
} else if (instr.kind == InstructionKind::SW && instr.get_src(1).is_imm()) {
if (instr.get_src(1).get_imm() == 0) {
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::INTEGER,
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::Kind::INTEGER,
make_reg(instr.get_src(2).get_reg(), idx),
make_reg(instr.get_src(0).get_reg(), idx), 4);
op->update_reginfo_self(0, 2, 0);
@ -1027,7 +1027,7 @@ std::shared_ptr<IR_Atomic> try_sw(Instruction& instr, int idx) {
return op;
} else {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1044,13 +1044,13 @@ std::shared_ptr<IR_Atomic> try_sb(Instruction& instr, int idx) {
if (instr.kind == InstructionKind::SB && instr.get_src(1).is_imm()) {
if (instr.get_src(1).get_imm() == 0) {
if (instr.get_src(0).is_reg(make_gpr(Reg::R0))) {
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::INTEGER,
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::Kind::INTEGER,
make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(0), 1);
op->update_reginfo_self(0, 1, 0);
return op;
} else {
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::INTEGER,
auto op = std::make_shared<IR_Store_Atomic>(IR_Store_Atomic::Kind::INTEGER,
make_reg(instr.get_src(2).get_reg(), idx),
make_reg(instr.get_src(0).get_reg(), idx), 1);
op->update_reginfo_self(0, 2, 0);
@ -1060,7 +1060,7 @@ std::shared_ptr<IR_Atomic> try_sb(Instruction& instr, int idx) {
} else {
if (instr.get_src(0).is_reg(make_gpr(Reg::R0))) {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1069,7 +1069,7 @@ std::shared_ptr<IR_Atomic> try_sb(Instruction& instr, int idx) {
return op;
} else {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1085,7 +1085,7 @@ std::shared_ptr<IR_Atomic> try_sb(Instruction& instr, int idx) {
std::shared_ptr<IR_Atomic> try_sh(Instruction& instr, int idx) {
if (instr.kind == InstructionKind::SH && instr.get_src(1).is_imm()) {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1099,7 +1099,7 @@ std::shared_ptr<IR_Atomic> try_sh(Instruction& instr, int idx) {
std::shared_ptr<IR_Atomic> try_sd(Instruction& instr, int idx) {
if (instr.kind == InstructionKind::SD && instr.get_src(1).is_imm()) {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1113,7 +1113,7 @@ std::shared_ptr<IR_Atomic> try_sd(Instruction& instr, int idx) {
std::shared_ptr<IR_Atomic> try_sq(Instruction& instr, int idx) {
if (instr.kind == InstructionKind::SQ && instr.get_src(1).is_imm()) {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::INTEGER,
IR_Store_Atomic::Kind::INTEGER,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),
@ -1127,7 +1127,7 @@ std::shared_ptr<IR_Atomic> try_sq(Instruction& instr, int idx) {
std::shared_ptr<IR_Atomic> try_swc1(Instruction& instr, int idx) {
if (instr.kind == InstructionKind::SWC1 && instr.get_src(1).is_imm()) {
auto op = std::make_shared<IR_Store_Atomic>(
IR_Store_Atomic::FLOAT,
IR_Store_Atomic::Kind::FLOAT,
std::make_shared<IR_IntMath2>(
IR_IntMath2::ADD, make_reg(instr.get_src(2).get_reg(), idx),
std::make_shared<IR_IntegerConstant>(instr.get_src(1).get_imm())),

View File

@ -275,10 +275,10 @@ void IR_Set_Atomic::update_reginfo_regreg() {
goos::Object IR_Store::to_form(const LinkedObjectFile& file) const {
std::string store_operator;
switch (kind) {
case FLOAT:
case Kind::FLOAT:
store_operator = "s.f";
break;
case INTEGER:
case Kind::INTEGER:
switch (size) {
case 1:
store_operator = "s.b";
@ -310,10 +310,10 @@ goos::Object IR_Store::to_form(const LinkedObjectFile& file) const {
goos::Object IR_Store_Atomic::to_form(const LinkedObjectFile& file) const {
std::string store_operator;
switch (kind) {
case FLOAT:
case Kind::FLOAT:
store_operator = "s.f";
break;
case INTEGER:
case Kind::INTEGER:
switch (size) {
case 1:
store_operator = "s.b";

View File

@ -139,7 +139,7 @@ void IR_Set_Atomic::update_reginfo_self<IR_IntMath2>(int n_dest, int n_src, int
class IR_Store : public virtual IR_Set {
public:
enum Kind { INTEGER, FLOAT } kind;
enum class Kind { INTEGER, FLOAT } kind;
IR_Store(Kind _kind, std::shared_ptr<IR> _dst, std::shared_ptr<IR> _src, int _size)
: IR_Set(IR_Set::STORE, std::move(_dst), std::move(_src)), kind(_kind), size(_size) {}
int size;
@ -152,7 +152,7 @@ class IR_Store : public virtual IR_Set {
*/
class IR_Store_Atomic : public IR_Set_Atomic {
public:
enum Kind { INTEGER, FLOAT } kind;
enum class Kind { INTEGER, FLOAT } kind;
IR_Store_Atomic(Kind _kind, std::shared_ptr<IR> _dst, std::shared_ptr<IR> _src, int _size)
: IR_Set_Atomic(IR_Set::STORE, std::move(_dst), std::move(_src)), kind(_kind), size(_size) {}
int size;

File diff suppressed because it is too large Load Diff

2
gc.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
out\build\Release\bin\goalc -v

2
gk.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
out\build\Release\bin\gk -fakeiso -debug -v

View File

@ -195,7 +195,7 @@
((data float :offset-assert 4))
(:methods
(print (_type_) _type_ 2) ;; we will override print later on. This is optional to include
(inspect (_type_) _type_ 3) ;; this is a parent method we won't override. This is also optional to inlcude
(inspect (_type_) _type_ 3) ;; this is a parent method we won't override. This is also optional to include
)
:size-assert 8

View File

@ -89,14 +89,14 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
// offset the stack
stack_offset += xmm_backup_stack_offset;
m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm(RSP, xmm_backup_stack_offset),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
// back up xmms
int i = 0;
for (auto& saved_reg : allocs.used_saved_regs) {
if (saved_reg.is_xmm()) {
int offset = i * XMM_SIZE;
m_gen.add_instr_no_ir(f_rec, IGen::store128_xmm128_reg_offset(RSP, saved_reg, offset),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
i++;
}
}
@ -106,9 +106,9 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
for (auto& saved_reg : allocs.used_saved_regs) {
if (saved_reg.is_xmm()) {
m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm8s(RSP, XMM_SIZE),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::store128_gpr64_xmm128(RSP, saved_reg),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
stack_offset += XMM_SIZE;
}
}
@ -117,7 +117,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
// back up gprs
for (auto& saved_reg : allocs.used_saved_regs) {
if (saved_reg.is_gpr()) {
m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(saved_reg), InstructionInfo::PROLOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(saved_reg), InstructionInfo::Kind::PROLOGUE);
stack_offset += GPR_SIZE;
}
}
@ -141,7 +141,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
// otherwise to an extra push, and remember so we can do an extra pop later on.
bonus_push = true;
m_gen.add_instr_no_ir(f_rec, IGen::push_gpr64(ri.get_saved_gpr(0)),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
}
stack_offset += 8;
}
@ -151,7 +151,7 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
// do manual stack offset.
if (manually_added_stack_offset) {
m_gen.add_instr_no_ir(f_rec, IGen::sub_gpr64_imm(RSP, manually_added_stack_offset),
InstructionInfo::PROLOGUE);
InstructionInfo::Kind::PROLOGUE);
}
}
@ -209,19 +209,20 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
env->needs_aligned_stack()) {
if (manually_added_stack_offset) {
m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm(RSP, manually_added_stack_offset),
InstructionInfo::EPILOGUE);
InstructionInfo::Kind::EPILOGUE);
}
if (bonus_push) {
assert(!manually_added_stack_offset);
m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(ri.get_saved_gpr(0)), InstructionInfo::EPILOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(ri.get_saved_gpr(0)),
InstructionInfo::Kind::EPILOGUE);
}
}
for (int i = int(allocs.used_saved_regs.size()); i-- > 0;) {
auto& saved_reg = allocs.used_saved_regs.at(i);
if (saved_reg.is_gpr()) {
m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(saved_reg), InstructionInfo::EPILOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::pop_gpr64(saved_reg), InstructionInfo::Kind::EPILOGUE);
}
}
@ -234,26 +235,26 @@ void CodeGenerator::do_goal_function(FunctionEnv* env, int f_idx) {
j--;
int offset = j * XMM_SIZE;
m_gen.add_instr_no_ir(f_rec, IGen::load128_xmm128_reg_offset(saved_reg, RSP, offset),
InstructionInfo::EPILOGUE);
InstructionInfo::Kind::EPILOGUE);
}
}
assert(j == 0);
m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm(RSP, xmm_backup_stack_offset),
InstructionInfo::EPILOGUE);
InstructionInfo::Kind::EPILOGUE);
}
} else {
for (int i = int(allocs.used_saved_regs.size()); i-- > 0;) {
auto& saved_reg = allocs.used_saved_regs.at(i);
if (saved_reg.is_xmm()) {
m_gen.add_instr_no_ir(f_rec, IGen::load128_xmm128_gpr64(saved_reg, RSP),
InstructionInfo::EPILOGUE);
InstructionInfo::Kind::EPILOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::add_gpr64_imm8s(RSP, XMM_SIZE),
InstructionInfo::EPILOGUE);
InstructionInfo::Kind::EPILOGUE);
}
}
}
m_gen.add_instr_no_ir(f_rec, IGen::ret(), InstructionInfo::EPILOGUE);
m_gen.add_instr_no_ir(f_rec, IGen::ret(), InstructionInfo::Kind::EPILOGUE);
}
void CodeGenerator::do_asm_function(FunctionEnv* env, int f_idx, bool allow_saved_regs) {

View File

@ -113,7 +113,7 @@ std::string disassemble_x86_function(u8* data,
if (current_instruction_idx >= 0 && current_instruction_idx < int(x86_instructions.size())) {
const auto& debug_instr = x86_instructions.at(current_instruction_idx);
if (debug_instr.kind == InstructionInfo::IR && debug_instr.ir_idx != current_ir_idx) {
if (debug_instr.kind == InstructionInfo::Kind::IR && debug_instr.ir_idx != current_ir_idx) {
current_ir_idx = debug_instr.ir_idx;
print_ir = true;
}

View File

@ -7,7 +7,7 @@
struct InstructionInfo {
emitter::Instruction instruction; //! the actual x86 instruction
enum Kind { PROLOGUE, IR, EPILOGUE } kind;
enum class Kind { PROLOGUE, IR, EPILOGUE } kind;
int ir_idx = -1;
int offset = -1;

2
log/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore