From 28a2ecdfd392e70f1fcfad35bd6ba701ab60de06 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 6 Jul 2022 21:18:08 -0400 Subject: [PATCH] [jak2] goalc supports multiple projects (#1619) * [jak2] goalc supports multiple projects * disable deci2 server if not debugging --- common/CMakeLists.txt | 1 + common/versions.cpp | 15 +++++ common/versions.h | 6 +- decompiler/extractor/main.cpp | 2 +- game/kernel/jak1/kmachine.cpp | 4 ++ game/runtime.cpp | 5 +- game/sce/deci2.cpp | 4 ++ game/sce/deci2.h | 1 + game/system/Deci2Server.cpp | 17 ++++-- game/system/Deci2Server.h | 4 +- goal_src/goal-lib.gc | 35 +++++------- goal_src/jak1/compiler-setup.gc | 18 ++++++ goal_src/jak1/kernel-defs.gc | 18 +++--- goal_src/jak2/compiler-setup.gc | 10 ++++ goal_src/jak2/game.gp | 0 goal_src/jak2/kernel-defs.gc | 77 ++++++++++++++++++++++++++ goalc/compiler/Compiler.cpp | 11 +++- goalc/compiler/Compiler.h | 5 +- goalc/main.cpp | 9 ++- test/goalc/test_arithmetic.cpp | 2 +- test/goalc/test_collections.cpp | 2 +- test/goalc/test_compiler.cpp | 3 +- test/goalc/test_control_statements.cpp | 2 +- test/goalc/test_debugger.cpp | 24 ++++---- test/goalc/test_game_no_debug.cpp | 6 +- test/goalc/test_goal_kernel.cpp | 15 ++--- test/goalc/test_variables.cpp | 3 +- test/goalc/test_with_game.cpp | 14 +++-- test/offline/offline_test_main.cpp | 7 ++- 29 files changed, 239 insertions(+), 81 deletions(-) create mode 100644 common/versions.cpp create mode 100644 goal_src/jak1/compiler-setup.gc create mode 100644 goal_src/jak2/compiler-setup.gc create mode 100644 goal_src/jak2/game.gp create mode 100644 goal_src/jak2/kernel-defs.gc diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7de2ece8b..a449be7a6 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(common + versions.cpp audio/audio_formats.cpp cross_os_debug/xdbg.cpp cross_sockets/XSocket.cpp diff --git a/common/versions.cpp b/common/versions.cpp new file mode 100644 index 000000000..ec3aac7e3 --- /dev/null +++ b/common/versions.cpp @@ -0,0 +1,15 @@ +#include "versions.h" + +#include "common/util/Assert.h" + +#include "third-party/fmt/core.h" + +GameVersion game_name_to_version(const std::string& name) { + if (name == "jak1") { + return GameVersion::Jak1; + } else if (name == "jak2") { + return GameVersion::Jak2; + } else { + ASSERT_MSG(false, fmt::format("invalid game name: {}", name)); + } +} \ No newline at end of file diff --git a/common/versions.h b/common/versions.h index 4f27f72a5..1345dc43f 100644 --- a/common/versions.h +++ b/common/versions.h @@ -5,6 +5,8 @@ * Version numbers for GOAL Language, Kernel, etc... */ +#include + #include "common/common_types.h" namespace versions { @@ -48,4 +50,6 @@ struct PerGameVersion { T data[2]; }; -constexpr PerGameVersion game_version_names = {"jak1", "jak2"}; \ No newline at end of file +constexpr PerGameVersion game_version_names = {"jak1", "jak2"}; + +GameVersion game_name_to_version(const std::string& name); \ No newline at end of file diff --git a/decompiler/extractor/main.cpp b/decompiler/extractor/main.cpp index b06c7aecb..bc2109eda 100644 --- a/decompiler/extractor/main.cpp +++ b/decompiler/extractor/main.cpp @@ -193,7 +193,7 @@ ExtractorErrorCode compile(const fs::path& iso_data_path, const std::string& dat // Determine which config to use from the database const auto version_info = get_version_info_or_default(iso_data_path); - Compiler compiler; + Compiler compiler(game_name_to_version(version_info.game_name)); compiler.make_system().set_constant("*iso-data*", absolute(iso_data_path).string()); compiler.make_system().set_constant("*use-iso-data-path*", true); diff --git a/game/kernel/jak1/kmachine.cpp b/game/kernel/jak1/kmachine.cpp index 453f821dd..2bf0d8abd 100644 --- a/game/kernel/jak1/kmachine.cpp +++ b/game/kernel/jak1/kmachine.cpp @@ -37,6 +37,7 @@ #include "game/kernel/jak1/ksound.h" #include "game/kernel/svnrev.h" #include "game/mips2c/mips2c_table.h" +#include "game/sce/deci2.h" #include "game/sce/libcdvd_ee.h" #include "game/sce/libdma.h" #include "game/sce/libgraph.h" @@ -336,6 +337,9 @@ int InitMachine() { if (MasterDebug) { // connect to GOAL compiler InitGoalProto(); + } else { + // shut down the deci2 stuff, we don't need it. + ee::sceDeci2Disable(); } lg::info("InitSound"); diff --git a/game/runtime.cpp b/game/runtime.cpp index c77ceaf34..5883c7154 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -92,7 +92,10 @@ void deci2_runner(SystemThreadInterface& iface) { // in our own thread, wait for the EE to register the first protocol driver lg::debug("[DECI2] Waiting for EE to register protos"); - server.wait_for_protos_ready(); + if (!server.wait_for_protos_ready()) { + // requested shutdown before protos became ready. + return; + } // then allow the server to accept connections bool server_ok = server.init_server(); if (!server_ok) { diff --git a/game/sce/deci2.cpp b/game/sce/deci2.cpp index 6a41dcaa5..2c6d513a4 100644 --- a/game/sce/deci2.cpp +++ b/game/sce/deci2.cpp @@ -137,4 +137,8 @@ s32 sceDeci2ExSend(s32 s, void* buf, u16 len) { server->send_data(buf, len); return len; } + +void sceDeci2Disable() { + server->send_shutdown(); +} } // namespace ee diff --git a/game/sce/deci2.h b/game/sce/deci2.h index 0bc71609d..3bccab543 100644 --- a/game/sce/deci2.h +++ b/game/sce/deci2.h @@ -20,5 +20,6 @@ s32 sceDeci2Close(s32 s); s32 sceDeci2ReqSend(s32 s, char dest); s32 sceDeci2ExRecv(s32 s, void* buf, u16 len); s32 sceDeci2ExSend(s32 s, void* buf, u16 len); +void sceDeci2Disable(); } // namespace ee diff --git a/game/system/Deci2Server.cpp b/game/system/Deci2Server.cpp index 5519e6d6f..54ae18a14 100644 --- a/game/system/Deci2Server.cpp +++ b/game/system/Deci2Server.cpp @@ -66,11 +66,20 @@ bool Deci2Server::is_client_connected() { * Wait for protocols to become ready. * This avoids the case where we receive messages before protocol handlers are set up. */ -void Deci2Server::wait_for_protos_ready() { - if (protocols_ready) - return; +bool Deci2Server::wait_for_protos_ready() { + if (protocols_ready || want_shutdown) { + return !want_shutdown; + } std::unique_lock lk(server_mutex); - cv.wait(lk, [&] { return protocols_ready; }); + cv.wait(lk, [&] { return protocols_ready || want_shutdown; }); + return !want_shutdown; +} + +void Deci2Server::send_shutdown() { + lock(); + want_shutdown = true; + unlock(); + cv.notify_all(); } /*! diff --git a/game/system/Deci2Server.h b/game/system/Deci2Server.h index ee37e7410..7e89294f6 100644 --- a/game/system/Deci2Server.h +++ b/game/system/Deci2Server.h @@ -19,8 +19,9 @@ class Deci2Server : public XSocketServer { void send_data(void* buf, u16 len); bool is_client_connected(); - void wait_for_protos_ready(); + bool wait_for_protos_ready(); // return true if ready, false if we should shut down. void send_proto_ready(Deci2Driver* drivers, int* driver_count); + void send_shutdown(); void lock(); void unlock(); @@ -29,6 +30,7 @@ class Deci2Server : public XSocketServer { void accept_thread_func(); private: + bool want_shutdown = false; bool protocols_ready = false; std::condition_variable cv; Deci2Driver* d2_drivers = nullptr; diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index b0f1dcacc..bb71cc2c8 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -1,13 +1,5 @@ ;;-*-Lisp-*- - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; OTHER STUFF -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; tell compiler about stuff defined/implemented in the runtime. -(asm-file "goal_src/jak1/kernel-defs.gc") - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; BUILD SYSTEM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -38,10 +30,6 @@ `(asm-file ,file :no-code) ) - -(defmacro load-art-import (name) - `(asm-file ,(string-append "goal_src/jak1/import/" (symbol->string name) "-ag.gc") :no-code :no-throw)) - (defmacro load-imports () `(begin ,@(apply run-frontend-command all-import-files) @@ -1044,14 +1032,17 @@ `(defconstant ,name (-> self draw art-group data ,idx)) ) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Load Project +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;; build system stuff -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; hack to get a goos variable in goal -(defmacro __get_jak1_full_game () *jak1-full-game*) -(defconstant *jak1-full-game* (__get_jak1_full_game)) - -;; todo: loading jak1 by default -(load-project "goal_src/jak1/game.gp") +(#cond + ((eq? GAME_VERSION 'jak1) + (asm-file "goal_src/jak1/compiler-setup.gc") + (seval (fmt #t "Jak 1 Mode\n")) + ) + ((eq? GAME_VERSION 'jak2) + (asm-file "goal_src/jak2/compiler-setup.gc") + (seval (fmt #t "Jak 2 Mode\n")) + ) + ) diff --git a/goal_src/jak1/compiler-setup.gc b/goal_src/jak1/compiler-setup.gc new file mode 100644 index 000000000..ad424e8b6 --- /dev/null +++ b/goal_src/jak1/compiler-setup.gc @@ -0,0 +1,18 @@ +;; +;; Compiler Setup for Jak 1 +;; + +;; load kernel type definitions. +;; these types/functions are provided by Jak 1's runtime. +(asm-file "goal_src/jak1/kernel-defs.gc") + +;; load jak 1 project +(load-project "goal_src/jak1/game.gp") + +;; jak 1 - specific library stuff. + +(defmacro __get_jak1_full_game () *jak1-full-game*) +(defconstant *jak1-full-game* (__get_jak1_full_game)) + +(defmacro load-art-import (name) + `(asm-file ,(string-append "goal_src/jak1/import/" (symbol->string name) "-ag.gc") :no-code :no-throw)) \ No newline at end of file diff --git a/goal_src/jak1/kernel-defs.gc b/goal_src/jak1/kernel-defs.gc index e5b3e7e06..4c62e4d1c 100644 --- a/goal_src/jak1/kernel-defs.gc +++ b/goal_src/jak1/kernel-defs.gc @@ -75,15 +75,15 @@ ) (defenum link-flag - :bitfield #t - :type int32 - (output-load-msg 0) - (output-load-true-msg 1) - (execute-login 2) - (print-login 3) - (force-debug 4) - (fast-link 5) - ) + :bitfield #t + :type int32 + (output-load-msg 0) + (output-load-true-msg 1) + (execute-login 2) + (print-login 3) + (force-debug 4) + (fast-link 5) + ) (define-extern string->symbol (function string symbol)) diff --git a/goal_src/jak2/compiler-setup.gc b/goal_src/jak2/compiler-setup.gc new file mode 100644 index 000000000..2ce625a35 --- /dev/null +++ b/goal_src/jak2/compiler-setup.gc @@ -0,0 +1,10 @@ +;; +;; Compiler Setup for Jak 2 +;; + +;; load kernel type definitions. +;; these types/functions are provided by Jak 2's runtime. +(asm-file "goal_src/jak2/kernel-defs.gc") + +;; load jak 1 project +(load-project "goal_src/jak2/game.gp") \ No newline at end of file diff --git a/goal_src/jak2/game.gp b/goal_src/jak2/game.gp new file mode 100644 index 000000000..e69de29bb diff --git a/goal_src/jak2/kernel-defs.gc b/goal_src/jak2/kernel-defs.gc new file mode 100644 index 000000000..265e0d2d2 --- /dev/null +++ b/goal_src/jak2/kernel-defs.gc @@ -0,0 +1,77 @@ +;; kernel-defs.gc +;; everything defined in the C Kernel / runtime + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; kscheme - InitHeapAndSymbol +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; fixed symbols +(define-extern #f symbol) +(define-extern #t symbol) +(define-extern function type) +(define-extern basic type) +(define-extern string type) +(define-extern symbol type) +(define-extern type type) +(define-extern object type) +(define-extern link-block type) +(define-extern integer type) +(define-extern sinteger type) +(define-extern uinteger type) +(define-extern binteger type) +(define-extern int8 type) +(define-extern int16 type) +(define-extern int32 type) +(define-extern int64 type) +(define-extern int128 type) +(define-extern uint8 type) +(define-extern uint16 type) +(define-extern uint32 type) +(define-extern uint64 type) +(define-extern uint128 type) +(define-extern float type) +(define-extern process-tree type) +(define-extern process type) +(define-extern thread type) +(define-extern structure type) +(define-extern pair type) +(define-extern pointer type) +(define-extern number type) +(define-extern array type) +(define-extern vu-function type) +(define-extern connectable type) +(define-extern stack-frame type) +(define-extern file-stream type) +(define-extern kheap type) +(define-extern nothing (function none)) +(define-extern delete-basic (function basic none)) +(define-extern static symbol) +(define-extern global kheap) +(define-extern debug kheap) +(define-extern loading-level kheap) ;; not a kheap at boot +(define-extern loading-package kheap) ;; not a kheap at boot +(define-extern process-level-heap kheap) ;; not a kheap at boot +(define-extern stack symbol) +(define-extern scratch symbol) +(define-extern *stratch-top* pointer) +(define-extern zero-func (function int)) + +(defenum kmalloc-flags + :bitfield #t + (align-16 4) + (align-64 6) + (align-256 8) + (memset 12) + (top 13) + ) + +(defenum link-flag + :bitfield #t + :type int32 + (output-load-msg 0) + (output-load-true-msg 1) + (execute-login 2) + (print-login 3) + (force-debug 4) + (fast-link 5) + ) \ No newline at end of file diff --git a/goalc/compiler/Compiler.cpp b/goalc/compiler/Compiler.cpp index 3d196c0c3..60584de4e 100644 --- a/goalc/compiler/Compiler.cpp +++ b/goalc/compiler/Compiler.cpp @@ -18,8 +18,11 @@ using namespace goos; -Compiler::Compiler(const std::string& user_profile, std::unique_ptr repl) - : m_goos(user_profile), +Compiler::Compiler(GameVersion version, + const std::string& user_profile, + std::unique_ptr repl) + : m_version(version), + m_goos(user_profile), m_debugger(&m_listener, &m_goos.reader), m_repl(std::move(repl)), m_make(user_profile) { @@ -31,8 +34,10 @@ Compiler::Compiler(const std::string& user_profile, std::unique_ptr // let the build system run us m_make.add_tool(std::make_shared(this)); + // define game version before loading goal-lib.gc + m_goos.set_global_variable_by_name("GAME_VERSION", m_goos.intern(game_version_names[m_version])); + // load GOAL library - // TODO - Jak2 - BAD! Object library_code = m_goos.reader.read_from_file({"goal_src", "goal-lib.gc"}); compile_object_file("goal-lib", library_code, false); diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index 7a58808bc..64404e495 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -39,7 +39,9 @@ struct CompilationOptions { class Compiler { public: - Compiler(const std::string& user_profile = "#f", std::unique_ptr repl = nullptr); + Compiler(GameVersion version, + const std::string& user_profile = "#f", + std::unique_ptr repl = nullptr); ~Compiler(); void asm_file(const CompilationOptions& options); @@ -90,6 +92,7 @@ class Compiler { MakeSystem& make_system() { return m_make; } private: + GameVersion m_version; TypeSystem m_ts; std::unique_ptr m_global_env = nullptr; std::unique_ptr m_none = nullptr; diff --git a/goalc/main.cpp b/goalc/main.cpp index 4d85a173a..4dd6cdd2c 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -28,6 +28,7 @@ int main(int argc, char** argv) { std::string cmd = ""; std::string startup_cmd = ""; std::string username = "#f"; + std::string game = "jak1"; int nrepl_port = 8181; CLI::App app{"OpenGOAL Compiler / REPL"}; @@ -43,6 +44,7 @@ int main(int argc, char** argv) { "Attempt to automatically connect to the debugger on startup"); app.add_flag("--user-auto", auto_find_user, "Attempt to automatically deduce the user, overrides '-user'"); + app.add_option("-g,--game", game, "The game name: 'jak1' or 'jak2'"); app.validate_positionals(); CLI11_PARSE(app, argc, argv); @@ -50,6 +52,8 @@ int main(int argc, char** argv) { return 1; } + GameVersion game_version = game_name_to_version(game); + if (auto_find_user) { username = "#f"; std::regex allowed_chars("[0-9a-zA-Z\\-\\.\\!\\?<>]"); @@ -91,7 +95,7 @@ int main(int argc, char** argv) { std::mutex compiler_mutex; // if a command is provided on the command line, no REPL just run the compiler on it if (!cmd.empty()) { - compiler = std::make_unique(); + compiler = std::make_unique(game_version); compiler->run_front_end_on_string(cmd); return 0; } @@ -127,7 +131,8 @@ int main(int argc, char** argv) { if (compiler) { compiler->save_repl_history(); } - compiler = std::make_unique(username, std::make_unique()); + compiler = + std::make_unique(game_version, username, std::make_unique()); if (!startup_cmd.empty()) { compiler->handle_repl_string(startup_cmd); // reset to prevent re-executing on manual reload diff --git a/test/goalc/test_arithmetic.cpp b/test/goalc/test_arithmetic.cpp index e7740c77a..450009aed 100644 --- a/test/goalc/test_arithmetic.cpp +++ b/test/goalc/test_arithmetic.cpp @@ -120,7 +120,7 @@ class ArithmeticTests : public testing::TestWithParam { // Called before the first test in this test suite. static void SetUpTestSuite() { runtime_thread = std::make_unique(std::thread((GoalTest::runtime_no_kernel))); - compiler = std::make_unique(); + compiler = std::make_unique(GameVersion::Jak1); runner = std::make_unique(); runner->c = compiler.get(); } diff --git a/test/goalc/test_collections.cpp b/test/goalc/test_collections.cpp index 9a7b2123f..887eb498a 100644 --- a/test/goalc/test_collections.cpp +++ b/test/goalc/test_collections.cpp @@ -24,7 +24,7 @@ class CollectionTests : public testing::TestWithParam { public: static void SetUpTestSuite() { runtime_thread = std::make_unique(std::thread((GoalTest::runtime_no_kernel))); - compiler = std::make_unique(); + compiler = std::make_unique(GameVersion::Jak1); runner = std::make_unique(); runner->c = compiler.get(); } diff --git a/test/goalc/test_compiler.cpp b/test/goalc/test_compiler.cpp index 3ac88d8ee..896d04b57 100644 --- a/test/goalc/test_compiler.cpp +++ b/test/goalc/test_compiler.cpp @@ -7,5 +7,6 @@ #include "gtest/gtest.h" TEST(CompilerAndRuntime, ConstructCompiler) { - Compiler compiler; + Compiler compiler1(GameVersion::Jak1); + Compiler compiler2(GameVersion::Jak2); } \ No newline at end of file diff --git a/test/goalc/test_control_statements.cpp b/test/goalc/test_control_statements.cpp index 496a92f23..72d8071fb 100644 --- a/test/goalc/test_control_statements.cpp +++ b/test/goalc/test_control_statements.cpp @@ -24,7 +24,7 @@ class ControlStatementTests : public testing::TestWithParam(std::thread((GoalTest::runtime_no_kernel))); - compiler = std::make_unique(); + compiler = std::make_unique(GameVersion::Jak1); runner = std::make_unique(); runner->c = compiler.get(); } diff --git a/test/goalc/test_debugger.cpp b/test/goalc/test_debugger.cpp index 0feadb25d..270773be8 100644 --- a/test/goalc/test_debugger.cpp +++ b/test/goalc/test_debugger.cpp @@ -33,8 +33,8 @@ void connect_compiler_and_debugger(Compiler& compiler, bool do_break) { } } } // namespace -TEST(Debugger, DebuggerBasicConnect) { - Compiler compiler; +TEST(Jak1Debugger, DebuggerBasicConnect) { + Compiler compiler(GameVersion::Jak1); // evidently you can't ptrace threads in your own process, so we need to run the runtime in a // separate process. if (!fork()) { @@ -50,8 +50,8 @@ TEST(Debugger, DebuggerBasicConnect) { } } -TEST(Debugger, DebuggerBreakAndContinue) { - Compiler compiler; +TEST(Jak1Debugger, DebuggerBreakAndContinue) { + Compiler compiler(GameVersion::Jak1); // evidently you can't ptrace threads in your own process, so we need to run the runtime in a // separate process. if (!fork()) { @@ -72,8 +72,8 @@ TEST(Debugger, DebuggerBreakAndContinue) { } } -TEST(Debugger, DebuggerReadMemory) { - Compiler compiler; +TEST(Jak1Debugger, DebuggerReadMemory) { + Compiler compiler(GameVersion::Jak1); // evidently you can't ptrace threads in your own process, so we need to run the runtime in a // separate process. if (!fork()) { @@ -96,8 +96,8 @@ TEST(Debugger, DebuggerReadMemory) { } } -TEST(Debugger, DebuggerWriteMemory) { - Compiler compiler; +TEST(Jak1Debugger, DebuggerWriteMemory) { + Compiler compiler(GameVersion::Jak1); // evidently you can't ptrace threads in your own process, so we need to run the runtime in a // separate process. if (!fork()) { @@ -127,8 +127,8 @@ TEST(Debugger, DebuggerWriteMemory) { } } -TEST(Debugger, Symbol) { - Compiler compiler; +TEST(Jak1Debugger, Symbol) { + Compiler compiler(GameVersion::Jak1); // evidently you can't ptrace threads in your own process, so we need to run the runtime in a // separate process. if (!fork()) { @@ -158,8 +158,8 @@ TEST(Debugger, Symbol) { } } -TEST(Debugger, SimpleBreakpoint) { - Compiler compiler; +TEST(Jak1Debugger, SimpleBreakpoint) { + Compiler compiler(GameVersion::Jak1); if (!fork()) { GoalTest::runtime_no_kernel(); diff --git a/test/goalc/test_game_no_debug.cpp b/test/goalc/test_game_no_debug.cpp index d71790579..2a81df8c0 100644 --- a/test/goalc/test_game_no_debug.cpp +++ b/test/goalc/test_game_no_debug.cpp @@ -1,11 +1,11 @@ -// Test the game running without loading debug segments. +// Test jak1 running without loading debug segments. #include "goalc/compiler/Compiler.h" #include "gtest/gtest.h" #include "test/goalc/framework/test_runner.h" -TEST(GameNoDebugSegment, Init) { - Compiler compiler; +TEST(Jak1NoDebugSegment, Init) { + Compiler compiler(GameVersion::Jak1); compiler.run_front_end_on_string("(build-kernel)"); std::thread runtime_thread = std::thread(GoalTest::runtime_with_kernel_no_debug_segment); diff --git a/test/goalc/test_goal_kernel.cpp b/test/goalc/test_goal_kernel.cpp index 2e72432b7..6796b7bbb 100644 --- a/test/goalc/test_goal_kernel.cpp +++ b/test/goalc/test_goal_kernel.cpp @@ -5,10 +5,10 @@ #include "gtest/gtest.h" #include "test/goalc/framework/test_runner.h" -class KernelTest : public testing::Test { +class Jak1KernelTest : public testing::Test { public: static void SetUpTestSuite() { - shared_compiler = std::make_unique(); + shared_compiler = std::make_unique(GameVersion::Jak1); printf("Building kernel...\n"); try { // a macro in goal-lib.gc @@ -37,6 +37,7 @@ class KernelTest : public testing::Test { void TearDown() {} struct SharedCompiler { + SharedCompiler(GameVersion v) : compiler(v) {} std::thread runtime_thread; Compiler compiler; GoalTest::CompilerTestRunner runner; @@ -45,7 +46,7 @@ class KernelTest : public testing::Test { static std::unique_ptr shared_compiler; }; -std::unique_ptr KernelTest::shared_compiler; +std::unique_ptr Jak1KernelTest::shared_compiler; namespace { std::string send_code_and_get_multiple_responses(const std::string& code, @@ -70,7 +71,7 @@ std::string send_code_and_get_multiple_responses(const std::string& code, } } // namespace -TEST_F(KernelTest, Basic) { +TEST_F(Jak1KernelTest, Basic) { shared_compiler->runner.c->run_test_from_string( "(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")"); std::string result = @@ -102,7 +103,7 @@ TEST_F(KernelTest, Basic) { EXPECT_EQ(expected, result); } -TEST_F(KernelTest, RunFunctionInProcess) { +TEST_F(Jak1KernelTest, RunFunctionInProcess) { shared_compiler->runner.c->run_test_from_string( "(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")"); std::string result = @@ -121,7 +122,7 @@ TEST_F(KernelTest, RunFunctionInProcess) { EXPECT_EQ(expected, result); } -TEST_F(KernelTest, StateAndXmm) { +TEST_F(Jak1KernelTest, StateAndXmm) { shared_compiler->runner.c->run_test_from_string( "(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")"); std::string result = @@ -135,7 +136,7 @@ TEST_F(KernelTest, StateAndXmm) { EXPECT_EQ(expected, result); } -TEST_F(KernelTest, ThrowXmm) { +TEST_F(Jak1KernelTest, ThrowXmm) { shared_compiler->runner.c->run_test_from_string( "(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")"); std::string result = diff --git a/test/goalc/test_variables.cpp b/test/goalc/test_variables.cpp index 7aa1271cf..420a2e2a4 100644 --- a/test/goalc/test_variables.cpp +++ b/test/goalc/test_variables.cpp @@ -23,7 +23,7 @@ struct VariableParam { class VariableTests : public testing::TestWithParam { public: static void SetUpTestSuite() { - shared_compiler = std::make_unique(); + shared_compiler = std::make_unique(GameVersion::Jak1); shared_compiler->runtime_thread = std::thread((GoalTest::runtime_no_kernel)); shared_compiler->runner.c = &shared_compiler->compiler; } @@ -42,6 +42,7 @@ class VariableTests : public testing::TestWithParam { void TearDown() {} struct SharedCompiler { + SharedCompiler(GameVersion version) : compiler(version) {} std::thread runtime_thread; Compiler compiler; GoalTest::CompilerTestRunner runner; diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index ed9bcc683..ac1562013 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -24,7 +24,7 @@ class WithGameTests : public ::testing::Test { public: static void SetUpTestSuite() { - shared_compiler = std::make_unique(); + shared_compiler = std::make_unique(GameVersion::Jak1); try { shared_compiler->compiler.run_test_no_load( "test/goalc/source_templates/with_game/test-build-game.gc"); @@ -56,6 +56,7 @@ class WithGameTests : public ::testing::Test { void TearDown() {} struct SharedCompiler { + SharedCompiler(GameVersion v) : compiler(v) {} std::thread runtime_thread; Compiler compiler; GoalTest::CompilerTestRunner runner; @@ -73,7 +74,7 @@ std::unique_ptr WithGameTests::shared_compiler; class WithMinimalGameTests : public ::testing::Test { public: static void SetUpTestSuite() { - shared_compiler = std::make_unique(); + shared_compiler = std::make_unique(GameVersion::Jak1); try { shared_compiler->compiler.run_front_end_on_string("(build-kernel)"); } catch (std::exception& e) { @@ -109,6 +110,7 @@ class WithMinimalGameTests : public ::testing::Test { void TearDown() {} struct SharedCompiler { + SharedCompiler(GameVersion v) : compiler(v) {} std::thread runtime_thread; Compiler compiler; GoalTest::CompilerTestRunner runner; @@ -943,16 +945,16 @@ void add_expected_type_mismatches(Compiler& c) { c.add_ignored_define_extern_symbol("tfrag-init-buffer"); } -TEST(TypeConsistency, MANUAL_TEST_TypeConsistencyWithBuildFirst) { - Compiler compiler; +TEST(Jak1TypeConsistency, MANUAL_TEST_TypeConsistencyWithBuildFirst) { + Compiler compiler(GameVersion::Jak1); compiler.enable_throw_on_redefines(); add_expected_type_mismatches(compiler); compiler.run_test_no_load("test/goalc/source_templates/with_game/test-build-all-code.gc"); compiler.run_test_no_load("decompiler/config/all-types.gc"); } -TEST(TypeConsistency, TypeConsistency) { - Compiler compiler; +TEST(Jak1TypeConsistency, TypeConsistency) { + Compiler compiler(GameVersion::Jak1); compiler.enable_throw_on_redefines(); add_expected_type_mismatches(compiler); compiler.run_test_no_load("decompiler/config/all-types.gc"); diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index 0499a3477..7ced28357 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -49,8 +49,9 @@ std::unordered_map game_name_to_config = { // TODO - i think these should be partitioned by game name instead of it being in the filename // (and the names not being consistent) -std::unordered_map game_name_to_all_types = {{"jak1", "all-types.gc"}, - {"jak2", "all-types2.gc"}}; +std::unordered_map game_name_to_all_types = { + {"jak1", "all-types.gc"}, + {"jak2", "jak2/all-types.gc"}}; Decompiler setup_decompiler(const std::vector& files, const std::vector& art_files, @@ -197,7 +198,7 @@ bool compile(Decompiler& dc, const OfflineTestConfig& config, const std::string& game_name) { fmt::print("Setting up compiler...\n"); - Compiler compiler; + Compiler compiler(game_name_to_version(game_name)); compiler.run_front_end_on_file({"decompiler", "config", game_name_to_all_types[game_name]}); compiler.run_front_end_on_file(