diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 79b8023985..0000000000 --- a/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\xtvas\Repositories\jak-project codebase based on best match to current usage at 2020-08-28 -# You can modify the rules from these initially generated values to suit your own policies -# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference -[*.cs] - diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f850d72f..5f3800e999 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ set(CMAKE_CXX_STANDARD 14) if (CMAKE_COMPILER_IS_GNUCXX) message(STATUS "GCC detected, adding compile flags") set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} \ + "${CMAKE_CXX_FLAGS} \ -Wall \ - -Winit-self \ - -ggdb \ + -Winit-self \ + -ggdb \ -Wextra \ -Wcast-align \ -Wcast-qual \ diff --git a/common/type_system/Type.cpp b/common/type_system/Type.cpp index 0c68f48d86..f6464890f8 100644 --- a/common/type_system/Type.cpp +++ b/common/type_system/Type.cpp @@ -16,7 +16,7 @@ std::string reg_kind_to_string(RegKind kind) { case RegKind::FLOAT_4X: return "float-4x"; default: - assert(false); + throw std::runtime_error("Unsupported RegKind"); } } diff --git a/decompiler/Disasm/Instruction.cpp b/decompiler/Disasm/Instruction.cpp index 59cadb9bff..721115c97f 100644 --- a/decompiler/Disasm/Instruction.cpp +++ b/decompiler/Disasm/Instruction.cpp @@ -26,7 +26,7 @@ std::string InstructionAtom::to_string(const LinkedObjectFile& file) const { case IMM_SYM: return sym; default: - assert(false); + throw std::runtime_error("Unsupported InstructionAtom"); } } diff --git a/decompiler/Disasm/Register.cpp b/decompiler/Disasm/Register.cpp index 4c8eb53c23..93ba6f1681 100644 --- a/decompiler/Disasm/Register.cpp +++ b/decompiler/Disasm/Register.cpp @@ -5,6 +5,7 @@ #include "Register.h" #include +#include //////////////////////////// // Register Name Constants @@ -126,7 +127,7 @@ const char* Register::to_charp() const { case Reg::PCR: return pcr_to_charp(get_pcr()); default: - assert(false); + throw std::runtime_error("Unsupported Register"); } } diff --git a/decompiler/Function/Function.h b/decompiler/Function/Function.h index c972496229..1e7a90db64 100644 --- a/decompiler/Function/Function.h +++ b/decompiler/Function/Function.h @@ -30,7 +30,7 @@ struct FunctionName { case FunctionKind::UNIDENTIFIED: return "(?)"; default: - assert(false); + throw std::runtime_error("Unsupported FunctionKind"); } } diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index df1fbe711f..ec6bcfc700 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -71,7 +71,7 @@ ObjectFileDB::ObjectFileDB(const std::vector& _dgos) { } printf("ObjectFileDB Initialized:\n"); - printf(" total dgos: %ld\n", _dgos.size()); + printf(" total dgos: %lld\n", _dgos.size()); printf(" total data: %d bytes\n", stats.total_dgo_bytes); printf(" total objs: %d\n", stats.total_obj_files); printf(" unique objs: %d\n", stats.unique_obj_files); diff --git a/game/kernel/kboot.cpp b/game/kernel/kboot.cpp index 03979e6f8a..d33fe4738a 100644 --- a/game/kernel/kboot.cpp +++ b/game/kernel/kboot.cpp @@ -151,7 +151,7 @@ void KernelCheckAndDispatch() { fprintf(stderr, "\n"); auto result = call_goal(Ptr(ListenerFunction->value), 0, 0, 0, s7.offset, g_ee_main_mem); - fprintf(stderr, "result of listener function: %ld\n", result); + fprintf(stderr, "result of listener function: %lld\n", result); #ifdef __linux__ cprintf("%ld\n", result); #else diff --git a/game/kernel/kprint.cpp b/game/kernel/kprint.cpp index 0fde516a49..44f1ae27a8 100644 --- a/game/kernel/kprint.cpp +++ b/game/kernel/kprint.cpp @@ -884,6 +884,8 @@ s32 format_impl(uint64_t* args) { call_method_of_type(in, type, GOAL_PRINT_METHOD); } } else { + // TODO - if we can't throw exceptions, what is the option? + // log, break and continue? throw std::runtime_error("failed to find symbol in format!"); } } diff --git a/game/runtime.cpp b/game/runtime.cpp index b53d1b19bb..bb0c7b84dc 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -123,7 +123,7 @@ void ee_runner(SystemThreadInterface& iface) { return; } - printf(" Main memory mapped at 0x%016lx\n", (u64)(g_ee_main_mem)); + printf(" Main memory mapped at 0x%016llx\n", (u64)(g_ee_main_mem)); printf(" Main memory size 0x%x bytes (%.3f MB)\n", EE_MAIN_MEM_SIZE, (double)EE_MAIN_MEM_SIZE / (1 << 20)); diff --git a/goalc/compiler/IR.cpp b/goalc/compiler/IR.cpp index e30b2d039b..81eb66b5bc 100644 --- a/goalc/compiler/IR.cpp +++ b/goalc/compiler/IR.cpp @@ -395,7 +395,7 @@ std::string IR_IntegerMath::print() { case IntegerMathKind::IDIV_32: return fmt::format("idiv {}, {}", m_dest->print(), m_arg->print()); default: - assert(false); + throw std::runtime_error("Unsupported IntegerMathKind"); } } @@ -451,7 +451,7 @@ std::string IR_FloatMath::print() { case FloatMathKind::DIV_SS: return fmt::format("divss {}, {}", m_dest->print(), m_arg->print()); default: - assert(false); + throw std::runtime_error("Unsupported FloatMathKind"); } } diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index 105e6c28ab..7c1b7c722a 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -165,7 +165,7 @@ emitter::RegKind Compiler::get_preferred_reg_kind(const TypeSpec& ts) { case RegKind::FLOAT: return emitter::RegKind::XMM; default: - assert(false); + throw std::runtime_error("Unknown preferred register kind"); } } diff --git a/goalc/compiler/Val.cpp b/goalc/compiler/Val.cpp index e280f64f40..e922c8c165 100644 --- a/goalc/compiler/Val.cpp +++ b/goalc/compiler/Val.cpp @@ -25,7 +25,7 @@ RegVal* Val::to_xmm(Env* fe) { if (rv->ireg().kind == emitter::RegKind::XMM) { return rv; } else { - assert(false); + throw std::runtime_error("Register is not an XMM[0-15] register."); } } diff --git a/goalc/compiler/compilation/Define.cpp b/goalc/compiler/compilation/Define.cpp index bb2419332a..4c24f2230d 100644 --- a/goalc/compiler/compilation/Define.cpp +++ b/goalc/compiler/compilation/Define.cpp @@ -98,5 +98,5 @@ Val* Compiler::compile_set(const goos::Object& form, const goos::Object& rest, E } else { throw_compile_error(form, "Set not implemented for this yet"); } - assert(false); + throw std::runtime_error("Unexpected error in Set"); } \ No newline at end of file diff --git a/goalc/compiler/compilation/Math.cpp b/goalc/compiler/compilation/Math.cpp index 84de857abe..e426bdb371 100644 --- a/goalc/compiler/compilation/Math.cpp +++ b/goalc/compiler/compilation/Math.cpp @@ -42,14 +42,13 @@ Val* Compiler::number_to_integer(Val* in, Env* env) { (void)env; auto ts = in->type(); if (is_binteger(ts)) { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (a binteger) to an integer."); } else if (is_float(ts)) { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (a float) to an integer."); } else if (is_integer(ts)) { return in; - } else { - throw std::runtime_error("Can't convert " + in->print() + " to an integer."); } + throw std::runtime_error("Can't convert " + in->print() + " to an integer."); } Val* Compiler::number_to_binteger(Val* in, Env* env) { @@ -58,25 +57,24 @@ Val* Compiler::number_to_binteger(Val* in, Env* env) { if (is_binteger(ts)) { return in; } else if (is_float(ts)) { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (a float) to a binteger."); } else if (is_integer(ts)) { - assert(false); - } else { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (an integer) to a binteger."); } + throw std::runtime_error("Can't convert " + in->print() + " to a binteger."); } Val* Compiler::number_to_float(Val* in, Env* env) { (void)env; auto ts = in->type(); if (is_binteger(ts)) { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (a binteger) to a float."); } else if (is_float(ts)) { return in; } else if (is_integer(ts)) { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " (an integer) to a float."); } else { - assert(false); + throw std::runtime_error("Can't convert " + in->print() + " a float."); } } @@ -89,7 +87,7 @@ Val* Compiler::to_math_type(Val* in, MathMode mode, Env* env) { case MATH_FLOAT: return number_to_float(in, env); default: - assert(false); + throw std::runtime_error("Unknown math type: " + in->print()); } } diff --git a/goalc/emitter/CodeTester.h b/goalc/emitter/CodeTester.h index ee174ac659..90d60d9a3d 100644 --- a/goalc/emitter/CodeTester.h +++ b/goalc/emitter/CodeTester.h @@ -13,6 +13,7 @@ #include "common/common_types.h" #include "Register.h" #include "Instruction.h" +#include namespace emitter { class CodeTester { @@ -67,7 +68,7 @@ class CodeTester { case 3: return R9; default: - assert(false); + throw std::runtime_error("Invalid arg register index"); } #else switch (i) { @@ -80,7 +81,7 @@ class CodeTester { case 3: return RCX; default: - assert(false); + throw std::runtime_error("Invaid arg register index"); } #endif } diff --git a/goalc/emitter/IGen.h b/goalc/emitter/IGen.h index 481e19f7b7..8dec219a5e 100644 --- a/goalc/emitter/IGen.h +++ b/goalc/emitter/IGen.h @@ -4,6 +4,7 @@ #include #include "Register.h" #include "Instruction.h" +#include namespace emitter { class IGen { @@ -1336,7 +1337,8 @@ class IGen { } else if (imm >= INT32_MIN && imm <= INT32_MAX) { return add_gpr64_imm32s(reg, imm); } else { - assert(false); + throw std::runtime_error("Invalid `add` with reg[" + reg.print() + "]/imm[" + + std::to_string(imm) + "]"); } } @@ -1346,7 +1348,8 @@ class IGen { } else if (imm >= INT32_MIN && imm <= INT32_MAX) { return sub_gpr64_imm32s(reg, imm); } else { - assert(false); + throw std::runtime_error("Invalid `sub` with reg[" + reg.print() + "]/imm[" + + std::to_string(imm) + "]"); } } diff --git a/goalc/emitter/Register.cpp b/goalc/emitter/Register.cpp index d1e745aef5..7f0648cc26 100644 --- a/goalc/emitter/Register.cpp +++ b/goalc/emitter/Register.cpp @@ -1,4 +1,5 @@ #include "Register.h" +#include namespace emitter { RegisterInfo RegisterInfo::make_register_info() { @@ -55,7 +56,7 @@ std::string to_string(RegKind kind) { case RegKind::XMM: return "xmm"; default: - assert(false); + throw std::runtime_error("Unsupported RegKind"); } } diff --git a/goalc/goos/Object.h b/goalc/goos/Object.h index 44fc1c9eef..5553c9f659 100644 --- a/goalc/goos/Object.h +++ b/goalc/goos/Object.h @@ -129,7 +129,7 @@ class FixedObject { return object_type_to_string(ObjectType::INTEGER); if (std::is_same()) return object_type_to_string(ObjectType::CHAR); - assert(false); + throw std::runtime_error("Unsupported FixedObject type"); } }; diff --git a/goalc/goos/TextDB.cpp b/goalc/goos/TextDB.cpp index 318e6b8968..6a636f74b9 100644 --- a/goalc/goos/TextDB.cpp +++ b/goalc/goos/TextDB.cpp @@ -60,7 +60,8 @@ int SourceText::get_line_idx(int offset) { return line; } } - assert(false); + throw std::runtime_error("Unable to get line index for character at position " + + std::to_string(offset)); } /*! diff --git a/goalc/regalloc/Allocator.cpp b/goalc/regalloc/Allocator.cpp index bbf70f2ad5..0cf087fce1 100644 --- a/goalc/regalloc/Allocator.cpp +++ b/goalc/regalloc/Allocator.cpp @@ -60,7 +60,7 @@ void find_basic_blocks(RegAllocCache* cache, const AllocationInput& in) { } } if (!found) { - printf("[RegAlloc Error] couldn't find basic block beginning with instr %d of %ld\n", instr, + printf("[RegAlloc Error] couldn't find basic block beginning with instr %d of %lld\n", instr, in.instructions.size()); } assert(found); @@ -612,7 +612,7 @@ const std::vector& get_default_alloc_order_for_var_spill(int } else if (info.kind == emitter::RegKind::XMM) { return emitter::gRegInfo.get_xmm_spill_alloc_order(); } else { - assert(false); + throw std::runtime_error("Unsupported RegKind"); } } @@ -624,7 +624,7 @@ const std::vector& get_default_alloc_order_for_var(int v, Reg } else if (info.kind == emitter::RegKind::XMM) { return emitter::gRegInfo.get_xmm_alloc_order(); } else { - assert(false); + throw std::runtime_error("Unsupported RegKind"); } } diff --git a/third-party/fmt/CMakeLists.txt b/third-party/fmt/CMakeLists.txt index 9e4c817387..8c9003855f 100644 --- a/third-party/fmt/CMakeLists.txt +++ b/third-party/fmt/CMakeLists.txt @@ -1,4 +1,8 @@ -set(CMAKE_CXX_FLAGS "-O3") +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "-O3") +else () + set(CMAKE_CXX_FLAGS "/EHsc") +endif (CMAKE_COMPILER_IS_GNUCXX) include_directories(../) add_library(fmt SHARED format.cc) \ No newline at end of file