diff --git a/README.md b/README.md index 31ab43a1f..f348e997b 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1725. +This is the source code for early-access 1730. ## Legal Notice diff --git a/externals/dynarmic/.clang-format b/externals/dynarmic/.clang-format new file mode 100755 index 000000000..5c5555eae --- /dev/null +++ b/externals/dynarmic/.clang-format @@ -0,0 +1,218 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: Right +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: false +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakBeforeInheritanceComma: false +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +# EmptyLineAfterAccessModifier: Leave +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '(^)|(^)|(^)' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<([^\.])*>$' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 4 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +# IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: NoIndent +IndentGotoLabels: false +IndentPPDirectives: AfterHash +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +# InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +NamespaceMacros: +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +# ShortNamespaceLines: 5 +SortIncludes: true +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +# SpacesInLineCommentPrefix: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +TypenameMacros: +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME + - FCODE + - ICODE +... + diff --git a/externals/dynarmic/CMakeLists.txt b/externals/dynarmic/CMakeLists.txt index e51b764ae..c62398ee0 100755 --- a/externals/dynarmic/CMakeLists.txt +++ b/externals/dynarmic/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.8) -project(dynarmic C CXX) +project(dynarmic C CXX ASM) # Determine if we're built as a subproject (using add_subdirectory) # or if this is the master project. @@ -140,7 +140,7 @@ endif() add_subdirectory(externals) # Dynarmic project files -add_subdirectory(src) +add_subdirectory(src/dynarmic) if (DYNARMIC_TESTS) add_subdirectory(tests) endif() diff --git a/externals/dynarmic/README.md b/externals/dynarmic/README.md index 3202a1413..b5b5533a3 100755 --- a/externals/dynarmic/README.md +++ b/externals/dynarmic/README.md @@ -7,7 +7,8 @@ A dynamic recompiler for ARM. ### Supported guest architectures -* ARMv6K +* ARMv6K, ARMv7A +* 32-bit ARMv8 * 64-bit ARMv8 ### Supported host architectures @@ -16,6 +17,15 @@ A dynamic recompiler for ARM. There are no plans to support x86-32. +Projects using Dynarmic +----------------------- + +* [Citra - Nintendo 3DS emulator](https://citra-emu.org) +* [yuzu - Nintendo Switch emulator](https://yuzu-emu.org) +* [EKA2L1 - An Experimental Symbian OS emulator](https://github.com/EKA2L1/EKA2L1) +* [Vita3K - An Experimental PSVita emulator](https://vita3k.org) +* [unidbg - Android native library emulation, with experimental iOS emulation](https://github.com/zhkl0228/unidbg) + Alternatives to Dynarmic ------------------------ @@ -84,8 +94,8 @@ The below is a minimal example. Bring-your-own memory system. #include #include -#include -#include +#include "dynarmic/interface/A32/a32.h" +#include "dynarmic/interface/A32/config.h" using u8 = std::uint8_t; using u16 = std::uint16_t; @@ -350,3 +360,30 @@ THE POSSIBILITY OF SUCH DAMAGE. 損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、 一切責任を負わないものとします。 ``` + +### zydis + +``` +The MIT License (MIT) + +Copyright (c) 2014-2020 Florian Bernd +Copyright (c) 2014-2020 Joel Höner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/externals/dynarmic/externals/CMakeLists.txt b/externals/dynarmic/externals/CMakeLists.txt index e5bbb9362..9419e1da6 100755 --- a/externals/dynarmic/externals/CMakeLists.txt +++ b/externals/dynarmic/externals/CMakeLists.txt @@ -40,3 +40,10 @@ if (NOT TARGET xbyak) target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES) endif() endif() + +# zydis + +option(ZYDIS_BUILD_TOOLS "" OFF) +option(ZYDIS_BUILD_EXAMPLES "" OFF) +set(ZYDIS_ZYCORE_PATH "${CMAKE_CURRENT_LIST_DIR}/zycore" CACHE PATH "") +add_subdirectory(zydis) diff --git a/externals/dynarmic/externals/README.md b/externals/dynarmic/externals/README.md index c1caca557..94ba26b0b 100755 --- a/externals/dynarmic/externals/README.md +++ b/externals/dynarmic/externals/README.md @@ -8,6 +8,8 @@ git remote add externals-mp https://github.com/MerryMage/mp.git --no-tags git remote add externals-robin-map https://github.com/Tessil/robin-map.git --no-tags git remote add externals-vixl https://git.linaro.org/arm/vixl.git --no-tags git remote add externals-xbyak https://github.com/herumi/xbyak.git --no-tags +git remote add externals-zycore https://github.com/zyantific/zycore-c.git --no-tags +git remote add externals-zydis https://github.com/zyantific/zydis.git --no-tags ``` ## Updating @@ -20,9 +22,13 @@ git fetch externals-mp git fetch externals-robin-map git fetch externals-vixl git fetch externals-xbyak +git fetch externals-zycore +git fetch externals-zydis git subtree pull --squash --prefix=externals/fmt externals-fmt git subtree pull --squash --prefix=externals/mp externals-mp git subtree pull --squash --prefix=externals/robin-map externals-robin-map git subtree pull --squash --prefix=externals/vixl/vixl externals-vixl git subtree pull --squash --prefix=externals/xbyak externals-xbyak +git subtree pull --squash --prefix=externals/zycore externals-zycore +git subtree pull --squash --prefix=externals/zydis externals-zydis ``` diff --git a/externals/dynarmic/externals/zycore/.gitignore b/externals/dynarmic/externals/zycore/.gitignore new file mode 100755 index 000000000..8941d9733 --- /dev/null +++ b/externals/dynarmic/externals/zycore/.gitignore @@ -0,0 +1,100 @@ +# Created by https://www.gitignore.io/api/c,c++,cmake + +### C ### +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su + + +### C++ ### +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + + +### CMake ### +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake + + +# MacOS +.DS_Store + +build* + +# MSVC +.vs +*.vcxproj.user +*.suo +*.sdf +*.opensdf +*.VC.db +*.VC.opendb +msvc/**/obj/ +msvc/**/bin/ + +doc/html + +/.vscode +/.idea +/cmake-build-* diff --git a/externals/dynarmic/externals/zycore/CMakeLists.txt b/externals/dynarmic/externals/zycore/CMakeLists.txt new file mode 100755 index 000000000..ad01d6507 --- /dev/null +++ b/externals/dynarmic/externals/zycore/CMakeLists.txt @@ -0,0 +1,266 @@ +if (TARGET Zycore) + return() +endif () + +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +include(GenerateExportHeader) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +project(Zycore VERSION 1.0.0.0 LANGUAGES C CXX) + +# =============================================================================================== # +# Overridable options # +# =============================================================================================== # + +# Global configuration +option(ZYAN_WHOLE_PROGRAM_OPTIMIZATION + "Enable whole program optimization (all targets)" + OFF) +option(ZYAN_NO_LIBC + "Don't use any C standard library functions (for exotic build-envs like kernel drivers)" + OFF) +option(ZYAN_DEV_MODE + "Enable developer mode (-Wall, -Werror, ...)" + OFF) + +# Build configuration +option(ZYCORE_BUILD_SHARED_LIB + "Build shared library" + OFF) +option(ZYCORE_BUILD_EXAMPLES + "Build examples" + OFF) +option(ZYCORE_BUILD_TESTS + "Build tests" + OFF) + +# =============================================================================================== # +# GoogleTest # +# =============================================================================================== # + +# Download and unpack googletest +if (ZYCORE_BUILD_TESTS) + if (NOT DEFINED ZYCORE_DOWNLOADED_GTEST) + configure_file("CMakeLists.txt.in" "${CMAKE_BINARY_DIR}/gtest/download/CMakeLists.txt") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/gtest/download") + if (result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") + endif() + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/gtest/download") + if (result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") + endif() + + set(ZYCORE_DOWNLOADED_GTEST TRUE CACHE BOOL "") + mark_as_advanced(ZYCORE_DOWNLOADED_GTEST) + endif () + + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + + add_subdirectory("${CMAKE_BINARY_DIR}/gtest/src" "${CMAKE_BINARY_DIR}/gtest/build" + EXCLUDE_FROM_ALL) +endif () + +# =============================================================================================== # +# Exported functions # +# =============================================================================================== # + +function (zyan_set_common_flags target) + if (NOT MSVC) + target_compile_options("${target}" PRIVATE "-std=c99") + endif () + + if (ZYAN_DEV_MODE) + # If in developer mode, be pedantic. + if (MSVC) + target_compile_options("${target}" PUBLIC "/WX" "/W4") + else () + target_compile_options("${target}" PUBLIC "-Wall" "-pedantic" "-Wextra" "-Werror") + endif () + endif () +endfunction () + +function (zyan_set_source_group target) + if (ZYAN_DEV_MODE) + if (((CMAKE_MAJOR_VERSION GREATER 3) OR (CMAKE_MAJOR_VERSION EQUAL 3)) AND + ((CMAKE_MINOR_VERSION GREATER 8) OR (CMAKE_MINOR_VERSION EQUAL 8))) + # Mirror directory structure in project files + get_property("TARGET_SOURCE_FILES" TARGET "${target}" PROPERTY SOURCES) + source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${TARGET_SOURCE_FILES}) + endif () + endif () +endfunction () + +function (zyan_maybe_enable_wpo target) + if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC) + set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL") + set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG") + endif () +endfunction () + +function (zyan_maybe_enable_wpo_for_lib target) + if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC) + set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL") + set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG") + set_target_properties("${target}" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG") + endif () +endfunction () + +# =============================================================================================== # +# Library configuration # +# =============================================================================================== # + +if (ZYCORE_BUILD_SHARED_LIB) + add_library("Zycore" SHARED) +else () + add_library("Zycore" STATIC) +endif () + +set_target_properties("Zycore" PROPERTIES LINKER_LANGUAGE C) +target_include_directories("Zycore" + PUBLIC "include" ${PROJECT_BINARY_DIR} + PRIVATE "src") +target_compile_definitions("Zycore" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYCORE_EXPORTS") +zyan_set_common_flags("Zycore") +zyan_maybe_enable_wpo_for_lib("Zycore") +generate_export_header("Zycore" BASE_NAME "ZYCORE" EXPORT_FILE_NAME "ZycoreExportConfig.h") + +if (ZYAN_NO_LIBC) + target_compile_definitions("Zycore" PUBLIC "ZYAN_NO_LIBC") + if (UNIX) + set_target_properties("Zycore" PROPERTIES LINK_FLAGS "-nostdlib -nodefaultlibs") + endif () +endif () + +target_sources("Zycore" + PRIVATE + # API + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Memory.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Process.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Synchronization.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Terminal.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Thread.h" + # Common + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Allocator.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/ArgParse.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Bitset.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Comparison.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Defines.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Format.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/LibC.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/List.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Object.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Status.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/String.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Types.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Vector.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Zycore.h" + # Common + "src/Allocator.c" + "src/ArgParse.c" + "src/Bitset.c" + "src/Format.c" + "src/List.c" + "src/String.c" + "src/Vector.c" + "src/Zycore.c") + +if (NOT ZYAN_NO_LIBC) + target_sources("Zycore" + PRIVATE + # API + "src/API/Memory.c" + "src/API/Process.c" + "src/API/Synchronization.c" + "src/API/Terminal.c" + "src/API/Thread.c") +endif () + +if (ZYCORE_BUILD_SHARED_LIB AND WIN32) + target_sources("Zycore" PRIVATE "resources/VersionInfo.rc") +endif () + +zyan_set_source_group("Zycore") + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT ZYAN_NO_LIBC) + target_compile_definitions("Zycore" PRIVATE "_GNU_SOURCE") + find_package(Threads REQUIRED) + target_link_libraries("Zycore" Threads::Threads) +endif () + +configure_package_config_file(cmake/zycore-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/zycore-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/zycore-config.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" +) + +install(TARGETS "Zycore" + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES + "${PROJECT_BINARY_DIR}/ZycoreExportConfig.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# =============================================================================================== # +# Developer mode # +# =============================================================================================== # + +if (ZYAN_DEV_MODE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) +endif () + +# =============================================================================================== # +# Examples # +# =============================================================================================== # + +if (ZYCORE_BUILD_EXAMPLES) + add_executable("String" "examples/String.c") + zyan_set_common_flags("String" "Zycore") + target_link_libraries("String" "Zycore") + set_target_properties("String" PROPERTIES FOLDER "Examples") + target_compile_definitions("String" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_maybe_enable_wpo("String") + + add_executable("Vector" "examples/Vector.c") + zyan_set_common_flags("Vector" "Zycore") + target_link_libraries("Vector" "Zycore") + set_target_properties("Vector" PROPERTIES FOLDER "Examples") + target_compile_definitions("Vector" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_maybe_enable_wpo("Vector") +endif () + +# =============================================================================================== # +# Tests # +# =============================================================================================== # + +function (zyan_add_test test) + add_executable("Test${test}" "tests/${test}.cpp") + + if (NOT MSVC) + target_compile_options("Test${test}" PRIVATE "-std=c++17") + endif () + + target_link_libraries("Test${test}" "Zycore") + target_link_libraries("Test${test}" "gtest") + set_target_properties("Test${test}" PROPERTIES FOLDER "Tests") + target_compile_definitions("Test${test}" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_maybe_enable_wpo("Test${test}") +endfunction () + +if (ZYCORE_BUILD_TESTS) + zyan_add_test("String") + zyan_add_test("Vector") + zyan_add_test("ArgParse") +endif () + +# =============================================================================================== # diff --git a/externals/dynarmic/externals/zycore/CMakeLists.txt.in b/externals/dynarmic/externals/zycore/CMakeLists.txt.in new file mode 100755 index 000000000..3333512ff --- /dev/null +++ b/externals/dynarmic/externals/zycore/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG ee3aa831172090fd5442820f215cb04ab6062756 + SOURCE_DIR "${CMAKE_BINARY_DIR}/gtest/src" + BINARY_DIR "${CMAKE_BINARY_DIR}/gtest/build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/externals/dynarmic/externals/zycore/LICENSE b/externals/dynarmic/externals/zycore/LICENSE new file mode 100755 index 000000000..4d9069aee --- /dev/null +++ b/externals/dynarmic/externals/zycore/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2018-2020 Florian Bernd +Copyright (c) 2018-2020 Joel Höner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/externals/dynarmic/externals/zycore/README.md b/externals/dynarmic/externals/zycore/README.md new file mode 100755 index 000000000..309a73b6d --- /dev/null +++ b/externals/dynarmic/externals/zycore/README.md @@ -0,0 +1,25 @@ +# Zyan Core Library for C + +Internal library providing platform independent types, macros and a fallback for environments without LibC. + +## Features + +- Platform independent types + - Integer types (`ZyanU8`, `ZyanI32`, `ZyanUSize`, ...) + - `ZyanBool` (+ `ZYAN_FALSE`, `ZYAN_TRUE`) + - `ZYAN_NULL` +- Macros + - Compiler/Platform/Architecture detection + - Asserts and static asserts + - Utils (`ARRAY_LENGTH`, `FALLTHROUGH`, `UNUSED`, ...) +- Common types + - `ZyanBitset` + - `ZyanString`/`ZyanStringView` +- Container types + - `ZyanVector` + - `ZyanList` +- LibC abstraction (WiP) + +## License + +Zycore is licensed under the MIT license. diff --git a/externals/dynarmic/externals/zycore/cmake/zycore-config.cmake.in b/externals/dynarmic/externals/zycore/cmake/zycore-config.cmake.in new file mode 100755 index 000000000..400ab53a5 --- /dev/null +++ b/externals/dynarmic/externals/zycore/cmake/zycore-config.cmake.in @@ -0,0 +1,8 @@ +set(zycore_VERSION @PROJECT_VERSION@) + +@PACKAGE_INIT@ + +set_and_check(zycore_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@") +set_and_check(zycore_LIB_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@") + +check_required_components(zycore) diff --git a/externals/dynarmic/externals/zycore/examples/String.c b/externals/dynarmic/externals/zycore/examples/String.c new file mode 100755 index 000000000..10ad84ccc --- /dev/null +++ b/externals/dynarmic/externals/zycore/examples/String.c @@ -0,0 +1,192 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Demonstrates the `String` implementation. + */ + +#include +#include +#include +#include +#include +#include + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + + +/* ============================================================================================== */ +/* Helper functions */ +/* ============================================================================================== */ + +/* ============================================================================================== */ +/* Tests */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Basic tests */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Performs some basic test on the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + */ +static ZyanStatus PerformBasicTests(ZyanString* string) +{ + ZYAN_ASSERT(string); + ZYAN_UNUSED(string); + + + + return ZYAN_STATUS_SUCCESS; +} + +/** + * Performs basic tests on a string that dynamically manages memory. + * + * @return A zyan status code. + */ +static ZyanStatus TestDynamic(void) +{ + PerformBasicTests(ZYAN_NULL); + return ZYAN_STATUS_SUCCESS; +} + +/** + * Performs basic tests on a string that uses a static buffer. + * + * @return A zyan status code. + */ +static ZyanStatus TestStatic(void) +{ + PerformBasicTests(ZYAN_NULL); + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Custom allocator */ +/* ---------------------------------------------------------------------------------------------- */ + +//static ZyanStatus AllocatorAllocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size, +// ZyanUSize n) +//{ +// ZYAN_ASSERT(allocator); +// ZYAN_ASSERT(p); +// ZYAN_ASSERT(element_size); +// ZYAN_ASSERT(n); +// +// ZYAN_UNUSED(allocator); +// +// *p = ZYAN_MALLOC(element_size * n); +// if (!*p) +// { +// return ZYAN_STATUS_NOT_ENOUGH_MEMORY; +// } +// +// return ZYAN_STATUS_SUCCESS; +//} +// +//static ZyanStatus AllocatorReallocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size, +// ZyanUSize n) +//{ +// ZYAN_ASSERT(allocator); +// ZYAN_ASSERT(p); +// ZYAN_ASSERT(element_size); +// ZYAN_ASSERT(n); +// +// ZYAN_UNUSED(allocator); +// +// void* const x = ZYAN_REALLOC(*p, element_size * n); +// if (!x) +// { +// return ZYAN_STATUS_NOT_ENOUGH_MEMORY; +// } +// *p = x; +// +// return ZYAN_STATUS_SUCCESS; +//} +// +//static ZyanStatus AllocatorDeallocate(ZyanAllocator* allocator, void* p, ZyanUSize element_size, +// ZyanUSize n) +//{ +// ZYAN_ASSERT(allocator); +// ZYAN_ASSERT(p); +// ZYAN_ASSERT(element_size); +// ZYAN_ASSERT(n); +// +// ZYAN_UNUSED(allocator); +// ZYAN_UNUSED(element_size); +// ZYAN_UNUSED(n); +// +// ZYAN_FREE(p); +// +// return ZYAN_STATUS_SUCCESS; +//} + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Performs basic tests on a vector that dynamically manages memory using a custom + * allocator and modified growth-factor/shrink-threshold. + * + * @return A zyan status code. + */ +static ZyanStatus TestAllocator(void) +{ + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Entry point */ +/* ============================================================================================== */ + +int main() +{ + if (!ZYAN_SUCCESS(TestDynamic())) + { + return EXIT_FAILURE; + } + if (!ZYAN_SUCCESS(TestStatic())) + { + return EXIT_FAILURE; + } + if (!ZYAN_SUCCESS(TestAllocator())) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/examples/Vector.c b/externals/dynarmic/externals/zycore/examples/Vector.c new file mode 100755 index 000000000..090ad3307 --- /dev/null +++ b/externals/dynarmic/externals/zycore/examples/Vector.c @@ -0,0 +1,395 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Demonstrates the `ZyanVector` implementation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `TestStruct` struct that represents a single element in the vector. + */ +typedef struct TestStruct_ +{ + ZyanU32 u32; + ZyanU64 u64; + float f; +} TestStruct; + +/* ============================================================================================== */ +/* Helper functions */ +/* ============================================================================================== */ + +/** + * Initializes the given `TestStruct` struct. + * + * @param data A pointer to the `TestStruct` struct. + * @param n The number to initialize the struct with. + */ +static void InitTestdata(TestStruct* data, ZyanU32 n) +{ + ZYAN_ASSERT(data); + + data->u32 = n; + data->u64 = n; + data->f = (float)n; +} + +/* ============================================================================================== */ +/* Tests */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Basic tests */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Performs some basic test on the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * + * @return A zyan status code. + */ +static ZyanStatus PerformBasicTests(ZyanVector* vector) +{ + ZYAN_ASSERT(vector); + + static TestStruct e_v; + static const TestStruct* e_p; + + // Insert `20` elements. The vector automatically manages its size + for (ZyanU32 i = 0; i < 20; ++i) + { + InitTestdata(&e_v, i); + ZYAN_CHECK(ZyanVectorPushBack(vector, &e_v)); + } + + // Remove elements `#05..#09` + ZYAN_CHECK(ZyanVectorDeleteRange(vector, 5, 5)); + + // Insert a new element at index `#05` + InitTestdata(&e_v, 12345678); + ZYAN_CHECK(ZyanVectorInsert(vector, 5, &e_v)); + + // Change value of element `#15` + InitTestdata(&e_v, 87654321); + ZYAN_CHECK(ZyanVectorSet(vector, 10, &e_v)); + + // Print `u64` of all vector elements + ZyanUSize value; + ZYAN_CHECK(ZyanVectorGetSize(vector, &value)); + puts("ELEMENTS"); + for (ZyanUSize i = 0; i < value; ++i) + { + ZYAN_CHECK(ZyanVectorGetPointer(vector, i, (const void**)&e_p)); + printf(" Element #%02" PRIuPTR ": %08" PRIu64 "\n", i, e_p->u64); + } + + // Print infos + puts("INFO"); + printf(" Size : %08" PRIuPTR "\n", value); + ZYAN_CHECK(ZyanVectorGetCapacity(vector, &value)); + printf(" Capacity : %08" PRIuPTR "\n\n", value); + + return ZYAN_STATUS_SUCCESS; +} + +/** + * A dummy comparison function for the `TestStruct` that uses the `u32` field as key + * value. + * + * @param left A pointer to the first element. + * @param right A pointer to the second element. + * + * @return Returns values in the following range: + * `left == right -> result == 0` + * `left < right -> result < 0` + * `left > right -> result > 0` + */ +static ZyanI32 TestDataComparison(const TestStruct* left, const TestStruct* right) +{ + ZYAN_ASSERT(left); + ZYAN_ASSERT(right); + + if (left->u32 < right->u32) + { + return -1; + } + if (left->u32 > right->u32) + { + return 1; + } + return 0; +} + +/** + * Tests the binary-search functionality of the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * + * @return A zyan status code. + */ +static ZyanStatus PerformBinarySearchTest(ZyanVector* vector) +{ + ZYAN_ASSERT(vector); + + static TestStruct e_v; + static const TestStruct* e_p; + + ZyanUSize value; + ZYAN_CHECK(ZyanVectorGetCapacity(vector, &value)); + + // Create a sorted test vector + for (ZyanUSize i = 0; i < value; ++i) + { + const ZyanU32 n = rand() % 100; + InitTestdata(&e_v, n); + + ZyanUSize found_index; + ZYAN_CHECK(ZyanVectorBinarySearch(vector, &e_v, &found_index, + (ZyanComparison)&TestDataComparison)); + ZYAN_CHECK(ZyanVectorInsert(vector, found_index, &e_v)); + } + + // Print `u32` of all vector elements + ZYAN_CHECK(ZyanVectorGetSize(vector, &value)); + puts("ELEMENTS"); + for (ZyanUSize i = 0; i < value; ++i) + { + ZYAN_CHECK(ZyanVectorGetPointer(vector, i, (const void**)&e_p)); + printf(" Element #%02" PRIuPTR ": %08" PRIu32 "\n", i, e_p->u32); + } + + return ZYAN_STATUS_SUCCESS; +} + +/** + * Performs basic tests on a vector that dynamically manages memory. + * + * @return A zyan status code. + */ +static ZyanStatus TestDynamic(void) +{ + // Initialize vector with a base capacity of `10` elements + ZyanVector vector; + ZYAN_CHECK(ZyanVectorInit(&vector, sizeof(TestStruct), 10, ZYAN_NULL)); + + ZYAN_CHECK(PerformBasicTests(&vector)); + ZYAN_CHECK(ZyanVectorClear(&vector)); + ZYAN_CHECK(ZyanVectorReserve(&vector, 20)); + ZYAN_CHECK(PerformBinarySearchTest(&vector)); + + // Cleanup + return ZyanVectorDestroy(&vector); +} + +/** + * Performs basic tests on a vector that uses a static buffer. + * + * @return A zyan status code. + */ +static ZyanStatus TestStatic(void) +{ + static TestStruct buffer[20]; + + // Initialize vector to use a static buffer with a total capacity of `20` elements. + ZyanVector vector; + ZYAN_CHECK(ZyanVectorInitCustomBuffer(&vector, sizeof(TestStruct), buffer, + ZYAN_ARRAY_LENGTH(buffer), ZYAN_NULL)); + + // Compare elements + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&vector, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + static TestStruct* element; + ZYAN_CHECK(ZyanVectorGetPointer(&vector, i, (const void**)&element)); + if (element->u64 != buffer[i].u64) + { + return ZYAN_STATUS_INVALID_OPERATION; + } + } + + ZYAN_CHECK(PerformBasicTests(&vector)); + ZYAN_CHECK(ZyanVectorClear(&vector)); + ZYAN_CHECK(PerformBinarySearchTest(&vector)); + + // Cleanup + return ZyanVectorDestroy(&vector); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Custom allocator */ +/* ---------------------------------------------------------------------------------------------- */ + +static ZyanStatus AllocatorAllocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size, + ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + + *p = ZYAN_MALLOC(element_size * n); + if (!*p) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus AllocatorReallocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size, + ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + + void* const x = ZYAN_REALLOC(*p, element_size * n); + if (!x) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + *p = x; + + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus AllocatorDeallocate(ZyanAllocator* allocator, void* p, ZyanUSize element_size, + ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + ZYAN_UNUSED(element_size); + ZYAN_UNUSED(n); + + ZYAN_FREE(p); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Performs basic tests on a vector that dynamically manages memory using a custom + * allocator and modified growth-factor/shrink-threshold. + * + * @return A zyan status code. + */ +static ZyanStatus TestAllocator(void) +{ + ZyanAllocator allocator; + ZYAN_CHECK(ZyanAllocatorInit(&allocator, &AllocatorAllocate, &AllocatorReallocate, + &AllocatorDeallocate)); + + // Initialize vector with a base capacity of `10` elements. Growth-factor is set to 10 and + // dynamic shrinking is disabled + ZyanVector vector; + ZYAN_CHECK(ZyanVectorInitEx(&vector, sizeof(TestStruct), 5, ZYAN_NULL, &allocator, + 10.0f, 0.0f)); + + static TestStruct e_v; + + // Insert `10` elements. The vector automatically manages its size + for (ZyanU32 i = 0; i < 10; ++i) + { + InitTestdata(&e_v, i); + ZYAN_CHECK(ZyanVectorPushBack(&vector, &e_v)); + } + + // Check capacity + ZyanUSize value; + ZYAN_CHECK(ZyanVectorGetCapacity(&vector, &value)); + if (value != 60) // (5 + 1) * 10.0f + { + return ZYAN_STATUS_INVALID_OPERATION; + } + + // Remove all elements + ZYAN_CHECK(ZyanVectorClear(&vector)); + + // Print infos + puts("INFO"); + ZYAN_CHECK(ZyanVectorGetSize(&vector, &value)); + printf(" Size : %08" PRIuPTR "\n", value); + ZYAN_CHECK(ZyanVectorGetCapacity(&vector, &value)); + printf(" Capacity : %08" PRIuPTR "\n\n", value); + + // Cleanup + return ZyanVectorDestroy(&vector); +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Entry point */ +/* ============================================================================================== */ + +int main() +{ + time_t t; + srand((unsigned)time(&t)); + + if (!ZYAN_SUCCESS(TestDynamic())) + { + return EXIT_FAILURE; + } + if (!ZYAN_SUCCESS(TestStatic())) + { + return EXIT_FAILURE; + } + if (!ZYAN_SUCCESS(TestAllocator())) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/API/Memory.h b/externals/dynarmic/externals/zycore/include/Zycore/API/Memory.h new file mode 100755 index 000000000..c5fa8a9b5 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/API/Memory.h @@ -0,0 +1,134 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief + */ + +#ifndef ZYCORE_API_MEMORY_H +#define ZYCORE_API_MEMORY_H + +#include +#include +#include +#include + +#if defined(ZYAN_WINDOWS) +# include +#elif defined(ZYAN_POSIX) +# include +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanMemoryPageProtection` enum. + */ +typedef enum ZyanMemoryPageProtection_ +{ +#if defined(ZYAN_WINDOWS) + + ZYAN_PAGE_READONLY = PAGE_READONLY, + ZYAN_PAGE_READWRITE = PAGE_READWRITE, + ZYAN_PAGE_EXECUTE = PAGE_EXECUTE, + ZYAN_PAGE_EXECUTE_READ = PAGE_EXECUTE_READ, + ZYAN_PAGE_EXECUTE_READWRITE = PAGE_EXECUTE_READWRITE + +#elif defined(ZYAN_POSIX) + + ZYAN_PAGE_READONLY = PROT_READ, + ZYAN_PAGE_READWRITE = PROT_READ | PROT_WRITE, + ZYAN_PAGE_EXECUTE = PROT_EXEC, + ZYAN_PAGE_EXECUTE_READ = PROT_EXEC | PROT_READ, + ZYAN_PAGE_EXECUTE_READWRITE = PROT_EXEC | PROT_READ | PROT_WRITE + +#endif +} ZyanMemoryPageProtection; + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the system page size. + * + * @return The system page size. + */ +ZYCORE_EXPORT ZyanU32 ZyanMemoryGetSystemPageSize(); + +/** + * Returns the system allocation granularity. + * + * The system allocation granularity specifies the minimum amount of bytes which can be allocated + * at a specific address by a single call of `ZyanMemoryVirtualAlloc`. + * + * This value is typically 64KiB on Windows systems and equal to the page size on most POSIX + * platforms. + * + * @return The system allocation granularity. + */ +ZYCORE_EXPORT ZyanU32 ZyanMemoryGetSystemAllocationGranularity(); + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Changes the memory protection value of one or more pages. + * + * @param address The start address aligned to a page boundary. + * @param size The size. + * @param protection The new page protection value. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanMemoryVirtualProtect(void* address, ZyanUSize size, + ZyanMemoryPageProtection protection); + +/** + * Releases one or more memory pages starting at the given address. + * + * @param address The start address aligned to a page boundary. + * @param size The size. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanMemoryVirtualFree(void* address, ZyanUSize size); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#endif /* ZYCORE_API_MEMORY_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/API/Process.h b/externals/dynarmic/externals/zycore/include/Zycore/API/Process.h new file mode 100755 index 000000000..0b6a5c6b6 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/API/Process.h @@ -0,0 +1,67 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief + */ + +#ifndef ZYCORE_API_PROCESS_H +#define ZYCORE_API_PROCESS_H + +#include +#include +#include + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + + + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * @brief Flushes the process instruction cache. + * + * @param address The address. + * @param size The size. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanProcessFlushInstructionCache(void* address, ZyanUSize size); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#endif /* ZYCORE_API_PROCESS_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/API/Synchronization.h b/externals/dynarmic/externals/zycore/include/Zycore/API/Synchronization.h new file mode 100755 index 000000000..8414a44b7 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/API/Synchronization.h @@ -0,0 +1,133 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief + */ + +#ifndef ZYCORE_API_SYNCHRONIZATION_H +#define ZYCORE_API_SYNCHRONIZATION_H + +#ifndef ZYAN_NO_LIBC + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +#if defined(ZYAN_POSIX) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* Critical Section */ +/* ---------------------------------------------------------------------------------------------- */ + +typedef pthread_mutex_t ZyanCriticalSection; + +/* ---------------------------------------------------------------------------------------------- */ + +#elif defined(ZYAN_WINDOWS) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* Critical Section */ +/* ---------------------------------------------------------------------------------------------- */ + +typedef CRITICAL_SECTION ZyanCriticalSection; + +/* ---------------------------------------------------------------------------------------------- */ + +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Critical Section */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Initializes a critical section. + * + * @param critical_section A pointer to the `ZyanCriticalSection` struct. + */ +ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section); + +/** + * Enters a critical section. + * + * @param critical_section A pointer to the `ZyanCriticalSection` struct. + */ +ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionEnter(ZyanCriticalSection* critical_section); + +/** + * Tries to enter a critical section. + * + * @param critical_section A pointer to the `ZyanCriticalSection` struct. + * + * @return Returns `ZYAN_TRUE` if the critical section was successfully entered or `ZYAN_FALSE`, + * if not. + */ +ZYCORE_EXPORT ZyanBool ZyanCriticalSectionTryEnter(ZyanCriticalSection* critical_section); + +/** + * Leaves a critical section. + * + * @param critical_section A pointer to the `ZyanCriticalSection` struct. + */ +ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionLeave(ZyanCriticalSection* critical_section); + +/** + * Deletes a critical section. + * + * @param critical_section A pointer to the `ZyanCriticalSection` struct. + */ +ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYAN_NO_LIBC */ + +#endif /* ZYCORE_API_SYNCHRONIZATION_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/API/Terminal.h b/externals/dynarmic/externals/zycore/include/Zycore/API/Terminal.h new file mode 100755 index 000000000..17dc384b9 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/API/Terminal.h @@ -0,0 +1,163 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file Provides cross-platform terminal helper functions. + * @brief + */ + +#ifndef ZYCORE_API_TERMINAL_H +#define ZYCORE_API_TERMINAL_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ZYAN_NO_LIBC + +/* ============================================================================================== */ +/* VT100 CSI SGR sequences */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +#define ZYAN_VT100SGR_RESET "\033[0m" + +/* ---------------------------------------------------------------------------------------------- */ +/* Foreground colors */ +/* ---------------------------------------------------------------------------------------------- */ + +#define ZYAN_VT100SGR_FG_DEFAULT "\033[39m" + +#define ZYAN_VT100SGR_FG_BLACK "\033[30m" +#define ZYAN_VT100SGR_FG_RED "\033[31m" +#define ZYAN_VT100SGR_FG_GREEN "\033[32m" +#define ZYAN_VT100SGR_FG_YELLOW "\033[33m" +#define ZYAN_VT100SGR_FG_BLUE "\033[34m" +#define ZYAN_VT100SGR_FG_MAGENTA "\033[35m" +#define ZYAN_VT100SGR_FG_CYAN "\033[36m" +#define ZYAN_VT100SGR_FG_WHITE "\033[37m" +#define ZYAN_VT100SGR_FG_BRIGHT_BLACK "\033[90m" +#define ZYAN_VT100SGR_FG_BRIGHT_RED "\033[91m" +#define ZYAN_VT100SGR_FG_BRIGHT_GREEN "\033[92m" +#define ZYAN_VT100SGR_FG_BRIGHT_YELLOW "\033[93m" +#define ZYAN_VT100SGR_FG_BRIGHT_BLUE "\033[94m" +#define ZYAN_VT100SGR_FG_BRIGHT_MAGENTA "\033[95m" +#define ZYAN_VT100SGR_FG_BRIGHT_CYAN "\033[96m" +#define ZYAN_VT100SGR_FG_BRIGHT_WHITE "\033[97m" + +/* ---------------------------------------------------------------------------------------------- */ +/* Background color */ +/* ---------------------------------------------------------------------------------------------- */ + +#define ZYAN_VT100SGR_BG_DEFAULT "\033[49m" + +#define ZYAN_VT100SGR_BG_BLACK "\033[40m" +#define ZYAN_VT100SGR_BG_RED "\033[41m" +#define ZYAN_VT100SGR_BG_GREEN "\033[42m" +#define ZYAN_VT100SGR_BG_YELLOW "\033[43m" +#define ZYAN_VT100SGR_BG_BLUE "\033[44m" +#define ZYAN_VT100SGR_BG_MAGENTA "\033[45m" +#define ZYAN_VT100SGR_BG_CYAN "\033[46m" +#define ZYAN_VT100SGR_BG_WHITE "\033[47m" +#define ZYAN_VT100SGR_BG_BRIGHT_BLACK "\033[100m" +#define ZYAN_VT100SGR_BG_BRIGHT_RED "\033[101m" +#define ZYAN_VT100SGR_BG_BRIGHT_GREEN "\033[102m" +#define ZYAN_VT100SGR_BG_BRIGHT_YELLOW "\033[103m" +#define ZYAN_VT100SGR_BG_BRIGHT_BLUE "\033[104m" +#define ZYAN_VT100SGR_BG_BRIGHT_MAGENTA "\033[105m" +#define ZYAN_VT100SGR_BG_BRIGHT_CYAN "\033[106m" +#define ZYAN_VT100SGR_BG_BRIGHT_WHITE "\033[107m" + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Declares the `ZyanStandardStream` enum. + */ +typedef enum ZyanStandardStream_ +{ + /** + * The default input stream. + */ + ZYAN_STDSTREAM_IN, + /** + * The default output stream. + */ + ZYAN_STDSTREAM_OUT, + /** + * The default error stream. + */ + ZYAN_STDSTREAM_ERR +} ZyanStandardStream; + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/** + * Enables VT100 ansi escape codes for the given stream. + * + * @param stream Either `ZYAN_STDSTREAM_OUT` or `ZYAN_STDSTREAM_ERR`. + * + * @return A zyan status code. + * + * This functions returns `ZYAN_STATUS_SUCCESS` on all non-Windows systems without performing any + * operations, assuming that VT100 is supported by default. + * + * On Windows systems, VT100 functionality is only supported on Windows 10 build 1607 (anniversary + * update) and later. + */ +ZYCORE_EXPORT ZyanStatus ZyanTerminalEnableVT100(ZyanStandardStream stream); + +/** + * Checks, if the given standard stream reads from or writes to a terminal. + * + * @param stream The standard stream to check. + * + * @return `ZYAN_STATUS_TRUE`, if the stream is bound to a terminal, `ZYAN_STATUS_FALSE` if not, + * or another zyan status code if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanTerminalIsTTY(ZyanStandardStream stream); + +/* ============================================================================================== */ + +#endif // ZYAN_NO_LIBC + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_API_TERMINAL_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/API/Thread.h b/externals/dynarmic/externals/zycore/include/Zycore/API/Thread.h new file mode 100755 index 000000000..b1ec085e9 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/API/Thread.h @@ -0,0 +1,244 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief + */ + +#ifndef ZYCORE_API_THREAD_H +#define ZYCORE_API_THREAD_H + +#ifndef ZYAN_NO_LIBC + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +#if defined(ZYAN_POSIX) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanThread` data-type. + */ +typedef pthread_t ZyanThread; + +/** + * Defines the `ZyanThreadId` data-type. + */ +typedef ZyanU64 ZyanThreadId; + +/* ---------------------------------------------------------------------------------------------- */ +/* Thread Local Storage (TLS) */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanThreadTlsIndex` data-type. + */ +typedef pthread_key_t ZyanThreadTlsIndex; + +/** + * Defines the `ZyanThreadTlsCallback` function prototype. + */ +typedef void(*ZyanThreadTlsCallback)(void* data); + +/** + * Declares a Thread Local Storage (TLS) callback function. + * + * @param name The callback function name. + * @param param_type The callback data parameter type. + * @param param_name The callback data parameter name. + */ +#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \ + void name(param_type* param_name) + +/* ---------------------------------------------------------------------------------------------- */ + +#elif defined(ZYAN_WINDOWS) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanThread` data-type. + */ +typedef HANDLE ZyanThread; + +/** + * Defines the `ZyanThreadId` data-type. + */ +typedef DWORD ZyanThreadId; + +/* ---------------------------------------------------------------------------------------------- */ +/* Thread Local Storage (TLS) */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanThreadTlsIndex` data-type. + */ +typedef DWORD ZyanThreadTlsIndex; + +/** + * Defines the `ZyanThreadTlsCallback` function prototype. + */ +typedef PFLS_CALLBACK_FUNCTION ZyanThreadTlsCallback; + +/** + * Declares a Thread Local Storage (TLS) callback function. + * + * @param name The callback function name. + * @param param_type The callback data parameter type. + * @param param_name The callback data parameter name. + */ +#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \ + VOID NTAPI name(param_type* param_name) + +/* ---------------------------------------------------------------------------------------------- */ + +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the handle of the current thread. + * + * @param thread Receives the handle of the current thread. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread); + +/** + * Returns the unique id of the current thread. + * + * @param thread_id Receives the unique id of the current thread. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId* thread_id); + +/* ---------------------------------------------------------------------------------------------- */ +/* Thread Local Storage (TLS) */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Allocates a new Thread Local Storage (TLS) slot. + * + * @param index Receives the TLS slot index. + * @param destructor A pointer to a destructor callback which is invoked to finalize the data + * in the TLS slot or `ZYAN_NULL`, if not needed. + * + * The maximum available number of TLS slots is implementation specific and different on each + * platform: + * - Windows + * - A total amount of 128 slots per process are guaranteed + * - POSIX + * - A total amount of 128 slots per process are guaranteed + * - Some systems guarantee larger amounts like e.g. 1024 slots per process + * + * Note that the invocation rules for the destructor callback are implementation specific and + * different on each platform: + * - Windows + * - The callback is invoked when a thread exits + * - The callback is invoked when the process exits + * - The callback is invoked when the TLS slot is released + * - POSIX + * - The callback is invoked when a thread exits and the stored value is not null + * - The callback is NOT invoked when the process exits + * - The callback is NOT invoked when the TLS slot is released + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, + ZyanThreadTlsCallback destructor); + +/** + * Releases a Thread Local Storage (TLS) slot. + * + * @param index The TLS slot index. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index); + +/** + * Returns the value inside the given Thread Local Storage (TLS) slot for the + * calling thread. + * + * @param index The TLS slot index. + * @param data Receives the value inside the given Thread Local Storage + * (TLS) slot for the calling thread. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void** data); + +/** + * Set the value of the given Thread Local Storage (TLS) slot for the calling thread. + * + * @param index The TLS slot index. + * @param data The value to store inside the given Thread Local Storage (TLS) slot for the + * calling thread + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYAN_NO_LIBC */ + +#endif /* ZYCORE_API_THREAD_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Allocator.h b/externals/dynarmic/externals/zycore/include/Zycore/Allocator.h new file mode 100755 index 000000000..643517192 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Allocator.h @@ -0,0 +1,143 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief + */ + +#ifndef ZYCORE_ALLOCATOR_H +#define ZYCORE_ALLOCATOR_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +struct ZyanAllocator_; + +/** + * Defines the `ZyanAllocatorAllocate` function prototype. + * + * @param allocator A pointer to the `ZyanAllocator` instance. + * @param p Receives a pointer to the first memory block sufficient to hold an + * array of `n` elements with a size of `element_size`. + * @param element_size The size of a single element. + * @param n The number of elements to allocate storage for. + * + * @return A zyan status code. + * + * This prototype is used for the `allocate()` and `reallocate()` functions. + * + * The result of the `reallocate()` function is undefined, if `p` does not point to a memory block + * previously obtained by `(re-)allocate()`. + */ +typedef ZyanStatus (*ZyanAllocatorAllocate)(struct ZyanAllocator_* allocator, void** p, + ZyanUSize element_size, ZyanUSize n); + +/** + * Defines the `ZyanAllocatorDeallocate` function prototype. + * + * @param allocator A pointer to the `ZyanAllocator` instance. + * @param p The pointer obtained from `(re-)allocate()`. + * @param element_size The size of a single element. + * @param n The number of elements earlier passed to `(re-)allocate()`. + * + * @return A zyan status code. + */ +typedef ZyanStatus (*ZyanAllocatorDeallocate)(struct ZyanAllocator_* allocator, void* p, + ZyanUSize element_size, ZyanUSize n); + +/** + * Defines the `ZyanAllocator` struct. + * + * This is the base class for all custom allocator implementations. + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanAllocator_ +{ + /** + * The allocate function. + */ + ZyanAllocatorAllocate allocate; + /** + * The reallocate function. + */ + ZyanAllocatorAllocate reallocate; + /** + * The deallocate function. + */ + ZyanAllocatorDeallocate deallocate; +} ZyanAllocator; + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/** + * Initializes the given `ZyanAllocator` instance. + * + * @param allocator A pointer to the `ZyanAllocator` instance. + * @param allocate The allocate function. + * @param reallocate The reallocate function. + * @param deallocate The deallocate function. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate, + ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate); + +#ifndef ZYAN_NO_LIBC + +/** + * Returns the default `ZyanAllocator` instance. + * + * @return A pointer to the default `ZyanAllocator` instance. + * + * The default allocator uses the default memory manager to allocate memory on the heap. + * + * You should in no case modify the returned allocator instance to avoid unexpected behavior. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocator* ZyanAllocatorDefault(void); + +#endif // ZYAN_NO_LIBC + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_ALLOCATOR_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/ArgParse.h b/externals/dynarmic/externals/zycore/include/Zycore/ArgParse.h new file mode 100755 index 000000000..5d389cb61 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/ArgParse.h @@ -0,0 +1,173 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Implements command-line argument parsing. + */ + +#ifndef ZYCORE_ARGPARSE_H +#define ZYCORE_ARGPARSE_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Structs and other types */ +/* ============================================================================================== */ + +/** + * Definition of a single argument. + */ +typedef struct ZyanArgParseDefinition_ +{ + /** + * The argument name, e.g. `--help`. + * + * Must start with either one or two dashes. Single dash arguments must consist of a single + * character, (e.g. `-n`), double-dash arguments can be of arbitrary length. + */ + const char* name; + /** + * Whether the argument is boolean or expects a value. + */ + ZyanBool boolean; + /** + * Whether this argument is required (error if missing). + */ + ZyanBool required; +} ZyanArgParseDefinition; + +/** + * Configuration for argument parsing. + */ +typedef struct ZyanArgParseConfig_ +{ + /** + * `argv` argument passed to `main` by LibC. + */ + const char** argv; + /** + * `argc` argument passed to `main` by LibC. + */ + ZyanUSize argc; + /** + * Minimum # of accepted unnamed / anonymous arguments. + */ + ZyanUSize min_unnamed_args; + /** + * Maximum # of accepted unnamed / anonymous arguments. + */ + ZyanUSize max_unnamed_args; + /** + * Argument definition array, or `ZYAN_NULL`. + * + * Expects a pointer to an array of `ZyanArgParseDefinition` instances. The array is + * terminated by setting the `.name` field of the last element to `ZYAN_NULL`. If no named + * arguments should be parsed, you can also set this to `ZYAN_NULL`. + */ + ZyanArgParseDefinition* args; +} ZyanArgParseConfig; + +/** + * Information about a parsed argument. + */ +typedef struct ZyanArgParseArg_ +{ + /** + * Corresponding argument definition, or `ZYAN_NULL` for unnamed args. + * + * This pointer is borrowed from the `cfg` pointer passed to `ZyanArgParse`. + */ + const ZyanArgParseDefinition* def; + /** + * Whether the argument has a value (is non-boolean). + */ + ZyanBool has_value; + /** + * If `has_value == true`, then the argument value. + * + * This is a view into the `argv` string array passed to `ZyanArgParse` via the `cfg` argument. + */ + ZyanStringView value; +} ZyanArgParseArg; + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +#ifndef ZYAN_NO_LIBC + +/** + * Parse arguments according to a `ZyanArgParseConfig` definition. + * + * @param cfg Argument parser config to use. + * @param parsed Receives the parsed output. Vector of `ZyanArgParseArg`. Ownership is + * transferred to the user. Input is expected to be uninitialized. On error, + * the vector remains uninitialized. + * @param error_token On error, if it makes sense, receives the argument fragment causing the + * error. Optional, may be `ZYAN_NULL`. The pointer borrows into the `cfg` + * struct and doesn't have to be freed by the user. + * + * @return A `ZyanStatus` status determining whether the parsing succeeded. + */ +ZYCORE_EXPORT ZyanStatus ZyanArgParse(const ZyanArgParseConfig *cfg, ZyanVector* parsed, + const char** error_token); + +#endif + +/** + * Parse arguments according to a `ZyanArgParseConfig` definition. + * + * This version allows specification of a custom memory allocator and thus supports no-libc. + * + * @param cfg Argument parser config to use. + * @param parsed Receives the parsed output. Vector of `ZyanArgParseArg`. Ownership is + * transferred to the user. Input is expected to be uninitialized. On error, + * the vector remains uninitialized. + * @param error_token On error, if it makes sense, receives the argument fragment causing the + * error. Optional, may be `ZYAN_NULL`. The pointer borrows into the `cfg` + * struct and doesn't have to be freed by the user. + * @param allocator The `ZyanAllocator` to be used for allocating the output vector's data. + * + * @return A `ZyanStatus` status determining whether the parsing succeeded. + */ +ZYCORE_EXPORT ZyanStatus ZyanArgParseEx(const ZyanArgParseConfig *cfg, ZyanVector* parsed, + const char** error_token, ZyanAllocator* allocator); + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_ARGPARSE_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Bitset.h b/externals/dynarmic/externals/zycore/include/Zycore/Bitset.h new file mode 100755 index 000000000..8c7eb1f3f --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Bitset.h @@ -0,0 +1,484 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Implements the bitset class. + */ + +#ifndef ZYCORE_BITSET_H +#define ZYCORE_BITSET_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanVector` struct. + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanBitset_ +{ + /** + * The bitset size. + */ + ZyanUSize size; + /** + * The bitset data. + */ + ZyanVector bits; +} ZyanBitset; + +/** + * Defines the `ZyanBitsetByteOperation` function prototype. + * + * @param v1 A pointer to the first byte. This value receives the result after performing the + * desired operation. + * @param v2 A pointer to the second byte. + * + * @return A zyan status code. + * + * This function is used to perform byte-wise operations on two `ZyanBitset` instances. + */ +typedef ZyanStatus (*ZyanBitsetByteOperation)(ZyanU8* v1, const ZyanU8* v2); + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param count The initial amount of bits. + * + * @return A zyan status code. + * + * The space for the bitset is dynamically allocated by the default allocator using the default + * growth factor of `2.0f` and the default shrink threshold of `0.5f`. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, ZyanUSize count); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanBitset` instance and sets a custom `allocator` and memory + * allocation/deallocation parameters. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param count The initial amount of bits. + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count, + ZyanAllocator* allocator, float growth_factor, float shrink_threshold); + +/** + * Initializes the given `ZyanBitset` instance and configures it to use a custom user + * defined buffer with a fixed size. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param count The initial amount of bits. + * @param buffer A pointer to the buffer that is used as storage for the bits. + * @param capacity The maximum capacity (number of bytes) of the buffer. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset* bitset, ZyanUSize count, void* buffer, + ZyanUSize capacity); + +/** + * Destroys the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetDestroy(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ +/* Logical operations */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Performs a byte-wise `operation` for every byte in the given `ZyanBitset` instances. + * + * @param destination A pointer to the `ZyanBitset` instance that is used as the first input and + * as the destination. + * @param source A pointer to the `ZyanBitset` instance that is used as the second input. + * @param operation A pointer to the function that performs the desired operation. + * + * @return A zyan status code. + * + * The `operation` callback is invoked once for every byte in the smallest of the `ZyanBitset` + * instances. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset* destination, + const ZyanBitset* source, ZyanBitsetByteOperation operation); + +/** + * Performs a logical `AND` operation on the given `ZyanBitset` instances. + * + * @param destination A pointer to the `ZyanBitset` instance that is used as the first input and + * as the destination. + * @param source A pointer to the `ZyanBitset` instance that is used as the second input. + * + * @return A zyan status code. + * + * If the destination bitmask contains more bits than the source one, the state of the remaining + * bits will be undefined. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetAND(ZyanBitset* destination, const ZyanBitset* source); + +/** + * Performs a logical `OR` operation on the given `ZyanBitset` instances. + * + * @param destination A pointer to the `ZyanBitset` instance that is used as the first input and + * as the destination. + * @param source A pointer to the `ZyanBitset` instance that is used as the second input. + * + * @return A zyan status code. + * + * If the destination bitmask contains more bits than the source one, the state of the remaining + * bits will be undefined. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetOR (ZyanBitset* destination, const ZyanBitset* source); + +/** + * Performs a logical `XOR` operation on the given `ZyanBitset` instances. + * + * @param destination A pointer to the `ZyanBitset` instance that is used as the first input and + * as the destination. + * @param source A pointer to the `ZyanBitset` instance that is used as the second input. + * + * @return A zyan status code. + * + * If the destination bitmask contains more bits than the source one, the state of the remaining + * bits will be undefined. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetXOR(ZyanBitset* destination, const ZyanBitset* source); + +/** + * Flips all bits of the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetFlip(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ +/* Bit access */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Sets the bit at `index` of the given `ZyanBitset` instance to `1`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param index The bit index. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetSet(ZyanBitset* bitset, ZyanUSize index); + +/** + * Sets the bit at `index` of the given `ZyanBitset` instance to `0`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param index The bit index. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetReset(ZyanBitset* bitset, ZyanUSize index); + +/** + * Sets the bit at `index` of the given `ZyanBitset` instance to the specified `value`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param index The bit index. + * @param value The new value. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetAssign(ZyanBitset* bitset, ZyanUSize index, ZyanBool value); + +/** + * Toggles the bit at `index` of the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param index The bit index. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset* bitset, ZyanUSize index); + +/** + * Returns the value of the bit at `index`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param index The bit index. + * + * @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not, Another zyan + * status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset* bitset, ZyanUSize index); + +/** + * Returns the value of the most significant bit. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan + * status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset* bitset); + +/** + * Returns the value of the least significant bit. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return `ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan + * status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Sets all bits of the given `ZyanBitset` instance to `1`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetSetAll(ZyanBitset* bitset); + +/** + * Sets all bits of the given `ZyanBitset` instance to `0`. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetResetAll(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ +/* Size management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Adds a new bit at the end of the bitset. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param value The value of the new bit. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetPush(ZyanBitset* bitset, ZyanBool value); + +/** + * Removes the last bit of the bitset. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetPop(ZyanBitset* bitset); + +/** + * Deletes all bits of the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetClear(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Changes the capacity of the given `ZyanBitset` instance. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param count The new capacity (number of bits). + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetReserve(ZyanBitset* bitset, ZyanUSize count); + +/** + * Shrinks the capacity of the given bitset to match it's size. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset* bitset); + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the current size of the bitset in bits. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param size Receives the size of the bitset in bits. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset* bitset, ZyanUSize* size); + +/** + * Returns the current capacity of the bitset in bits. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param capacity Receives the size of the bitset in bits. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset* bitset, ZyanUSize* capacity); + +/** + * Returns the current size of the bitset in bytes. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param size Receives the size of the bitset in bytes. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset* bitset, ZyanUSize* size); + +/** + * Returns the current capacity of the bitset in bytes. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param capacity Receives the size of the bitset in bytes. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset* bitset, ZyanUSize* capacity); + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the amount of bits set in the given bitset. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * @param count Receives the amount of bits set in the given bitset. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* count); + +/** + * Checks, if all bits of the given bitset are set. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return `ZYAN_STATUS_TRUE`, if all bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan + * status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset* bitset); + +/** + * Checks, if at least one bit of the given bitset is set. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return `ZYAN_STATUS_TRUE`, if at least one bit is set, `ZYAN_STATUS_FALSE`, if not. Another + * zyan status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset* bitset); + +/** + * Checks, if none bits of the given bitset are set. + * + * @param bitset A pointer to the `ZyanBitset` instance. + * + * @return `ZYAN_STATUS_TRUE`, if none bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan + * status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset* bitset); + +///* ---------------------------------------------------------------------------------------------- */ +// +///** +// * Returns a 32-bit unsigned integer representation of the data. +// * +// * @param bitset A pointer to the `ZyanBitset` instance. +// * @param value Receives the 32-bit unsigned integer representation of the data. +// * +// * @return A zyan status code. +// */ +//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU32(const ZyanBitset* bitset, ZyanU32* value); +// +///** +// * Returns a 64-bit unsigned integer representation of the data. +// * +// * @param bitset A pointer to the `ZyanBitset` instance. +// * @param value Receives the 64-bit unsigned integer representation of the data. +// * +// * @return A zyan status code. +// */ +//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU64(const ZyanBitset* bitset, ZyanU64* value); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_BITSET_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Comparison.h b/externals/dynarmic/externals/zycore/include/Zycore/Comparison.h new file mode 100755 index 000000000..6d8b518b3 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Comparison.h @@ -0,0 +1,316 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Defines prototypes of general-purpose comparison functions. + */ + +#ifndef ZYCORE_COMPARISON_H +#define ZYCORE_COMPARISON_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanEqualityComparison` function prototype. + * + * @param left A pointer to the first element. + * @param right A pointer to the second element. + * + * @return This function should return `ZYAN_TRUE` if the `left` element equals the `right` one + * or `ZYAN_FALSE`, if not. + */ +typedef ZyanBool (*ZyanEqualityComparison)(const void* left, const void* right); + +/** + * Defines the `ZyanComparison` function prototype. + * + * @param left A pointer to the first element. + * @param right A pointer to the second element. + * + * @return This function should return values in the following range: + * `left == right -> result == 0` + * `left < right -> result < 0` + * `left > right -> result > 0` + */ +typedef ZyanI32 (*ZyanComparison)(const void* left, const void* right); + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Equality comparison functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Declares a generic equality comparison function for an integral data-type. + * + * @param name The name of the function. + * @param type The name of the integral data-type. + */ +#define ZYAN_DECLARE_EQUALITY_COMPARISON(name, type) \ + ZyanBool name(const type* left, const type* right) \ + { \ + ZYAN_ASSERT(left); \ + ZYAN_ASSERT(right); \ + \ + return (*left == *right) ? ZYAN_TRUE : ZYAN_FALSE; \ + } + +/** + * Declares a generic equality comparison function that compares a single integral + * data-type field of a struct. + * + * @param name The name of the function. + * @param type The name of the integral data-type. + * @param field_name The name of the struct field. + */ +#define ZYAN_DECLARE_EQUALITY_COMPARISON_FOR_FIELD(name, type, field_name) \ + ZyanBool name(const type* left, const type* right) \ + { \ + ZYAN_ASSERT(left); \ + ZYAN_ASSERT(right); \ + \ + return (left->field_name == right->field_name) ? ZYAN_TRUE : ZYAN_FALSE; \ + } + +/* ---------------------------------------------------------------------------------------------- */ +/* Comparison functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Declares a generic comparison function for an integral data-type. + * + * @param name The name of the function. + * @param type The name of the integral data-type. + */ +#define ZYAN_DECLARE_COMPARISON(name, type) \ + ZyanI32 name(const type* left, const type* right) \ + { \ + ZYAN_ASSERT(left); \ + ZYAN_ASSERT(right); \ + \ + if (*left < *right) \ + { \ + return -1; \ + } \ + if (*left > *right) \ + { \ + return 1; \ + } \ + return 0; \ + } + +/** + * Declares a generic comparison function that compares a single integral data-type field + * of a struct. + * + * @param name The name of the function. + * @param type The name of the integral data-type. + * @param field_name The name of the struct field. + */ +#define ZYAN_DECLARE_COMPARISON_FOR_FIELD(name, type, field_name) \ + ZyanI32 name(const type* left, const type* right) \ + { \ + ZYAN_ASSERT(left); \ + ZYAN_ASSERT(right); \ + \ + if (left->field_name < right->field_name) \ + { \ + return -1; \ + } \ + if (left->field_name > right->field_name) \ + { \ + return 1; \ + } \ + return 0; \ + } + + /* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Default equality comparison functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines a default equality comparison function for pointer values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsPointer, void* const) + +/** + * Defines a default equality comparison function for `ZyanBool` values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsBool, ZyanBool) + +/** + * Defines a default equality comparison function for 8-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsNumeric8, ZyanU8) + +/** + * Defines a default equality comparison function for 16-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsNumeric16, ZyanU16) + +/** + * Defines a default equality comparison function for 32-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsNumeric32, ZyanU32) + +/** + * Defines a default equality comparison function for 64-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if + * not. + */ +ZYAN_INLINE ZYAN_DECLARE_EQUALITY_COMPARISON(ZyanEqualsNumeric64, ZyanU64) + +/* ---------------------------------------------------------------------------------------------- */ +/* Default comparison functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines a default comparison function for pointer values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanComparePointer, void* const) + +/** + * Defines a default comparison function for `ZyanBool` values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanCompareBool, ZyanBool) + +/** + * Defines a default comparison function for 8-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanCompareNumeric8, ZyanU8) + +/** + * Defines a default comparison function for 16-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanCompareNumeric16, ZyanU16) + +/** + * Defines a default comparison function for 32-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanCompareNumeric32, ZyanU32) + +/** + * Defines a default comparison function for 64-bit numeric values. + * + * @param left A pointer to the first value. + * @param right A pointer to the second value. + * + * @return Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is + * less than the `right` one, or `1` if the `left` value is greater than the `right` one. + */ +ZYAN_INLINE ZYAN_DECLARE_COMPARISON(ZyanCompareNumeric64, ZyanU64) + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_COMPARISON_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Defines.h b/externals/dynarmic/externals/zycore/include/Zycore/Defines.h new file mode 100755 index 000000000..65afbaa39 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Defines.h @@ -0,0 +1,443 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd, Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * General helper and platform detection macros. + */ + +#ifndef ZYCORE_DEFINES_H +#define ZYCORE_DEFINES_H + +/* ============================================================================================== */ +/* Meta macros */ +/* ============================================================================================== */ + +/** + * Concatenates two values using the stringify operator (`##`). + * + * @param x The first value. + * @param y The second value. + * + * @return The combined string of the given values. + */ +#define ZYAN_MACRO_CONCAT(x, y) x ## y + +/** + * Concatenates two values using the stringify operator (`##`) and expands the value to + * be used in another macro. + * + * @param x The first value. + * @param y The second value. + * + * @return The combined string of the given values. + */ +#define ZYAN_MACRO_CONCAT_EXPAND(x, y) ZYAN_MACRO_CONCAT(x, y) + +/* ============================================================================================== */ +/* Compiler detection */ +/* ============================================================================================== */ + +#if defined(__clang__) +# define ZYAN_CLANG +# define ZYAN_GNUC +#elif defined(__ICC) || defined(__INTEL_COMPILER) +# define ZYAN_ICC +#elif defined(__GNUC__) || defined(__GNUG__) +# define ZYAN_GCC +# define ZYAN_GNUC +#elif defined(_MSC_VER) +# define ZYAN_MSVC +#elif defined(__BORLANDC__) +# define ZYAN_BORLAND +#else +# define ZYAN_UNKNOWN_COMPILER +#endif + +/* ============================================================================================== */ +/* Platform detection */ +/* ============================================================================================== */ + +#if defined(_WIN32) +# define ZYAN_WINDOWS +#elif defined(__EMSCRIPTEN__) +# define ZYAN_EMSCRIPTEN +#elif defined(__APPLE__) +# define ZYAN_APPLE +# define ZYAN_POSIX +#elif defined(__linux) +# define ZYAN_LINUX +# define ZYAN_POSIX +#elif defined(__FreeBSD__) +# define ZYAN_FREEBSD +# define ZYAN_POSIX +#elif defined(sun) || defined(__sun) +# define ZYAN_SOLARIS +# define ZYAN_POSIX +#elif defined(__unix) +# define ZYAN_UNIX +# define ZYAN_POSIX +#elif defined(__posix) +# define ZYAN_POSIX +#else +# define ZYAN_UNKNOWN_PLATFORM +#endif + +/* ============================================================================================== */ +/* Kernel mode detection */ +/* ============================================================================================== */ + +#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \ + (defined(ZYAN_APPLE) && defined(KERNEL)) || \ + (defined(ZYAN_LINUX) && defined(__KERNEL__)) || \ + (defined(__FreeBSD_kernel__)) +# define ZYAN_KERNEL +#else +# define ZYAN_USER +#endif + +/* ============================================================================================== */ +/* Architecture detection */ +/* ============================================================================================== */ + +#if defined(_M_AMD64) || defined(__x86_64__) +# define ZYAN_X64 +#elif defined(_M_IX86) || defined(__i386__) +# define ZYAN_X86 +#elif defined(_M_ARM64) || defined(__aarch64__) +# define ZYAN_AARCH64 +#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__) +# define ZYAN_ARM +#elif defined(__EMSCRIPTEN__) + // Nothing to do, `ZYAN_EMSCRIPTEN` is both platform and arch macro for this one. +#else +# error "Unsupported architecture detected" +#endif + +/* ============================================================================================== */ +/* Debug/Release detection */ +/* ============================================================================================== */ + +#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND) +# ifdef _DEBUG +# define ZYAN_DEBUG +# else +# define ZYAN_RELEASE +# endif +#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC) +# ifdef NDEBUG +# define ZYAN_RELEASE +# else +# define ZYAN_DEBUG +# endif +#else +# define ZYAN_RELEASE +#endif + +/* ============================================================================================== */ +/* Misc compatibility macros */ +/* ============================================================================================== */ + +#if defined(ZYAN_CLANG) +# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what))) +#else +# define ZYAN_NO_SANITIZE(what) +#endif + +#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND) +# define ZYAN_INLINE __inline +#else +# define ZYAN_INLINE static inline +#endif + +/* ============================================================================================== */ +/* Debugging and optimization macros */ +/* ============================================================================================== */ + +/** + * Runtime debug assertion. + */ +#if defined(ZYAN_NO_LIBC) +# define ZYAN_ASSERT(condition) (void)(condition) +#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL) +# include +# define ZYAN_ASSERT(condition) NT_ASSERT(condition) +#else +# include +# define ZYAN_ASSERT(condition) assert(condition) +#endif + +/** + * Compiler-time assertion. + */ +#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus) +# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x) +#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \ + (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \ + (defined (_MSC_VER) && (_MSC_VER >= 1800)) +# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x) +#else +# define ZYAN_STATIC_ASSERT(x) \ + typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1] +#endif + +/** + * Marks the current code path as unreachable. + */ +#if defined(ZYAN_RELEASE) +# if defined(ZYAN_CLANG) // GCC eagerly evals && RHS, we have to use nested ifs. +# if __has_builtin(__builtin_unreachable) +# define ZYAN_UNREACHABLE __builtin_unreachable() +# else +# define ZYAN_UNREACHABLE for(;;) +# endif +# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4) +# define ZYAN_UNREACHABLE __builtin_unreachable() +# elif defined(ZYAN_ICC) +# ifdef ZYAN_WINDOWS +# include // "missing return statement" workaround +# define ZYAN_UNREACHABLE __assume(0); (void)abort() +# else +# define ZYAN_UNREACHABLE __builtin_unreachable() +# endif +# elif defined(ZYAN_MSVC) +# define ZYAN_UNREACHABLE __assume(0) +# else +# define ZYAN_UNREACHABLE for(;;) +# endif +#elif defined(ZYAN_NO_LIBC) +# define ZYAN_UNREACHABLE for(;;) +#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL) +# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} } +#else +# include +# define ZYAN_UNREACHABLE { assert(0); abort(); } +#endif + +/* ============================================================================================== */ +/* Utils */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General purpose */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Marks the specified parameter as unused. + * + * @param x The name of the unused parameter. + */ +#define ZYAN_UNUSED(x) (void)(x) + +/** + * Intentional fallthrough. + */ +#if defined(ZYAN_GCC) && __GNUC__ >= 7 +# define ZYAN_FALLTHROUGH __attribute__((fallthrough)) +#else +# define ZYAN_FALLTHROUGH +#endif + +/** + * Declares a bitfield. + * + * @param x The size (in bits) of the bitfield. + */ +#define ZYAN_BITFIELD(x) : x + +/** + * Marks functions that require libc (cannot be used with `ZYAN_NO_LIBC`). + */ +#define ZYAN_REQUIRES_LIBC + +/** + * Decorator for `printf`-style functions. + * + * @param format_index The 1-based index of the format string parameter. + * @param first_to_check The 1-based index of the format arguments parameter. + */ +#if defined(__RESHARPER__) +# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \ + [[gnu::format(printf, format_index, first_to_check)]] +#elif defined(ZYAN_GCC) +# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \ + __attribute__((format(printf, format_index, first_to_check))) +#else +# define ZYAN_PRINTF_ATTR(format_index, first_to_check) +#endif + +/** + * Decorator for `wprintf`-style functions. + * + * @param format_index The 1-based index of the format string parameter. + * @param first_to_check The 1-based index of the format arguments parameter. + */ +#if defined(__RESHARPER__) +# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \ + [[rscpp::format(wprintf, format_index, first_to_check)]] +#else +# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) +#endif + +/* ---------------------------------------------------------------------------------------------- */ +/* Arrays */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the length (number of elements) of an array. + * + * @param a The name of the array. + * + * @return The number of elements of the given array. + */ +#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0])) + +/* ---------------------------------------------------------------------------------------------- */ +/* Arithmetic */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the smaller value of `a` or `b`. + * + * @param a The first value. + * @param b The second value. + * + * @return The smaller value of `a` or `b`. + */ +#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b)) + +/** + * Returns the bigger value of `a` or `b`. + * + * @param a The first value. + * @param b The second value. + * + * @return The bigger value of `a` or `b`. + */ +#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b)) + +/** + * Returns the absolute value of `a`. + * + * @param a The value. + * + * @return The absolute value of `a`. + */ +#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a)) + +/** + * Checks, if the given value is a power of 2. + * + * @param x The value. + * + * @return `ZYAN_TRUE`, if the given value is a power of 2 or `ZYAN_FALSE`, if not. + * + * Note that this macro always returns `ZYAN_TRUE` for `x == 0`. + */ +#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0) + +/** + * Checks, if the given value is properly aligned. + * + * Note that this macro only works for powers of 2. + */ +#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0) + +/** + * Aligns the value to the nearest given alignment boundary (by rounding it up). + * + * @param x The value. + * @param align The desired alignment. + * + * @return The aligned value. + * + * Note that this macro only works for powers of 2. + */ +#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1)) + +/** + * Aligns the value to the nearest given alignment boundary (by rounding it down). + * + * @param x The value. + * @param align The desired alignment. + * + * @return The aligned value. + * + * Note that this macro only works for powers of 2. + */ +#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1)) + +/* ---------------------------------------------------------------------------------------------- */ +/* Bit operations */ +/* ---------------------------------------------------------------------------------------------- */ + +/* + * Checks, if the bit at index `b` is required to present the ordinal value `n`. + * + * @param n The ordinal value. + * @param b The bit index. + * + * @return `ZYAN_TRUE`, if the bit at index `b` is required to present the ordinal value `n` or + * `ZYAN_FALSE`, if not. + * + * Note that this macro always returns `ZYAN_FALSE` for `n == 0`. + */ +#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0) + +/* + * Returns the number of bits required to represent the ordinal value `n`. + * + * @param n The ordinal value. + * + * @return The number of bits required to represent the ordinal value `n`. + * + * Note that this macro returns `0` for `n == 0`. + */ +#define ZYAN_BITS_TO_REPRESENT(n) \ + ( \ + ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \ + ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \ + ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \ + ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \ + ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \ + ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \ + ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \ + ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \ + ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \ + ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \ + ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \ + ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \ + ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \ + ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \ + ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \ + ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \ + ) + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#endif /* ZYCORE_DEFINES_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Format.h b/externals/dynarmic/externals/zycore/include/Zycore/Format.h new file mode 100755 index 000000000..b0401e625 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Format.h @@ -0,0 +1,286 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Provides helper functions for performant number to string conversion. + */ + +#ifndef ZYCORE_FORMAT_H +#define ZYCORE_FORMAT_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Helpers */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Get the absolute value of a 64 bit int. + * + * @param x The value to process. + * @return The absolute, unsigned value. + * + * This gracefully deals with the special case of `x` being `INT_MAX`. + */ +ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x) +{ + // INT_MIN special case. Can't use the value directly because GCC thinks + // it's too big for an INT64 literal, however is perfectly happy to accept + // this expression. This is also hit INT64_MIN is defined in `stdint.h`. + if (x == (-0x7fffffffffffffff - 1)) + { + return 0x8000000000000000u; + } + + return (ZyanU64)(x < 0 ? -x : x); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Inserts formatted text in the destination string at the given `index`. + * + * @param string The destination string. + * @param index The insert index. + * @param format The format string. + * @param ... The format arguments. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYAN_PRINTF_ATTR(3, 4) +ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat(ZyanString* string, ZyanUSize index, + const char* format, ...); + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Formats the given unsigned ordinal `value` to its decimal text-representation and + * inserts it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The insert index. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecU(ZyanString* string, ZyanUSize index, ZyanU64 value, + ZyanU8 padding_length); + +/** + * Formats the given signed ordinal `value` to its decimal text-representation and + * inserts it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The insert index. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param force_sign Set `ZYAN_TRUE`, to force printing of the `+` sign for positive numbers. + * @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecS(ZyanString* string, ZyanUSize index, ZyanI64 value, + ZyanU8 padding_length, ZyanBool force_sign, const ZyanString* prefix); + +/** + * Formats the given unsigned ordinal `value` to its hexadecimal text-representation and + * inserts it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The insert index. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param uppercase Set `ZYAN_TRUE` to use uppercase letters ('A'-'F') instead of lowercase + * ones ('a'-'f'). + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexU(ZyanString* string, ZyanUSize index, ZyanU64 value, + ZyanU8 padding_length, ZyanBool uppercase); + +/** + * Formats the given signed ordinal `value` to its hexadecimal text-representation and + * inserts it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The insert index. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param uppercase Set `ZYAN_TRUE` to use uppercase letters ('A'-'F') instead of lowercase + * ones ('a'-'f'). + * @param force_sign Set `ZYAN_TRUE`, to force printing of the `+` sign for positive numbers. + * @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString* string, ZyanUSize index, ZyanI64 value, + ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString* prefix); + +/* ---------------------------------------------------------------------------------------------- */ +/* Appending */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Appends formatted text to the destination string. + * + * @param string The destination string. + * @param format The format string. + * @param ... The format arguments. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYAN_PRINTF_ATTR(2, 3) +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat( + ZyanString* string, const char* format, ...); + +#endif // ZYAN_NO_LIBC + +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Formats the given unsigned ordinal `value` to its decimal text-representation and + * appends it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecU(ZyanString* string, ZyanU64 value, + ZyanU8 padding_length); + +/** + * Formats the given signed ordinal `value` to its decimal text-representation and + * appends it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param force_sign Set `ZYAN_TRUE`, to force printing of the `+` sign for positive numbers. + * @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecS(ZyanString* string, ZyanI64 value, + ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView* prefix); + +/** + * Formats the given unsigned ordinal `value` to its hexadecimal text-representation and + * appends it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param uppercase Set `ZYAN_TRUE` to use uppercase letters ('A'-'F') instead of lowercase + * ones ('a'-'f'). + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexU(ZyanString* string, ZyanU64 value, + ZyanU8 padding_length, ZyanBool uppercase); + +/** + * Formats the given signed ordinal `value` to its hexadecimal text-representation and + * appends it to the `string`. + * + * @param string A pointer to the `ZyanString` instance. + * @param value The value. + * @param padding_length Padds the converted value with leading zeros, if the number of chars is + * less than the `padding_length`. + * @param uppercase Set `ZYAN_TRUE` to use uppercase letters ('A'-'F') instead of lowercase + * ones ('a'-'f'). + * @param force_sign Set `ZYAN_TRUE`, to force printing of the `+` sign for positive numbers. + * @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexS(ZyanString* string, ZyanI64 value, + ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView* prefix); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif // ZYCORE_FORMAT_H diff --git a/externals/dynarmic/externals/zycore/include/Zycore/LibC.h b/externals/dynarmic/externals/zycore/include/Zycore/LibC.h new file mode 100755 index 000000000..cb0b2f325 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/LibC.h @@ -0,0 +1,511 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd, Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Provides a simple LibC abstraction and fallback routines. + */ + +#ifndef ZYCORE_LIBC_H +#define ZYCORE_LIBC_H + +#ifndef ZYAN_CUSTOM_LIBC + +// Include a custom LibC header and define `ZYAN_CUSTOM_LIBC` to provide your own LibC +// replacement functions + +#ifndef ZYAN_NO_LIBC + +/* ============================================================================================== */ +/* LibC is available */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* errno.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#include + +#define ZYAN_ERRNO errno + +/* ---------------------------------------------------------------------------------------------- */ +/* stdarg.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#include + +/** + * Defines the `ZyanVAList` datatype. + */ +typedef va_list ZyanVAList; + +#define ZYAN_VA_START va_start +#define ZYAN_VA_ARG va_arg +#define ZYAN_VA_END va_end +#define ZYAN_VA_COPY(dest, source) va_copy((dest), (source)) + +/* ---------------------------------------------------------------------------------------------- */ +/* stdio.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#include + +#define ZYAN_FPUTS fputs +#define ZYAN_FPUTC fputc +#define ZYAN_FPRINTF fprintf +#define ZYAN_PRINTF printf +#define ZYAN_PUTC putc +#define ZYAN_PUTS puts +#define ZYAN_SCANF scanf +#define ZYAN_SSCANF sscanf +#define ZYAN_VSNPRINTF vsnprintf + +/** + * Defines the `ZyanFile` datatype. + */ +typedef FILE ZyanFile; + +#define ZYAN_STDIN stdin +#define ZYAN_STDOUT stdout +#define ZYAN_STDERR stderr + +/* ---------------------------------------------------------------------------------------------- */ +/* stdlib.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#include +#define ZYAN_CALLOC calloc +#define ZYAN_FREE free +#define ZYAN_MALLOC malloc +#define ZYAN_REALLOC realloc + +/* ---------------------------------------------------------------------------------------------- */ +/* string.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#include +#define ZYAN_MEMCHR memchr +#define ZYAN_MEMCMP memcmp +#define ZYAN_MEMCPY memcpy +#define ZYAN_MEMMOVE memmove +#define ZYAN_MEMSET memset +#define ZYAN_STRCAT strcat +#define ZYAN_STRCHR strchr +#define ZYAN_STRCMP strcmp +#define ZYAN_STRCOLL strcoll +#define ZYAN_STRCPY strcpy +#define ZYAN_STRCSPN strcspn +#define ZYAN_STRLEN strlen +#define ZYAN_STRNCAT strncat +#define ZYAN_STRNCMP strncmp +#define ZYAN_STRNCPY strncpy +#define ZYAN_STRPBRK strpbrk +#define ZYAN_STRRCHR strrchr +#define ZYAN_STRSPN strspn +#define ZYAN_STRSTR strstr +#define ZYAN_STRTOK strtok +#define ZYAN_STRXFRM strxfrm + +/* ---------------------------------------------------------------------------------------------- */ + +#else // if ZYAN_NO_LIBC + +/* ============================================================================================== */ +/* No LibC available, use our own functions */ +/* ============================================================================================== */ + +#include +#include + +/* + * These implementations are by no means optimized and will be outperformed by pretty much any + * libc implementation out there. We do not aim towards providing competetive implementations here, + * but towards providing a last resort fallback for environments without a working libc. + */ + +/* ---------------------------------------------------------------------------------------------- */ +/* stdarg.h */ +/* ---------------------------------------------------------------------------------------------- */ + +#if defined(ZYAN_MSVC) || defined(ZYAN_ICC) + +/** + * Defines the `ZyanVAList` datatype. + */ +typedef char* ZyanVAList; + +# define ZYAN_VA_START __crt_va_start +# define ZYAN_VA_ARG __crt_va_arg +# define ZYAN_VA_END __crt_va_end +# define ZYAN_VA_COPY(destination, source) ((destination) = (source)) + +#elif defined(ZYAN_GNUC) + +/** + * Defines the `ZyanVAList` datatype. + */ +typedef __builtin_va_list ZyanVAList; + +# define ZYAN_VA_START(v, l) __builtin_va_start(v, l) +# define ZYAN_VA_END(v) __builtin_va_end(v) +# define ZYAN_VA_ARG(v, l) __builtin_va_arg(v, l) +# define ZYAN_VA_COPY(d, s) __builtin_va_copy(d, s) + +#else +# error "Unsupported compiler for no-libc mode." +#endif + +/* ---------------------------------------------------------------------------------------------- */ +/* stdio.h */ +/* ---------------------------------------------------------------------------------------------- */ + +// ZYAN_INLINE int ZYAN_VSNPRINTF (char* const buffer, ZyanUSize const count, +// char const* const format, ZyanVAList args) +// { +// // We cant provide a fallback implementation for this function +// ZYAN_UNUSED(buffer); +// ZYAN_UNUSED(count); +// ZYAN_UNUSED(format); +// ZYAN_UNUSED(args); +// return ZYAN_NULL; +// } + +/* ---------------------------------------------------------------------------------------------- */ +/* stdlib.h */ +/* ---------------------------------------------------------------------------------------------- */ + +// ZYAN_INLINE void* ZYAN_CALLOC(ZyanUSize nitems, ZyanUSize size) +// { +// // We cant provide a fallback implementation for this function +// ZYAN_UNUSED(nitems); +// ZYAN_UNUSED(size); +// return ZYAN_NULL; +// } +// +// ZYAN_INLINE void ZYAN_FREE(void *p) +// { +// // We cant provide a fallback implementation for this function +// ZYAN_UNUSED(p); +// } +// +// ZYAN_INLINE void* ZYAN_MALLOC(ZyanUSize n) +// { +// // We cant provide a fallback implementation for this function +// ZYAN_UNUSED(n); +// return ZYAN_NULL; +// } +// +// ZYAN_INLINE void* ZYAN_REALLOC(void* p, ZyanUSize n) +// { +// // We cant provide a fallback implementation for this function +// ZYAN_UNUSED(p); +// ZYAN_UNUSED(n); +// return ZYAN_NULL; +// } + +/* ---------------------------------------------------------------------------------------------- */ +/* string.h */ +/* ---------------------------------------------------------------------------------------------- */ + +ZYAN_INLINE void* ZYAN_MEMCHR(const void* str, int c, ZyanUSize n) +{ + const ZyanU8* p = (ZyanU8*)str; + while (n--) + { + if (*p != (ZyanU8)c) + { + p++; + } else + { + return (void*)p; + } + } + return 0; +} + +ZYAN_INLINE int ZYAN_MEMCMP(const void* s1, const void* s2, ZyanUSize n) +{ + const ZyanU8* p1 = s1, *p2 = s2; + while (n--) + { + if (*p1 != *p2) + { + return *p1 - *p2; + } + p1++, p2++; + } + return 0; +} + +ZYAN_INLINE void* ZYAN_MEMCPY(void* dst, const void* src, ZyanUSize n) +{ + volatile ZyanU8* dp = dst; + const ZyanU8* sp = src; + while (n--) + { + *dp++ = *sp++; + } + return dst; +} + +ZYAN_INLINE void* ZYAN_MEMMOVE(void* dst, const void* src, ZyanUSize n) +{ + volatile ZyanU8* pd = dst; + const ZyanU8* ps = src; + if (ps < pd) + { + for (pd += n, ps += n; n--;) + { + *--pd = *--ps; + } + } else + { + while (n--) + { + *pd++ = *ps++; + } + } + return dst; +} + +ZYAN_INLINE void* ZYAN_MEMSET(void* dst, int val, ZyanUSize n) +{ + volatile ZyanU8* p = dst; + while (n--) + { + *p++ = (unsigned char)val; + } + return dst; +} + +ZYAN_INLINE char* ZYAN_STRCAT(char* dest, const char* src) +{ + char* ret = dest; + while (*dest) + { + dest++; + } + while ((*dest++ = *src++)); + return ret; +} + +ZYAN_INLINE char* ZYAN_STRCHR(const char* s, int c) +{ + while (*s != (char)c) + { + if (!*s++) + { + return 0; + } + } + return (char*)s; +} + +ZYAN_INLINE int ZYAN_STRCMP(const char* s1, const char* s2) +{ + while (*s1 && (*s1 == *s2)) + { + s1++, s2++; + } + return *(const ZyanU8*)s1 - *(const ZyanU8*)s2; +} + +ZYAN_INLINE int ZYAN_STRCOLL(const char *s1, const char *s2) +{ + // TODO: Implement + + ZYAN_UNUSED(s1); + ZYAN_UNUSED(s2); + + return 0; +} + +ZYAN_INLINE char* ZYAN_STRCPY(char* dest, const char* src) +{ + char* ret = dest; + while ((*dest++ = *src++)); + return ret; +} + +ZYAN_INLINE ZyanUSize ZYAN_STRCSPN(const char *s1, const char *s2) +{ + ZyanUSize ret = 0; + while (*s1) + { + if (ZYAN_STRCHR(s2, *s1)) + { + return ret; + } + s1++, ret++; + } + return ret; +} + +ZYAN_INLINE ZyanUSize ZYAN_STRLEN(const char* str) +{ + const char* p = str; + while (*str) + { + ++str; + } + return str - p; +} + +ZYAN_INLINE char* ZYAN_STRNCAT(char* dest, const char* src, ZyanUSize n) +{ + char* ret = dest; + while (*dest) + { + dest++; + } + while (n--) + { + if (!(*dest++ = *src++)) + { + return ret; + } + } + *dest = 0; + return ret; +} + +ZYAN_INLINE int ZYAN_STRNCMP(const char* s1, const char* s2, ZyanUSize n) +{ + while (n--) + { + if (*s1++ != *s2++) + { + return *(unsigned char*)(s1 - 1) - *(unsigned char*)(s2 - 1); + } + } + return 0; +} + +ZYAN_INLINE char* ZYAN_STRNCPY(char* dest, const char* src, ZyanUSize n) +{ + char* ret = dest; + do + { + if (!n--) + { + return ret; + } + } while ((*dest++ = *src++)); + while (n--) + { + *dest++ = 0; + } + return ret; +} + +ZYAN_INLINE char* ZYAN_STRPBRK(const char* s1, const char* s2) +{ + while (*s1) + { + if(ZYAN_STRCHR(s2, *s1++)) + { + return (char*)--s1; + } + } + return 0; +} + +ZYAN_INLINE char* ZYAN_STRRCHR(const char* s, int c) +{ + char* ret = 0; + do + { + if (*s == (char)c) + { + ret = (char*)s; + } + } while (*s++); + return ret; +} + +ZYAN_INLINE ZyanUSize ZYAN_STRSPN(const char* s1, const char* s2) +{ + ZyanUSize ret = 0; + while (*s1 && ZYAN_STRCHR(s2, *s1++)) + { + ret++; + } + return ret; +} + +ZYAN_INLINE char* ZYAN_STRSTR(const char* s1, const char* s2) +{ + const ZyanUSize n = ZYAN_STRLEN(s2); + while (*s1) + { + if (!ZYAN_MEMCMP(s1++, s2, n)) + { + return (char*)(s1 - 1); + } + } + return 0; +} + +ZYAN_INLINE char* ZYAN_STRTOK(char* str, const char* delim) +{ + static char* p = 0; + if (str) + { + p = str; + } else + if (!p) + { + return 0; + } + str = p + ZYAN_STRSPN(p, delim); + p = str + ZYAN_STRCSPN(str, delim); + if (p == str) + { + return p = 0; + } + p = *p ? *p = 0, p + 1 : 0; + return str; +} + +ZYAN_INLINE ZyanUSize ZYAN_STRXFRM(char* dest, const char* src, ZyanUSize n) +{ + const ZyanUSize n2 = ZYAN_STRLEN(src); + if (n > n2) + { + ZYAN_STRCPY(dest, src); + } + return n2; +} + +/* ---------------------------------------------------------------------------------------------- */ + +#endif + +#endif + +/* ============================================================================================== */ + +#endif /* ZYCORE_LIBC_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/List.h b/externals/dynarmic/externals/zycore/include/Zycore/List.h new file mode 100755 index 000000000..015a324d3 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/List.h @@ -0,0 +1,574 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Implements a doubly linked list. + */ + +#ifndef ZYCORE_LIST_H +#define ZYCORE_LIST_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanListNode` struct. + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanListNode_ +{ + /** + * A pointer to the previous list node. + */ + struct ZyanListNode_* prev; + /** + * A pointer to the next list node. + */ + struct ZyanListNode_* next; +} ZyanListNode; + +/** + * Defines the `ZyanList` struct. + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanList_ +{ + /** + * The memory allocator. + */ + ZyanAllocator* allocator; + /** + * The current number of elements in the list. + */ + ZyanUSize size; + /** + * The size of a single element in bytes. + */ + ZyanUSize element_size; + /** + * The element destructor callback. + */ + ZyanMemberProcedure destructor; + /** + * The head node. + */ + ZyanListNode* head; + /** + * The tail node. + */ + ZyanListNode* tail; + /** + * The data buffer. + * + * Only used for instances created by `ZyanListInitCustomBuffer`. + */ + void* buffer; + /** + * The data buffer capacity (number of bytes). + * + * Only used for instances created by `ZyanListInitCustomBuffer`. + */ + ZyanUSize capacity; + /** + * The first unused node. + * + * When removing a node, the first-unused value is updated to point at the removed node and the + * next node of the removed node will be updated to point at the old first-unused node. + * + * When appending the memory of the first unused-node is recycled to store the new node. The + * value of the first-unused node is then updated to point at the reused nodes next node. + * + * If the first-unused value is `ZYAN_NULL`, any new node will be "allocated" behind the tail + * node (if there is enough space left in the fixed size buffer). + * + * Only used for instances created by `ZyanListInitCustomBuffer`. + */ + ZyanListNode* first_unused; +} ZyanList; + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines an uninitialized `ZyanList` instance. + */ +#define ZYAN_LIST_INITIALIZER \ + { \ + /* allocator */ ZYAN_NULL, \ + /* size */ 0, \ + /* element_size */ 0, \ + /* head */ ZYAN_NULL, \ + /* destructor */ ZYAN_NULL, \ + /* tail */ ZYAN_NULL, \ + /* buffer */ ZYAN_NULL, \ + /* capacity */ 0, \ + /* first_unused */ ZYAN_NULL \ + } + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper macros */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the data value of the given `node`. + * + * @param type The desired value type. + * @param node A pointer to the `ZyanListNode` struct. + * + * @result The data value of the given `node`. + * + * Note that this function is unsafe and might dereference a null-pointer. + */ +#ifdef __cplusplus +#define ZYAN_LIST_GET(type, node) \ + (*reinterpret_cast(ZyanListGetNodeData(node))) +#else +#define ZYAN_LIST_GET(type, node) \ + (*(const type*)ZyanListGetNodeData(node)) +#endif + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanList` instance. + * + * @param list A pointer to the `ZyanList` instance. + * @param element_size The size of a single element in bytes. + * @param destructor A destructor callback that is invoked every time an item is deleted, or + * `ZYAN_NULL` if not needed. + * + * @return A zyan status code. + * + * The memory for the list elements is dynamically allocated by the default allocator. + * + * Finalization with `ZyanListDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList* list, ZyanUSize element_size, + ZyanMemberProcedure destructor); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanList` instance and sets a custom `allocator`. + * + * @param list A pointer to the `ZyanList` instance. + * @param element_size The size of a single element in bytes. + * @param destructor A destructor callback that is invoked every time an item is deleted, or + * `ZYAN_NULL` if not needed. + * @param allocator A pointer to a `ZyanAllocator` instance. + * + * @return A zyan status code. + * + * Finalization with `ZyanListDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size, + ZyanMemberProcedure destructor, ZyanAllocator* allocator); + +/** + * Initializes the given `ZyanList` instance and configures it to use a custom user + * defined buffer with a fixed size. + * + * @param list A pointer to the `ZyanList` instance. + * @param element_size The size of a single element in bytes. + * @param destructor A destructor callback that is invoked every time an item is deleted, or + * `ZYAN_NULL` if not needed. + * @param buffer A pointer to the buffer that is used as storage for the elements. + * @param capacity The maximum capacity (number of bytes) of the buffer including the + * space required for the list-nodes. + * + * @return A zyan status code. + * + * The buffer capacity required to store `n` elements of type `T` is be calculated by: + * `size = n * sizeof(ZyanListNode) + n * sizeof(T)` + * + * Finalization is not required for instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanListInitCustomBuffer(ZyanList* list, ZyanUSize element_size, + ZyanMemberProcedure destructor, void* buffer, ZyanUSize capacity); + +/** + * Destroys the given `ZyanList` instance. + * + * @param list A pointer to the `ZyanList` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListDestroy(ZyanList* list); + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanList` instance by duplicating an existing list. + * + * @param destination A pointer to the (uninitialized) destination `ZyanList` instance. + * @param source A pointer to the source list. + * + * @return A zyan status code. + * + * The memory for the list is dynamically allocated by the default allocator. + * + * Finalization with `ZyanListDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListDuplicate(ZyanList* destination, + const ZyanList* source); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanList` instance by duplicating an existing list and sets a + * custom `allocator`. + * + * @param destination A pointer to the (uninitialized) destination `ZyanList` instance. + * @param source A pointer to the source list. + * @param allocator A pointer to a `ZyanAllocator` instance. + * + * @return A zyan status code. + + * Finalization with `ZyanListDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanListDuplicateEx(ZyanList* destination, const ZyanList* source, + ZyanAllocator* allocator); + +/** + * Initializes a new `ZyanList` instance by duplicating an existing list and + * configures it to use a custom user defined buffer with a fixed size. + * + * @param destination A pointer to the (uninitialized) destination `ZyanList` instance. + * @param source A pointer to the source list. + * @param buffer A pointer to the buffer that is used as storage for the elements. + * @param capacity The maximum capacity (number of bytes) of the buffer including the + * space required for the list-nodes. + + * This function will fail, if the capacity of the buffer is not sufficient + * to store all elements of the source list. + * + * @return A zyan status code. + * + * The buffer capacity required to store `n` elements of type `T` is be calculated by: + * `size = n * sizeof(ZyanListNode) + n * sizeof(T)` + * + * Finalization is not required for instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanListDuplicateCustomBuffer(ZyanList* destination, + const ZyanList* source, void* buffer, ZyanUSize capacity); + +/* ---------------------------------------------------------------------------------------------- */ +/* Item access */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns a pointer to the first `ZyanListNode` struct of the given list. + * + * @param list A pointer to the `ZyanList` instance. + * @param node Receives a pointer to the first `ZyanListNode` struct of the list. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetHeadNode(const ZyanList* list, const ZyanListNode** node); + +/** + * Returns a pointer to the last `ZyanListNode` struct of the given list. + * + * @param list A pointer to the `ZyanList` instance. + * @param node Receives a pointer to the last `ZyanListNode` struct of the list. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetTailNode(const ZyanList* list, const ZyanListNode** node); + +/** + * Receives a pointer to the previous `ZyanListNode` struct linked to the passed one. + * + * @param node Receives a pointer to the previous `ZyanListNode` struct linked to the passed + * one. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetPrevNode(const ZyanListNode** node); + +/** + * Receives a pointer to the next `ZyanListNode` struct linked to the passed one. + * + * @param node Receives a pointer to the next `ZyanListNode` struct linked to the passed one. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetNextNode(const ZyanListNode** node); + +/** + * Returns a constant pointer to the data of the given `node`. + * + * @param node A pointer to the `ZyanListNode` struct. + * + * @return A constant pointer to the the data of the given `node` or `ZYAN_NULL`, if an error + * occured. + * + * Take a look at `ZyanListGetNodeDataEx`, if you need a function that returns a zyan status code. + */ +ZYCORE_EXPORT const void* ZyanListGetNodeData(const ZyanListNode* node); + +/** + * Returns a constant pointer to the data of the given `node`.. + * + * @param node A pointer to the `ZyanListNode` struct. + * @param value Receives a constant pointer to the data of the given `node`. + * + * Take a look at `ZyanListGetNodeData`, if you need a function that directly returns a pointer. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode* node, const void** value); + +/** + * Returns a mutable pointer to the data of the given `node`. + * + * @param node A pointer to the `ZyanListNode` struct. + * + * @return A mutable pointer to the the data of the given `node` or `ZYAN_NULL`, if an error + * occured. + * + * Take a look at `ZyanListGetPointerMutableEx` instead, if you need a function that returns a + * zyan status code. + */ +ZYCORE_EXPORT void* ZyanListGetNodeDataMutable(const ZyanListNode* node); + +/** + * Returns a mutable pointer to the data of the given `node`.. + * + * @param node A pointer to the `ZyanListNode` struct. + * @param value Receives a mutable pointer to the data of the given `node`. + * + * Take a look at `ZyanListGetNodeDataMutable`, if you need a function that directly returns a + * pointer. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode* node, void** value); + +/** + * Assigns a new data value to the given `node`. + * + * @param list A pointer to the `ZyanList` instance. + * @param node A pointer to the `ZyanListNode` struct. + * @param value The value to assign. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListSetNodeData(const ZyanList* list, const ZyanListNode* node, + const void* value); + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Adds a new `item` to the end of the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param item A pointer to the item to add. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListPushBack(ZyanList* list, const void* item); + +/** + * Adds a new `item` to the beginning of the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param item A pointer to the item to add. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListPushFront(ZyanList* list, const void* item); + +/** + * Constructs an `item` in-place at the end of the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param item Receives a pointer to the new item. + * @param constructor The constructor callback or `ZYAN_NULL`. The new item will be in + * undefined state, if no constructor was passed. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListEmplaceBack(ZyanList* list, void** item, + ZyanMemberFunction constructor); + +/** + * Constructs an `item` in-place at the beginning of the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param item Receives a pointer to the new item. + * @param constructor The constructor callback or `ZYAN_NULL`. The new item will be in + * undefined state, if no constructor was passed. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListEmplaceFront(ZyanList* list, void** item, + ZyanMemberFunction constructor); + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Removes the last element of the list. + * + * @param list A pointer to the `ZyanList` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListPopBack(ZyanList* list); + +/** + * Removes the firstelement of the list. + * + * @param list A pointer to the `ZyanList` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListPopFront(ZyanList* list); + +/** + * Removes the given `node` from the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param node A pointer to the `ZyanListNode` struct. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListRemove(ZyanList* list, const ZyanListNode* node); + +/** + * Removes multiple nodes from the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param first A pointer to the first node. + * @param last A pointer to the last node. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListRemoveRange(ZyanList* list, const ZyanListNode* first, + const ZyanListNode* last); + +/** + * Erases all elements of the list. + * + * @param list A pointer to the `ZyanList` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListClear(ZyanList* list); + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + +// TODO: + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Resizes the given `ZyanList` instance. + * + * @param list A pointer to the `ZyanList` instance. + * @param size The new size of the list. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListResize(ZyanList* list, ZyanUSize size); + +/** + * Resizes the given `ZyanList` instance. + * + * @param list A pointer to the `ZyanList` instance. + * @param size The new size of the list. + * @param initializer A pointer to a value to be used as initializer for new items. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListResizeEx(ZyanList* list, ZyanUSize size, const void* initializer); + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the current size of the list. + * + * @param list A pointer to the `ZyanList` instance. + * @param size Receives the size of the list. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_VECTOR_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Object.h b/externals/dynarmic/externals/zycore/include/Zycore/Object.h new file mode 100755 index 000000000..d015cef77 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Object.h @@ -0,0 +1,84 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Defines some generic object-related datatypes. + */ + +#ifndef ZYCORE_OBJECT_H +#define ZYCORE_OBJECT_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanMemberProcedure` function prototype. + * + * @param object A pointer to the object. + */ +typedef void (*ZyanMemberProcedure)(void* object); + +/** + * Defines the `ZyanConstMemberProcedure` function prototype. + * + * @param object A pointer to the object. + */ +typedef void (*ZyanConstMemberProcedure)(const void* object); + +/** + * Defines the `ZyanMemberFunction` function prototype. + * + * @param object A pointer to the object. + * + * @return A zyan status code. + */ +typedef ZyanStatus (*ZyanMemberFunction)(void* object); + +/** + * Defines the `ZyanConstMemberFunction` function prototype. + * + * @param object A pointer to the object. + * + * @return A zyan status code. + */ +typedef ZyanStatus (*ZyanConstMemberFunction)(const void* object); + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_OBJECT_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Status.h b/externals/dynarmic/externals/zycore/include/Zycore/Status.h new file mode 100755 index 000000000..b0d7fdf58 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Status.h @@ -0,0 +1,287 @@ +/*************************************************************************************************** + + Zyan Core Library (Zyan-C) + + Original Author : Florian Bernd, Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Status code definitions and check macros. + */ + +#ifndef ZYCORE_STATUS_H +#define ZYCORE_STATUS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanStatus` data type. + */ +typedef ZyanU32 ZyanStatus; + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Definition */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines a zyan status code. + * + * @param error `1`, if the status code signals an error or `0`, if not. + * @param module The module id. + * @param code The actual code. + * + * @return The zyan status code. + */ +#define ZYAN_MAKE_STATUS(error, module, code) \ + (ZyanStatus)((((error) & 0x01u) << 31u) | (((module) & 0x7FFu) << 20u) | ((code) & 0xFFFFFu)) + +/* ---------------------------------------------------------------------------------------------- */ +/* Checks */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Checks if a zyan operation was successful. + * + * @param status The zyan status-code to check. + * + * @return `ZYAN_TRUE`, if the operation succeeded or `ZYAN_FALSE`, if not. + */ +#define ZYAN_SUCCESS(status) \ + (!((status) & 0x80000000u)) + +/** + * Checks if a zyan operation failed. + * + * @param status The zyan status-code to check. + * + * @return `ZYAN_TRUE`, if the operation failed or `ZYAN_FALSE`, if not. + */ +#define ZYAN_FAILED(status) \ + ((status) & 0x80000000u) + +/** + * Checks if a zyan operation was successful and returns with the status-code, if not. + * + * @param status The zyan status-code to check. + */ +#define ZYAN_CHECK(status) \ + do \ + { \ + const ZyanStatus status_047620348 = (status); \ + if (!ZYAN_SUCCESS(status_047620348)) \ + { \ + return status_047620348; \ + } \ + } while (0) + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + + /** + * Returns the module id of a zyan status-code. + * + * @param status The zyan status-code. + * + * @return The module id of the zyan status-code. + */ +#define ZYAN_STATUS_MODULE(status) \ + (((status) >> 20) & 0x7FFu) + + /** + * Returns the code of a zyan status-code. + * + * @param status The zyan status-code. + * + * @return The code of the zyan status-code. + */ +#define ZYAN_STATUS_CODE(status) \ + ((status) & 0xFFFFFu) + +/* ============================================================================================== */ +/* Status codes */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Module IDs */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * The zycore generic module id. + */ +#define ZYAN_MODULE_ZYCORE 0x001u + +/** + * The zycore arg-parse submodule id. + */ +#define ZYAN_MODULE_ARGPARSE 0x003u + +/** + * The base module id for user-defined status codes. + */ +#define ZYAN_MODULE_USER 0x3FFu + +/* ---------------------------------------------------------------------------------------------- */ +/* Status codes (general purpose) */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * The operation completed successfully. + */ +#define ZYAN_STATUS_SUCCESS \ + ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x00u) + +/** + * The operation failed with an generic error. + */ +#define ZYAN_STATUS_FAILED \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x01u) + +/** + * The operation completed successfully and returned `ZYAN_TRUE`. + */ +#define ZYAN_STATUS_TRUE \ + ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x02u) + +/** + * The operation completed successfully and returned `ZYAN_FALSE`. + */ +#define ZYAN_STATUS_FALSE \ + ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x03u) + +/** + * An invalid argument was passed to a function. + */ +#define ZYAN_STATUS_INVALID_ARGUMENT \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x04u) + +/** + * An attempt was made to perform an invalid operation. + */ +#define ZYAN_STATUS_INVALID_OPERATION \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x05u) + +/** + * Insufficient privileges to perform the requested operation. + */ +#define ZYAN_STATUS_ACCESS_DENIED \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x06u) + +/** + * The requested entity was not found. + */ +#define ZYAN_STATUS_NOT_FOUND \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x07u) + +/** + * An index passed to a function was out of bounds. + */ +#define ZYAN_STATUS_OUT_OF_RANGE \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x08u) + +/** + * A buffer passed to a function was too small to complete the requested operation. + */ +#define ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x09u) + +/** + * Insufficient memory to perform the operation. + */ +#define ZYAN_STATUS_NOT_ENOUGH_MEMORY \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Au) + +/** + * An unknown error occurred during a system function call. + */ +#define ZYAN_STATUS_BAD_SYSTEMCALL \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Bu) + +/** + * The process ran out of resources while performing an operation. + */ +#define ZYAN_STATUS_OUT_OF_RESOURCES \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Cu) + +/** + * A dependency library was not found or does have an unexpected version number or + * feature-set. + */ +#define ZYAN_STATUS_MISSING_DEPENDENCY \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Du) + +/* ---------------------------------------------------------------------------------------------- */ +/* Status codes (arg parse) */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Argument was not expected. + */ +#define ZYAN_STATUS_ARG_NOT_UNDERSTOOD \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x00u) + +/** + * Too few arguments were provided. + */ +#define ZYAN_STATUS_TOO_FEW_ARGS \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x01u) + +/** + * Too many arguments were provided. + */ +#define ZYAN_STATUS_TOO_MANY_ARGS \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x02u) + +/** + * An argument that expected a value misses its value. + */ +#define ZYAN_STATUS_ARG_MISSES_VALUE \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x03u) + +/** +* A required argument is missing. +*/ +#define ZYAN_STATUS_REQUIRED_ARG_MISSING \ + ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x04u) + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_STATUS_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/String.h b/externals/dynarmic/externals/zycore/include/Zycore/String.h new file mode 100755 index 000000000..c3157bc3c --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/String.h @@ -0,0 +1,1012 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Implements a string type. + */ + +#ifndef ZYCORE_STRING_H +#define ZYCORE_STRING_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Constants */ +/* ============================================================================================== */ + +/** + * The initial minimum capacity (number of characters) for all dynamically allocated + * string instances - not including the terminating '\0'-character. + */ +#define ZYAN_STRING_MIN_CAPACITY 32 + +/** + * The default growth factor for all string instances. + */ +#define ZYAN_STRING_DEFAULT_GROWTH_FACTOR 2.00f + +/** + * The default shrink threshold for all string instances. + */ +#define ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD 0.25f + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* String flags */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanStringFlags` datatype. + */ +typedef ZyanU8 ZyanStringFlags; + +/** + * The string uses a custom user-defined buffer with a fixed capacity. + */ +#define ZYAN_STRING_HAS_FIXED_CAPACITY 0x01 // (1 << 0) + +/* ---------------------------------------------------------------------------------------------- */ +/* String */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanString` struct. + * + * The `ZyanString` type is implemented as a size-prefixed string - which allows for a lot of + * performance optimizations. + * Nevertheless null-termination is guaranteed at all times to provide maximum compatibility with + * default C-style strings (use `ZyanStringGetData` to access the C-style string). + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanString_ +{ + /** + * String flags. + */ + ZyanStringFlags flags; + /** + * The vector that contains the actual string. + */ + ZyanVector vector; +} ZyanString; + +/* ---------------------------------------------------------------------------------------------- */ +/* View */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanStringView` struct. + * + * The `ZyanStringView` type provides a view inside a string (`ZyanString` instances, null- + * terminated C-style strings, or even not-null-terminated custom strings). A view is immutable + * by design and can't be directly converted to a C-style string. + * + * Views might become invalid (e.g. pointing to invalid memory), if the underlying string gets + * destroyed or resized. + * + * The `ZYAN_STRING_TO_VIEW` macro can be used to cast a `ZyanString` to a `ZyanStringView` pointer + * without any runtime overhead. + * Casting a view to a normal string is not supported and will lead to unexpected behavior (use + * `ZyanStringDuplicate` to create a deep-copy instead). + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanStringView_ +{ + /** + * The string data. + * + * The view internally re-uses the normal string struct to allow casts without any runtime + * overhead. + */ + ZyanString string; +} ZyanStringView; + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines an uninitialized `ZyanString` instance. + */ +#define ZYAN_STRING_INITIALIZER \ + { \ + /* flags */ 0, \ + /* vector */ ZYAN_VECTOR_INITIALIZER \ + } + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper macros */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Casts a `ZyanString` pointer to a constant `ZyanStringView` pointer. + */ +#define ZYAN_STRING_TO_VIEW(string) (const ZyanStringView*)(string) + +/** + * Defines a `ZyanStringView` struct that provides a view into a static C-style string. + * + * @param string The C-style string. + */ +#define ZYAN_DEFINE_STRING_VIEW(string) \ + { \ + /* string */ \ + { \ + /* flags */ 0, \ + /* vector */ \ + { \ + /* allocator */ ZYAN_NULL, \ + /* growth_factor */ 1.0f, \ + /* shrink_threshold */ 0.0f, \ + /* size */ sizeof(string), \ + /* capacity */ sizeof(string), \ + /* element_size */ sizeof(char), \ + /* destructor */ ZYAN_NULL, \ + /* data */ (char*)(string) \ + } \ + } \ + } + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * @param capacity The initial capacity (number of characters). + * + * @return A zyan status code. + * + * The memory for the string is dynamically allocated by the default allocator using the default + * growth factor of `2.0f` and the default shrink threshold of `0.25f`. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringInit(ZyanString* string, ZyanUSize capacity); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanString` instance and sets a custom `allocator` and memory + * allocation/deallocation parameters. + * + * @param string A pointer to the `ZyanString` instance. + * @param capacity The initial capacity (number of characters). + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInitEx(ZyanString* string, ZyanUSize capacity, + ZyanAllocator* allocator, float growth_factor, float shrink_threshold); + +/** + * Initializes the given `ZyanString` instance and configures it to use a custom user + * defined buffer with a fixed size. + * + * @param string A pointer to the `ZyanString` instance. + * @param buffer A pointer to the buffer that is used as storage for the string. + * @param capacity The maximum capacity (number of characters) of the buffer, including + * the terminating '\0'. + * + * @return A zyan status code. + * + * Finalization is not required for strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInitCustomBuffer(ZyanString* string, char* buffer, + ZyanUSize capacity); + +/** + * Destroys the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + * + */ +ZYCORE_EXPORT ZyanStatus ZyanStringDestroy(ZyanString* string); + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanString` instance by duplicating an existing string. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * @param source A pointer to the source string. + * @param capacity The initial capacity (number of characters). + * + * This value is automatically adjusted to the size of the source string, if + * a smaller value was passed. + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `source` is a view into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * The memory for the string is dynamically allocated by the default allocator using the default + * growth factor of `2.0f` and the default shrink threshold of `0.25f`. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringDuplicate(ZyanString* destination, + const ZyanStringView* source, ZyanUSize capacity); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanString` instance by duplicating an existing string and sets a + * custom `allocator` and memory allocation/deallocation parameters. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * @param source A pointer to the source string. + * @param capacity The initial capacity (number of characters). + + * This value is automatically adjusted to the size of the source + * string, if a smaller value was passed. + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `source` is a view into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateEx(ZyanString* destination, + const ZyanStringView* source, ZyanUSize capacity, ZyanAllocator* allocator, + float growth_factor, float shrink_threshold); + +/** + * Initializes a new `ZyanString` instance by duplicating an existing string and + * configures it to use a custom user defined buffer with a fixed size. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * @param source A pointer to the source string. + * @param buffer A pointer to the buffer that is used as storage for the string. + * @param capacity The maximum capacity (number of characters) of the buffer, including the + * terminating '\0'. + + * This function will fail, if the capacity of the buffer is less or equal to + * the size of the source string. + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `source` is a view into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * Finalization is not required for strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringDuplicateCustomBuffer(ZyanString* destination, + const ZyanStringView* source, char* buffer, ZyanUSize capacity); + +/* ---------------------------------------------------------------------------------------------- */ +/* Concatenation */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanString` instance by concatenating two existing strings. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * + * This function will fail, if the destination `ZyanString` instance equals + * one of the source strings. + * @param s1 A pointer to the first source string. + * @param s2 A pointer to the second source string. + * @param capacity The initial capacity (number of characters). + + * This value is automatically adjusted to the combined size of the source + * strings, if a smaller value was passed. + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `s1` or `s2` are views into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * The memory for the string is dynamically allocated by the default allocator using the default + * growth factor of `2.0f` and the default shrink threshold of `0.25f`. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringConcat(ZyanString* destination, + const ZyanStringView* s1, const ZyanStringView* s2, ZyanUSize capacity); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanString` instance by concatenating two existing strings and sets + * a custom `allocator` and memory allocation/deallocation parameters. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * + * This function will fail, if the destination `ZyanString` instance + * equals one of the source strings. + * @param s1 A pointer to the first source string. + * @param s2 A pointer to the second source string. + * @param capacity The initial capacity (number of characters). + * + * This value is automatically adjusted to the combined size of the + * source strings, if a smaller value was passed. + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `s1` or `s2` are views into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + * + * The allocated buffer will be at least one character larger than the given `capacity`, to reserve + * space for the terminating '\0'. + * + * Finalization with `ZyanStringDestroy` is required for all strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringConcatEx(ZyanString* destination, const ZyanStringView* s1, + const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, + float shrink_threshold); + +/** + * Initializes a new `ZyanString` instance by concatenating two existing strings and + * configures it to use a custom user defined buffer with a fixed size. + * + * @param destination A pointer to the (uninitialized) destination `ZyanString` instance. + * + * This function will fail, if the destination `ZyanString` instance equals + * one of the source strings. + * @param s1 A pointer to the first source string. + * @param s2 A pointer to the second source string. + * @param buffer A pointer to the buffer that is used as storage for the string. + * @param capacity The maximum capacity (number of characters) of the buffer. + * + * This function will fail, if the capacity of the buffer is less or equal to + * the combined size of the source strings. + * + * @return A zyan status code. + * + * The behavior of this function is undefined, if `s1` or `s2` are views into the `destination` + * string or `destination` points to an already initialized `ZyanString` instance. + * + * Finalization is not required for strings created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringConcatCustomBuffer(ZyanString* destination, + const ZyanStringView* s1, const ZyanStringView* s2, char* buffer, ZyanUSize capacity); + +/* ---------------------------------------------------------------------------------------------- */ +/* Views */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns a view inside an existing view/string. + * + * @param view A pointer to the `ZyanStringView` instance. + * @param source A pointer to the source string. + * + * @return A zyan status code. + * + * The `ZYAN_STRING_TO_VEW` macro can be used to pass any `ZyanString` instance as value for the + * `source` string. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideView(ZyanStringView* view, + const ZyanStringView* source); + +/** + * Returns a view inside an existing view/string starting from the given `index`. + * + * @param view A pointer to the `ZyanStringView` instance. + * @param source A pointer to the source string. + * @param index The start index. + * @param count The number of characters. + * + * @return A zyan status code. + * + * The `ZYAN_STRING_TO_VEW` macro can be used to pass any `ZyanString` instance as value for the + * `source` string. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideViewEx(ZyanStringView* view, + const ZyanStringView* source, ZyanUSize index, ZyanUSize count); + +/** + * Returns a view inside a null-terminated C-style string. + * + * @param view A pointer to the `ZyanStringView` instance. + * @param string The C-style string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBuffer(ZyanStringView* view, const char* string); + +/** + * Returns a view inside a character buffer with custom length. + * + * @param view A pointer to the `ZyanStringView` instance. + * @param buffer A pointer to the buffer containing the string characters. + * @param length The length of the string (number of characters). + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewInsideBufferEx(ZyanStringView* view, const char* buffer, + ZyanUSize length); + +/** + * Returns the size (number of characters) of the view. + * + * @param view A pointer to the `ZyanStringView` instance. + * @param size Receives the size (number of characters) of the view. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewGetSize(const ZyanStringView* view, ZyanUSize* size); + +/** + * Returns the C-style string of the given `ZyanString` instance. + * + * @warning The string is not guaranteed to be null terminated! + * + * @param string A pointer to the `ZyanStringView` instance. + * @param value Receives a pointer to the C-style string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringViewGetData(const ZyanStringView* view, const char** buffer); + +/* ---------------------------------------------------------------------------------------------- */ +/* Character access */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the character at the given `index`. + * + * @param string A pointer to the `ZyanStringView` instance. + * @param index The character index. + * @param value Receives the desired character of the string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringGetChar(const ZyanStringView* string, ZyanUSize index, + char* value); + +/** + * Returns a pointer to the character at the given `index`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The character index. + * @param value Receives a pointer to the desired character in the string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringGetCharMutable(ZyanString* string, ZyanUSize index, + char** value); + +/** + * Assigns a new value to the character at the given `index`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The character index. + * @param value The character to assign. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringSetChar(ZyanString* string, ZyanUSize index, char value); + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Inserts the content of the source string in the destination string at the given `index`. + * + * @param destination The destination string. + * @param index The insert index. + * @param source The source string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsert(ZyanString* destination, ZyanUSize index, + const ZyanStringView* source); + +/** + * Inserts `count` characters of the source string in the destination string at the given + * `index`. + * + * @param destination The destination string. + * @param destination_index The insert index. + * @param source The source string. + * @param source_index The index of the first character to be inserted from the source + * string. + * @param count The number of chars to insert from the source string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringInsertEx(ZyanString* destination, ZyanUSize destination_index, + const ZyanStringView* source, ZyanUSize source_index, ZyanUSize count); + +/* ---------------------------------------------------------------------------------------------- */ +/* Appending */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Appends the content of the source string to the end of the destination string. + * + * @param destination The destination string. + * @param source The source string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppend(ZyanString* destination, const ZyanStringView* source); + +/** + * Appends `count` characters of the source string to the end of the destination string. + * + * @param destination The destination string. + * @param source The source string. + * @param source_index The index of the first character to be appended from the source string. + * @param count The number of chars to append from the source string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringAppendEx(ZyanString* destination, const ZyanStringView* source, + ZyanUSize source_index, ZyanUSize count); + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Deletes characters from the given string, starting at `index`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The index of the first character to delete. + * @param count The number of characters to delete. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringDelete(ZyanString* string, ZyanUSize index, ZyanUSize count); + +/** + * Deletes all remaining characters from the given string, starting at `index`. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The index of the first character to delete. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringTruncate(ZyanString* string, ZyanUSize index); + +/** + * Erases the given string. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringClear(ZyanString* string); + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Searches for the first occurrence of `needle` in the given `haystack` starting from the + * left. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringLPos(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index); + +/** + * Searches for the first occurrence of `needle` in the given `haystack` starting from the + * left. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * @param index The start index. + * @param count The maximum number of characters to iterate, beginning from the start + * `index`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringLPosEx(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index, ZyanUSize index, ZyanUSize count); + +/** + * Performs a case-insensitive search for the first occurrence of `needle` in the given + * `haystack` starting from the left. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringLPosI(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index); + +/** + * Performs a case-insensitive search for the first occurrence of `needle` in the given + * `haystack` starting from the left. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * @param index The start index. + * @param count The maximum number of characters to iterate, beginning from the start + * `index`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringLPosIEx(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index, ZyanUSize index, ZyanUSize count); + +/** + * Searches for the first occurrence of `needle` in the given `haystack` starting from the + * right. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringRPos(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index); + +/** + * Searches for the first occurrence of `needle` in the given `haystack` starting from the + * right. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * @param index The start index. + * @param count The maximum number of characters to iterate, beginning from the start + * `index`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringRPosEx(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index, ZyanUSize index, ZyanUSize count); + +/** + * Performs a case-insensitive search for the first occurrence of `needle` in the given + * `haystack` starting from the right. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringRPosI(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index); + +/** + * Performs a case-insensitive search for the first occurrence of `needle` in the given + * `haystack` starting from the right. + * + * @param haystack The string to search in. + * @param needle The sub-string to search for. + * @param found_index A pointer to a variable that receives the index of the first occurrence of + * `needle`. + * @param index The start index. + * @param count The maximum number of characters to iterate, beginning from the start + * `index`. + * + * @return `ZYAN_STATUS_TRUE`, if the needle was found, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + * + * The `found_index` is set to `-1`, if the needle was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringRPosIEx(const ZyanStringView* haystack, + const ZyanStringView* needle, ZyanISize* found_index, ZyanUSize index, ZyanUSize count); + +/* ---------------------------------------------------------------------------------------------- */ +/* Comparing */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Compares two strings. + * + * @param s1 The first string + * @param s2 The second string. + * @param result Receives the comparison result. + * + * Values: + * - `result < 0` -> The first character that does not match has a lower value + * in `s1` than in `s2`. + * - `result == 0` -> The contents of both strings are equal. + * - `result > 0` -> The first character that does not match has a greater value + * in `s1` than in `s2`. + * + * @return `ZYAN_STATUS_TRUE`, if the strings are equal, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringCompare(const ZyanStringView* s1, const ZyanStringView* s2, + ZyanI32* result); + +/** + * Performs a case-insensitive comparison of two strings. + * + * @param s1 The first string + * @param s2 The second string. + * @param result Receives the comparison result. + * + * Values: + * - `result < 0` -> The first character that does not match has a lower value + * in `s1` than in `s2`. + * - `result == 0` -> The contents of both strings are equal. + * - `result > 0` -> The first character that does not match has a greater value + * in `s1` than in `s2`. + * + * @return `ZYAN_STATUS_TRUE`, if the strings are equal, `ZYAN_STATUS_FALSE`, if not, or another + * zyan status code, if an error occured. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringCompareI(const ZyanStringView* s1, const ZyanStringView* s2, + ZyanI32* result); + +/* ---------------------------------------------------------------------------------------------- */ +/* Case conversion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Converts the given string to lowercase letters. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCase(ZyanString* string); + +/** + * Converts `count` characters of the given string to lowercase letters. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The start index. + * @param count The number of characters to convert, beginning from the start `index`. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringToLowerCaseEx(ZyanString* string, ZyanUSize index, + ZyanUSize count); + +/** + * Converts the given string to uppercase letters. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCase(ZyanString* string); + +/** + * Converts `count` characters of the given string to uppercase letters. + * + * @param string A pointer to the `ZyanString` instance. + * @param index The start index. + * @param count The number of characters to convert, beginning from the start `index`. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringToUpperCaseEx(ZyanString* string, ZyanUSize index, + ZyanUSize count); + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Resizes the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * @param size The new size of the string. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringResize(ZyanString* string, ZyanUSize size); + +/** + * Changes the capacity of the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * @param capacity The new minimum capacity of the string. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringReserve(ZyanString* string, ZyanUSize capacity); + +/** + * Shrinks the capacity of the given string to match it's size. + * + * @param string A pointer to the `ZyanString` instance. + * + * @return A zyan status code. + * + * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified + * `ZyanString` instance. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringShrinkToFit(ZyanString* string); + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the current capacity of the string. + * + * @param string A pointer to the `ZyanString` instance. + * @param capacity Receives the size of the string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringGetCapacity(const ZyanString* string, ZyanUSize* capacity); + +/** + * Returns the current size (number of characters) of the string (excluding the + * terminating zero character). + * + * @param string A pointer to the `ZyanString` instance. + * @param size Receives the size (number of characters) of the string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringGetSize(const ZyanString* string, ZyanUSize* size); + +/** + * Returns the C-style string of the given `ZyanString` instance. + * + * @param string A pointer to the `ZyanString` instance. + * @param value Receives a pointer to the C-style string. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanStringGetData(const ZyanString* string, const char** value); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif // ZYCORE_STRING_H diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Types.h b/externals/dynarmic/externals/zycore/include/Zycore/Types.h new file mode 100755 index 000000000..74fe9056c --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Types.h @@ -0,0 +1,195 @@ +/*************************************************************************************************** + + Zyan Core Library (Zyan-C) + + Original Author : Florian Bernd, Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Includes and defines some default data types. + */ + +#ifndef ZYCORE_TYPES_H +#define ZYCORE_TYPES_H + +#include + +/* ============================================================================================== */ +/* Integer types */ +/* ============================================================================================== */ + +#if defined(ZYAN_NO_LIBC) || \ + (defined(ZYAN_MSVC) && defined(ZYAN_KERNEL)) // The WDK LibC lacks stdint.h. + // No LibC mode, use compiler built-in types / macros. +# if defined(ZYAN_MSVC) || defined(ZYAN_ICC) + typedef unsigned __int8 ZyanU8; + typedef unsigned __int16 ZyanU16; + typedef unsigned __int32 ZyanU32; + typedef unsigned __int64 ZyanU64; + typedef signed __int8 ZyanI8; + typedef signed __int16 ZyanI16; + typedef signed __int32 ZyanI32; + typedef signed __int64 ZyanI64; +# if _WIN64 + typedef ZyanU64 ZyanUSize; + typedef ZyanI64 ZyanISize; + typedef ZyanU64 ZyanUPointer; + typedef ZyanI64 ZyanIPointer; +# else + typedef ZyanU32 ZyanUSize; + typedef ZyanI32 ZyanISize; + typedef ZyanU32 ZyanUPointer; + typedef ZyanI32 ZyanIPointer; +# endif +# elif defined(ZYAN_GNUC) + typedef __UINT8_TYPE__ ZyanU8; + typedef __UINT16_TYPE__ ZyanU16; + typedef __UINT32_TYPE__ ZyanU32; + typedef __UINT64_TYPE__ ZyanU64; + typedef __INT8_TYPE__ ZyanI8; + typedef __INT16_TYPE__ ZyanI16; + typedef __INT32_TYPE__ ZyanI32; + typedef __INT64_TYPE__ ZyanI64; + typedef __SIZE_TYPE__ ZyanUSize; + typedef __PTRDIFF_TYPE__ ZyanISize; + typedef __UINTPTR_TYPE__ ZyanUPointer; + typedef __INTPTR_TYPE__ ZyanIPointer; +# else +# error "Unsupported compiler for no-libc mode." +# endif +#else + // If is LibC present, we use stdint types. +# include +# include + typedef uint8_t ZyanU8; + typedef uint16_t ZyanU16; + typedef uint32_t ZyanU32; + typedef uint64_t ZyanU64; + typedef int8_t ZyanI8; + typedef int16_t ZyanI16; + typedef int32_t ZyanI32; + typedef int64_t ZyanI64; + typedef size_t ZyanUSize; + typedef ptrdiff_t ZyanISize; + typedef uintptr_t ZyanUPointer; + typedef intptr_t ZyanIPointer; +#endif + +// Verify size assumptions. +ZYAN_STATIC_ASSERT(sizeof(ZyanU8 ) == 1 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanU16 ) == 2 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanU32 ) == 4 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanU64 ) == 8 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanI8 ) == 1 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanI16 ) == 2 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanI32 ) == 4 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanI64 ) == 8 ); +ZYAN_STATIC_ASSERT(sizeof(ZyanUSize ) == sizeof(void*)); // TODO: This one is incorrect! +ZYAN_STATIC_ASSERT(sizeof(ZyanISize ) == sizeof(void*)); // TODO: This one is incorrect! +ZYAN_STATIC_ASSERT(sizeof(ZyanUPointer) == sizeof(void*)); +ZYAN_STATIC_ASSERT(sizeof(ZyanIPointer) == sizeof(void*)); + +// Verify signedness assumptions (relies on size checks above). +ZYAN_STATIC_ASSERT((ZyanI8 )-1 >> 1 < (ZyanI8 )((ZyanU8 )-1 >> 1)); +ZYAN_STATIC_ASSERT((ZyanI16)-1 >> 1 < (ZyanI16)((ZyanU16)-1 >> 1)); +ZYAN_STATIC_ASSERT((ZyanI32)-1 >> 1 < (ZyanI32)((ZyanU32)-1 >> 1)); +ZYAN_STATIC_ASSERT((ZyanI64)-1 >> 1 < (ZyanI64)((ZyanU64)-1 >> 1)); + +/* ============================================================================================== */ +/* Pointer */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanVoidPointer` data-type. + */ +typedef char* ZyanVoidPointer; + +/** + * Defines the `ZyanConstVoidPointer` data-type. + */ +typedef const void* ZyanConstVoidPointer; + +#define ZYAN_NULL ((void*)0) + +/* ============================================================================================== */ +/* Logic types */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Boolean */ +/* ---------------------------------------------------------------------------------------------- */ + +#define ZYAN_FALSE 0 +#define ZYAN_TRUE 1 + +/** + * Defines the `ZyanBool` data-type. + * + * Represents a default boolean data-type where `0` is interpreted as `false` and all other values + * as `true`. + */ +typedef ZyanU8 ZyanBool; + +/* ---------------------------------------------------------------------------------------------- */ +/* Ternary */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanTernary` data-type. + * + * The `ZyanTernary` is a balanced ternary type that uses three truth values indicating `true`, + * `false` and an indeterminate third value. + */ +typedef ZyanI8 ZyanTernary; + +#define ZYAN_TERNARY_FALSE (-1) +#define ZYAN_TERNARY_UNKNOWN 0x00 +#define ZYAN_TERNARY_TRUE 0x01 + +/* ============================================================================================== */ +/* String types */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* C-style strings */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines the `ZyanCharPointer` data-type. + * + * This type is most often used to represent null-terminated strings aka. C-style strings. + */ +typedef char* ZyanCharPointer; + +/** + * Defines the `ZyanConstCharPointer` data-type. + * + * This type is most often used to represent null-terminated strings aka. C-style strings. + */ +typedef const char* ZyanConstCharPointer; + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#endif /* ZYCORE_TYPES_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Vector.h b/externals/dynarmic/externals/zycore/include/Zycore/Vector.h new file mode 100755 index 000000000..47e728cc1 --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Vector.h @@ -0,0 +1,723 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Implements the vector container class. + */ + +#ifndef ZYCORE_VECTOR_H +#define ZYCORE_VECTOR_H + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Constants */ +/* ============================================================================================== */ + +/** + * The initial minimum capacity (number of elements) for all dynamically allocated vector + * instances. + */ +#define ZYAN_VECTOR_MIN_CAPACITY 1 + +/** + * The default growth factor for all vector instances. + */ +#define ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR 2.00f + +/** + * The default shrink threshold for all vector instances. + */ +#define ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD 0.25f + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + +/** + * Defines the `ZyanVector` struct. + * + * All fields in this struct should be considered as "private". Any changes may lead to unexpected + * behavior. + */ +typedef struct ZyanVector_ +{ + /** + * The memory allocator. + */ + ZyanAllocator* allocator; + /** + * The growth factor. + */ + float growth_factor; + /** + * The shrink threshold. + */ + float shrink_threshold; + /** + * The current number of elements in the vector. + */ + ZyanUSize size; + /** + * The maximum capacity (number of elements). + */ + ZyanUSize capacity; + /** + * The size of a single element in bytes. + */ + ZyanUSize element_size; + /** + * The element destructor callback. + */ + ZyanMemberProcedure destructor; + /** + * The data pointer. + */ + void* data; +} ZyanVector; + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Defines an uninitialized `ZyanVector` instance. + */ +#define ZYAN_VECTOR_INITIALIZER \ + { \ + /* allocator */ ZYAN_NULL, \ + /* growth_factor */ 0.0f, \ + /* shrink_threshold */ 0.0f, \ + /* size */ 0, \ + /* capacity */ 0, \ + /* element_size */ 0, \ + /* destructor */ ZYAN_NULL, \ + /* data */ ZYAN_NULL \ + } + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper macros */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the value of the element at the given `index`. + * + * @param type The desired value type. + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * + * @result The value of the desired element in the vector. + * + * Note that this function is unsafe and might dereference a null-pointer. + */ +#ifdef __cplusplus +#define ZYAN_VECTOR_GET(type, vector, index) \ + (*reinterpret_cast(ZyanVectorGet(vector, index))) +#else +#define ZYAN_VECTOR_GET(type, vector, index) \ + (*(const type*)ZyanVectorGet(vector, index)) +#endif + +/** + * Loops through all elements of the vector. + * + * @param type The desired value type. + * @param vector A pointer to the `ZyanVector` instance. + * @param item_name The name of the iterator item. + * @param body The body to execute for each item in the vector. + */ +#define ZYAN_VECTOR_FOREACH(type, vector, item_name, body) \ + { \ + const ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name) = (vector)->size; \ + for (ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) = 0; \ + ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) < \ + ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name); \ + ++ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)) \ + { \ + const type item_name = ZYAN_VECTOR_GET(type, vector, \ + ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)); \ + body \ + } \ + } + +/** + * Loops through all elements of the vector. + * + * @param type The desired value type. + * @param vector A pointer to the `ZyanVector` instance. + * @param item_name The name of the iterator item. + * @param body The body to execute for each item in the vector. + */ +#define ZYAN_VECTOR_FOREACH_MUTABLE(type, vector, item_name, body) \ + { \ + const ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name) = (vector)->size; \ + for (ZyanUSize ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) = 0; \ + ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name) < \ + ZYAN_MACRO_CONCAT_EXPAND(size_d50d3303, item_name); \ + ++ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)) \ + { \ + type* const item_name = ZyanVectorGetMutable(vector, \ + ZYAN_MACRO_CONCAT_EXPAND(i_bfd62679, item_name)); \ + body \ + } \ + } + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element_size The size of a single element in bytes. + * @param capacity The initial capacity (number of elements). + * @param destructor A destructor callback that is invoked every time an item is deleted, or + * `ZYAN_NULL` if not needed. + * + * @return A zyan status code. + * + * The memory for the vector elements is dynamically allocated by the default allocator using the + * default growth factor of `2.0f` and the default shrink threshold of `0.25f`. + * + * Finalization with `ZyanVectorDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanVectorInit(ZyanVector* vector, + ZyanUSize element_size, ZyanUSize capacity, ZyanMemberProcedure destructor); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes the given `ZyanVector` instance and sets a custom `allocator` and memory + * allocation/deallocation parameters. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element_size The size of a single element in bytes. + * @param capacity The initial capacity (number of elements). + * @param destructor A destructor callback that is invoked every time an item is deleted, + * or `ZYAN_NULL` if not needed. + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + * + * Finalization with `ZyanVectorDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorInitEx(ZyanVector* vector, ZyanUSize element_size, + ZyanUSize capacity, ZyanMemberProcedure destructor, ZyanAllocator* allocator, + float growth_factor, float shrink_threshold); + +/** + * Initializes the given `ZyanVector` instance and configures it to use a custom user + * defined buffer with a fixed size. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element_size The size of a single element in bytes. + * @param buffer A pointer to the buffer that is used as storage for the elements. + * @param capacity The maximum capacity (number of elements) of the buffer. + * @param destructor A destructor callback that is invoked every time an item is deleted, or + * `ZYAN_NULL` if not needed. + * + * @return A zyan status code. + * + * Finalization is not required for instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorInitCustomBuffer(ZyanVector* vector, ZyanUSize element_size, + void* buffer, ZyanUSize capacity, ZyanMemberProcedure destructor); + +/** + * Destroys the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance.. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorDestroy(ZyanVector* vector); + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanVector` instance by duplicating an existing vector. + * + * @param destination A pointer to the (uninitialized) destination `ZyanVector` instance. + * @param source A pointer to the source vector. + * @param capacity The initial capacity (number of elements). + * + * This value is automatically adjusted to the size of the source vector, if + * a smaller value was passed. + * + * @return A zyan status code. + * + * The memory for the vector is dynamically allocated by the default allocator using the default + * growth factor of `2.0f` and the default shrink threshold of `0.25f`. + * + * Finalization with `ZyanVectorDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanVectorDuplicate(ZyanVector* destination, + const ZyanVector* source, ZyanUSize capacity); + +#endif // ZYAN_NO_LIBC + +/** + * Initializes a new `ZyanVector` instance by duplicating an existing vector and sets a + * custom `allocator` and memory allocation/deallocation parameters. + * + * @param destination A pointer to the (uninitialized) destination `ZyanVector` instance. + * @param source A pointer to the source vector. + * @param capacity The initial capacity (number of elements). + + * This value is automatically adjusted to the size of the source + * vector, if a smaller value was passed. + * @param allocator A pointer to a `ZyanAllocator` instance. + * @param growth_factor The growth factor (from `1.0f` to `x.xf`). + * @param shrink_threshold The shrink threshold (from `0.0f` to `1.0f`). + * + * @return A zyan status code. + * + * A growth factor of `1.0f` disables overallocation and a shrink threshold of `0.0f` disables + * dynamic shrinking. + * + * Finalization with `ZyanVectorDestroy` is required for all instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorDuplicateEx(ZyanVector* destination, const ZyanVector* source, + ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, float shrink_threshold); + +/** + * Initializes a new `ZyanVector` instance by duplicating an existing vector and + * configures it to use a custom user defined buffer with a fixed size. + * + * @param destination A pointer to the (uninitialized) destination `ZyanVector` instance. + * @param source A pointer to the source vector. + * @param buffer A pointer to the buffer that is used as storage for the elements. + * @param capacity The maximum capacity (number of elements) of the buffer. + + * This function will fail, if the capacity of the buffer is less than the + * size of the source vector. + * + * @return A zyan status code. + * + * Finalization is not required for instances created by this function. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorDuplicateCustomBuffer(ZyanVector* destination, + const ZyanVector* source, void* buffer, ZyanUSize capacity); + +/* ---------------------------------------------------------------------------------------------- */ +/* Element access */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns a constant pointer to the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * + * @return A constant pointer to the desired element in the vector or `ZYAN_NULL`, if an error + * occured. + * + * Note that the returned pointer might get invalid when the vector is resized by either a manual + * call to the memory-management functions or implicitly by inserting or removing elements. + * + * Take a look at `ZyanVectorGetPointer` instead, if you need a function that returns a zyan status + * code. + */ +ZYCORE_EXPORT const void* ZyanVectorGet(const ZyanVector* vector, ZyanUSize index); + +/** + * Returns a mutable pointer to the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * + * @return A mutable pointer to the desired element in the vector or `ZYAN_NULL`, if an error + * occured. + * + * Note that the returned pointer might get invalid when the vector is resized by either a manual + * call to the memory-management functions or implicitly by inserting or removing elements. + * + * Take a look at `ZyanVectorGetPointerMutable` instead, if you need a function that returns a + * zyan status code. + */ +ZYCORE_EXPORT void* ZyanVectorGetMutable(const ZyanVector* vector, ZyanUSize index); + +/** + * Returns a constant pointer to the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * @param value Receives a constant pointer to the desired element in the vector. + * + * Note that the returned pointer might get invalid when the vector is resized by either a manual + * call to the memory-management functions or implicitly by inserting or removing elements. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorGetPointer(const ZyanVector* vector, ZyanUSize index, + const void** value); + +/** + * Returns a mutable pointer to the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * @param value Receives a mutable pointer to the desired element in the vector. + * + * Note that the returned pointer might get invalid when the vector is resized by either a manual + * call to the memory-management functions or implicitly by inserting or removing elements. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorGetPointerMutable(const ZyanVector* vector, ZyanUSize index, + void** value); + +/** + * Assigns a new value to the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The value index. + * @param value The value to assign. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorSet(ZyanVector* vector, ZyanUSize index, + const void* value); + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Adds a new `element` to the end of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element A pointer to the element to add. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorPushBack(ZyanVector* vector, const void* element); + +/** + * Inserts an `element` at the given `index` of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The insert index. + * @param element A pointer to the element to insert. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorInsert(ZyanVector* vector, ZyanUSize index, + const void* element); + +/** + * Inserts multiple `elements` at the given `index` of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The insert index. + * @param elements A pointer to the first element. + * @param count The number of elements to insert. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorInsertRange(ZyanVector* vector, ZyanUSize index, + const void* elements, ZyanUSize count); + +/** + * Constructs an `element` in-place at the end of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element Receives a pointer to the new element. + * @param constructor The constructor callback or `ZYAN_NULL`. The new element will be in + * undefined state, if no constructor was passed. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorEmplace(ZyanVector* vector, void** element, + ZyanMemberFunction constructor); + +/** + * Constructs an `element` in-place and inserts it at the given `index` of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The insert index. + * @param element Receives a pointer to the new element. + * @param constructor The constructor callback or `ZYAN_NULL`. The new element will be in + * undefined state, if no constructor was passed. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorEmplaceEx(ZyanVector* vector, ZyanUSize index, + void** element, ZyanMemberFunction constructor); + +/* ---------------------------------------------------------------------------------------------- */ +/* Utils */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Swaps the element at `index_first` with the element at `index_second`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index_first The index of the first element. + * @param index_second The index of the second element. + * + * @return A zyan status code. + * + * This function requires the vector to have spare capacity for one temporary element. Call + * `ZyanVectorReserve` before this function to increase capacity, if needed. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorSwapElements(ZyanVector* vector, ZyanUSize index_first, + ZyanUSize index_second); + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Deletes the element at the given `index` of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorDelete(ZyanVector* vector, ZyanUSize index); + +/** + * Deletes multiple elements from the given vector, starting at `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The index of the first element to delete. + * @param count The number of elements to delete. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorDeleteRange(ZyanVector* vector, ZyanUSize index, + ZyanUSize count); + +/** + * Removes the last element of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorPopBack(ZyanVector* vector); + +/** + * Erases all elements of the given vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorClear(ZyanVector* vector); + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Sequentially searches for the first occurrence of `element` in the given vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element A pointer to the element to search for. + * @param found_index A pointer to a variable that receives the index of the found element. + * @param comparison The comparison function to use. + * + * @return `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic + * zyan status code if an error occured. + * + * The `found_index` is set to `-1`, if the element was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorFind(const ZyanVector* vector, const void* element, + ZyanISize* found_index, ZyanEqualityComparison comparison); + +/** + * Sequentially searches for the first occurrence of `element` in the given vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element A pointer to the element to search for. + * @param found_index A pointer to a variable that receives the index of the found element. + * @param comparison The comparison function to use. + * @param index The start index. + * @param count The maximum number of elements to iterate, beginning from the start `index`. + * + * @return `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic + * zyan status code if an error occured. + * + * The `found_index` is set to `-1`, if the element was not found. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorFindEx(const ZyanVector* vector, const void* element, + ZyanISize* found_index, ZyanEqualityComparison comparison, ZyanUSize index, ZyanUSize count); + +/** + * Searches for the first occurrence of `element` in the given vector using a binary- + * search algorithm. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element A pointer to the element to search for. + * @param found_index A pointer to a variable that receives the index of the found element. + * @param comparison The comparison function to use. + * + * @return `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic + * zyan status code if an error occured. + * + * If found, `found_index` contains the zero-based index of `element`. If not found, `found_index` + * contains the index of the first entry larger than `element`. + * + * This function requires all elements in the vector to be strictly ordered (sorted). + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorBinarySearch(const ZyanVector* vector, const void* element, + ZyanUSize* found_index, ZyanComparison comparison); + +/** + * Searches for the first occurrence of `element` in the given vector using a binary- + * search algorithm. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param element A pointer to the element to search for. + * @param found_index A pointer to a variable that receives the index of the found element. + * @param comparison The comparison function to use. + * @param index The start index. + * @param count The maximum number of elements to iterate, beginning from the start `index`. + * + * @return `ZYAN_STATUS_TRUE` if the element was found, `ZYAN_STATUS_FALSE` if not or a generic + * zyan status code if an error occured. + * + * If found, `found_index` contains the zero-based index of `element`. If not found, `found_index` + * contains the index of the first entry larger than `element`. + * + * This function requires all elements in the vector to be strictly ordered (sorted). + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorBinarySearchEx(const ZyanVector* vector, const void* element, + ZyanUSize* found_index, ZyanComparison comparison, ZyanUSize index, ZyanUSize count); + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Resizes the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param size The new size of the vector. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorResize(ZyanVector* vector, ZyanUSize size); + +/** + * Resizes the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param size The new size of the vector. + * @param initializer A pointer to a value to be used as initializer for new items. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorResizeEx(ZyanVector* vector, ZyanUSize size, + const void* initializer); + +/** + * Changes the capacity of the given `ZyanVector` instance. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param capacity The new minimum capacity of the vector. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorReserve(ZyanVector* vector, ZyanUSize capacity); + +/** + * Shrinks the capacity of the given vector to match it's size. + * + * @param vector A pointer to the `ZyanVector` instance. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorShrinkToFit(ZyanVector* vector); + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Returns the current capacity of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param capacity Receives the size of the vector. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorGetCapacity(const ZyanVector* vector, ZyanUSize* capacity); + +/** + * Returns the current size of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param size Receives the size of the vector. + * + * @return A zyan status code. + */ +ZYCORE_EXPORT ZyanStatus ZyanVectorGetSize(const ZyanVector* vector, ZyanUSize* size); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_VECTOR_H */ diff --git a/externals/dynarmic/externals/zycore/include/Zycore/Zycore.h b/externals/dynarmic/externals/zycore/include/Zycore/Zycore.h new file mode 100755 index 000000000..e136acf5d --- /dev/null +++ b/externals/dynarmic/externals/zycore/include/Zycore/Zycore.h @@ -0,0 +1,111 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * Master include file, including everything else. + */ + +#ifndef ZYCORE_H +#define ZYCORE_H + +#include +#include + +// TODO: + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================================== */ +/* Macros */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constants */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * A macro that defines the zycore version. + */ +#define ZYCORE_VERSION (ZyanU64)0x0001000000000000 + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper macros */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Extracts the major-part of the zycore version. + * + * @param version The zycore version value + */ +#define ZYCORE_VERSION_MAJOR(version) (ZyanU16)((version & 0xFFFF000000000000) >> 48) + +/** + * Extracts the minor-part of the zycore version. + * + * @param version The zycore version value + */ +#define ZYCORE_VERSION_MINOR(version) (ZyanU16)((version & 0x0000FFFF00000000) >> 32) + +/** + * Extracts the patch-part of the zycore version. + * + * @param version The zycore version value + */ +#define ZYCORE_VERSION_PATCH(version) (ZyanU16)((version & 0x00000000FFFF0000) >> 16) + +/** + * Extracts the build-part of the zycore version. + * + * @param version The zycore version value + */ +#define ZYCORE_VERSION_BUILD(version) (ZyanU16)(version & 0x000000000000FFFF) + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/** + * Returns the zycore version. + * + * @return The zycore version. + * + * Use the macros provided in this file to extract the major, minor, patch and build part from the + * returned version value. + */ +ZYCORE_EXPORT ZyanU64 ZycoreGetVersion(void); + +/* ============================================================================================== */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZYCORE_H */ diff --git a/externals/dynarmic/externals/zycore/resources/VersionInfo.rc b/externals/dynarmic/externals/zycore/resources/VersionInfo.rc new file mode 100755 index 000000000..ab8c48020 Binary files /dev/null and b/externals/dynarmic/externals/zycore/resources/VersionInfo.rc differ diff --git a/externals/dynarmic/externals/zycore/src/API/Memory.c b/externals/dynarmic/externals/zycore/src/API/Memory.c new file mode 100755 index 000000000..490f5cdf4 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/API/Memory.c @@ -0,0 +1,128 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include + +#if defined(ZYAN_WINDOWS) + +#elif defined(ZYAN_POSIX) +# include +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanU32 ZyanMemoryGetSystemPageSize() +{ +#if defined(ZYAN_WINDOWS) + + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + + return system_info.dwPageSize; + +#elif defined(ZYAN_POSIX) + + return sysconf(_SC_PAGE_SIZE); + +#endif +} + +ZyanU32 ZyanMemoryGetSystemAllocationGranularity() +{ +#if defined(ZYAN_WINDOWS) + + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + + return system_info.dwAllocationGranularity; + +#elif defined(ZYAN_POSIX) + + return sysconf(_SC_PAGE_SIZE); + +#endif +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanMemoryVirtualProtect(void* address, ZyanUSize size, + ZyanMemoryPageProtection protection) +{ +#if defined(ZYAN_WINDOWS) + + DWORD old; + if (!VirtualProtect(address, size, protection, &old)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#elif defined(ZYAN_POSIX) + + if (mprotect(address, size, protection)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#endif + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanMemoryVirtualFree(void* address, ZyanUSize size) +{ +#if defined(ZYAN_WINDOWS) + + ZYAN_UNUSED(size); + if (!VirtualFree(address, 0, MEM_RELEASE)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#elif defined(ZYAN_POSIX) + + if (munmap(address, size)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#endif + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/API/Process.c b/externals/dynarmic/externals/zycore/src/API/Process.c new file mode 100755 index 000000000..dbda8d1cd --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/API/Process.c @@ -0,0 +1,68 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#if defined(ZYAN_WINDOWS) +# include +#elif defined(ZYAN_POSIX) +# include +#else +# error "Unsupported platform detected" +#endif +#include + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanProcessFlushInstructionCache(void* address, ZyanUSize size) +{ +#if defined(ZYAN_WINDOWS) + + if (!FlushInstructionCache(GetCurrentProcess(), address, size)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#elif defined(ZYAN_POSIX) + + if (msync(address, size, MS_SYNC | MS_INVALIDATE)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + +#endif + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/API/Synchronization.c b/externals/dynarmic/externals/zycore/src/API/Synchronization.c new file mode 100755 index 000000000..9be79af25 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/API/Synchronization.c @@ -0,0 +1,200 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* */ +/* ---------------------------------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +#if defined(ZYAN_POSIX) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* Critical Section */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section) +{ + pthread_mutexattr_t attribute; + + int error = pthread_mutexattr_init(&attribute); + if (error != 0) + { + if (error == ENOMEM) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + pthread_mutexattr_settype(&attribute, PTHREAD_MUTEX_RECURSIVE); + + error = pthread_mutex_init(critical_section, &attribute); + pthread_mutexattr_destroy(&attribute); + if (error != 0) + { + if (error == EAGAIN) + { + return ZYAN_STATUS_OUT_OF_RESOURCES; + } + if (error == ENOMEM) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + if (error == EPERM) + { + return ZYAN_STATUS_ACCESS_DENIED; + } + if ((error == EBUSY) || (error == EINVAL)) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanCriticalSectionEnter(ZyanCriticalSection* critical_section) +{ + const int error = pthread_mutex_lock(critical_section); + if (error != 0) + { + if (error == EINVAL) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (error == EAGAIN) + { + return ZYAN_STATUS_INVALID_OPERATION; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanBool ZyanCriticalSectionTryEnter(ZyanCriticalSection* critical_section) +{ + // No fine grained error handling for this one + return pthread_mutex_trylock(critical_section) ? ZYAN_FALSE : ZYAN_TRUE; +} + +ZyanStatus ZyanCriticalSectionLeave(ZyanCriticalSection* critical_section) +{ + const int error = pthread_mutex_unlock(critical_section); + if (error != 0) + { + if (error == EINVAL) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (error == EPERM) + { + return ZYAN_STATUS_INVALID_OPERATION; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section) +{ + const int error = pthread_mutex_destroy(critical_section); + if (error != 0) + { + if ((error == EBUSY) || (error == EINVAL)) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +#elif defined(ZYAN_WINDOWS) + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section) +{ + InitializeCriticalSection(critical_section); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanCriticalSectionEnter(ZyanCriticalSection* critical_section) +{ + EnterCriticalSection(critical_section); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanBool ZyanCriticalSectionTryEnter(ZyanCriticalSection* critical_section) +{ + return TryEnterCriticalSection(critical_section) ? ZYAN_TRUE : ZYAN_FALSE; +} + +ZyanStatus ZyanCriticalSectionLeave(ZyanCriticalSection* critical_section) +{ + LeaveCriticalSection(critical_section); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section) +{ + DeleteCriticalSection(critical_section); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/API/Terminal.c b/externals/dynarmic/externals/zycore/src/API/Terminal.c new file mode 100755 index 000000000..376d8e120 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/API/Terminal.c @@ -0,0 +1,156 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include + +#if defined(ZYAN_POSIX) +# include +#elif defined(ZYAN_WINDOWS) +# include +# include +#else +# error "Unsupported platform detected" +#endif + +// Provide fallback for old SDK versions +#ifdef ZYAN_WINDOWS +# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 +# endif +#endif + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +ZyanStatus ZyanTerminalEnableVT100(ZyanStandardStream stream) +{ + if ((stream != ZYAN_STDSTREAM_OUT) && (stream != ZYAN_STDSTREAM_ERR)) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + +#ifdef ZYAN_WINDOWS + // Get file descriptor + int file; + switch (stream) + { + case ZYAN_STDSTREAM_OUT: + file = _fileno(ZYAN_STDOUT); + break; + case ZYAN_STDSTREAM_ERR: + file = _fileno(ZYAN_STDERR); + break; + default: + ZYAN_UNREACHABLE; + } + if (file < 0) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + HANDLE const handle = (HANDLE)_get_osfhandle(file); + if (handle == INVALID_HANDLE_VALUE) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + DWORD mode; + if (!GetConsoleMode(handle, &mode)) + { + // The given standard stream is not bound to a terminal + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (!SetConsoleMode(handle, mode)) + { + return ZYAN_STATUS_BAD_SYSTEMCALL; + } +#endif + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanTerminalIsTTY(ZyanStandardStream stream) +{ + // Get file descriptor + int file; +#ifdef ZYAN_WINDOWS + switch (stream) + { + case ZYAN_STDSTREAM_IN: + file = _fileno(ZYAN_STDIN); + break; + case ZYAN_STDSTREAM_OUT: + file = _fileno(ZYAN_STDOUT); + break; + case ZYAN_STDSTREAM_ERR: + file = _fileno(ZYAN_STDERR); + break; + default: + ZYAN_UNREACHABLE; + } + if (file < 0) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } +#else + switch (stream) + { + case ZYAN_STDSTREAM_IN: + file = STDIN_FILENO; + break; + case ZYAN_STDSTREAM_OUT: + file = STDOUT_FILENO; + break; + case ZYAN_STDSTREAM_ERR: + file = STDERR_FILENO; + break; + default: + ZYAN_UNREACHABLE; + } +#endif + +#ifdef ZYAN_WINDOWS + if (_isatty(file)) +#else + if ( isatty(file)) +#endif + { + return ZYAN_STATUS_TRUE; + } + if (ZYAN_ERRNO == EBADF) + { + // Invalid file descriptor + return ZYAN_STATUS_INVALID_ARGUMENT; + } + //ZYAN_ASSERT((errno == EINVAL) || (errno == ENOTTY)); + + return ZYAN_STATUS_FALSE; +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/API/Thread.c b/externals/dynarmic/externals/zycore/src/API/Thread.c new file mode 100755 index 000000000..34158c3fb --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/API/Thread.c @@ -0,0 +1,194 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* */ +/* ---------------------------------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +#if defined(ZYAN_POSIX) + +#include + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread) +{ + *thread = pthread_self(); + + return ZYAN_STATUS_SUCCESS; +} + +ZYAN_STATIC_ASSERT(sizeof(ZyanThreadId) <= sizeof(ZyanU64)); +ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId* thread_id) +{ + // TODO: Use `pthread_getthreadid_np` on platforms where it is available + + pthread_t ptid = pthread_self(); + *thread_id = *(ZyanThreadId*)ptid; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Thread Local Storage */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, ZyanThreadTlsCallback destructor) +{ + ZyanThreadTlsIndex value; + const int error = pthread_key_create(&value, destructor); + if (error != 0) + { + if (error == EAGAIN) + { + return ZYAN_STATUS_OUT_OF_RESOURCES; + } + if (error == ENOMEM) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + *index = value; + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index) +{ + return !pthread_key_delete(index) ? ZYAN_STATUS_SUCCESS : ZYAN_STATUS_BAD_SYSTEMCALL; +} + +ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void** data) +{ + *data = pthread_getspecific(index); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data) +{ + const int error = pthread_setspecific(index, data); + if (error != 0) + { + if (error == EINVAL) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +#elif defined(ZYAN_WINDOWS) + +/* ---------------------------------------------------------------------------------------------- */ +/* General */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread) +{ + *thread = GetCurrentThread(); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId* thread_id) +{ + *thread_id = GetCurrentThreadId(); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Thread Local Storage (TLS) */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, ZyanThreadTlsCallback destructor) +{ + const ZyanThreadTlsIndex value = FlsAlloc(destructor); + if (value == FLS_OUT_OF_INDEXES) + { + return ZYAN_STATUS_OUT_OF_RESOURCES; + } + + *index = value; + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index) +{ + return FlsFree(index) ? ZYAN_STATUS_SUCCESS : ZYAN_STATUS_BAD_SYSTEMCALL; +} + +ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void** data) +{ + *data = FlsGetValue(index); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data) +{ + if (!FlsSetValue(index, data)) + { + const DWORD error = GetLastError(); + if (error == ERROR_INVALID_PARAMETER) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + return ZYAN_STATUS_BAD_SYSTEMCALL; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +#else +# error "Unsupported platform detected" +#endif + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/Allocator.c b/externals/dynarmic/externals/zycore/src/Allocator.c new file mode 100755 index 000000000..5fadf6476 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/Allocator.c @@ -0,0 +1,134 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Default allocator */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +static ZyanStatus ZyanAllocatorDefaultAllocate(ZyanAllocator* allocator, void** p, + ZyanUSize element_size, ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + + *p = ZYAN_MALLOC(element_size * n); + if (!*p) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus ZyanAllocatorDefaultReallocate(ZyanAllocator* allocator, void** p, + ZyanUSize element_size, ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + + void* const x = ZYAN_REALLOC(*p, element_size * n); + if (!x) + { + return ZYAN_STATUS_NOT_ENOUGH_MEMORY; + } + *p = x; + + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus ZyanAllocatorDefaultDeallocate(ZyanAllocator* allocator, void* p, + ZyanUSize element_size, ZyanUSize n) +{ + ZYAN_ASSERT(allocator); + ZYAN_ASSERT(p); + ZYAN_ASSERT(element_size); + ZYAN_ASSERT(n); + + ZYAN_UNUSED(allocator); + ZYAN_UNUSED(element_size); + ZYAN_UNUSED(n); + + ZYAN_FREE(p); + + return ZYAN_STATUS_SUCCESS; +} + +#endif // ZYAN_NO_LIBC + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate, + ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate) +{ + if (!allocator || !allocate || !reallocate || !deallocate) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + allocator->allocate = allocate; + allocator->reallocate = reallocate; + allocator->deallocate = deallocate; + + return ZYAN_STATUS_SUCCESS; +} + +#ifndef ZYAN_NO_LIBC + +ZyanAllocator* ZyanAllocatorDefault(void) +{ + static ZyanAllocator allocator = + { + &ZyanAllocatorDefaultAllocate, + &ZyanAllocatorDefaultReallocate, + &ZyanAllocatorDefaultDeallocate + }; + return &allocator; +} + +#endif + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/ArgParse.c b/externals/dynarmic/externals/zycore/src/ArgParse.c new file mode 100755 index 000000000..109cfc8ac --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/ArgParse.c @@ -0,0 +1,279 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanArgParse(const ZyanArgParseConfig *cfg, ZyanVector* parsed, + const char** error_token) +{ + return ZyanArgParseEx(cfg, parsed, error_token, ZyanAllocatorDefault()); +} + +#endif + +ZyanStatus ZyanArgParseEx(const ZyanArgParseConfig *cfg, ZyanVector* parsed, + const char** error_token, ZyanAllocator* allocator) +{ +# define ZYAN_ERR_TOK(tok) if (error_token) { *error_token = tok; } + + ZYAN_ASSERT(cfg); + ZYAN_ASSERT(parsed); + + // TODO: Once we have a decent hash map impl, refactor this to use it. The majority of for + // loops through the argument list could be avoided. + + if (cfg->min_unnamed_args > cfg->max_unnamed_args) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Check argument syntax. + for (const ZyanArgParseDefinition* def = cfg->args; def && def->name; ++def) + { + // TODO: Duplicate check + + if (!def->name) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize arg_len = ZYAN_STRLEN(def->name); + if (arg_len < 2 || def->name[0] != '-') + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Single dash arguments only accept a single char name. + if (def->name[1] != '-' && arg_len != 2) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + } + + // Initialize output vector. + ZYAN_CHECK(ZyanVectorInitEx(parsed, sizeof(ZyanArgParseArg), cfg->argc, ZYAN_NULL, allocator, + ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR, ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD)); + + ZyanStatus err; + ZyanBool accept_dash_args = ZYAN_TRUE; + ZyanUSize num_unnamed_args = 0; + for (ZyanUSize i = 1; i < cfg->argc; ++i) + { + const char* cur_arg = cfg->argv[i]; + ZyanUSize arg_len = ZYAN_STRLEN(cfg->argv[i]); + + // Double-dash argument? + if (accept_dash_args && arg_len >= 2 && ZYAN_MEMCMP(cur_arg, "--", 2) == 0) + { + // GNU style end of argument parsing. + if (arg_len == 2) + { + accept_dash_args = ZYAN_FALSE; + } + // Regular double-dash argument. + else + { + // Allocate parsed argument struct. + ZyanArgParseArg* parsed_arg; + ZYAN_CHECK(ZyanVectorEmplace(parsed, (void**)&parsed_arg, ZYAN_NULL)); + ZYAN_MEMSET(parsed_arg, 0, sizeof(*parsed_arg)); + + // Find corresponding argument definition. + for (const ZyanArgParseDefinition* def = cfg->args; def && def->name; ++def) + { + if (ZYAN_STRCMP(def->name, cur_arg) == 0) + { + parsed_arg->def = def; + break; + } + } + + // Search exhausted & argument not found. RIP. + if (!parsed_arg->def) + { + err = ZYAN_STATUS_ARG_NOT_UNDERSTOOD; + ZYAN_ERR_TOK(cur_arg); + goto failure; + } + + // Does the argument expect a value? If yes, consume next token. + if (!parsed_arg->def->boolean) + { + if (i == cfg->argc - 1) + { + err = ZYAN_STATUS_ARG_MISSES_VALUE; + ZYAN_ERR_TOK(cur_arg); + goto failure; + } + parsed_arg->has_value = ZYAN_TRUE; + ZYAN_CHECK(ZyanStringViewInsideBuffer(&parsed_arg->value, cfg->argv[++i])); + } + } + + // Continue parsing at next token. + continue; + } + + // Single-dash argument? + // TODO: How to deal with just dashes? Current code treats it as unnamed arg. + if (accept_dash_args && arg_len > 1 && cur_arg[0] == '-') + { + // Iterate argument token chars until there are either no more chars left + // or we encounter a non-boolean argument, in which case we consume the + // remaining chars as its value. + for (const char* read_ptr = cur_arg + 1; *read_ptr; ++read_ptr) + { + // Allocate parsed argument struct. + ZyanArgParseArg* parsed_arg; + ZYAN_CHECK(ZyanVectorEmplace(parsed, (void**)&parsed_arg, ZYAN_NULL)); + ZYAN_MEMSET(parsed_arg, 0, sizeof(*parsed_arg)); + + // Find corresponding argument definition. + for (const ZyanArgParseDefinition* def = cfg->args; def && def->name; ++def) + { + if (ZYAN_STRLEN(def->name) == 2 && + def->name[0] == '-' && + def->name[1] == *read_ptr) + { + parsed_arg->def = def; + break; + } + } + + // Search exhausted, no match found? + if (!parsed_arg->def) + { + err = ZYAN_STATUS_ARG_NOT_UNDERSTOOD; + ZYAN_ERR_TOK(cur_arg); + goto failure; + } + + // Requires value? + if (!parsed_arg->def->boolean) + { + // If there are chars left, consume them (e.g. `-n1000`). + if (read_ptr[1]) + { + parsed_arg->has_value = ZYAN_TRUE; + ZYAN_CHECK(ZyanStringViewInsideBuffer(&parsed_arg->value, read_ptr + 1)); + } + // If not, consume next token (e.g. `-n 1000`). + else + { + if (i == cfg->argc - 1) + { + err = ZYAN_STATUS_ARG_MISSES_VALUE; + ZYAN_ERR_TOK(cur_arg) + goto failure; + } + + parsed_arg->has_value = ZYAN_TRUE; + ZYAN_CHECK(ZyanStringViewInsideBuffer(&parsed_arg->value, cfg->argv[++i])); + } + + // Either way, continue with next argument. + goto continue_main_loop; + } + } + } + + // Still here? We're looking at an unnamed argument. + ++num_unnamed_args; + if (num_unnamed_args > cfg->max_unnamed_args) + { + err = ZYAN_STATUS_TOO_MANY_ARGS; + ZYAN_ERR_TOK(cur_arg); + goto failure; + } + + // Allocate parsed argument struct. + ZyanArgParseArg* parsed_arg; + ZYAN_CHECK(ZyanVectorEmplace(parsed, (void**)&parsed_arg, ZYAN_NULL)); + ZYAN_MEMSET(parsed_arg, 0, sizeof(*parsed_arg)); + parsed_arg->has_value = ZYAN_TRUE; + ZYAN_CHECK(ZyanStringViewInsideBuffer(&parsed_arg->value, cur_arg)); + + continue_main_loop:; + } + + // All tokens processed. Do we have enough unnamed arguments? + if (num_unnamed_args < cfg->min_unnamed_args) + { + err = ZYAN_STATUS_TOO_FEW_ARGS; + // No sensible error token for this error type. + goto failure; + } + + // Check whether all required arguments are present. + ZyanUSize num_parsed_args; + ZYAN_CHECK(ZyanVectorGetSize(parsed, &num_parsed_args)); + for (const ZyanArgParseDefinition* def = cfg->args; def && def->name; ++def) + { + if (!def->required) continue; + + ZyanBool arg_found = ZYAN_FALSE; + for (ZyanUSize i = 0; i < num_parsed_args; ++i) + { + const ZyanArgParseArg* arg = ZYAN_NULL; + ZYAN_CHECK(ZyanVectorGetPointer(parsed, i, (const void**)&arg)); + + // Skip unnamed args. + if (!arg->def) continue; + + if (arg->def == def) + { + arg_found = ZYAN_TRUE; + break; + } + } + + if (!arg_found) + { + err = ZYAN_STATUS_REQUIRED_ARG_MISSING; + ZYAN_ERR_TOK(def->name); + goto failure; + } + } + + // Yay! + ZYAN_ERR_TOK(ZYAN_NULL); + return ZYAN_STATUS_SUCCESS; + +failure: + ZYAN_CHECK(ZyanVectorDestroy(parsed)); + return err; + +# undef ZYAN_ERR_TOK +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/Bitset.c b/externals/dynarmic/externals/zycore/src/Bitset.c new file mode 100755 index 000000000..289aa69da --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/Bitset.c @@ -0,0 +1,670 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Internal constants */ +/* ============================================================================================== */ + +#define ZYAN_BITSET_GROWTH_FACTOR 2.00f +#define ZYAN_BITSET_SHRINK_THRESHOLD 0.50f + +/* ============================================================================================== */ +/* Internal macros */ +/* ============================================================================================== */ + +/** + * Computes the smallest integer value not less than `x`. + * + * @param x The value. + * + * @return The smallest integer value not less than `x`. + */ +#define ZYAN_BITSET_CEIL(x) \ + (((x) == ((ZyanU32)(x))) ? (ZyanU32)(x) : ((ZyanU32)(x)) + 1) + +/** + * Converts bits to bytes. + * + * @param x The value in bits. + * + * @return The amount of bytes needed to fit `x` bits. + */ +#define ZYAN_BITSET_BITS_TO_BYTES(x) \ + ZYAN_BITSET_CEIL((x) / 8.0f) + +/** + * Returns the offset of the given bit. + * + * @param index The bit index. + * + * @return The offset of the given bit. + */ +#define ZYAN_BITSET_BIT_OFFSET(index) \ + (7 - ((index) % 8)) + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Initializes the given `vector` with `count` "zero"-bytes. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param count The number of bytes. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanBitsetInitVectorElements(ZyanVector* vector, ZyanUSize count) +{ + ZYAN_ASSERT(vector); + + static const ZyanU8 zero = 0; + for (ZyanUSize i = 0; i < count; ++i) + { + ZYAN_CHECK(ZyanVectorPushBack(vector, &zero)); + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Byte operations */ +/* ---------------------------------------------------------------------------------------------- */ + +static ZyanStatus ZyanBitsetOperationAND(ZyanU8* b1, const ZyanU8* b2) +{ + *b1 &= *b2; + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus ZyanBitsetOperationOR (ZyanU8* b1, const ZyanU8* b2) +{ + *b1 |= *b2; + return ZYAN_STATUS_SUCCESS; +} + +static ZyanStatus ZyanBitsetOperationXOR(ZyanU8* b1, const ZyanU8* b2) +{ + *b1 ^= *b2; + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, ZyanUSize count) +{ + return ZyanBitsetInitEx(bitset, count, ZyanAllocatorDefault(), ZYAN_BITSET_GROWTH_FACTOR, + ZYAN_BITSET_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count, ZyanAllocator* allocator, + float growth_factor, float shrink_threshold) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanU32 bytes = ZYAN_BITSET_BITS_TO_BYTES(count); + + bitset->size = count; + ZYAN_CHECK(ZyanVectorInitEx(&bitset->bits, sizeof(ZyanU8), bytes, ZYAN_NULL, allocator, + growth_factor, shrink_threshold)); + ZYAN_CHECK(ZyanBitsetInitVectorElements(&bitset->bits, bytes)); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetInitBuffer(ZyanBitset* bitset, ZyanUSize count, void* buffer, + ZyanUSize capacity) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanU32 bytes = ZYAN_BITSET_BITS_TO_BYTES(count); + if (capacity < bytes) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + bitset->size = count; + ZYAN_CHECK(ZyanVectorInitCustomBuffer(&bitset->bits, sizeof(ZyanU8), buffer, capacity, + ZYAN_NULL)); + ZYAN_CHECK(ZyanBitsetInitVectorElements(&bitset->bits, bytes)); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetDestroy(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorDestroy(&bitset->bits); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Logical operations */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset* destination, const ZyanBitset* source, + ZyanBitsetByteOperation operation) +{ + if (!destination || !source || !operation) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize s1; + ZyanUSize s2; + ZYAN_CHECK(ZyanVectorGetSize(&destination->bits, &s1)); + ZYAN_CHECK(ZyanVectorGetSize(&source->bits, &s2)); + + const ZyanUSize min = ZYAN_MIN(s1, s2); + for (ZyanUSize i = 0; i < min; ++i) + { + ZyanU8* v1; + const ZyanU8* v2; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&destination->bits, i, (void**)&v1)); + ZYAN_CHECK(ZyanVectorGetPointer(&source->bits, i, (const void**)&v2)); + + ZYAN_ASSERT(v1); + ZYAN_ASSERT(v2); + + ZYAN_CHECK(operation(v1, v2)); + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetAND(ZyanBitset* destination, const ZyanBitset* source) +{ + return ZyanBitsetPerformByteOperation(destination, source, ZyanBitsetOperationAND); +} + +ZyanStatus ZyanBitsetOR (ZyanBitset* destination, const ZyanBitset* source) +{ + return ZyanBitsetPerformByteOperation(destination, source, ZyanBitsetOperationOR ); +} + +ZyanStatus ZyanBitsetXOR(ZyanBitset* destination, const ZyanBitset* source) +{ + return ZyanBitsetPerformByteOperation(destination, source, ZyanBitsetOperationXOR); +} + +ZyanStatus ZyanBitsetFlip(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, i, (void**)&value)); + *value = ~(*value); + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Bit access */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetSet(ZyanBitset* bitset, ZyanUSize index) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= bitset->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, index / 8, (void**)&value)); + + *value |= (1 << ZYAN_BITSET_BIT_OFFSET(index)); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetReset(ZyanBitset* bitset, ZyanUSize index) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= bitset->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, index / 8, (void**)&value)); + *value &= ~(1 << ZYAN_BITSET_BIT_OFFSET(index)); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetAssign(ZyanBitset* bitset, ZyanUSize index, ZyanBool value) +{ + if (value) + { + return ZyanBitsetSet(bitset, index); + } + return ZyanBitsetReset(bitset, index); +} + +ZyanStatus ZyanBitsetToggle(ZyanBitset* bitset, ZyanUSize index) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= bitset->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, index / 8, (void**)&value)); + *value ^= (1 << ZYAN_BITSET_BIT_OFFSET(index)); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetTest(ZyanBitset* bitset, ZyanUSize index) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= bitset->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + const ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, index / 8, (const void**)&value)); + if ((*value & (1 << ZYAN_BITSET_BIT_OFFSET(index))) == 0) + { + return ZYAN_STATUS_FALSE; + } + return ZYAN_STATUS_TRUE; +} + +ZyanStatus ZyanBitsetTestMSB(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanBitsetTest(bitset, bitset->size - 1); +} + +ZyanStatus ZyanBitsetTestLSB(ZyanBitset* bitset) +{ + return ZyanBitsetTest(bitset, 0); +} + +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetSetAll(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, i, (void**)&value)); + *value = 0xFF; + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetResetAll(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, i, (void**)&value)); + *value = 0x00; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Size management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetPush(ZyanBitset* bitset, ZyanBool value) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if ((bitset->size++ % 8) == 0) + { + static const ZyanU8 zero = 0; + ZYAN_CHECK(ZyanVectorPushBack(&bitset->bits, &zero)); + } + + return ZyanBitsetAssign(bitset, bitset->size - 1, value); +} + +ZyanStatus ZyanBitsetPop(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if ((--bitset->size % 8) == 0) + { + return ZyanVectorPopBack(&bitset->bits); + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetClear(ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + bitset->size = 0; + return ZyanVectorClear(&bitset->bits); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetReserve(ZyanBitset* bitset, ZyanUSize count) +{ + return ZyanVectorReserve(&bitset->bits, ZYAN_BITSET_BITS_TO_BYTES(count)); +} + +ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset* bitset) +{ + return ZyanVectorShrinkToFit(&bitset->bits); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetGetSize(const ZyanBitset* bitset, ZyanUSize* size) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *size = bitset->size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset* bitset, ZyanUSize* capacity) +{ + ZYAN_CHECK(ZyanBitsetGetCapacityBytes(bitset, capacity)); + *capacity *= 8; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset* bitset, ZyanUSize* size) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorGetSize(&bitset->bits, size); +} + +ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset* bitset, ZyanUSize* capacity) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorGetCapacity(&bitset->bits, capacity); +} + +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* count) +{ + if (!bitset || !count) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *count = 0; + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, i, (const void**)&value)); + + ZyanU8 popcnt = *value; + popcnt = (popcnt & 0x55) + ((popcnt >> 1) & 0x55); + popcnt = (popcnt & 0x33) + ((popcnt >> 2) & 0x33); + popcnt = (popcnt & 0x0F) + ((popcnt >> 4) & 0x0F); + + *count += popcnt; + } + + *count = ZYAN_MIN(*count, bitset->size); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanBitsetAll(const ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, i, (const void**)&value)); + if (i < (size - 1)) + { + if (*value != 0xFF) + { + return ZYAN_STATUS_FALSE; + } + } else + { + const ZyanU8 mask = ~(8 - (bitset->size % 8)); + if ((*value & mask) != mask) + { + return ZYAN_STATUS_FALSE; + } + } + } + + return ZYAN_STATUS_TRUE; +} + +ZyanStatus ZyanBitsetAny(const ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, i, (const void**)&value)); + if (i < (size - 1)) + { + if (*value != 0x00) + { + return ZYAN_STATUS_TRUE; + } + } else + { + const ZyanU8 mask = ~(8 - (bitset->size % 8)); + if ((*value & mask) != 0x00) + { + return ZYAN_STATUS_TRUE; + } + } + } + + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanBitsetNone(const ZyanBitset* bitset) +{ + if (!bitset) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanUSize size; + ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size)); + for (ZyanUSize i = 0; i < size; ++i) + { + ZyanU8* value; + ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, i, (const void**)&value)); + if (i < (size - 1)) + { + if (*value != 0x00) + { + return ZYAN_STATUS_FALSE; + } + } else + { + const ZyanU8 mask = ~(8 - (bitset->size % 8)); + if ((*value & mask) != 0x00) + { + return ZYAN_STATUS_FALSE; + } + } + } + + return ZYAN_STATUS_TRUE; +} + +/* ---------------------------------------------------------------------------------------------- */ + +//ZyanStatus ZyanBitsetToU32(const ZyanBitset* bitset, ZyanU32* value) +//{ +// if (!bitset) +// { +// return ZYAN_STATUS_INVALID_ARGUMENT; +// } +// if (bitset->size > 32) +// { +// return ZYAN_STATUS_INVALID_OPERATION; +// } +// +// // TODO: +// +// return ZYAN_STATUS_SUCCESS; +//} +// +//ZyanStatus ZyanBitsetToU64(const ZyanBitset* bitset, ZyanU64* value) +//{ +// if (!bitset) +// { +// return ZYAN_STATUS_INVALID_ARGUMENT; +// } +// if (bitset->size > 64) +// { +// return ZYAN_STATUS_INVALID_OPERATION; +// } +// +// // TODO: +// +// return ZYAN_STATUS_SUCCESS; +//} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/Format.c b/externals/dynarmic/externals/zycore/src/Format.c new file mode 100755 index 000000000..d187d2a2b --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/Format.c @@ -0,0 +1,507 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Constants */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Defines */ +/* ---------------------------------------------------------------------------------------------- */ + +#define ZYCORE_MAXCHARS_DEC_32 10 +#define ZYCORE_MAXCHARS_DEC_64 20 +#define ZYCORE_MAXCHARS_HEX_32 8 +#define ZYCORE_MAXCHARS_HEX_64 16 + +/* ---------------------------------------------------------------------------------------------- */ +/* Lookup Tables */ +/* ---------------------------------------------------------------------------------------------- */ + +static const char* const DECIMAL_LOOKUP = + "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899"; + +/* ---------------------------------------------------------------------------------------------- */ +/* Static strings */ +/* ---------------------------------------------------------------------------------------------- */ + +static const ZyanStringView STR_ADD = ZYAN_DEFINE_STRING_VIEW("+"); +static const ZyanStringView STR_SUB = ZYAN_DEFINE_STRING_VIEW("-"); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Internal macros */ +/* ============================================================================================== */ + +/** + * Writes a terminating '\0' character at the end of the string data. + */ +#define ZYCORE_STRING_NULLTERMINATE(string) \ + *(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0'; + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Decimal */ +/* ---------------------------------------------------------------------------------------------- */ + +#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) +ZyanStatus ZyanStringAppendDecU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + char buffer[ZYCORE_MAXCHARS_DEC_32]; + char *buffer_end = &buffer[ZYCORE_MAXCHARS_DEC_32]; + char *buffer_write_pointer = buffer_end; + while (value >= 100) + { + const ZyanU32 value_old = value; + buffer_write_pointer -= 2; + value /= 100; + ZYAN_MEMCPY(buffer_write_pointer, &DECIMAL_LOOKUP[(value_old - (value * 100)) * 2], 2); + } + buffer_write_pointer -= 2; + ZYAN_MEMCPY(buffer_write_pointer, &DECIMAL_LOOKUP[value * 2], 2); + + const ZyanUSize offset_odd = (ZyanUSize)(value < 10); + const ZyanUSize length_number = buffer_end - buffer_write_pointer - offset_odd; + const ZyanUSize length_total = ZYAN_MAX(length_number, padding_length); + const ZyanUSize length_target = string->vector.size; + + if (string->vector.size + length_total > string->vector.capacity) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + length_total - 1)); + } + + ZyanUSize offset_write = 0; + if (padding_length > length_number) + { + offset_write = padding_length - length_number; + ZYAN_MEMSET((char*)string->vector.data + length_target - 1, '0', offset_write); + } + + ZYAN_MEMCPY((char*)string->vector.data + length_target + offset_write - 1, + buffer_write_pointer + offset_odd, length_number); + string->vector.size = length_target + length_total; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} +#endif + +ZyanStatus ZyanStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + char buffer[ZYCORE_MAXCHARS_DEC_64]; + char *buffer_end = &buffer[ZYCORE_MAXCHARS_DEC_64]; + char *buffer_write_pointer = buffer_end; + while (value >= 100) + { + const ZyanU64 value_old = value; + buffer_write_pointer -= 2; + value /= 100; + ZYAN_MEMCPY(buffer_write_pointer, &DECIMAL_LOOKUP[(value_old - (value * 100)) * 2], 2); + } + buffer_write_pointer -= 2; + ZYAN_MEMCPY(buffer_write_pointer, &DECIMAL_LOOKUP[value * 2], 2); + + const ZyanUSize offset_odd = (ZyanUSize)(value < 10); + const ZyanUSize length_number = buffer_end - buffer_write_pointer - offset_odd; + const ZyanUSize length_total = ZYAN_MAX(length_number, padding_length); + const ZyanUSize length_target = string->vector.size; + + if (string->vector.size + length_total > string->vector.capacity) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + length_total - 1)); + } + + ZyanUSize offset_write = 0; + if (padding_length > length_number) + { + offset_write = padding_length - length_number; + ZYAN_MEMSET((char*)string->vector.data + length_target - 1, '0', offset_write); + } + + ZYAN_MEMCPY((char*)string->vector.data + length_target + offset_write - 1, + buffer_write_pointer + offset_odd, length_number); + string->vector.size = length_target + length_total; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Hexadecimal */ +/* ---------------------------------------------------------------------------------------------- */ + +#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) +ZyanStatus ZyanStringAppendHexU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length, + ZyanBool uppercase) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = string->vector.size; + ZyanUSize remaining = string->vector.capacity - string->vector.size; + + if (remaining < (ZyanUSize)padding_length) + { + ZYAN_CHECK(ZyanStringResize(string, len + padding_length - 1)); + remaining = padding_length; + } + + if (!value) + { + const ZyanU8 n = (padding_length ? padding_length : 1); + + if (remaining < (ZyanUSize)n) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + n - 1)); + } + + ZYAN_MEMSET((char*)string->vector.data + len - 1, '0', n); + string->vector.size = len + n; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; + } + + ZyanU8 n = 0; + char* buffer = ZYAN_NULL; + for (ZyanI8 i = ZYCORE_MAXCHARS_HEX_32 - 1; i >= 0; --i) + { + const ZyanU8 v = (value >> i * 4) & 0x0F; + if (!n) + { + if (!v) + { + continue; + } + if (remaining <= (ZyanU8)i) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + i)); + } + buffer = (char*)string->vector.data + len - 1; + if (padding_length > i) + { + n = padding_length - i - 1; + ZYAN_MEMSET(buffer, '0', n); + } + } + ZYAN_ASSERT(buffer); + if (uppercase) + { + buffer[n++] = "0123456789ABCDEF"[v]; + } else + { + buffer[n++] = "0123456789abcdef"[v]; + } + } + string->vector.size = len + n; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} +#endif + +ZyanStatus ZyanStringAppendHexU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length, + ZyanBool uppercase) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = string->vector.size; + ZyanUSize remaining = string->vector.capacity - string->vector.size; + + if (remaining < (ZyanUSize)padding_length) + { + ZYAN_CHECK(ZyanStringResize(string, len + padding_length - 1)); + remaining = padding_length; + } + + if (!value) + { + const ZyanU8 n = (padding_length ? padding_length : 1); + + if (remaining < (ZyanUSize)n) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + n - 1)); + } + + ZYAN_MEMSET((char*)string->vector.data + len - 1, '0', n); + string->vector.size = len + n; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; + } + + ZyanU8 n = 0; + char* buffer = ZYAN_NULL; + for (ZyanI8 i = ((value & 0xFFFFFFFF00000000) ? + ZYCORE_MAXCHARS_HEX_64 : ZYCORE_MAXCHARS_HEX_32) - 1; i >= 0; --i) + { + const ZyanU8 v = (value >> i * 4) & 0x0F; + if (!n) + { + if (!v) + { + continue; + } + if (remaining <= (ZyanU8)i) + { + ZYAN_CHECK(ZyanStringResize(string, string->vector.size + i)); + } + buffer = (char*)string->vector.data + len - 1; + if (padding_length > i) + { + n = padding_length - i - 1; + ZYAN_MEMSET(buffer, '0', n); + } + } + ZYAN_ASSERT(buffer); + if (uppercase) + { + buffer[n++] = "0123456789ABCDEF"[v]; + } else + { + buffer[n++] = "0123456789abcdef"[v]; + } + } + string->vector.size = len + n; + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +//ZyanStatus ZyanStringInsertFormat(ZyanString* string, ZyanUSize index, const char* format, ...) +//{ +// +//} +// +///* ---------------------------------------------------------------------------------------------- */ +// +//ZyanStatus ZyanStringInsertDecU(ZyanString* string, ZyanUSize index, ZyanU64 value, +// ZyanUSize padding_length) +//{ +// +//} +// +//ZyanStatus ZyanStringInsertDecS(ZyanString* string, ZyanUSize index, ZyanI64 value, +// ZyanUSize padding_length, ZyanBool force_sign, const ZyanString* prefix) +//{ +// +//} +// +//ZyanStatus ZyanStringInsertHexU(ZyanString* string, ZyanUSize index, ZyanU64 value, +// ZyanUSize padding_length, ZyanBool uppercase) +//{ +// +//} +// +//ZyanStatus ZyanStringInsertHexS(ZyanString* string, ZyanUSize index, ZyanI64 value, +// ZyanUSize padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString* prefix) +//{ +// +//} + +/* ---------------------------------------------------------------------------------------------- */ +/* Appending */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanStringAppendFormat(ZyanString* string, const char* format, ...) +{ + if (!string || !format) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanVAList arglist; + ZYAN_VA_START(arglist, format); + + const ZyanUSize len = string->vector.size; + + ZyanI32 w = ZYAN_VSNPRINTF((char*)string->vector.data + len - 1, + string->vector.capacity - len + 1, format, arglist); + if (w < 0) + { + ZYAN_VA_END(arglist); + return ZYAN_STATUS_FAILED; + } + if (w <= (ZyanI32)(string->vector.capacity - len)) + { + string->vector.size = len + w; + + ZYAN_VA_END(arglist); + return ZYAN_STATUS_SUCCESS; + } + + // The remaining capacity was not sufficent to fit the formatted string. Trying to resize .. + const ZyanStatus status = ZyanStringResize(string, string->vector.size + w - 1); + if (!ZYAN_SUCCESS(status)) + { + ZYAN_VA_END(arglist); + return status; + } + + w = ZYAN_VSNPRINTF((char*)string->vector.data + len - 1, + string->vector.capacity - string->vector.size + 1, format, arglist); + if (w < 0) + { + ZYAN_VA_END(arglist); + return ZYAN_STATUS_FAILED; + } + ZYAN_ASSERT(w <= (ZyanI32)(string->vector.capacity - string->vector.size)); + + ZYAN_VA_END(arglist); + return ZYAN_STATUS_SUCCESS; +} + +#endif // ZYAN_NO_LIBC + +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length) +{ +#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) + return ZyanStringAppendDecU64(string, value, padding_length); +#else + // Working with 64-bit values is slow on non 64-bit systems + if (value & 0xFFFFFFFF00000000) + { + return ZyanStringAppendDecU64(string, value, padding_length); + } + return ZyanStringAppendDecU32(string, (ZyanU32)value, padding_length); +#endif +} + +ZyanStatus ZyanStringAppendDecS(ZyanString* string, ZyanI64 value, ZyanU8 padding_length, + ZyanBool force_sign, const ZyanStringView* prefix) +{ + if (value < 0) + { + ZYAN_CHECK(ZyanStringAppend(string, &STR_SUB)); + if (prefix) + { + ZYAN_CHECK(ZyanStringAppend(string, prefix)); + } + return ZyanStringAppendDecU(string, ZyanAbsI64(value), padding_length); + } + + if (force_sign) + { + ZYAN_ASSERT(value >= 0); + ZYAN_CHECK(ZyanStringAppend(string, &STR_ADD)); + } + + if (prefix) + { + ZYAN_CHECK(ZyanStringAppend(string, prefix)); + } + return ZyanStringAppendDecU(string, value, padding_length); +} + +ZyanStatus ZyanStringAppendHexU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length, + ZyanBool uppercase) +{ +#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) + return ZyanStringAppendHexU64(string, value, padding_length, uppercase); +#else + // Working with 64-bit values is slow on non 64-bit systems + if (value & 0xFFFFFFFF00000000) + { + return ZyanStringAppendHexU64(string, value, padding_length, uppercase); + } + return ZyanStringAppendHexU32(string, (ZyanU32)value, padding_length, uppercase); +#endif +} + +ZyanStatus ZyanStringAppendHexS(ZyanString* string, ZyanI64 value, ZyanU8 padding_length, + ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView* prefix) +{ + if (value < 0) + { + ZYAN_CHECK(ZyanStringAppend(string, &STR_SUB)); + if (prefix) + { + ZYAN_CHECK(ZyanStringAppend(string, prefix)); + } + return ZyanStringAppendHexU(string, ZyanAbsI64(value), padding_length, uppercase); + } + + if (force_sign) + { + ZYAN_ASSERT(value >= 0); + ZYAN_CHECK(ZyanStringAppend(string, &STR_ADD)); + } + + if (prefix) + { + ZYAN_CHECK(ZyanStringAppend(string, prefix)); + } + return ZyanStringAppendHexU(string, value, padding_length, uppercase); +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/List.c b/externals/dynarmic/externals/zycore/src/List.c new file mode 100755 index 000000000..e233da81f --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/List.c @@ -0,0 +1,673 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Internal macros */ +/* ============================================================================================== */ + +/** + * Returns a pointer to the data of the given `node`. + * + * @param node A pointer to the `ZyanNodeData` struct. + * + * @return A pointer to the data of the given `node`. + */ +#define ZYCORE_LIST_GET_NODE_DATA(node) \ + ((void*)(node + 1)) + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Allocates memory for a new list node. + * + * @param list A pointer to the `ZyanList` instance. + * @param node Receives a pointer to the new `ZyanListNode` struct. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanListAllocateNode(ZyanList* list, ZyanListNode** node) +{ + ZYAN_ASSERT(list); + ZYAN_ASSERT(node); + + const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL); + if (is_dynamic) + { + ZYAN_ASSERT(list->allocator->allocate); + ZYAN_CHECK(list->allocator->allocate(list->allocator, (void**)node, + sizeof(ZyanListNode) + list->element_size, 1)); + } else + { + if (list->first_unused) + { + *node = list->first_unused; + list->first_unused = (*node)->next; + } else + { + const ZyanUSize size = list->size * (sizeof(ZyanListNode) + list->element_size); + if (size + (sizeof(ZyanListNode) + list->element_size) > list->capacity) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + *node = (ZyanListNode*)((ZyanU8*)list->buffer + size); + } + } + + return ZYAN_STATUS_SUCCESS; +} + +/** + * Frees memory of a node. + * + * @param list A pointer to the `ZyanList` instance. + * @param node A pointer to the `ZyanListNode` struct. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanListDeallocateNode(ZyanList* list, ZyanListNode* node) +{ + ZYAN_ASSERT(list); + ZYAN_ASSERT(node); + + const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL); + if (is_dynamic) + { + ZYAN_ASSERT(list->allocator->deallocate); + ZYAN_CHECK(list->allocator->deallocate(list->allocator, (void*)node, + sizeof(ZyanListNode) + list->element_size, 1)); + } else + { + node->next = list->first_unused; + list->first_unused = node; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList* list, ZyanUSize element_size, + ZyanMemberProcedure destructor) +{ + return ZyanListInitEx(list, element_size, destructor, ZyanAllocatorDefault()); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size, ZyanMemberProcedure destructor, + ZyanAllocator* allocator) +{ + if (!list || !element_size || !allocator) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + list->allocator = allocator; + list->size = 0; + list->element_size = element_size; + list->destructor = destructor; + list->head = ZYAN_NULL; + list->tail = ZYAN_NULL; + list->buffer = ZYAN_NULL; + list->capacity = 0; + list->first_unused = ZYAN_NULL; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListInitCustomBuffer(ZyanList* list, ZyanUSize element_size, + ZyanMemberProcedure destructor, void* buffer, ZyanUSize capacity) +{ + if (!list || !element_size || !buffer || !capacity) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + list->allocator = ZYAN_NULL; + list->size = 0; + list->element_size = element_size; + list->destructor = destructor; + list->head = ZYAN_NULL; + list->tail = ZYAN_NULL; + list->buffer = buffer; + list->capacity = capacity; + list->first_unused = ZYAN_NULL; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListDestroy(ZyanList* list) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(list->element_size); + + const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL); + ZyanListNode* node = (is_dynamic || list->destructor) ? list->head : ZYAN_NULL; + while (node) + { + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + ZyanListNode* const next = node->next; + + if (is_dynamic) + { + ZYAN_CHECK(list->allocator->deallocate(list->allocator, node, + sizeof(ZyanListNode) + list->element_size, 1)); + } + + node = next; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------------------------------- */ +/* Item access */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanListGetHeadNode(const ZyanList* list, const ZyanListNode** node) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *node = list->head; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListGetTailNode(const ZyanList* list, const ZyanListNode** node) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *node = list->tail; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListGetPrevNode(const ZyanListNode** node) +{ + if (!node || !*node) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *node = (*node)->prev; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListGetNextNode(const ZyanListNode** node) +{ + if (!node || !*node) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *node = (*node)->next; + + return ZYAN_STATUS_SUCCESS; +} + +const void* ZyanListGetNodeData(const ZyanListNode* node) +{ + if (!node) + { + return ZYAN_NULL; + } + + return (const void*)ZYCORE_LIST_GET_NODE_DATA(node); +} + +ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode* node, const void** value) +{ + if (!node) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *value = (const void*)ZYCORE_LIST_GET_NODE_DATA(node); + + return ZYAN_STATUS_SUCCESS; +} + +void* ZyanListGetNodeDataMutable(const ZyanListNode* node) +{ + if (!node) + { + return ZYAN_NULL; + } + + return ZYCORE_LIST_GET_NODE_DATA(node); +} + +ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode* node, void** value) +{ + if (!node) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *value = ZYCORE_LIST_GET_NODE_DATA(node); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListSetNodeData(const ZyanList* list, const ZyanListNode* node, const void* value) +{ + if (!list || !node || !value) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + ZYAN_ASSERT(list->element_size); + ZYAN_MEMCPY(ZYCORE_LIST_GET_NODE_DATA(node), value, list->element_size); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanListPushBack(ZyanList* list, const void* item) +{ + if (!list || !item) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanListNode* node; + ZYAN_CHECK(ZyanListAllocateNode(list, &node)); + node->prev = list->tail; + node->next = ZYAN_NULL; + + ZYAN_MEMCPY(ZYCORE_LIST_GET_NODE_DATA(node), item, list->element_size); + + if (!list->head) + { + list->head = node; + list->tail = node; + } else + { + list->tail->next = node; + list->tail = node; + } + ++list->size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListPushFront(ZyanList* list, const void* item) +{ + if (!list || !item) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanListNode* node; + ZYAN_CHECK(ZyanListAllocateNode(list, &node)); + node->prev = ZYAN_NULL; + node->next = list->head; + + ZYAN_MEMCPY(ZYCORE_LIST_GET_NODE_DATA(node), item, list->element_size); + + if (!list->head) + { + list->head = node; + list->tail = node; + } else + { + list->head->prev= node; + list->head = node; + } + ++list->size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListEmplaceBack(ZyanList* list, void** item, ZyanMemberFunction constructor) +{ + if (!list || !item) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanListNode* node; + ZYAN_CHECK(ZyanListAllocateNode(list, &node)); + node->prev = list->tail; + node->next = ZYAN_NULL; + + *item = ZYCORE_LIST_GET_NODE_DATA(node); + if (constructor) + { + constructor(*item); + } + + if (!list->head) + { + list->head = node; + list->tail = node; + } else + { + list->tail->next = node; + list->tail = node; + } + ++list->size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListEmplaceFront(ZyanList* list, void** item, ZyanMemberFunction constructor) +{ + if (!list || !item) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZyanListNode* node; + ZYAN_CHECK(ZyanListAllocateNode(list, &node)); + node->prev = ZYAN_NULL; + node->next = list->head; + + *item = ZYCORE_LIST_GET_NODE_DATA(node); + if (constructor) + { + constructor(*item); + } + + if (!list->head) + { + list->head = node; + list->tail = node; + } else + { + list->head->prev= node; + list->head = node; + } + ++list->size; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanListPopBack(ZyanList* list) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (!list->tail) + { + return ZYAN_STATUS_INVALID_OPERATION; + } + + ZyanListNode* const node = list->tail; + + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + list->tail = node->prev; + if (list->tail) + { + list->tail->next = ZYAN_NULL; + } + if (list->head == node) + { + list->head = list->tail; + } + --list->size; + + return ZyanListDeallocateNode(list, node); +} + +ZyanStatus ZyanListPopFront(ZyanList* list) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (!list->head) + { + return ZYAN_STATUS_INVALID_OPERATION; + } + + ZyanListNode* const node = list->head; + + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + list->head = node->next; + if (list->head) + { + list->head->prev = ZYAN_NULL; + } + if (list->tail == node) + { + list->tail = list->head; + } + --list->size; + + return ZyanListDeallocateNode(list, node); +} + +ZyanStatus ZyanListRemove(ZyanList* list, const ZyanListNode* node) +{ + ZYAN_UNUSED(list); + ZYAN_UNUSED(node); + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListRemoveRange(ZyanList* list, const ZyanListNode* first, const ZyanListNode* last) +{ + ZYAN_UNUSED(list); + ZYAN_UNUSED(first); + ZYAN_UNUSED(last); + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanListClear(ZyanList* list) +{ + return ZyanListResizeEx(list, 0, ZYAN_NULL); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanListResize(ZyanList* list, ZyanUSize size) +{ + return ZyanListResizeEx(list, size, ZYAN_NULL); +} + +ZyanStatus ZyanListResizeEx(ZyanList* list, ZyanUSize size, const void* initializer) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (size == list->size) + { + return ZYAN_STATUS_SUCCESS; + } + + if (size == 0) + { + const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL); + ZyanListNode* node = (is_dynamic || list->destructor) ? list->head : ZYAN_NULL; + while (node) + { + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + ZyanListNode* const next = node->next; + + if (is_dynamic) + { + ZYAN_CHECK(list->allocator->deallocate(list->allocator, node, + sizeof(ZyanListNode) + list->element_size, 1)); + } + + node = next; + } + + list->size = 0; + list->head = 0; + list->tail = 0; + list->first_unused = ZYAN_NULL; + + return ZYAN_STATUS_SUCCESS; + } + + if (size > list->size) + { + ZyanListNode* node; + for (ZyanUSize i = list->size; i < size; ++i) + { + ZYAN_CHECK(ZyanListAllocateNode(list, &node)); + node->prev = list->tail; + node->next = ZYAN_NULL; + + if (initializer) + { + ZYAN_MEMCPY(ZYCORE_LIST_GET_NODE_DATA(node), initializer, list->element_size); + } + + if (!list->head) + { + list->head = node; + list->tail = node; + } else + { + list->tail->next = node; + list->tail = node; + } + + // `ZyanListAllocateNode` needs the list size + ++list->size; + } + } else + { + for (ZyanUSize i = size; i < list->size; ++i) + { + ZyanListNode* const node = list->tail; + + if (list->destructor) + { + list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)); + } + + list->tail = node->prev; + if (list->tail) + { + list->tail->next = ZYAN_NULL; + } + + ZYAN_CHECK(ZyanListDeallocateNode(list, node)); + } + + list->size = size; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size) +{ + if (!list) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *size = list->size; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/String.c b/externals/dynarmic/externals/zycore/src/String.c new file mode 100755 index 000000000..feeb04d04 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/String.c @@ -0,0 +1,1098 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Internal macros */ +/* ============================================================================================== */ + +/** + * Writes a terminating '\0' character at the end of the string data. + */ +#define ZYCORE_STRING_NULLTERMINATE(string) \ + *(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0'; + +/** + * Checks for a terminating '\0' character at the end of the string data. + */ +#define ZYCORE_STRING_ASSERT_NULLTERMINATION(string) \ + ZYAN_ASSERT(*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) == '\0'); + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanStringInit(ZyanString* string, ZyanUSize capacity) +{ + return ZyanStringInitEx(string, capacity, ZyanAllocatorDefault(), + ZYAN_STRING_DEFAULT_GROWTH_FACTOR, ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanStringInitEx(ZyanString* string, ZyanUSize capacity, ZyanAllocator* allocator, + float growth_factor, float shrink_threshold) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + string->flags = 0; + capacity = ZYAN_MAX(ZYAN_STRING_MIN_CAPACITY, capacity) + 1; + ZYAN_CHECK(ZyanVectorInitEx(&string->vector, sizeof(char), capacity, ZYAN_NULL, allocator, + growth_factor, shrink_threshold)); + ZYAN_ASSERT(string->vector.capacity >= capacity); + // Some of the string code relies on `sizeof(char) == 1` + ZYAN_ASSERT(string->vector.element_size == 1); + + *(char*)string->vector.data = '\0'; + ++string->vector.size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringInitCustomBuffer(ZyanString* string, char* buffer, ZyanUSize capacity) +{ + if (!string || !capacity) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + string->flags = ZYAN_STRING_HAS_FIXED_CAPACITY; + ZYAN_CHECK(ZyanVectorInitCustomBuffer(&string->vector, sizeof(char), (void*)buffer, capacity, + ZYAN_NULL)); + ZYAN_ASSERT(string->vector.capacity == capacity); + // Some of the string code relies on `sizeof(char) == 1` + ZYAN_ASSERT(string->vector.element_size == 1); + + *(char*)string->vector.data = '\0'; + ++string->vector.size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringDestroy(ZyanString* string) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (string->flags & ZYAN_STRING_HAS_FIXED_CAPACITY) + { + return ZYAN_STATUS_SUCCESS; + } + + return ZyanVectorDestroy(&string->vector); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanStringDuplicate(ZyanString* destination, const ZyanStringView* source, + ZyanUSize capacity) +{ + return ZyanStringDuplicateEx(destination, source, capacity, ZyanAllocatorDefault(), + ZYAN_STRING_DEFAULT_GROWTH_FACTOR, ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanStringDuplicateEx(ZyanString* destination, const ZyanStringView* source, + ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, float shrink_threshold) +{ + if (!source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = source->string.vector.size; + capacity = ZYAN_MAX(capacity, len - 1); + ZYAN_CHECK(ZyanStringInitEx(destination, capacity, allocator, growth_factor, shrink_threshold)); + ZYAN_ASSERT(destination->vector.capacity >= len); + + ZYAN_MEMCPY(destination->vector.data, source->string.vector.data, + source->string.vector.size - 1); + destination->vector.size = len; + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringDuplicateCustomBuffer(ZyanString* destination, const ZyanStringView* source, + char* buffer, ZyanUSize capacity) +{ + if (!source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = source->string.vector.size; + if (capacity < len) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + ZYAN_CHECK(ZyanStringInitCustomBuffer(destination, buffer, capacity)); + ZYAN_ASSERT(destination->vector.capacity >= len); + + ZYAN_MEMCPY(destination->vector.data, source->string.vector.data, + source->string.vector.size - 1); + destination->vector.size = len; + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Concatenation */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanStringConcat(ZyanString* destination, const ZyanStringView* s1, + const ZyanStringView* s2, ZyanUSize capacity) +{ + return ZyanStringConcatEx(destination, s1, s2, capacity, ZyanAllocatorDefault(), + ZYAN_STRING_DEFAULT_GROWTH_FACTOR, ZYAN_STRING_DEFAULT_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanStringConcatEx(ZyanString* destination, const ZyanStringView* s1, + const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, + float shrink_threshold) +{ + if (!s1 || !s2 || !s1->string.vector.size || !s2->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = s1->string.vector.size + s2->string.vector.size - 1; + capacity = ZYAN_MAX(capacity, len - 1); + ZYAN_CHECK(ZyanStringInitEx(destination, capacity, allocator, growth_factor, shrink_threshold)); + ZYAN_ASSERT(destination->vector.capacity >= len); + + ZYAN_MEMCPY(destination->vector.data, s1->string.vector.data, s1->string.vector.size - 1); + ZYAN_MEMCPY((char*)destination->vector.data + s1->string.vector.size - 1, + s2->string.vector.data, s2->string.vector.size - 1); + destination->vector.size = len; + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringConcatCustomBuffer(ZyanString* destination, const ZyanStringView* s1, + const ZyanStringView* s2, char* buffer, ZyanUSize capacity) +{ + if (!s1 || !s2 || !s1->string.vector.size || !s2->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = s1->string.vector.size + s2->string.vector.size - 1; + if (capacity < len) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + ZYAN_CHECK(ZyanStringInitCustomBuffer(destination, buffer, capacity)); + ZYAN_ASSERT(destination->vector.capacity >= len); + + ZYAN_MEMCPY(destination->vector.data, s1->string.vector.data, s1->string.vector.size - 1); + ZYAN_MEMCPY((char*)destination->vector.data + s1->string.vector.size - 1, + s2->string.vector.data, s2->string.vector.size - 1); + destination->vector.size = len; + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Views */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringViewInsideView(ZyanStringView* view, const ZyanStringView* source) +{ + if (!view || !source) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + view->string.vector.data = source->string.vector.data; + view->string.vector.size = source->string.vector.size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringViewInsideViewEx(ZyanStringView* view, const ZyanStringView* source, + ZyanUSize index, ZyanUSize count) +{ + if (!view || !source) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (index + count >= source->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + view->string.vector.data = (void*)((char*)source->string.vector.data + index); + view->string.vector.size = count; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringViewInsideBuffer(ZyanStringView* view, const char* string) +{ + if (!view || !string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + view->string.vector.data = (void*)string; + view->string.vector.size = ZYAN_STRLEN(string) + 1; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringViewInsideBufferEx(ZyanStringView* view, const char* buffer, ZyanUSize length) +{ + if (!view || !buffer || !length) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + view->string.vector.data = (void*)buffer; + view->string.vector.size = length + 1; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringViewGetSize(const ZyanStringView* view, ZyanUSize* size) +{ + if (!view || !size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(view->string.vector.size >= 1); + *size = view->string.vector.size - 1; + + return ZYAN_STATUS_SUCCESS; +} + +ZYCORE_EXPORT ZyanStatus ZyanStringViewGetData(const ZyanStringView* view, const char** buffer) +{ + if (!view || !buffer) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *buffer = view->string.vector.data; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Character access */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringGetChar(const ZyanStringView* string, ZyanUSize index, char* value) +{ + if (!string || !value) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow direct access to the terminating '\0' character + if (index + 1 >= string->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + const char* chr; + ZYAN_CHECK(ZyanVectorGetPointer(&string->string.vector, index, (const void**)&chr)); + *value = *chr; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringGetCharMutable(ZyanString* string, ZyanUSize index, char** value) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow direct access to the terminating '\0' character + if (index + 1 >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + return ZyanVectorGetPointerMutable(&string->vector, index, (void**)value); +} + +ZyanStatus ZyanStringSetChar(ZyanString* string, ZyanUSize index, char value) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow direct access to the terminating '\0' character + if (index + 1 >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + return ZyanVectorSet(&string->vector, index, (void*)&value); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringInsert(ZyanString* destination, ZyanUSize index, const ZyanStringView* source) +{ + if (!destination || !source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (index == destination->vector.size) + { + return ZyanStringAppend(destination, source); + } + + // Don't allow insertion after the terminating '\0' character + if (index >= destination->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_CHECK(ZyanVectorInsertRange(&destination->vector, index, source->string.vector.data, + source->string.vector.size - 1)); + ZYCORE_STRING_ASSERT_NULLTERMINATION(destination); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringInsertEx(ZyanString* destination, ZyanUSize destination_index, + const ZyanStringView* source, ZyanUSize source_index, ZyanUSize count) +{ + if (!destination || !source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (destination_index == destination->vector.size) + { + return ZyanStringAppendEx(destination, source, source_index, count); + } + + // Don't allow insertion after the terminating '\0' character + if (destination_index >= destination->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + // Don't allow access to the terminating '\0' character + if (source_index + count >= source->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_CHECK(ZyanVectorInsertRange(&destination->vector, destination_index, + (char*)source->string.vector.data + source_index, count)); + ZYCORE_STRING_ASSERT_NULLTERMINATION(destination); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Appending */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringAppend(ZyanString* destination, const ZyanStringView* source) +{ + if (!destination || !source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = destination->vector.size; + ZYAN_CHECK(ZyanVectorResize(&destination->vector, len + source->string.vector.size - 1)); + ZYAN_MEMCPY((char*)destination->vector.data + len - 1, source->string.vector.data, + source->string.vector.size - 1); + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringAppendEx(ZyanString* destination, const ZyanStringView* source, + ZyanUSize source_index, ZyanUSize count) +{ + if (!destination || !source || !source->string.vector.size) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if (source_index + count >= source->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + const ZyanUSize len = destination->vector.size; + ZYAN_CHECK(ZyanVectorResize(&destination->vector, len + count)); + ZYAN_MEMCPY((char*)destination->vector.data + len - 1, + (const char*)source->string.vector.data + source_index, count); + ZYCORE_STRING_NULLTERMINATE(destination); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringDelete(ZyanString* string, ZyanUSize index, ZyanUSize count) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow removal of the terminating '\0' character + if (index + count >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_CHECK(ZyanVectorDeleteRange(&string->vector, index, count)); + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringTruncate(ZyanString* string, ZyanUSize index) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow removal of the terminating '\0' character + if (index >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_CHECK(ZyanVectorDeleteRange(&string->vector, index, string->vector.size - index - 1)); + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringClear(ZyanString* string) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_CHECK(ZyanVectorClear(&string->vector)); + // `ZyanVector` guarantees a minimum capacity of 1 element/character + ZYAN_ASSERT(string->vector.capacity >= 1); + + *(char*)string->vector.data = '\0'; + string->vector.size++; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringLPos(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index) +{ + if (!haystack) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringLPosEx(haystack, needle, found_index, 0, haystack->string.vector.size - 1); +} + +ZyanStatus ZyanStringLPosEx(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index, ZyanUSize index, ZyanUSize count) +{ + if (!haystack || !needle || !found_index) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if (index + count >= haystack->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if ((haystack->string.vector.size == 1) || (needle->string.vector.size == 1) || + (haystack->string.vector.size < needle->string.vector.size)) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + + const char* s = (const char*)haystack->string.vector.data + index; + const char* b = (const char*)needle->string.vector.data; + for (; s + 1 < (const char*)haystack->string.vector.data + haystack->string.vector.size; ++s) + { + if (*s != *b) + { + continue; + } + const char* a = s; + for (;;) + { + if ((ZyanUSize)(a - (const char*)haystack->string.vector.data) > index + count) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + if (*b == 0) + { + *found_index = (ZyanISize)(s - (const char*)haystack->string.vector.data); + return ZYAN_STATUS_TRUE; + } + if (*a++ != *b++) + { + break; + } + } + b = (char*)needle->string.vector.data; + } + + *found_index = -1; + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanStringLPosI(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index) +{ + if (!haystack) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringLPosIEx(haystack, needle, found_index, 0, haystack->string.vector.size - 1); +} + +ZyanStatus ZyanStringLPosIEx(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index, ZyanUSize index, ZyanUSize count) +{ + // This solution assumes that characters are represented using ASCII representation, i.e., + // codes for 'a', 'b', 'c', .. 'z' are 97, 98, 99, .. 122 respectively. And codes for 'A', + // 'B', 'C', .. 'Z' are 65, 66, .. 95 respectively. + + if (!haystack || !needle || !found_index) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if (index + count >= haystack->string.vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if ((haystack->string.vector.size == 1) || (needle->string.vector.size == 1) || + (haystack->string.vector.size < needle->string.vector.size)) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + + const char* s = (const char*)haystack->string.vector.data + index; + const char* b = (const char*)needle->string.vector.data; + for (; s + 1 < (const char*)haystack->string.vector.data + haystack->string.vector.size; ++s) + { + if ((*s != *b) && ((*s ^ 32) != *b)) + { + continue; + } + const char* a = s; + for (;;) + { + if ((ZyanUSize)(a - (const char*)haystack->string.vector.data) > index + count) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + if (*b == 0) + { + *found_index = (ZyanISize)(s - (const char*)haystack->string.vector.data); + return ZYAN_STATUS_TRUE; + } + const char c1 = *a++; + const char c2 = *b++; + if ((c1 != c2) && ((c1 ^ 32) != c2)) + { + break; + } + } + b = (char*)needle->string.vector.data; + } + + *found_index = -1; + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanStringRPos(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index) +{ + if (!haystack) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringRPosEx(haystack, needle, found_index, haystack->string.vector.size - 1, + haystack->string.vector.size - 1); +} + +ZyanStatus ZyanStringRPosEx(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index, ZyanUSize index, ZyanUSize count) +{ + if (!haystack || !needle || !found_index) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if ((index >= haystack->string.vector.size) || (count > index)) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (!index || !count || + (haystack->string.vector.size == 1) || (needle->string.vector.size == 1) || + (haystack->string.vector.size < needle->string.vector.size)) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + + const char* s = (const char*)haystack->string.vector.data + index - 1; + const char* b = (const char*)needle->string.vector.data + needle->string.vector.size - 2; + for (; s >= (const char*)haystack->string.vector.data; --s) + { + if (*s != *b) + { + continue; + } + const char* a = s; + for (;;) + { + if (b < (const char*)needle->string.vector.data) + { + *found_index = (ZyanISize)(a - (const char*)haystack->string.vector.data + 1); + return ZYAN_STATUS_TRUE; + } + if (a < (const char*)haystack->string.vector.data + index - count) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + if (*a-- != *b--) + { + break; + } + } + b = (char*)needle->string.vector.data + needle->string.vector.size - 2; + } + + *found_index = -1; + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanStringRPosI(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index) +{ + if (!haystack) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringRPosIEx(haystack, needle, found_index, haystack->string.vector.size - 1, + haystack->string.vector.size - 1); +} + +ZyanStatus ZyanStringRPosIEx(const ZyanStringView* haystack, const ZyanStringView* needle, + ZyanISize* found_index, ZyanUSize index, ZyanUSize count) +{ + // This solution assumes that characters are represented using ASCII representation, i.e., + // codes for 'a', 'b', 'c', .. 'z' are 97, 98, 99, .. 122 respectively. And codes for 'A', + // 'B', 'C', .. 'Z' are 65, 66, .. 95 respectively. + + if (!haystack || !needle || !found_index) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if ((index >= haystack->string.vector.size) || (count > index)) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (!index || !count || + (haystack->string.vector.size == 1) || (needle->string.vector.size == 1) || + (haystack->string.vector.size < needle->string.vector.size)) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + + const char* s = (const char*)haystack->string.vector.data + index - 1; + const char* b = (const char*)needle->string.vector.data + needle->string.vector.size - 2; + for (; s >= (const char*)haystack->string.vector.data; --s) + { + if ((*s != *b) && ((*s ^ 32) != *b)) + { + continue; + } + const char* a = s; + for (;;) + { + if (b < (const char*)needle->string.vector.data) + { + *found_index = (ZyanISize)(a - (const char*)haystack->string.vector.data + 1); + return ZYAN_STATUS_TRUE; + } + if (a < (const char*)haystack->string.vector.data + index - count) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + const char c1 = *a--; + const char c2 = *b--; + if ((c1 != c2) && ((c1 ^ 32) != c2)) + { + break; + } + } + b = (char*)needle->string.vector.data + needle->string.vector.size - 2; + } + + *found_index = -1; + return ZYAN_STATUS_FALSE; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Comparing */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringCompare(const ZyanStringView* s1, const ZyanStringView* s2, ZyanI32* result) +{ + if (!s1 || !s2) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (s1->string.vector.size < s2->string.vector.size) + { + *result = -1; + return ZYAN_STATUS_FALSE; + } + if (s1->string.vector.size > s2->string.vector.size) + { + *result = 1; + return ZYAN_STATUS_FALSE; + } + + const char* const a = (char*)s1->string.vector.data; + const char* const b = (char*)s2->string.vector.data; + ZyanUSize i; + for (i = 0; (i + 1 < s1->string.vector.size) && (i + 1 < s2->string.vector.size); ++i) + { + if (a[i] == b[i]) + { + continue; + } + break; + } + + if (a[i] == b[i]) + { + *result = 0; + return ZYAN_STATUS_TRUE; + } + + if ((a[i] | 32) < (b[i] | 32)) + { + *result = -1; + return ZYAN_STATUS_FALSE; + } + + *result = 1; + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanStringCompareI(const ZyanStringView* s1, const ZyanStringView* s2, ZyanI32* result) +{ + // This solution assumes that characters are represented using ASCII representation, i.e., + // codes for 'a', 'b', 'c', .. 'z' are 97, 98, 99, .. 122 respectively. And codes for 'A', + // 'B', 'C', .. 'Z' are 65, 66, .. 95 respectively. + + if (!s1 || !s2) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (s1->string.vector.size < s2->string.vector.size) + { + *result = -1; + return ZYAN_STATUS_FALSE; + } + if (s1->string.vector.size > s2->string.vector.size) + { + *result = 1; + return ZYAN_STATUS_FALSE; + } + + const char* const a = (char*)s1->string.vector.data; + const char* const b = (char*)s2->string.vector.data; + ZyanUSize i; + for (i = 0; (i + 1 < s1->string.vector.size) && (i + 1 < s2->string.vector.size); ++i) + { + if ((a[i] == b[i]) || ((a[i] ^ 32) == b[i])) + { + continue; + } + break; + } + + if (a[i] == b[i]) + { + *result = 0; + return ZYAN_STATUS_TRUE; + } + + if ((a[i] | 32) < (b[i] | 32)) + { + *result = -1; + return ZYAN_STATUS_FALSE; + } + + *result = 1; + return ZYAN_STATUS_FALSE; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Case conversion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringToLowerCase(ZyanString* string) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringToLowerCaseEx(string, 0, string->vector.size - 1); +} + +ZyanStatus ZyanStringToLowerCaseEx(ZyanString* string, ZyanUSize index, ZyanUSize count) +{ + // This solution assumes that characters are represented using ASCII representation, i.e., + // codes for 'a', 'b', 'c', .. 'z' are 97, 98, 99, .. 122 respectively. And codes for 'A', + // 'B', 'C', .. 'Z' are 65, 66, .. 95 respectively. + + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if (index + count >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + char* s = (char*)string->vector.data + index; + for (ZyanUSize i = index; i < index + count; ++i) + { + const char c = *s; + if ((c >= 'A') && (c <= 'Z')) + { + *s = c | 32; + } + ++s; + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringToUpperCase(ZyanString* string) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanStringToUpperCaseEx(string, 0, string->vector.size - 1); +} + +ZyanStatus ZyanStringToUpperCaseEx(ZyanString* string, ZyanUSize index, ZyanUSize count) +{ + // This solution assumes that characters are represented using ASCII representation, i.e., + // codes for 'a', 'b', 'c', .. 'z' are 97, 98, 99, .. 122 respectively. And codes for 'A', + // 'B', 'C', .. 'Z' are 65, 66, .. 95 respectively. + + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + // Don't allow access to the terminating '\0' character + if (index + count >= string->vector.size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + char* s = (char*)string->vector.data + index; + for (ZyanUSize i = index; i < index + count; ++i) + { + const char c = *s; + if ((c >= 'a') && (c <= 'z')) + { + *s = c & ~32; + } + ++s; + } + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringResize(ZyanString* string, ZyanUSize size) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_CHECK(ZyanVectorResize(&string->vector, size + 1)); + ZYCORE_STRING_NULLTERMINATE(string); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringReserve(ZyanString* string, ZyanUSize capacity) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorReserve(&string->vector, capacity); +} + +ZyanStatus ZyanStringShrinkToFit(ZyanString* string) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorShrinkToFit(&string->vector); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanStringGetCapacity(const ZyanString* string, ZyanUSize* capacity) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(string->vector.capacity >= 1); + *capacity = string->vector.capacity - 1; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringGetSize(const ZyanString* string, ZyanUSize* size) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(string->vector.size >= 1); + *size = string->vector.size - 1; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanStringGetData(const ZyanString* string, const char** value) +{ + if (!string) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *value = string->vector.data; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/Vector.c b/externals/dynarmic/externals/zycore/src/Vector.c new file mode 100755 index 000000000..6b8d67c4a --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/Vector.c @@ -0,0 +1,848 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include +#include + +/* ============================================================================================== */ +/* Internal macros */ +/* ============================================================================================== */ + +/** + * Checks, if the passed vector should grow. + * + * @param size The desired size of the vector. + * @param capacity The current capacity of the vector. + * + * @return `ZYAN_TRUE`, if the vector should grow or `ZYAN_FALSE`, if not. + */ +#define ZYCORE_VECTOR_SHOULD_GROW(size, capacity) \ + ((size) > (capacity)) + +/** + * Checks, if the passed vector should shrink. + * + * @param size The desired size of the vector. + * @param capacity The current capacity of the vector. + * @param threshold The shrink threshold. + * + * @return `ZYAN_TRUE`, if the vector should shrink or `ZYAN_FALSE`, if not. + */ +#define ZYCORE_VECTOR_SHOULD_SHRINK(size, capacity, threshold) \ + ((size) < (capacity) * (threshold)) + +/** + * Returns the offset of the element at the given `index`. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The element index. + * + * @return The offset of the element at the given `index`. + */ +#define ZYCORE_VECTOR_OFFSET(vector, index) \ + ((void*)((ZyanU8*)(vector)->data + ((index) * (vector)->element_size))) + +/* ============================================================================================== */ +/* Internal functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Helper functions */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * Reallocates the internal buffer of the vector. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param capacity The new capacity. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanVectorReallocate(ZyanVector* vector, ZyanUSize capacity) +{ + ZYAN_ASSERT(vector); + ZYAN_ASSERT(vector->capacity >= ZYAN_VECTOR_MIN_CAPACITY); + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + if (!vector->allocator) + { + if (vector->capacity < capacity) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + return ZYAN_STATUS_SUCCESS; + } + + ZYAN_ASSERT(vector->allocator); + ZYAN_ASSERT(vector->allocator->reallocate); + + if (capacity < ZYAN_VECTOR_MIN_CAPACITY) + { + if (vector->capacity > ZYAN_VECTOR_MIN_CAPACITY) + { + capacity = ZYAN_VECTOR_MIN_CAPACITY; + } else + { + return ZYAN_STATUS_SUCCESS; + } + } + + vector->capacity = capacity; + ZYAN_CHECK(vector->allocator->reallocate(vector->allocator, &vector->data, + vector->element_size, vector->capacity)); + + return ZYAN_STATUS_SUCCESS; +} + +/** + * Shifts all elements starting at the specified `index` by the amount of + * `count` to the left. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The start index. + * @param count The amount of shift operations. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanVectorShiftLeft(ZyanVector* vector, ZyanUSize index, ZyanUSize count) +{ + ZYAN_ASSERT(vector); + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + ZYAN_ASSERT(count > 0); + //ZYAN_ASSERT((ZyanISize)count - (ZyanISize)index + 1 >= 0); + + void* const source = ZYCORE_VECTOR_OFFSET(vector, index + count); + void* const dest = ZYCORE_VECTOR_OFFSET(vector, index); + const ZyanUSize size = (vector->size - index - count) * vector->element_size; + ZYAN_MEMMOVE(dest, source, size); + + return ZYAN_STATUS_SUCCESS; +} + +/** + * Shifts all elements starting at the specified `index` by the amount of + * `count` to the right. + * + * @param vector A pointer to the `ZyanVector` instance. + * @param index The start index. + * @param count The amount of shift operations. + * + * @return A zyan status code. + */ +static ZyanStatus ZyanVectorShiftRight(ZyanVector* vector, ZyanUSize index, ZyanUSize count) +{ + ZYAN_ASSERT(vector); + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + ZYAN_ASSERT(count > 0); + ZYAN_ASSERT(vector->size + count <= vector->capacity); + + void* const source = ZYCORE_VECTOR_OFFSET(vector, index); + void* const dest = ZYCORE_VECTOR_OFFSET(vector, index + count); + const ZyanUSize size = (vector->size - index) * vector->element_size; + ZYAN_MEMMOVE(dest, source, size); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Constructor and destructor */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanVectorInit(ZyanVector* vector, ZyanUSize element_size, ZyanUSize capacity, + ZyanMemberProcedure destructor) +{ + return ZyanVectorInitEx(vector, element_size, capacity, destructor, ZyanAllocatorDefault(), + ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR, ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanVectorInitEx(ZyanVector* vector, ZyanUSize element_size, ZyanUSize capacity, + ZyanMemberProcedure destructor, ZyanAllocator* allocator, float growth_factor, + float shrink_threshold) +{ + if (!vector || !element_size || !allocator || (growth_factor < 1.0f) || + (shrink_threshold < 0.0f) || (shrink_threshold > 1.0f)) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(allocator->allocate); + + vector->allocator = allocator; + vector->growth_factor = growth_factor; + vector->shrink_threshold = shrink_threshold; + vector->size = 0; + vector->capacity = ZYAN_MAX(ZYAN_VECTOR_MIN_CAPACITY, capacity); + vector->element_size = element_size; + vector->destructor = destructor; + vector->data = ZYAN_NULL; + + return allocator->allocate(vector->allocator, &vector->data, vector->element_size, + vector->capacity); +} + +ZyanStatus ZyanVectorInitCustomBuffer(ZyanVector* vector, ZyanUSize element_size, + void* buffer, ZyanUSize capacity, ZyanMemberProcedure destructor) +{ + if (!vector || !element_size || !buffer || !capacity) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + vector->allocator = ZYAN_NULL; + vector->growth_factor = 1.0f; + vector->shrink_threshold = 0.0f; + vector->size = 0; + vector->capacity = capacity; + vector->element_size = element_size; + vector->destructor = destructor; + vector->data = buffer; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorDestroy(ZyanVector* vector) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + if (vector->destructor) + { + for (ZyanUSize i = 0; i < vector->size; ++i) + { + vector->destructor(ZYCORE_VECTOR_OFFSET(vector, i)); + } + } + + if (vector->allocator && vector->capacity) + { + ZYAN_ASSERT(vector->allocator->deallocate); + ZYAN_CHECK(vector->allocator->deallocate(vector->allocator, vector->data, + vector->element_size, vector->capacity)); + } + + vector->data = ZYAN_NULL; + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Duplication */ +/* ---------------------------------------------------------------------------------------------- */ + +#ifndef ZYAN_NO_LIBC + +ZyanStatus ZyanVectorDuplicate(ZyanVector* destination, const ZyanVector* source, + ZyanUSize capacity) +{ + return ZyanVectorDuplicateEx(destination, source, capacity, ZyanAllocatorDefault(), + ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR, ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD); +} + +#endif // ZYAN_NO_LIBC + +ZyanStatus ZyanVectorDuplicateEx(ZyanVector* destination, const ZyanVector* source, + ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, float shrink_threshold) +{ + if (!source) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = source->size; + + capacity = ZYAN_MAX(capacity, len); + ZYAN_CHECK(ZyanVectorInitEx(destination, source->element_size, capacity, source->destructor, + allocator, growth_factor, shrink_threshold)); + ZYAN_ASSERT(destination->capacity >= len); + + ZYAN_MEMCPY(destination->data, source->data, len * source->element_size); + destination->size = len; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorDuplicateCustomBuffer(ZyanVector* destination, const ZyanVector* source, + void* buffer, ZyanUSize capacity) +{ + if (!source) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + const ZyanUSize len = source->size; + + if (capacity < len) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + ZYAN_CHECK(ZyanVectorInitCustomBuffer(destination, source->element_size, buffer, capacity, + source->destructor)); + ZYAN_ASSERT(destination->capacity >= len); + + ZYAN_MEMCPY(destination->data, source->data, len * source->element_size); + destination->size = len; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Element access */ +/* ---------------------------------------------------------------------------------------------- */ + +const void* ZyanVectorGet(const ZyanVector* vector, ZyanUSize index) +{ + if (!vector || (index >= vector->size)) + { + return ZYAN_NULL; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + return ZYCORE_VECTOR_OFFSET(vector, index); +} + +void* ZyanVectorGetMutable(const ZyanVector* vector, ZyanUSize index) +{ + if (!vector || (index >= vector->size)) + { + return ZYAN_NULL; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + return ZYCORE_VECTOR_OFFSET(vector, index); +} + +ZyanStatus ZyanVectorGetPointer(const ZyanVector* vector, ZyanUSize index, const void** value) +{ + if (!vector || !value) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + *value = (const void*)ZYCORE_VECTOR_OFFSET(vector, index); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorGetPointerMutable(const ZyanVector* vector, ZyanUSize index, void** value) +{ + if (!vector || !value) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + *value = ZYCORE_VECTOR_OFFSET(vector, index); + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorSet(ZyanVector* vector, ZyanUSize index, const void* value) +{ + if (!vector || !value) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index >= vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + void* const offset = ZYCORE_VECTOR_OFFSET(vector, index); + if (vector->destructor) + { + vector->destructor(offset); + } + ZYAN_MEMCPY(offset, value, vector->element_size); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Insertion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorPushBack(ZyanVector* vector, const void* element) +{ + if (!vector || !element) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + if (ZYCORE_VECTOR_SHOULD_GROW(vector->size + 1, vector->capacity)) + { + ZYAN_CHECK(ZyanVectorReallocate(vector, + ZYAN_MAX(1, (ZyanUSize)((vector->size + 1) * vector->growth_factor)))); + } + + void* const offset = ZYCORE_VECTOR_OFFSET(vector, vector->size); + ZYAN_MEMCPY(offset, element, vector->element_size); + + ++vector->size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorInsert(ZyanVector* vector, ZyanUSize index, const void* element) +{ + return ZyanVectorInsertRange(vector, index, element, 1); +} + +ZyanStatus ZyanVectorInsertRange(ZyanVector* vector, ZyanUSize index, const void* elements, + ZyanUSize count) +{ + if (!vector || !elements || !count) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index > vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + if (ZYCORE_VECTOR_SHOULD_GROW(vector->size + count, vector->capacity)) + { + ZYAN_CHECK(ZyanVectorReallocate(vector, + ZYAN_MAX(1, (ZyanUSize)((vector->size + count) * vector->growth_factor)))); + } + + if (index < vector->size) + { + ZYAN_CHECK(ZyanVectorShiftRight(vector, index, count)); + } + + void* const offset = ZYCORE_VECTOR_OFFSET(vector, index); + ZYAN_MEMCPY(offset, elements, count * vector->element_size); + vector->size += count; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorEmplace(ZyanVector* vector, void** element, ZyanMemberFunction constructor) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorEmplaceEx(vector, vector->size, element, constructor); +} + +ZyanStatus ZyanVectorEmplaceEx(ZyanVector* vector, ZyanUSize index, void** element, + ZyanMemberFunction constructor) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index > vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + if (ZYCORE_VECTOR_SHOULD_GROW(vector->size + 1, vector->capacity)) + { + ZYAN_CHECK(ZyanVectorReallocate(vector, + ZYAN_MAX(1, (ZyanUSize)((vector->size + 1) * vector->growth_factor)))); + } + + if (index < vector->size) + { + ZYAN_CHECK(ZyanVectorShiftRight(vector, index, 1)); + } + + *element = ZYCORE_VECTOR_OFFSET(vector, index); + if (constructor) + { + ZYAN_CHECK(constructor(*element)); + } + + ++vector->size; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Utils */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorSwapElements(ZyanVector* vector, ZyanUSize index_first, ZyanUSize index_second) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if ((index_first >= vector->size) || (index_second >= vector->size)) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (vector->size == vector->capacity) + { + return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + ZyanU64* const t = ZYCORE_VECTOR_OFFSET(vector, vector->size); + ZyanU64* const a = ZYCORE_VECTOR_OFFSET(vector, index_first); + ZyanU64* const b = ZYCORE_VECTOR_OFFSET(vector, index_second); + ZYAN_MEMCPY(t, a, vector->element_size); + ZYAN_MEMCPY(a, b, vector->element_size); + ZYAN_MEMCPY(b, t, vector->element_size); + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Deletion */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorDelete(ZyanVector* vector, ZyanUSize index) +{ + return ZyanVectorDeleteRange(vector, index, 1); +} + +ZyanStatus ZyanVectorDeleteRange(ZyanVector* vector, ZyanUSize index, ZyanUSize count) +{ + if (!vector || !count) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (index + count > vector->size) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (vector->destructor) + { + for (ZyanUSize i = index; i < index + count; ++i) + { + vector->destructor(ZYCORE_VECTOR_OFFSET(vector, i)); + } + } + + if (index + count < vector->size) + { + ZYAN_CHECK(ZyanVectorShiftLeft(vector, index, count)); + } + + vector->size -= count; + if (ZYCORE_VECTOR_SHOULD_SHRINK(vector->size, vector->capacity, vector->shrink_threshold)) + { + return ZyanVectorReallocate(vector, + ZYAN_MAX(1, (ZyanUSize)(vector->size * vector->growth_factor))); + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorPopBack(ZyanVector* vector) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (vector->size == 0) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (vector->destructor) + { + vector->destructor(ZYCORE_VECTOR_OFFSET(vector, vector->size - 1)); + } + + --vector->size; + if (ZYCORE_VECTOR_SHOULD_SHRINK(vector->size, vector->capacity, vector->shrink_threshold)) + { + return ZyanVectorReallocate(vector, + ZYAN_MAX(1, (ZyanUSize)(vector->size * vector->growth_factor))); + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorClear(ZyanVector* vector) +{ + return ZyanVectorResizeEx(vector, 0, ZYAN_NULL); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Searching */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorFind(const ZyanVector* vector, const void* element, ZyanISize* found_index, + ZyanEqualityComparison comparison) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorFindEx(vector, element, found_index, comparison, 0, vector->size); +} + +ZyanStatus ZyanVectorFindEx(const ZyanVector* vector, const void* element, ZyanISize* found_index, + ZyanEqualityComparison comparison, ZyanUSize index, ZyanUSize count) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if ((index + count > vector->size) || (index == vector->size)) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (!count) + { + *found_index = -1; + return ZYAN_STATUS_FALSE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + for (ZyanUSize i = index; i < index + count; ++i) + { + if (comparison(ZYCORE_VECTOR_OFFSET(vector, i), element)) + { + *found_index = i; + return ZYAN_STATUS_TRUE; + } + } + + *found_index = -1; + return ZYAN_STATUS_FALSE; +} + +ZyanStatus ZyanVectorBinarySearch(const ZyanVector* vector, const void* element, + ZyanUSize* found_index, ZyanComparison comparison) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorBinarySearchEx(vector, element, found_index, comparison, 0, vector->size); +} + +ZyanStatus ZyanVectorBinarySearchEx(const ZyanVector* vector, const void* element, + ZyanUSize* found_index, ZyanComparison comparison, ZyanUSize index, ZyanUSize count) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (((index >= vector->size) && (count > 0)) || (index + count > vector->size)) + { + return ZYAN_STATUS_OUT_OF_RANGE; + } + + if (!count) + { + *found_index = index; + return ZYAN_STATUS_FALSE; + } + + ZYAN_ASSERT(vector->element_size); + ZYAN_ASSERT(vector->data); + + ZyanStatus status = ZYAN_STATUS_FALSE; + ZyanISize l = index; + ZyanISize h = index + count - 1; + while (l <= h) + { + const ZyanUSize mid = l + ((h - l) >> 1); + const ZyanI32 cmp = comparison(ZYCORE_VECTOR_OFFSET(vector, mid), element); + if (cmp < 0) + { + l = mid + 1; + } else + { + h = mid - 1; + if (cmp == 0) + { + status = ZYAN_STATUS_TRUE; + } + } + } + + *found_index = l; + return status; +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Memory management */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorResize(ZyanVector* vector, ZyanUSize size) +{ + return ZyanVectorResizeEx(vector, size, ZYAN_NULL); +} + +ZyanStatus ZyanVectorResizeEx(ZyanVector* vector, ZyanUSize size, const void* initializer) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + if (size == vector->size) + { + return ZYAN_STATUS_SUCCESS; + } + + if (vector->destructor && (size < vector->size)) + { + for (ZyanUSize i = size; i < vector->size; ++i) + { + vector->destructor(ZYCORE_VECTOR_OFFSET(vector, i)); + } + } + + if (ZYCORE_VECTOR_SHOULD_GROW(size, vector->capacity) || + ZYCORE_VECTOR_SHOULD_SHRINK(size, vector->capacity, vector->shrink_threshold)) + { + ZYAN_CHECK(ZyanVectorReallocate(vector, (ZyanUSize)(size * vector->growth_factor))); + }; + + if (initializer && (size > vector->size)) + { + for (ZyanUSize i = vector->size; i < size; ++i) + { + ZYAN_MEMCPY(ZYCORE_VECTOR_OFFSET(vector, i), initializer, vector->element_size); + } + } + + vector->size = size; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorReserve(ZyanVector* vector, ZyanUSize capacity) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + if (capacity > vector->capacity) + { + ZYAN_CHECK(ZyanVectorReallocate(vector, capacity)); + } + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorShrinkToFit(ZyanVector* vector) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + return ZyanVectorReallocate(vector, vector->size); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Information */ +/* ---------------------------------------------------------------------------------------------- */ + +ZyanStatus ZyanVectorGetCapacity(const ZyanVector* vector, ZyanUSize* capacity) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *capacity = vector->capacity; + + return ZYAN_STATUS_SUCCESS; +} + +ZyanStatus ZyanVectorGetSize(const ZyanVector* vector, ZyanUSize* size) +{ + if (!vector) + { + return ZYAN_STATUS_INVALID_ARGUMENT; + } + + *size = vector->size; + + return ZYAN_STATUS_SUCCESS; +} + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/src/Zycore.c b/externals/dynarmic/externals/zycore/src/Zycore.c new file mode 100755 index 000000000..9bbb20024 --- /dev/null +++ b/externals/dynarmic/externals/zycore/src/Zycore.c @@ -0,0 +1,38 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +#include + +/* ============================================================================================== */ +/* Exported functions */ +/* ============================================================================================== */ + +ZyanU64 ZycoreGetVersion(void) +{ + return ZYCORE_VERSION; +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/tests/ArgParse.cpp b/externals/dynarmic/externals/zycore/tests/ArgParse.cpp new file mode 100755 index 000000000..612a5dd9e --- /dev/null +++ b/externals/dynarmic/externals/zycore/tests/ArgParse.cpp @@ -0,0 +1,320 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Joel Hoener + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief Tests the the arg parse implementation. + */ + +#include + +#include +#include +#include + +/* ============================================================================================== */ +/* Helpers */ +/* ============================================================================================== */ + +auto cvt_string_view(const ZyanStringView *sv) +{ + const char* buf; + if (ZYAN_FAILED(ZyanStringViewGetData(sv, &buf))) throw std::exception{}; + ZyanUSize len; + if (ZYAN_FAILED(ZyanStringViewGetSize(sv, &len))) throw std::exception{}; + + return std::string_view{buf, len}; +} + +/* ============================================================================================== */ +/* Tests */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* Unnamed args */ +/* ---------------------------------------------------------------------------------------------- */ + +static auto UnnamedArgTest(ZyanU64 min, ZyanU64 max) +{ + const char* argv[] + { + "./test", "a", "xxx" + }; + + ZyanArgParseConfig cfg + { + argv, // argv + 3, // argc + min, // min_unnamed_args + max, // max_unnamed_args + nullptr // args + }; + + ZyanVector parsed; + const char* err_tok = nullptr; + ZYAN_MEMSET(&parsed, 0, sizeof(parsed)); + auto status = ZyanArgParse(&cfg, &parsed, &err_tok); + return std::make_tuple(status, parsed, err_tok); +} + +TEST(UnnamedArgs, TooFew) +{ + auto [status, parsed, err_tok] = UnnamedArgTest(5, 5); + ASSERT_EQ(status, ZYAN_STATUS_TOO_FEW_ARGS); + ASSERT_STREQ(err_tok, nullptr); +} + +TEST(UnnamedArgs, TooMany) +{ + auto [status, parsed, err_tok] = UnnamedArgTest(1, 1); + ASSERT_EQ(status, ZYAN_STATUS_TOO_MANY_ARGS); + ASSERT_STREQ(err_tok, "xxx"); +} + +TEST(UnnamedArgs, PerfectFit) +{ + auto [status, parsed, err_tok] = UnnamedArgTest(2, 2); + ASSERT_TRUE(ZYAN_SUCCESS(status)); + + ZyanUSize size; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetSize(&parsed, &size))); + ASSERT_EQ(size, 2); + + auto arg = (const ZyanArgParseArg*)ZyanVectorGet(&parsed, 0); + ASSERT_NE(arg, nullptr); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "a"); + + arg = (const ZyanArgParseArg*)ZyanVectorGet(&parsed, 1); + ASSERT_NE(arg, nullptr); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "xxx"); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Dash args */ +/* ---------------------------------------------------------------------------------------------- */ + +TEST(DashArg, MixedBoolAndValueArgs) +{ + const char* argv[] + { + "./test", "-aio42", "-n", "xxx" + }; + + ZyanArgParseDefinition args[] + { + {"-o", ZYAN_FALSE, ZYAN_FALSE}, + {"-a", ZYAN_TRUE, ZYAN_FALSE}, + {"-n", ZYAN_FALSE, ZYAN_FALSE}, + {"-i", ZYAN_TRUE, ZYAN_FALSE}, + {nullptr, ZYAN_FALSE, ZYAN_FALSE} + }; + + ZyanArgParseConfig cfg + { + argv, // argv + 4, // argc + 0, // min_unnamed_args + 0, // max_unnamed_args + args // args + }; + + ZyanVector parsed; + ZYAN_MEMSET(&parsed, 0, sizeof(parsed)); + auto status = ZyanArgParse(&cfg, &parsed, nullptr); + ASSERT_TRUE(ZYAN_SUCCESS(status)); + + ZyanUSize size; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetSize(&parsed, &size))); + ASSERT_EQ(size, 4); + + const ZyanArgParseArg* arg; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 0, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "-a"); + ASSERT_FALSE(arg->has_value); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 1, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "-i"); + ASSERT_FALSE(arg->has_value); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 2, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "-o"); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "42"); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 3, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "-n"); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "xxx"); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Double dash args */ +/* ---------------------------------------------------------------------------------------------- */ + +TEST(DoubleDashArg, PerfectFit) +{ + const char* argv[] + { + "./test", "--help", "--stuff", "1337" + }; + + ZyanArgParseDefinition args[] + { + {"--help", ZYAN_TRUE, ZYAN_FALSE}, + {"--stuff", ZYAN_FALSE, ZYAN_FALSE}, + {nullptr, ZYAN_FALSE, ZYAN_FALSE} + }; + + ZyanArgParseConfig cfg + { + argv, // argv + 4, // argc + 0, // min_unnamed_args + 0, // max_unnamed_args + args // args + }; + + ZyanVector parsed; + ZYAN_MEMSET(&parsed, 0, sizeof(parsed)); + auto status = ZyanArgParse(&cfg, &parsed, nullptr); + ASSERT_TRUE(ZYAN_SUCCESS(status)); + + ZyanUSize size; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetSize(&parsed, &size))); + ASSERT_EQ(size, 2); + + const ZyanArgParseArg* arg; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 0, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "--help"); + ASSERT_FALSE(arg->has_value); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 1, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "--stuff"); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "1337"); +} + +/* ---------------------------------------------------------------------------------------------- */ +/* Mixed */ +/* ---------------------------------------------------------------------------------------------- */ + +TEST(MixedArgs, MissingRequiredArg) +{ + const char* argv[] + { + "./test", "blah.c", "woof.moo" + }; + + ZyanArgParseDefinition args[] + { + {"--feature-xyz", ZYAN_TRUE, ZYAN_FALSE}, + {"-n", ZYAN_FALSE, ZYAN_TRUE}, + {nullptr, ZYAN_FALSE, ZYAN_FALSE} + }; + + ZyanArgParseConfig cfg + { + argv, // argv + 3, // argc + 0, // min_unnamed_args + 100, // max_unnamed_args + args // args + }; + + ZyanVector parsed; + ZYAN_MEMSET(&parsed, 0, sizeof(parsed)); + const char* err_tok = nullptr; + auto status = ZyanArgParse(&cfg, &parsed, &err_tok); + ASSERT_EQ(status, ZYAN_STATUS_REQUIRED_ARG_MISSING); + ASSERT_STREQ(err_tok, "-n"); +} + +TEST(MixedArgs, Stuff) +{ + const char* argv[] + { + "./test", "--feature-xyz", "-n5", "blah.c", "woof.moo" + }; + + ZyanArgParseDefinition args[] + { + {"--feature-xyz", ZYAN_TRUE, ZYAN_FALSE}, + {"-n", ZYAN_FALSE, ZYAN_FALSE}, + {nullptr, ZYAN_FALSE, ZYAN_FALSE} + }; + + ZyanArgParseConfig cfg + { + argv, // argv + 5, // argc + 0, // min_unnamed_args + 100, // max_unnamed_args + args // args + }; + + ZyanVector parsed; + ZYAN_MEMSET(&parsed, 0, sizeof(parsed)); + auto status = ZyanArgParse(&cfg, &parsed, nullptr); + ASSERT_TRUE(ZYAN_SUCCESS(status)); + + ZyanUSize size; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetSize(&parsed, &size))); + ASSERT_EQ(size, 4); + + const ZyanArgParseArg* arg; + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 0, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "--feature-xyz"); + ASSERT_FALSE(arg->has_value); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 1, (const void**)&arg))); + ASSERT_STREQ(arg->def->name, "-n"); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "5"); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 2, (const void**)&arg))); + ASSERT_EQ(arg->def, nullptr); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "blah.c"); + + ASSERT_TRUE(ZYAN_SUCCESS(ZyanVectorGetPointer(&parsed, 3, (const void**)&arg))); + ASSERT_EQ(arg->def, nullptr); + ASSERT_TRUE(arg->has_value); + ASSERT_EQ(cvt_string_view(&arg->value), "woof.moo"); +} + +/* ============================================================================================== */ +/* Entry point */ +/* ============================================================================================== */ + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/tests/String.cpp b/externals/dynarmic/externals/zycore/tests/String.cpp new file mode 100755 index 000000000..3c00fb99a --- /dev/null +++ b/externals/dynarmic/externals/zycore/tests/String.cpp @@ -0,0 +1,69 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief Tests the `ZyanString` implementation. + */ + +#include +#include + +/* ============================================================================================== */ +/* Enums and types */ +/* ============================================================================================== */ + + + +/* ============================================================================================== */ +/* Helper functions */ +/* ============================================================================================== */ + + + +/* ============================================================================================== */ +/* Tests */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* */ +/* ---------------------------------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Entry point */ +/* ============================================================================================== */ + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zycore/tests/Vector.cpp b/externals/dynarmic/externals/zycore/tests/Vector.cpp new file mode 100755 index 000000000..ade6b09f6 --- /dev/null +++ b/externals/dynarmic/externals/zycore/tests/Vector.cpp @@ -0,0 +1,505 @@ +/*************************************************************************************************** + + Zyan Core Library (Zycore-C) + + Original Author : Florian Bernd + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + +***************************************************************************************************/ + +/** + * @file + * @brief Tests the `ZyanVector` implementation. + */ + +#include +#include +#include +#include + +/* ============================================================================================== */ +/* Fixtures */ +/* ============================================================================================== */ + +/* ---------------------------------------------------------------------------------------------- */ +/* VectorTestBase */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * @brief Implements a fixture-class that provides an initialized `ZyanVector` instance for + * `ZyanU64` values. + */ +class VectorTestBase : public ::testing::TestWithParam +{ +protected: + static const ZyanUSize m_test_size = 100; + ZyanBool m_has_fixed_capacity; + ZyanVector m_vector; + std::vector m_buffer; +protected: + void SetUp() override + { + m_has_fixed_capacity = GetParam(); + + if (!m_has_fixed_capacity) + { + ASSERT_EQ(ZyanVectorInit(&m_vector, sizeof(ZyanU64), m_test_size, + reinterpret_cast(ZYAN_NULL)), ZYAN_STATUS_SUCCESS); + } else + { + m_buffer.reserve(m_test_size); + ASSERT_EQ(ZyanVectorInitCustomBuffer(&m_vector, sizeof(ZyanU64), m_buffer.data(), + m_test_size, reinterpret_cast(ZYAN_NULL)), + ZYAN_STATUS_SUCCESS); + } + } + + void TearDown() override + { + EXPECT_EQ(ZyanVectorDestroy(&m_vector), ZYAN_STATUS_SUCCESS); + } +}; + +/* ---------------------------------------------------------------------------------------------- */ +/* VectorTestFilled */ +/* ---------------------------------------------------------------------------------------------- */ + +/** + * @brief Implements a fixture-class that provides an initialized `ZyanVector` instance which + * is filled with `ZyanU64` values from 0..100. + */ +class VectorTestFilled : public VectorTestBase +{ +protected: + void SetUp() override + { + VectorTestBase::SetUp(); + + if (m_has_fixed_capacity) + { + m_buffer.resize(m_test_size); + } + for (ZyanU64 i = 0; i < m_test_size; ++i) + { + ASSERT_EQ(ZyanVectorPushBack(&m_vector, &i), ZYAN_STATUS_SUCCESS); + } + } +}; + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Helper functions */ +/* ============================================================================================== */ + +/** + * @brief A dummy constructor for `ZyanU64` objects. + * + * @param object A pointer to the object. + * + * @return A zyan status code. + */ +static ZyanStatus InitZyanU64(ZyanU64* object) +{ + *object = 1337; + return ZYAN_STATUS_SUCCESS; +} + +/** + * @brief A dummy destructor for `ZyanU16` objects. + * + * @param object A pointer to the object. + * + * @return A zyan status code. + */ +static ZyanStatus FreeZyanU16(ZyanU16* object) +{ + *object = 0; + return ZYAN_STATUS_SUCCESS; +} + +/* ============================================================================================== */ +/* Tests */ +/* ============================================================================================== */ + +TEST(VectorTest, InitBasic) +{ + ZyanVector vector; + + ASSERT_EQ(ZyanVectorInit(&vector, sizeof(ZyanU64), 0, + reinterpret_cast(ZYAN_NULL)), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(vector.allocator, ZyanAllocatorDefault()); + EXPECT_FLOAT_EQ(vector.growth_factor, ZYAN_VECTOR_DEFAULT_GROWTH_FACTOR); + EXPECT_FLOAT_EQ(vector.shrink_threshold, ZYAN_VECTOR_DEFAULT_SHRINK_THRESHOLD); + EXPECT_EQ(vector.size, static_cast(0)); + EXPECT_EQ(vector.capacity, static_cast(ZYAN_VECTOR_MIN_CAPACITY)); + EXPECT_EQ(vector.element_size, sizeof(ZyanU64)); + EXPECT_NE(vector.data, ZYAN_NULL); + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); + + // Custom capacity + EXPECT_EQ(ZyanVectorInit(&vector, sizeof(ZyanU16), 10, + reinterpret_cast(ZYAN_NULL)), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(vector.capacity, static_cast(ZYAN_MAX(ZYAN_VECTOR_MIN_CAPACITY, 10))); + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); +} + +TEST(VectorTest, InitAdvanced) +{ + ZyanVector vector; + + ASSERT_EQ(ZyanVectorInitEx(&vector, sizeof(ZyanU16), 0, + reinterpret_cast(ZYAN_NULL), ZyanAllocatorDefault(), 1.0f, 0.0f), + ZYAN_STATUS_SUCCESS); + EXPECT_EQ(vector.allocator, ZyanAllocatorDefault()); + EXPECT_FLOAT_EQ(vector.growth_factor, 1.0f); + EXPECT_FLOAT_EQ(vector.shrink_threshold, 0.0f); + EXPECT_EQ(vector.size, static_cast(0)); + EXPECT_EQ(vector.capacity, static_cast(ZYAN_VECTOR_MIN_CAPACITY)); + EXPECT_EQ(vector.element_size, sizeof(ZyanU16)); + EXPECT_NE(vector.data, ZYAN_NULL); + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); + + // Custom capacity + EXPECT_EQ(ZyanVectorInitEx(&vector, sizeof(ZyanU16), 10, + reinterpret_cast(ZYAN_NULL), ZyanAllocatorDefault(), 1.0f, 0.0f), + ZYAN_STATUS_SUCCESS); + EXPECT_EQ(vector.capacity, static_cast(ZYAN_MAX(ZYAN_VECTOR_MIN_CAPACITY, 10))); + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); +} + +TEST(VectorTest, InitCustomBuffer) +{ + ZyanVector vector; + + ZyanU16 buffer[32]; + EXPECT_EQ(ZyanVectorInitCustomBuffer(&vector, sizeof(ZyanU16), &buffer, 0, + reinterpret_cast(ZYAN_NULL)), ZYAN_STATUS_INVALID_ARGUMENT); + ASSERT_EQ(ZyanVectorInitCustomBuffer(&vector, sizeof(ZyanU16), &buffer, + ZYAN_ARRAY_LENGTH(buffer), reinterpret_cast(ZYAN_NULL)), + ZYAN_STATUS_SUCCESS); + EXPECT_EQ(vector.allocator, ZYAN_NULL); + EXPECT_FLOAT_EQ(vector.growth_factor, 1.0f); + EXPECT_FLOAT_EQ(vector.shrink_threshold, 0.0f); + EXPECT_EQ(vector.size, static_cast(0)); + EXPECT_EQ(vector.capacity, ZYAN_ARRAY_LENGTH(buffer)); + EXPECT_EQ(vector.element_size, sizeof(ZyanU16)); + EXPECT_EQ(vector.data, &buffer); + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); +} + +TEST(VectorTest, Destructor) +{ + ZyanVector vector; + + ZyanU16 buffer[16]; + ASSERT_EQ(ZyanVectorInitCustomBuffer(&vector, sizeof(ZyanU16), &buffer, + ZYAN_ARRAY_LENGTH(buffer), reinterpret_cast(&FreeZyanU16)), + ZYAN_STATUS_SUCCESS); + + for (ZyanUSize i = 0; i < ZYAN_ARRAY_LENGTH(buffer); ++i) + { + const auto element = static_cast(i) + 0; + ASSERT_EQ(ZyanVectorPushBack(&vector, &element), ZYAN_STATUS_SUCCESS); + ASSERT_EQ(buffer[i], element); + } + + ASSERT_EQ(ZyanVectorPopBack(&vector), ZYAN_STATUS_SUCCESS); + ASSERT_EQ(buffer[15], 0); + + ASSERT_EQ(ZyanVectorDeleteRange(&vector, 12, 3), ZYAN_STATUS_SUCCESS); + ASSERT_EQ(buffer[12], 0); + ASSERT_EQ(buffer[13], 0); + ASSERT_EQ(buffer[14], 0); + + ASSERT_EQ(ZyanVectorClear(&vector), ZYAN_STATUS_SUCCESS); + for (ZyanUSize i : buffer) + { + ASSERT_EQ(i, 0); + } + + for (ZyanUSize i = 0; i < ZYAN_ARRAY_LENGTH(buffer); ++i) + { + const auto element = static_cast(i) + 1; + ASSERT_EQ(ZyanVectorPushBack(&vector, &element), ZYAN_STATUS_SUCCESS); + ASSERT_EQ(buffer[i], element); + } + + EXPECT_EQ(ZyanVectorDestroy(&vector), ZYAN_STATUS_SUCCESS); + for (ZyanUSize i : buffer) + { + ASSERT_EQ(i, 0); + } +} + +TEST_P(VectorTestFilled, ElementAccess) +{ + static const ZyanU64 element_in = 1337; + const ZyanU64* element_dummy; + ZyanU64* element_out_mut; + + EXPECT_EQ(ZyanVectorSet(&m_vector, m_vector.size, &element_in), + ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorSet(&m_vector, m_vector.size - 1, &element_in), + ZYAN_STATUS_SUCCESS); + + EXPECT_EQ(ZyanVectorGetPointer(&m_vector, m_vector.size, + reinterpret_cast(&element_dummy)), ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, m_vector.size - 1), element_in); + + EXPECT_EQ(ZyanVectorGetPointerMutable(&m_vector, m_vector.size, + reinterpret_cast(&element_out_mut)), ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorGetPointerMutable(&m_vector, m_vector.size - 1, + reinterpret_cast(&element_out_mut)), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(*element_out_mut, element_in); + *element_out_mut = 42; + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, m_vector.size - 1), 42); + + if (m_has_fixed_capacity) + { + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, m_vector.size - 1), + m_buffer[m_vector.size - 1]); + } +} + +TEST_P(VectorTestFilled, PushPop) +{ + static const ZyanU64 element_in = 1337; + const ZyanUSize size = m_vector.size; + + if (!m_has_fixed_capacity) + { + EXPECT_EQ(ZyanVectorPushBack(&m_vector, &element_in), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size + 1); + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, size), element_in); + EXPECT_EQ(ZyanVectorPopBack(&m_vector), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size); + } else + { + EXPECT_EQ(ZyanVectorPushBack(&m_vector, &element_in), ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE); + EXPECT_EQ(m_vector.size, size); + EXPECT_EQ(ZyanVectorPopBack(&m_vector), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size - 1); + EXPECT_EQ(ZyanVectorPushBack(&m_vector, &element_in), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size); + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, size - 1), element_in); + } +} + +TEST_P(VectorTestFilled, Insert) +{ + static const ZyanU64 elements[4] = + { + 1337, 1338, 1339, 1340 + }; + const ZyanUSize count = ZYAN_ARRAY_LENGTH(elements); + + if (m_has_fixed_capacity) + { + const ZyanUSize size_temp = m_vector.size; + EXPECT_EQ(ZyanVectorInsertRange(&m_vector, size_temp / 2, &elements, count), + ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE); + EXPECT_EQ(ZyanVectorResize(&m_vector, size_temp - count), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size_temp - count); + } + + const ZyanUSize size = m_vector.size; + const ZyanUSize half = (size / 2); + + EXPECT_EQ(ZyanVectorInsertRange(&m_vector, half, &elements, ZYAN_ARRAY_LENGTH(elements)), + ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size + count); + for (ZyanUSize i = 0; i < m_vector.size; ++i) + { + const ZyanU64 element_out = ZYAN_VECTOR_GET(ZyanU64, &m_vector, i); + + if ((i >= half) && (i < half + count)) + { + EXPECT_EQ(element_out, elements[i - half]); + } else + if (i < half) + { + EXPECT_EQ(element_out, i); + } else + { + EXPECT_EQ(element_out, i - count); + } + } +} + +TEST_P(VectorTestFilled, Delete) +{ + EXPECT_EQ(ZyanVectorDeleteRange(&m_vector, m_vector.size, 1), ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorDeleteRange(&m_vector, 1, m_vector.size), ZYAN_STATUS_OUT_OF_RANGE); + + const ZyanUSize size = m_vector.size; + const ZyanUSize half = (size / 2); + const ZyanUSize count = (half / 2); + + EXPECT_EQ(ZyanVectorDeleteRange(&m_vector, half, count), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(m_vector.size, size - count); + for (ZyanUSize i = 0; i < m_vector.size; ++i) + { + const ZyanU64 element_out = ZYAN_VECTOR_GET(ZyanU64, &m_vector, i); + + if ((i >= half) && (i < half + count)) + { + EXPECT_EQ(element_out, i + count); + } else + if (i < half) + { + EXPECT_EQ(element_out, i); + } else + { + EXPECT_EQ(element_out, i - count); + } + } +} + +TEST_P(VectorTestFilled, Find) +{ + ZyanISize index; + ZyanU64 element_in = m_vector.size / 2; + EXPECT_EQ(ZyanVectorFind(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanEqualsNumeric64)), ZYAN_STATUS_TRUE); + EXPECT_EQ(static_cast(index), element_in); + + element_in = 1337; + EXPECT_EQ(ZyanVectorFind(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanEqualsNumeric64)), ZYAN_STATUS_FALSE); + EXPECT_EQ(index, -1); + + // Edge cases + EXPECT_EQ(ZyanVectorFindEx(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanEqualsNumeric64), 0, 0), + ZYAN_STATUS_FALSE); + EXPECT_EQ(ZyanVectorFindEx(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanEqualsNumeric64), 0, m_vector.size + 1), + ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorFindEx(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanEqualsNumeric64), 1, m_vector.size), + ZYAN_STATUS_OUT_OF_RANGE); +} + +TEST_P(VectorTestBase, BinarySearch) +{ + EXPECT_EQ(ZyanVectorReserve(&m_vector, 100), ZYAN_STATUS_SUCCESS); + for (ZyanUSize i = 0; i < 100; ++i) + { + const ZyanU64 element = rand() % 100; + + ZyanUSize index; + const ZyanStatus status = ZyanVectorBinarySearch(&m_vector, &element, &index, + reinterpret_cast(&ZyanCompareNumeric64)); + EXPECT_EQ(ZYAN_SUCCESS(status), ZYAN_TRUE); + EXPECT_EQ(ZyanVectorInsert(&m_vector, index, &element), ZYAN_STATUS_SUCCESS); + } + EXPECT_EQ(m_vector.size, static_cast(100)); + + ZyanU64 element_out = ZYAN_VECTOR_GET(ZyanU64, &m_vector, 0); + for (ZyanUSize i = 1; i < m_vector.size; ++i) + { + const ZyanU64 value = element_out; + element_out = ZYAN_VECTOR_GET(ZyanU64, &m_vector, i); + EXPECT_GE(element_out, value); + } + + // Edge cases + const ZyanU64 element_in = 1337; + ZyanUSize index; + EXPECT_EQ(ZyanVectorBinarySearchEx(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanCompareNumeric64), 0, 101), + ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorBinarySearchEx(&m_vector, &element_in, &index, + reinterpret_cast(&ZyanCompareNumeric64), 1, 100), + ZYAN_STATUS_OUT_OF_RANGE); +} + +TEST_P(VectorTestBase, Emplace) +{ + ZyanU64* element_new; + + for (ZyanUSize i = 0; i < 10; ++i) + { + EXPECT_EQ(ZyanVectorEmplace(&m_vector, reinterpret_cast(&element_new), + reinterpret_cast(ZYAN_NULL)), ZYAN_STATUS_SUCCESS); + *element_new = i; + } + EXPECT_EQ(m_vector.size, static_cast(10)); + + for (ZyanUSize i = 0; i < m_vector.size; ++i) + { + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, i), i); + } + + EXPECT_EQ(ZyanVectorEmplaceEx(&m_vector, 5, reinterpret_cast(&element_new), + reinterpret_cast(&InitZyanU64)), ZYAN_STATUS_SUCCESS); + EXPECT_EQ(*element_new, 1337); + EXPECT_EQ(ZYAN_VECTOR_GET(ZyanU64, &m_vector, 5), 1337); +} + +TEST_P(VectorTestFilled, SwapElements) +{ + EXPECT_EQ(m_vector.capacity, m_vector.size); + + // Edge cases + EXPECT_EQ(ZyanVectorSwapElements(&m_vector, 0, m_vector.size), ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorSwapElements(&m_vector, m_vector.size, 0), ZYAN_STATUS_OUT_OF_RANGE); + EXPECT_EQ(ZyanVectorSwapElements(&m_vector, 0, m_vector.size - 1), + ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE); + + // Free space for the temporary element + EXPECT_EQ(ZyanVectorPopBack(&m_vector), ZYAN_STATUS_SUCCESS); + + // Retrieve element pointers + const ZyanU64* element_first; + EXPECT_EQ(ZyanVectorGetPointer(&m_vector, 0, reinterpret_cast(&element_first)), + ZYAN_STATUS_SUCCESS); + const ZyanU64* element_second; + EXPECT_EQ(ZyanVectorGetPointer(&m_vector, m_vector.size - 1, + reinterpret_cast(&element_second)), ZYAN_STATUS_SUCCESS); + + const ZyanU64 values_before[2] = { *element_first, *element_second }; + EXPECT_EQ(ZyanVectorSwapElements(&m_vector, 0, m_vector.size - 1), ZYAN_STATUS_SUCCESS); + const ZyanU64 values_after [2] = { *element_first, *element_second }; + + EXPECT_EQ(values_before[0], values_after[1]); + EXPECT_EQ(values_before[1], values_after[0]); +} + +INSTANTIATE_TEST_SUITE_P(Param, VectorTestBase, ::testing::Values(false, true)); +INSTANTIATE_TEST_SUITE_P(Param, VectorTestFilled, ::testing::Values(false, true)); + +/* ---------------------------------------------------------------------------------------------- */ + +/* ============================================================================================== */ +/* Entry point */ +/* ============================================================================================== */ + +int main(int argc, char **argv) +{ + time_t t; + srand(static_cast(time(&t))); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +/* ============================================================================================== */ diff --git a/externals/dynarmic/externals/zydis/.gitattributes b/externals/dynarmic/externals/zydis/.gitattributes new file mode 100755 index 000000000..ef3a96fa0 --- /dev/null +++ b/externals/dynarmic/externals/zydis/.gitattributes @@ -0,0 +1 @@ +*.inc linguist-language=C diff --git a/externals/dynarmic/externals/zydis/.github/FUNDING.yml b/externals/dynarmic/externals/zydis/.github/FUNDING.yml new file mode 100755 index 000000000..c18b510ff --- /dev/null +++ b/externals/dynarmic/externals/zydis/.github/FUNDING.yml @@ -0,0 +1 @@ +github: flobernd \ No newline at end of file diff --git a/externals/dynarmic/externals/zydis/.github/workflows/main.yml b/externals/dynarmic/externals/zydis/.github/workflows/main.yml new file mode 100755 index 000000000..080e1214e --- /dev/null +++ b/externals/dynarmic/externals/zydis/.github/workflows/main.yml @@ -0,0 +1,69 @@ +name: GitHub Actions CI + +on: [push, pull_request] + +jobs: + build: + name: "Build Zydis (${{ matrix.image_name }}, ${{ matrix.no_libc }})" + runs-on: "${{ matrix.image_name }}" + + strategy: + matrix: + image_name: ["macOS-latest", "windows-2016", "ubuntu-18.04"] + no_libc: ["", "-DZYAN_NO_LIBC=ON"] + include: + - image_name: "ubuntu-16.04" + no_libc: "-DCMAKE_BUILD_TYPE=Release" + dev_mode: "-DZYAN_DEV_MODE=ON" + + steps: + - uses: "actions/checkout@v1" + - name: "Cloning submodules" + run: | + git submodule update --init + - name: "Configuring" + run: | + mkdir build + cd build + cmake ${{ matrix.dev_mode }} ${{ matrix.no_libc }} .. + - name: "Building" + run: | + cmake --build build --config Release + - name: "Running regression tests" + run: | + cd tests + python3 regression.py test ../build/ZydisInfo + if: "!matrix.no_libc && matrix.image_name != 'windows-2016'" + - name: "Running regression tests" + run: | + cd tests + python regression.py test ..\\build\\Release\\ZydisInfo.exe + if: "!matrix.no_libc && matrix.image_name == 'windows-2016'" + + fuzzing: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sanitizer: [address, undefined, memory] + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master + with: + oss-fuzz-project-name: 'zydis' + dry-run: false + sanitizer: ${{ matrix.sanitizer }} + - name: Run Fuzzers (${{ matrix.sanitizer }}) + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master + with: + oss-fuzz-project-name: 'zydis' + fuzz-seconds: 600 + dry-run: false + sanitizer: ${{ matrix.sanitizer }} + - name: Upload Crash + uses: actions/upload-artifact@v1 + if: failure() && steps.build.outcome == 'success' + with: + name: ${{ matrix.sanitizer }}-artifacts + path: ./out/artifacts diff --git a/externals/dynarmic/externals/zydis/.gitignore b/externals/dynarmic/externals/zydis/.gitignore new file mode 100755 index 000000000..7e1b0d733 --- /dev/null +++ b/externals/dynarmic/externals/zydis/.gitignore @@ -0,0 +1,101 @@ +# Created by https://www.gitignore.io/api/c,c++,cmake + +### C ### +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su + + +### C++ ### +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + + +### CMake ### +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake + + +# MacOS +.DS_Store + +build* + +# MSVC +.vs +*.vcxproj.user +*.suo +*.sdf +*.opensdf +*.VC.db +*.VC.opendb +msvc/**/*.user +msvc/**/obj/ +msvc/**/bin/ + +doc/html + +.vscode +.idea +cmake-build-debug \ No newline at end of file diff --git a/externals/dynarmic/externals/zydis/.gitmodules b/externals/dynarmic/externals/zydis/.gitmodules new file mode 100755 index 000000000..e0a443d5e --- /dev/null +++ b/externals/dynarmic/externals/zydis/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dependencies/zycore"] + path = dependencies/zycore + url = https://github.com/zyantific/zycore-c diff --git a/externals/dynarmic/externals/zydis/CMakeLists.txt b/externals/dynarmic/externals/zydis/CMakeLists.txt new file mode 100755 index 000000000..4bacb5d8b --- /dev/null +++ b/externals/dynarmic/externals/zydis/CMakeLists.txt @@ -0,0 +1,296 @@ +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) + +project(Zydis VERSION 3.1.0.0 LANGUAGES C CXX) + +include(GenerateExportHeader) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +# =============================================================================================== # +# Overridable options # +# =============================================================================================== # + +# Features +option(ZYDIS_MINIMAL_MODE + "Enable minimal mode (forces ZYDIS_DECODER_MODE_MINIMAL runtime option)" + OFF) +option(ZYDIS_FEATURE_DECODER + "Enable instruction decoding functionality" + ON) +option(ZYDIS_FEATURE_FORMATTER + "Enable instruction formatting functionality" + ON) +option(ZYDIS_FEATURE_AVX512 + "Enable support for AVX-512 instructions" + ON) +option(ZYDIS_FEATURE_KNC + "Enable support for KNC instructions" + ON) + +# Build configuration +option(ZYDIS_BUILD_SHARED_LIB + "Build shared library" + OFF) +option(ZYDIS_BUILD_EXAMPLES + "Build examples" + ON) +option(ZYDIS_BUILD_TOOLS + "Build tools" + ON) +option(ZYDIS_FUZZ_AFL_FAST + "Enables AFL persistent mode and reduces prints in ZydisFuzzIn" + OFF) +option(ZYDIS_LIBFUZZER + "Enables LLVM libfuzzer mode and reduces prints in ZydisFuzzIn" + OFF) +set(ZYDIS_ZYCORE_PATH + "${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore" + CACHE + PATH + "The path to look for Zycore") + +# =============================================================================================== # +# Dependencies # +# =============================================================================================== # + +# Try to initialize the Zycore submodule using Git +if (NOT EXISTS "${ZYDIS_ZYCORE_PATH}/CMakeLists.txt" AND + "${ZYDIS_ZYCORE_PATH}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore") + find_package(Git QUIET) + if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() +endif () + +if (NOT EXISTS "${ZYDIS_ZYCORE_PATH}/CMakeLists.txt") + message( + FATAL_ERROR + "Can't find zycore submodule. Please make sure to clone the repo recursively.\n" + "You can fix this by running\n" + " git submodule update --init\n" + "or by cloning using\n" + " git clone --recursive \n" + "Alternatively, you can manually clone zycore to some path and set ZYDIS_ZYCORE_PATH." + ) +endif () + +add_subdirectory(${ZYDIS_ZYCORE_PATH} "zycore" EXCLUDE_FROM_ALL) + +# =============================================================================================== # +# Library configuration # +# =============================================================================================== # + +if (ZYDIS_BUILD_SHARED_LIB) + add_library("Zydis" SHARED) +else () + add_library("Zydis" STATIC) +endif () + +target_link_libraries("Zydis" PUBLIC "Zycore") +target_include_directories("Zydis" + PUBLIC "include" ${PROJECT_BINARY_DIR} + PRIVATE "src") +target_compile_definitions("Zydis" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYDIS_EXPORTS") +zyan_set_common_flags("Zydis") +zyan_maybe_enable_wpo_for_lib("Zydis") +generate_export_header("Zydis" BASE_NAME "ZYDIS" EXPORT_FILE_NAME "ZydisExportConfig.h") + +if (ZYDIS_FEATURE_FORMATTER AND NOT ZYDIS_FEATURE_DECODER) + message( + FATAL_ERROR + "\nZYDIS_FEATURE_FORMATTER requires ZYDIS_FEATURE_DECODER to be enabled" + ) +endif () + +if (ZYDIS_MINIMAL_MODE) + target_compile_definitions("Zydis" PUBLIC "ZYDIS_MINIMAL_MODE") +endif () +if (NOT ZYDIS_FEATURE_DECODER) + target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_DECODER") +endif () +if (NOT ZYDIS_FEATURE_FORMATTER) + target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_FORMATTER") +endif () +if (NOT ZYDIS_FEATURE_AVX512) + target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_AVX512") +endif () +if (NOT ZYDIS_FEATURE_KNC) + target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_KNC") +endif () + +target_sources("Zydis" + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/MetaInfo.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Mnemonic.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Register.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/SharedTypes.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/ShortString.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Status.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Utils.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Zydis.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/SharedData.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/String.h" + "src/MetaInfo.c" + "src/Mnemonic.c" + "src/Register.c" + "src/SharedData.c" + "src/String.c" + "src/Utils.c" + "src/Zydis.c") + +if (ZYDIS_FEATURE_DECODER) + target_sources("Zydis" + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Decoder.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/DecoderData.h" + "src/Decoder.c" + "src/DecoderData.c") + if (ZYDIS_FEATURE_FORMATTER AND (NOT ZYDIS_MINIMAL_MODE)) + target_sources("Zydis" + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Formatter.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/FormatterBuffer.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/FormatterATT.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/FormatterBase.h" + "${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/FormatterIntel.h" + "src/Formatter.c" + "src/FormatterBuffer.c" + "src/FormatterATT.c" + "src/FormatterBase.c" + "src/FormatterIntel.c") + endif () +endif () + +if (ZYDIS_BUILD_SHARED_LIB AND WIN32) + target_sources("Zydis" PRIVATE "resources/VersionInfo.rc") +endif () + +zyan_set_source_group("Zydis") + +configure_package_config_file(cmake/zydis-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/zydis-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/zydis-config.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" +) + +install(TARGETS "Zydis" + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES + "${PROJECT_BINARY_DIR}/ZydisExportConfig.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +function (_maybe_set_emscripten_cfg target) + if (EMSCRIPTEN) + # Yep, that madness below is how Emscripten likes its quotes. + set_target_properties("${target}" + PROPERTIES COMPILE_FLAGS + "-s \"EXPORT_NAME='${target}'\" -s MODULARIZE=1") + set_target_properties("${target}" + PROPERTIES LINK_FLAGS_RELEASE + "-s \"EXPORT_NAME='${target}'\" -s MODULARIZE=1") + endif () +endfunction () + +# =============================================================================================== # +# Examples # +# =============================================================================================== # + +if (ZYDIS_BUILD_EXAMPLES AND NOT ZYAN_NO_LIBC) + if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER AND (NOT ZYDIS_MINIMAL_MODE)) + add_executable("Formatter01" "examples/Formatter01.c") + target_link_libraries("Formatter01" "Zydis") + set_target_properties("Formatter01" PROPERTIES FOLDER "Examples/Formatter") + target_compile_definitions("Formatter01" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("Formatter01") + zyan_maybe_enable_wpo("Formatter01") + _maybe_set_emscripten_cfg("Formatter01") + + add_executable("Formatter02" "examples/Formatter02.c") + target_link_libraries("Formatter02" "Zydis") + set_target_properties("Formatter02" PROPERTIES FOLDER "Examples/Formatter") + target_compile_definitions("Formatter02" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("Formatter02") + zyan_maybe_enable_wpo("Formatter02") + _maybe_set_emscripten_cfg("Formatter02") + + add_executable("Formatter03" "examples/Formatter03.c") + target_link_libraries("Formatter03" "Zydis") + set_target_properties("Formatter03" PROPERTIES FOLDER "Examples/Formatter") + target_compile_definitions("Formatter03" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("Formatter03") + zyan_maybe_enable_wpo("Formatter03") + _maybe_set_emscripten_cfg("Formatter03") + + add_executable("ZydisPerfTest" "examples/ZydisPerfTest.c") + target_link_libraries("ZydisPerfTest" "Zydis") + set_target_properties("ZydisPerfTest" PROPERTIES FOLDER "Examples") + target_compile_definitions("ZydisPerfTest" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("ZydisPerfTest") + zyan_maybe_enable_wpo("ZydisPerfTest") + _maybe_set_emscripten_cfg("ZydisPerfTest") + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" + OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + target_compile_definitions("ZydisPerfTest" PRIVATE "_GNU_SOURCE") + find_package(Threads REQUIRED) + target_link_libraries("ZydisPerfTest" Threads::Threads) + endif () + endif () +endif () + +# =============================================================================================== # +# Tools # +# =============================================================================================== # + +if (ZYDIS_BUILD_TOOLS AND NOT ZYAN_NO_LIBC) + if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER AND (NOT ZYDIS_MINIMAL_MODE)) + add_executable("ZydisDisasm" "tools/ZydisDisasm.c") + target_link_libraries("ZydisDisasm" "Zydis") + set_target_properties ("ZydisDisasm" PROPERTIES FOLDER "Tools") + target_compile_definitions("ZydisDisasm" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("ZydisDisasm") + zyan_maybe_enable_wpo("ZydisDisasm") + _maybe_set_emscripten_cfg("ZydisDisasm") + install(TARGETS "ZydisDisasm" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable("ZydisFuzzIn" "tools/ZydisFuzzIn.c") + target_link_libraries("ZydisFuzzIn" "Zydis") + set_target_properties("ZydisFuzzIn" PROPERTIES FOLDER "Tools") + target_compile_definitions("ZydisFuzzIn" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("ZydisFuzzIn") + zyan_maybe_enable_wpo("ZydisFuzzIn") + _maybe_set_emscripten_cfg("ZydisFuzzIn") + if (ZYDIS_FUZZ_AFL_FAST) + target_compile_definitions("ZydisFuzzIn" PRIVATE "ZYDIS_FUZZ_AFL_FAST") + endif () + if (ZYDIS_LIBFUZZER) + target_compile_definitions("ZydisFuzzIn" PRIVATE "ZYDIS_LIBFUZZER") + endif () + + add_executable("ZydisInfo" "tools/ZydisInfo.c") + target_link_libraries("ZydisInfo" "Zydis") + set_target_properties ("ZydisInfo" PROPERTIES FOLDER "Tools") + target_compile_definitions("ZydisInfo" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("ZydisInfo") + zyan_maybe_enable_wpo("ZydisInfo") + _maybe_set_emscripten_cfg("ZydisInfo") + install(TARGETS "ZydisInfo" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable("ZydisPE" "tools/ZydisPE.c") + target_link_libraries("ZydisPE" "Zydis") + set_target_properties ("ZydisPE" PROPERTIES FOLDER "Tools") + target_compile_definitions("ZydisPE" PRIVATE "_CRT_SECURE_NO_WARNINGS") + zyan_set_common_flags("ZydisPE") + zyan_maybe_enable_wpo("ZydisPE") + _maybe_set_emscripten_cfg("ZydisPE") + endif () +endif () diff --git a/externals/dynarmic/externals/zydis/Doxyfile b/externals/dynarmic/externals/zydis/Doxyfile new file mode 100755 index 000000000..dc101bb94 --- /dev/null +++ b/externals/dynarmic/externals/zydis/Doxyfile @@ -0,0 +1,2471 @@ +# Doxyfile 1.8.13 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = Zydis + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = v3.1.0 + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = ./doc + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 0. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 0 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = NO + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = YES + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = ./include \ + ./README.md \ + ./files.dox + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.cs \ + *.d \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f \ + *.for \ + *.tcl \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = README.md + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /