From f952c8a373af0a71465f45f34881cc1af4337bed Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:29:12 +0100 Subject: [PATCH 1/8] Only append compiler flags in cmake --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdbcc6e5d4..69eb2bcbde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,8 @@ endif() if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) message(STATUS "Clang on MSVC detected! Adding compile flags") set(CMAKE_CXX_FLAGS - "-Xclang -fcxx-exceptions \ + "${CMAKE_CXX_FLAGS} \ + -Xclang -fcxx-exceptions \ -Xclang -fexceptions \ -Xclang -std=c++17 \ -Xclang -D_CRT_SECURE_NO_WARNINGS \ @@ -34,7 +35,7 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) endif() # linker flags - set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") elseif(UNIX) message(STATUS "GCC detected! Adding compile flags") @@ -69,10 +70,10 @@ elseif(MSVC) # set(CMAKE_CXX_FLAGS_DEBUG "/ZI") endif() # c++ flags for all build types - set(CMAKE_CXX_FLAGS "/EHsc /utf-8 /arch:AVX") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /arch:AVX") # linker flags - set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") endif() if(WIN32) From a8598176089ed7fcfcbbffe272ed9cb113bf9769 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:48:18 +0100 Subject: [PATCH 2/8] add `RelWithDebInfo-clang` windows build --- CMakeLists.txt | 3 +++ CMakePresets.json | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69eb2bcbde..081d10f5de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,9 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) # additional c++ flags for release mode for our projects if(CMAKE_BUILD_TYPE MATCHES "Release") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") endif() # linker flags diff --git a/CMakePresets.json b/CMakePresets.json index c82ad4fd9e..c3b0997d62 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -54,6 +54,25 @@ }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } } }, + { + "name": "RelWithDebInfo-clang", + "displayName": "Windows RelWithDebInfo (clang-cl)", + "description": "Target Windows with the Visual Studio development environment.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/Release", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "INSTALL_GTEST": "True", + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + }, + "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } } + }, { "name": "Debug-msvc", "displayName": "Windows Debug (msvc)", From ecd6751863daa55cd465c5823e7214f82b61d8b6 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 19:13:48 +0100 Subject: [PATCH 3/8] bump serializer initial buffer size to 32mb --- common/util/Serializer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/util/Serializer.h b/common/util/Serializer.h index f49076dfc6..fa410f607b 100644 --- a/common/util/Serializer.h +++ b/common/util/Serializer.h @@ -3,6 +3,7 @@ #include #include #include +#include "common/common_types.h" #include "common/util/Assert.h" /*! @@ -35,7 +36,7 @@ class Serializer { * later be accessed with get_save_result. */ Serializer() : m_writing(true) { - const size_t initial_size = 32; + constexpr size_t initial_size = 32 * 1024 * 1024; m_data = (u8*)malloc(initial_size); m_size = initial_size; } From b6b29aa502a90e07774fdf2907e5ae380f522a56 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 19:21:59 +0100 Subject: [PATCH 4/8] extra flags for msvc --- CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 081d10f5de..292c946e1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,10 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) -mavx \ -Wno-c++11-narrowing -Wno-c++98-compat -W3") - # additional c++ flags for release mode for our projects + # linker flags + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") + + # additional c++ and linker flags for release mode for our projects if(CMAKE_BUILD_TYPE MATCHES "Release") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") @@ -37,9 +40,6 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") endif() - # linker flags - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") - elseif(UNIX) message(STATUS "GCC detected! Adding compile flags") set(CMAKE_CXX_FLAGS @@ -77,6 +77,14 @@ elseif(MSVC) # linker flags set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384") + + # additional c++ and linker flags for specific build types + if(CMAKE_BUILD_TYPE MATCHES "Release") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") + endif() endif() if(WIN32) From 25a796641d92cb71e8798b3cf3a15690d58d5883 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 19:26:19 +0100 Subject: [PATCH 5/8] proper anaphoric goal macros --- goal_src/engine/level/level.gc | 6 +++--- goal_src/engine/load/loader.gc | 4 ++-- goal_src/engine/sound/gsound.gc | 8 ++++---- goal_src/goal-lib.gc | 20 ++++++++++++++------ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/goal_src/engine/level/level.gc b/goal_src/engine/level/level.gc index 8347779cfb..3f23b434ff 100644 --- a/goal_src/engine/level/level.gc +++ b/goal_src/engine/level/level.gc @@ -314,9 +314,9 @@ (let* ((level-info (lookup-level-info name)) (level-name (remap-level-name level-info)) ) - (swhen (level-get obj level-name) - (level-status-set! bc want-status) - (return bc) + (awhen (level-get obj level-name) + (level-status-set! it want-status) + (return it) ) (let ((a0-7 (level-get-most-disposable obj))) (set! s5-1 (if a0-7 (level-status-set! a0-7 'inactive) diff --git a/goal_src/engine/load/loader.gc b/goal_src/engine/load/loader.gc index 41cfa76e61..967a33a50c 100644 --- a/goal_src/engine/load/loader.gc +++ b/goal_src/engine/load/loader.gc @@ -553,8 +553,8 @@ "Get the status of a file in this art control. #f = file not found" (dotimes (i 2) - (swhen (file-status (-> obj buffer i) name part) - (return bc) + (awhen (file-status (-> obj buffer i) name part) + (return it) ) ) #f diff --git a/goal_src/engine/sound/gsound.gc b/goal_src/engine/sound/gsound.gc index b716839840..5a59622e14 100644 --- a/goal_src/engine/sound/gsound.gc +++ b/goal_src/engine/sound/gsound.gc @@ -544,13 +544,13 @@ ) (case (-> src type) ((entity-actor entity-ambient) - (swhen (res-lump-struct-exact (the entity src) 'effect-name symbol) - (set! name (string->sound-name (symbol->string bc))) + (awhen (res-lump-struct-exact (the entity src) 'effect-name symbol) + (set! name (string->sound-name (symbol->string it))) (set! sound-times (res-lump-data (the entity src) 'cycle-speed (pointer float))) (set! spec *ambient-spec*) (let ((tag (new 'static 'res-tag))) - (swhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag)) - (set! params bc) + (awhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag)) + (set! params it) (set! param-count (the int (-> tag elt-count))) ) ) diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index cc913939b3..aa7b6fa6f3 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -438,16 +438,23 @@ ) ) -(defmacro swhen (condition &rest body) - "Same as when, but saves the branch condition onto a variable named bc" +(defmacro aif (condition true false) + "Anaphoric if, similar to Common Lisp" - `(let ((bc ,condition)) - (if bc - (begin ,@body) + `(let ((it ,condition)) + (if it + ,true + ,false ) ) ) +(defmacro awhen (condition &rest body) + "Anaphoric when, similar to Common Lisp" + + `(aif ,condition (begin ,@body) #f) + ) + (defmacro return (val) `(return-from #f ,val) ) @@ -460,7 +467,8 @@ (defmacro case (switch &key (comp =) &rest cases) "A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially. - else can be used like the 'default' case, but it must be the last one." + else can be used like the 'default' case, but it must be the last one. + comp is the function to use when evaluating the clauses. It can be any valid head of a form (operator or call)." (with-gensyms (sw) ;; save the switch to a variable (only evaluated once) From 3efa93e21a072be887627dc6e84a5f4aadb5ac32 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 19:32:26 +0100 Subject: [PATCH 6/8] specify windows sdk version? --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 292c946e1e..53707a4370 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,9 @@ if(WIN32) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + + set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 7.1.7600.0.30514) # win7.1, supports xp + message("Windows SDK version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") endif() if(ASAN_BUILD) From f3bb1b0b3123def72d88e2d88b1ee2355a3d38c3 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 15 Apr 2022 19:56:22 +0100 Subject: [PATCH 7/8] fix "Object files are not named properly" fake error --- decompiler/ObjectFile/ObjectFileDB.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 9ed02e414a..dda918c543 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -393,11 +393,14 @@ std::string ObjectFileDB::generate_obj_listing(const std::unordered_set Date: Fri, 15 Apr 2022 23:24:44 +0100 Subject: [PATCH 8/8] Update goal-lib.gc --- goal_src/goal-lib.gc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index aa7b6fa6f3..c2ccc6b33a 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -450,7 +450,7 @@ ) (defmacro awhen (condition &rest body) - "Anaphoric when, similar to Common Lisp" + "Anaphoric when" `(aif ,condition (begin ,@body) #f) )