├── .gitattributes ├── .github └── workflows │ └── builds.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.bat ├── build.sh ├── data ├── Inconsolata-Regular.ttf ├── Roboto-Regular.ttf ├── icons.ttf ├── liberation-mono.ttf ├── logo.ico └── logo.rc ├── project.4coder ├── run_tests.bat └── src ├── async ├── async.c └── async.h ├── base ├── base_arena.c ├── base_arena.h ├── base_command_line.c ├── base_command_line.h ├── base_context_cracking.h ├── base_core.c ├── base_core.h ├── base_entry_point.c ├── base_entry_point.h ├── base_inc.c ├── base_inc.h ├── base_log.c ├── base_log.h ├── base_markup.c ├── base_markup.h ├── base_math.c ├── base_math.h ├── base_meta.c ├── base_meta.h ├── base_profile.c ├── base_profile.h ├── base_strings.c ├── base_strings.h ├── base_thread_context.c └── base_thread_context.h ├── codeview ├── codeview.c ├── codeview.h ├── codeview.mdesk ├── codeview_enum.c ├── codeview_enum.h ├── codeview_parse.c ├── codeview_parse.h └── generated │ ├── codeview.meta.c │ └── codeview.meta.h ├── coff ├── coff.c ├── coff.h ├── coff_enum.c ├── coff_enum.h ├── coff_parse.c └── coff_parse.h ├── ctrl ├── ctrl.mdesk ├── ctrl_core.c ├── ctrl_core.h ├── ctrl_inc.c ├── ctrl_inc.h └── generated │ ├── ctrl.meta.c │ └── ctrl.meta.h ├── dasm_cache ├── dasm_cache.c └── dasm_cache.h ├── dbg_engine ├── dbg_engine.mdesk ├── dbg_engine_core.c ├── dbg_engine_core.h ├── dbg_engine_inc.c ├── dbg_engine_inc.h └── generated │ ├── dbg_engine.meta.c │ └── dbg_engine.meta.h ├── dbgi ├── dbgi.c └── dbgi.h ├── demon ├── demon_core.c ├── demon_core.h ├── demon_core.mdesk ├── demon_inc.c ├── demon_inc.h ├── generated │ ├── demon.meta.c │ └── demon.meta.h ├── linux │ ├── demon_core_linux.c │ ├── demon_core_linux.h │ ├── demon_os_linux.c │ └── demon_os_linux.h └── win32 │ ├── demon_core_win32.c │ └── demon_core_win32.h ├── draw ├── draw.c ├── draw.h ├── draw.mdesk └── generated │ ├── draw.meta.c │ └── draw.meta.h ├── dwarf ├── dwarf.c ├── dwarf.h ├── dwarf_coff.c ├── dwarf_coff.h ├── dwarf_elf.c ├── dwarf_elf.h ├── dwarf_enum.c ├── dwarf_enum.h ├── dwarf_expr.c ├── dwarf_expr.h ├── dwarf_notes.txt ├── dwarf_parse.c ├── dwarf_parse.h ├── dwarf_unwind.c └── dwarf_unwind.h ├── elf ├── elf.c ├── elf.h ├── elf_parse.c └── elf_parse.h ├── eval ├── eval.mdesk ├── eval_core.c ├── eval_core.h ├── eval_inc.c ├── eval_inc.h ├── eval_interpret.c ├── eval_interpret.h ├── eval_ir.c ├── eval_ir.h ├── eval_parse.c ├── eval_parse.h ├── eval_types.c ├── eval_types.h └── generated │ ├── eval.meta.c │ └── eval.meta.h ├── eval_visualization ├── eval_visualization_core.c ├── eval_visualization_core.h ├── eval_visualization_inc.c └── eval_visualization_inc.h ├── file_stream ├── file_stream.c └── file_stream.h ├── font_cache ├── font_cache.c └── font_cache.h ├── font_provider ├── dwrite │ ├── font_provider_dwrite.c │ └── font_provider_dwrite.h ├── font_provider.c ├── font_provider.h ├── font_provider_inc.c ├── font_provider_inc.h └── freetype │ ├── font_provider_freetype.c │ └── font_provider_freetype.h ├── geo_cache ├── geo_cache.c └── geo_cache.h ├── hash_store ├── hash_store.c └── hash_store.h ├── lib_raddbg_markup └── raddbg_markup.h ├── lib_rdi_format ├── rdi_format.c ├── rdi_format.h ├── rdi_format_parse.c └── rdi_format_parse.h ├── lib_rdi_make ├── rdi_make.c └── rdi_make.h ├── linker ├── base_ext │ ├── base_arena.c │ ├── base_arena.h │ ├── base_arrays.c │ ├── base_arrays.h │ ├── base_bit_array.c │ ├── base_bit_array.h │ ├── base_blake3.c │ ├── base_blake3.h │ ├── base_blake3_asm.c │ ├── base_blake3_asm.h │ ├── base_core.c │ ├── base_core.h │ ├── base_crc32.c │ ├── base_crc32.h │ ├── base_inc.c │ ├── base_inc.h │ ├── base_md5.c │ ├── base_md5.h │ ├── base_strings.c │ └── base_strings.h ├── codeview_ext │ ├── codeview.c │ └── codeview.h ├── hash_table.c ├── hash_table.h ├── linker.natvis ├── lnk.c ├── lnk.h ├── lnk_chunk.c ├── lnk_chunk.h ├── lnk_cmd_line.c ├── lnk_cmd_line.h ├── lnk_config.c ├── lnk_config.h ├── lnk_debug_info.c ├── lnk_debug_info.h ├── lnk_error.c ├── lnk_error.h ├── lnk_export_table.c ├── lnk_export_table.h ├── lnk_import_table.c ├── lnk_import_table.h ├── lnk_io.c ├── lnk_io.h ├── lnk_lib.c ├── lnk_lib.h ├── lnk_log.c ├── lnk_log.h ├── lnk_obj.c ├── lnk_obj.h ├── lnk_reloc.c ├── lnk_reloc.h ├── lnk_section_table.c ├── lnk_section_table.h ├── lnk_symbol_table.c ├── lnk_symbol_table.h ├── lnk_timer.c ├── lnk_timer.h ├── pdb_ext │ ├── msf_builder.c │ ├── msf_builder.h │ ├── pdb.c │ ├── pdb.h │ ├── pdb_builder.c │ ├── pdb_builder.h │ ├── pdb_helpers.c │ └── pdb_helpers.h ├── rdi │ ├── rdi.c │ ├── rdi.h │ ├── rdi_builder.c │ ├── rdi_builder.h │ ├── rdi_coff.c │ ├── rdi_coff.h │ ├── rdi_cv.c │ ├── rdi_cv.h │ └── rdi_overrides.h └── thread_pool │ ├── thread_pool.c │ └── thread_pool.h ├── mdesk ├── mdesk.c └── mdesk.h ├── metagen ├── metagen.c ├── metagen.h ├── metagen_base │ ├── metagen_base_arena.c │ ├── metagen_base_arena.h │ ├── metagen_base_command_line.c │ ├── metagen_base_command_line.h │ ├── metagen_base_context_cracking.h │ ├── metagen_base_core.c │ ├── metagen_base_core.h │ ├── metagen_base_entry_point.c │ ├── metagen_base_entry_point.h │ ├── metagen_base_inc.c │ ├── metagen_base_inc.h │ ├── metagen_base_log.c │ ├── metagen_base_log.h │ ├── metagen_base_markup.c │ ├── metagen_base_markup.h │ ├── metagen_base_math.c │ ├── metagen_base_math.h │ ├── metagen_base_meta.c │ ├── metagen_base_meta.h │ ├── metagen_base_profile.c │ ├── metagen_base_profile.h │ ├── metagen_base_strings.c │ ├── metagen_base_strings.h │ ├── metagen_base_thread_context.c │ └── metagen_base_thread_context.h ├── metagen_main.c └── metagen_os │ ├── core │ ├── linux │ │ ├── metagen_os_core_linux.c │ │ └── metagen_os_core_linux.h │ ├── metagen_os_core.c │ ├── metagen_os_core.h │ └── win32 │ │ ├── metagen_os_core_win32.c │ │ └── metagen_os_core_win32.h │ ├── metagen_os_inc.c │ └── metagen_os_inc.h ├── msf ├── msf.c ├── msf.h ├── msf_parse.c └── msf_parse.h ├── msvc_crt ├── msvc_crt.c ├── msvc_crt.h ├── msvc_crt_enum.c └── msvc_crt_enum.h ├── mule ├── inline_body.cpp ├── mule_c.c ├── mule_c.h ├── mule_hotload_main.c ├── mule_hotload_module_main.c ├── mule_inline.cpp ├── mule_main.cpp ├── mule_module.cpp ├── mule_o2.cpp ├── mule_peb_trample.c └── mule_peb_trample_reload.c ├── mutable_text ├── mutable_text.c └── mutable_text.h ├── natvis └── base.natvis ├── os ├── core │ ├── linux │ │ ├── os_core_linux.c │ │ ├── os_core_linux.h │ │ ├── os_core_linux_old.c │ │ └── os_core_linux_old.h │ ├── os_core.c │ ├── os_core.h │ └── win32 │ │ ├── os_core_win32.c │ │ └── os_core_win32.h ├── gfx │ ├── generated │ │ ├── os_gfx.meta.c │ │ └── os_gfx.meta.h │ ├── linux │ │ ├── os_gfx_linux.c │ │ └── os_gfx_linux.h │ ├── os_gfx.c │ ├── os_gfx.h │ ├── os_gfx.mdesk │ ├── stub │ │ ├── os_gfx_stub.c │ │ └── os_gfx_stub.h │ └── win32 │ │ ├── os_gfx_win32.c │ │ └── os_gfx_win32.h ├── os_inc.c └── os_inc.h ├── path ├── path.c └── path.h ├── pdb ├── pdb.c ├── pdb.h ├── pdb_parse.c ├── pdb_parse.h ├── pdb_stringize.c └── pdb_stringize.h ├── pe ├── dos_program.asm ├── pe.c └── pe.h ├── ptr_graph_cache ├── ptr_graph_cache.c └── ptr_graph_cache.h ├── radcon ├── radcon.c ├── radcon.h ├── radcon_coff.c ├── radcon_coff.h ├── radcon_cv.c ├── radcon_cv.h ├── radcon_dwarf.c ├── radcon_dwarf.h ├── radcon_elf.c ├── radcon_elf.h ├── radcon_main.c ├── radcon_pdb.c └── radcon_pdb.h ├── raddbg ├── generated │ ├── raddbg.meta.c │ └── raddbg.meta.h ├── raddbg.mdesk ├── raddbg_core.c ├── raddbg_core.h ├── raddbg_eval.c ├── raddbg_eval.h ├── raddbg_inc.c ├── raddbg_inc.h ├── raddbg_legacy_config.c ├── raddbg_legacy_config.h ├── raddbg_main.c ├── raddbg_views.c ├── raddbg_views.h ├── raddbg_widgets.c └── raddbg_widgets.h ├── raddump ├── raddump.c ├── raddump.h └── raddump_main.c ├── rdi_breakpad_from_pdb └── rdi_breakpad_from_pdb_main.c ├── rdi_format ├── rdi_format.mdesk ├── rdi_format_local.c └── rdi_format_local.h ├── rdi_from_dwarf ├── rdi_from_dwarf.c ├── rdi_from_dwarf.h └── rdi_from_dwarf_main.c ├── rdi_from_pdb ├── rdi_from_pdb.c ├── rdi_from_pdb.h └── rdi_from_pdb_main.c ├── rdi_make ├── rdi_make_help.c ├── rdi_make_help.h ├── rdi_make_local.c └── rdi_make_local.h ├── regs ├── generated │ ├── regs.meta.c │ └── regs.meta.h ├── rdi │ ├── generated │ │ ├── regs_rdi.meta.c │ │ └── regs_rdi.meta.h │ ├── regs_rdi.c │ ├── regs_rdi.h │ └── regs_rdi.mdesk ├── regs.c ├── regs.h └── regs.mdesk ├── render ├── d3d11 │ ├── generated │ │ ├── render_d3d11.meta.c │ │ └── render_d3d11.meta.h │ ├── render_d3d11.c │ ├── render_d3d11.h │ └── render_d3d11.mdesk ├── generated │ ├── render.meta.c │ └── render.meta.h ├── opengl │ ├── generated │ │ ├── render_opengl.meta.c │ │ └── render_opengl.meta.h │ ├── linux │ │ ├── egl │ │ │ ├── render_opengl_linux_egl.c │ │ │ └── render_opengl_linux_egl.h │ │ ├── glx │ │ │ ├── render_opengl_linux_glx.c │ │ │ └── render_opengl_linux_glx.h │ │ ├── render_opengl_linux.c │ │ └── render_opengl_linux.h │ ├── render_opengl.c │ ├── render_opengl.h │ ├── render_opengl.mdesk │ └── win32 │ │ ├── render_opengl_win32.c │ │ └── render_opengl_win32.h ├── render_core.c ├── render_core.h ├── render_core.mdesk ├── render_inc.c ├── render_inc.h └── stub │ ├── render_stub.c │ └── render_stub.h ├── scratch ├── convertperf.c ├── debugstringperf.c ├── eval_scratch.c ├── parse_inline_sites.c ├── ryan_scratch.c └── textperf.c ├── strip_lib_debug └── strip_lib_debug.c ├── tester └── tester_main.c ├── text_cache ├── text_cache.c └── text_cache.h ├── texture_cache ├── texture_cache.c └── texture_cache.h ├── third_party ├── blake3 │ ├── asm │ │ ├── LICENSE │ │ ├── blake3.c │ │ ├── blake3.h │ │ ├── blake3_avx2_x86-64_unix.S │ │ ├── blake3_avx2_x86-64_windows_msvc.asm │ │ ├── blake3_avx512_x86-64_unix.S │ │ ├── blake3_avx512_x86-64_windows_msvc.asm │ │ ├── blake3_dispatch.c │ │ ├── blake3_impl.h │ │ ├── blake3_neon.c │ │ ├── blake3_portable.c │ │ ├── blake3_sse2_x86-64_unix.S │ │ ├── blake3_sse2_x86-64_windows_msvc.asm │ │ ├── blake3_sse41_x86-64_unix.S │ │ └── blake3_sse41_x86-64_windows_msvc.asm │ └── c │ │ ├── LICENSE │ │ ├── blake3.c │ │ ├── blake3.h │ │ ├── blake3_avx2.c │ │ ├── blake3_avx512.c │ │ ├── blake3_dispatch.c │ │ ├── blake3_impl.h │ │ ├── blake3_neon.c │ │ ├── blake3_portable.c │ │ ├── blake3_sse2.c │ │ └── blake3_sse41.c ├── md5 │ ├── md5.c │ └── md5.h ├── rad_lzb_simple │ ├── rad_lzb_simple.c │ └── rad_lzb_simple.h ├── radsort │ └── radsort.h ├── sinfl │ └── sinfl.h ├── stb │ ├── stb_image.h │ └── stb_sprintf.h ├── xxHash │ ├── LICENSE │ ├── README.md │ ├── SECURITY.md │ ├── doc │ │ ├── README.md │ │ ├── xxhash.cry │ │ └── xxhash_spec.md │ ├── xxh3.h │ ├── xxh_x86dispatch.c │ ├── xxh_x86dispatch.h │ ├── xxhash.c │ └── xxhash.h └── zydis │ ├── zydis.c │ └── zydis.h └── ui ├── generated ├── ui.meta.c └── ui.meta.h ├── ui.mdesk ├── ui_basic_widgets.c ├── ui_basic_widgets.h ├── ui_core.c ├── ui_core.h ├── ui_inc.c └── ui_inc.h /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/builds.yml: -------------------------------------------------------------------------------- 1 | name: builds 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - '**.md' 7 | pull_request: 8 | paths-ignore: 9 | - '**.md' 10 | 11 | jobs: 12 | build-windows-2022: 13 | runs-on: windows-2022 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | target: 18 | - raddbg 19 | - radlink 20 | - rdi_from_pdb 21 | - raddump 22 | - rdi_breakpad_from_pdb 23 | compiler: 24 | - msvc 25 | - clang 26 | mode: 27 | - debug 28 | - release 29 | steps: 30 | - name: checkout 31 | uses: actions/checkout@v2 32 | - name: build (vs 2022) 33 | shell: cmd 34 | run: | 35 | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 36 | call build ${{ matrix.target }} ${{ matrix.compiler }} ${{ matrix.mode }} || exit /b 1 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /local/ 3 | *~ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024 Epic Games Tools 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the “Software”), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /data/Inconsolata-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EpicGamesExt/raddebugger/e83c74db295497073134dfaa0654afbe791f3c04/data/Inconsolata-Regular.ttf -------------------------------------------------------------------------------- /data/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EpicGamesExt/raddebugger/e83c74db295497073134dfaa0654afbe791f3c04/data/Roboto-Regular.ttf -------------------------------------------------------------------------------- /data/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EpicGamesExt/raddebugger/e83c74db295497073134dfaa0654afbe791f3c04/data/icons.ttf -------------------------------------------------------------------------------- /data/liberation-mono.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EpicGamesExt/raddebugger/e83c74db295497073134dfaa0654afbe791f3c04/data/liberation-mono.ttf -------------------------------------------------------------------------------- /data/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EpicGamesExt/raddebugger/e83c74db295497073134dfaa0654afbe791f3c04/data/logo.ico -------------------------------------------------------------------------------- /data/logo.rc: -------------------------------------------------------------------------------- 1 | 1 ICON DISCARDABLE "logo.ico" -------------------------------------------------------------------------------- /run_tests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D "%~dp0" 4 | 5 | echo --- getting test data folder path --------------------------------------------- 6 | if not exist .\local\test_data_path.txt ( 7 | echo error: You must first store the full path of your test data folder inside of `local/test_data_path.txt`. 8 | goto :EOF 9 | ) 10 | set /p test_data_folder=<.\local\test_data_path.txt 11 | echo test data path: %test_data_folder% 12 | echo: 13 | 14 | echo --- building all testing executables ------------------------------------------ 15 | call build rdi_from_pdb rdi_dump raddbg radlink tester 16 | echo: 17 | 18 | echo --- running tests ------------------------------------------------------------- 19 | pushd build 20 | call tester.exe --test_data:%test_data_folder% 21 | popd 22 | -------------------------------------------------------------------------------- /src/base/base_arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_ARENA_H 5 | #define BASE_ARENA_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Constants 9 | 10 | #define ARENA_HEADER_SIZE 128 11 | 12 | //////////////////////////////// 13 | //~ rjf: Types 14 | 15 | typedef U64 ArenaFlags; 16 | enum 17 | { 18 | ArenaFlag_NoChain = (1<<0), 19 | ArenaFlag_LargePages = (1<<1), 20 | }; 21 | 22 | typedef struct ArenaParams ArenaParams; 23 | struct ArenaParams 24 | { 25 | ArenaFlags flags; 26 | U64 reserve_size; 27 | U64 commit_size; 28 | void *optional_backing_buffer; 29 | }; 30 | 31 | typedef struct Arena Arena; 32 | struct Arena 33 | { 34 | Arena *prev; // previous arena in chain 35 | Arena *current; // current arena in chain 36 | ArenaFlags flags; 37 | U64 cmt_size; 38 | U64 res_size; 39 | U64 base_pos; 40 | U64 pos; 41 | U64 cmt; 42 | U64 res; 43 | #if ARENA_FREE_LIST 44 | U64 free_size; 45 | Arena *free_last; 46 | #endif 47 | }; 48 | StaticAssert(sizeof(Arena) <= ARENA_HEADER_SIZE, arena_header_size_check); 49 | 50 | typedef struct Temp Temp; 51 | struct Temp 52 | { 53 | Arena *arena; 54 | U64 pos; 55 | }; 56 | 57 | //////////////////////////////// 58 | //~ rjf: Global Defaults 59 | 60 | global U64 arena_default_reserve_size = MB(64); 61 | global U64 arena_default_commit_size = KB(64); 62 | global ArenaFlags arena_default_flags = 0; 63 | 64 | //////////////////////////////// 65 | //~ rjf: Arena Functions 66 | 67 | //- rjf: arena creation/destruction 68 | internal Arena *arena_alloc_(ArenaParams *params); 69 | #define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, __VA_ARGS__}) 70 | internal void arena_release(Arena *arena); 71 | 72 | //- rjf: arena push/pop/pos core functions 73 | internal void *arena_push(Arena *arena, U64 size, U64 align); 74 | internal U64 arena_pos(Arena *arena); 75 | internal void arena_pop_to(Arena *arena, U64 pos); 76 | 77 | //- rjf: arena push/pop helpers 78 | internal void arena_clear(Arena *arena); 79 | internal void arena_pop(Arena *arena, U64 amt); 80 | 81 | //- rjf: temporary arena scopes 82 | internal Temp temp_begin(Arena *arena); 83 | internal void temp_end(Temp temp); 84 | 85 | //- rjf: push helper macros 86 | #define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align)) 87 | #define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T)*(c)) 88 | #define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T))) 89 | #define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T))) 90 | 91 | #endif // BASE_ARENA_H 92 | -------------------------------------------------------------------------------- /src/base/base_command_line.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_COMMAND_LINE_H 5 | #define BASE_COMMAND_LINE_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Parsed Command Line Types 9 | 10 | typedef struct CmdLineOpt CmdLineOpt; 11 | struct CmdLineOpt 12 | { 13 | CmdLineOpt *next; 14 | CmdLineOpt *hash_next; 15 | U64 hash; 16 | String8 string; 17 | String8List value_strings; 18 | String8 value_string; 19 | }; 20 | 21 | typedef struct CmdLineOptList CmdLineOptList; 22 | struct CmdLineOptList 23 | { 24 | U64 count; 25 | CmdLineOpt *first; 26 | CmdLineOpt *last; 27 | }; 28 | 29 | typedef struct CmdLine CmdLine; 30 | struct CmdLine 31 | { 32 | String8 exe_name; 33 | CmdLineOptList options; 34 | String8List inputs; 35 | U64 option_table_size; 36 | CmdLineOpt **option_table; 37 | U64 argc; 38 | char **argv; 39 | }; 40 | 41 | //////////////////////////////// 42 | //~ NOTE(rjf): Command Line Option Parsing 43 | 44 | internal U64 cmd_line_hash_from_string(String8 string); 45 | internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string); 46 | internal CmdLineOpt* cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string); 47 | internal void cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var); 48 | internal CmdLineOpt* cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List values); 49 | internal CmdLine cmd_line_from_string_list(Arena *arena, String8List arguments); 50 | internal CmdLineOpt* cmd_line_opt_from_string(CmdLine *cmd_line, String8 name); 51 | internal String8List cmd_line_strings(CmdLine *cmd_line, String8 name); 52 | internal String8 cmd_line_string(CmdLine *cmd_line, String8 name); 53 | internal B32 cmd_line_has_flag(CmdLine *cmd_line, String8 name); 54 | internal B32 cmd_line_has_argument(CmdLine *cmd_line, String8 name); 55 | 56 | #endif // BASE_COMMAND_LINE_H 57 | -------------------------------------------------------------------------------- /src/base/base_entry_point.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_ENTRY_POINT_H 5 | #define BASE_ENTRY_POINT_H 6 | 7 | internal void main_thread_base_entry_point(int argc, char **argv); 8 | internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params); 9 | internal U64 update_tick_idx(void); 10 | internal B32 update(void); 11 | 12 | #endif // BASE_ENTRY_POINT_H 13 | -------------------------------------------------------------------------------- /src/base/base_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Base Includes 6 | 7 | #undef LAYER_COLOR 8 | #define LAYER_COLOR 0.20f, 0.60f, 0.80f 9 | 10 | #include "base_core.c" 11 | #include "base_profile.c" 12 | #include "base_arena.c" 13 | #include "base_math.c" 14 | #include "base_strings.c" 15 | #include "base_thread_context.c" 16 | #include "base_command_line.c" 17 | #include "base_markup.c" 18 | #include "base_meta.c" 19 | #include "base_log.c" 20 | #include "base_entry_point.c" 21 | -------------------------------------------------------------------------------- /src/base/base_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_INC_H 5 | #define BASE_INC_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Base Includes 9 | 10 | #include "base_context_cracking.h" 11 | 12 | #include "base_core.h" 13 | #include "base_profile.h" 14 | #include "base_arena.h" 15 | #include "base_math.h" 16 | #include "base_strings.h" 17 | #include "base_thread_context.h" 18 | #include "base_command_line.h" 19 | #include "base_markup.h" 20 | #include "base_meta.h" 21 | #include "base_log.h" 22 | #include "base_entry_point.h" 23 | 24 | #endif // BASE_INC_H 25 | -------------------------------------------------------------------------------- /src/base/base_log.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Globals/Thread-Locals 6 | 7 | C_LINKAGE thread_static Log *log_active; 8 | #if !BUILD_SUPPLEMENTARY_UNIT 9 | C_LINKAGE thread_static Log *log_active = 0; 10 | #endif 11 | 12 | //////////////////////////////// 13 | //~ rjf: Log Creation/Selection 14 | 15 | internal Log * 16 | log_alloc(void) 17 | { 18 | Arena *arena = arena_alloc(); 19 | Log *log = push_array(arena, Log, 1); 20 | log->arena = arena; 21 | return log; 22 | } 23 | 24 | internal void 25 | log_release(Log *log) 26 | { 27 | arena_release(log->arena); 28 | } 29 | 30 | internal void 31 | log_select(Log *log) 32 | { 33 | log_active = log; 34 | } 35 | 36 | //////////////////////////////// 37 | //~ rjf: Log Building/Clearing 38 | 39 | internal void 40 | log_msg(LogMsgKind kind, String8 string) 41 | { 42 | if(log_active != 0 && log_active->top_scope != 0) 43 | { 44 | String8 string_copy = push_str8_copy(log_active->arena, string); 45 | str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy); 46 | } 47 | } 48 | 49 | internal void 50 | log_msgf(LogMsgKind kind, char *fmt, ...) 51 | { 52 | if(log_active != 0) 53 | { 54 | Temp scratch = scratch_begin(0, 0); 55 | va_list args; 56 | va_start(args, fmt); 57 | String8 string = push_str8fv(scratch.arena, fmt, args); 58 | log_msg(kind, string); 59 | va_end(args); 60 | scratch_end(scratch); 61 | } 62 | } 63 | 64 | //////////////////////////////// 65 | //~ rjf: Log Scopes 66 | 67 | internal void 68 | log_scope_begin(void) 69 | { 70 | if(log_active != 0) 71 | { 72 | U64 pos = arena_pos(log_active->arena); 73 | LogScope *scope = push_array(log_active->arena, LogScope, 1); 74 | scope->pos = pos; 75 | SLLStackPush(log_active->top_scope, scope); 76 | } 77 | } 78 | 79 | internal LogScopeResult 80 | log_scope_end(Arena *arena) 81 | { 82 | LogScopeResult result = {0}; 83 | if(log_active != 0) 84 | { 85 | LogScope *scope = log_active->top_scope; 86 | if(scope != 0) 87 | { 88 | SLLStackPop(log_active->top_scope); 89 | if(arena != 0) 90 | { 91 | for EachEnumVal(LogMsgKind, kind) 92 | { 93 | Temp scratch = scratch_begin(&arena, 1); 94 | String8 result_unindented = str8_list_join(scratch.arena, &scope->strings[kind], 0); 95 | result.strings[kind] = indented_from_string(arena, result_unindented); 96 | scratch_end(scratch); 97 | } 98 | } 99 | arena_pop_to(log_active->arena, scope->pos); 100 | } 101 | } 102 | return result; 103 | } 104 | -------------------------------------------------------------------------------- /src/base/base_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_LOG_H 5 | #define BASE_LOG_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Log Types 9 | 10 | typedef enum LogMsgKind 11 | { 12 | LogMsgKind_Info, 13 | LogMsgKind_UserError, 14 | LogMsgKind_COUNT 15 | } 16 | LogMsgKind; 17 | 18 | typedef struct LogScope LogScope; 19 | struct LogScope 20 | { 21 | LogScope *next; 22 | U64 pos; 23 | String8List strings[LogMsgKind_COUNT]; 24 | }; 25 | 26 | typedef struct LogScopeResult LogScopeResult; 27 | struct LogScopeResult 28 | { 29 | String8 strings[LogMsgKind_COUNT]; 30 | }; 31 | 32 | typedef struct Log Log; 33 | struct Log 34 | { 35 | Arena *arena; 36 | LogScope *top_scope; 37 | }; 38 | 39 | //////////////////////////////// 40 | //~ rjf: Log Creation/Selection 41 | 42 | internal Log *log_alloc(void); 43 | internal void log_release(Log *log); 44 | internal void log_select(Log *log); 45 | 46 | //////////////////////////////// 47 | //~ rjf: Log Building 48 | 49 | internal void log_msg(LogMsgKind kind, String8 string); 50 | internal void log_msgf(LogMsgKind kind, char *fmt, ...); 51 | #define log_info(s) log_msg(LogMsgKind_Info, (s)) 52 | #define log_infof(...) log_msgf(LogMsgKind_Info, __VA_ARGS__) 53 | #define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) 54 | #define log_user_errorf(...) log_msgf(LogMsgKind_UserError, __VA_ARGS__) 55 | 56 | #define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) 57 | #define LogInfoNamedBlockF(...) DeferLoop((log_infof(__VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) 58 | 59 | //////////////////////////////// 60 | //~ rjf: Log Scopes 61 | 62 | internal void log_scope_begin(void); 63 | internal LogScopeResult log_scope_end(Arena *arena); 64 | 65 | #endif // BASE_LOG_H 66 | -------------------------------------------------------------------------------- /src/base/base_markup.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal void 5 | set_thread_name(String8 string) 6 | { 7 | ProfThreadName("%.*s", str8_varg(string)); 8 | os_set_thread_name(string); 9 | } 10 | 11 | internal void 12 | set_thread_namef(char *fmt, ...) 13 | { 14 | Temp scratch = scratch_begin(0, 0); 15 | va_list args; 16 | va_start(args, fmt); 17 | String8 string = push_str8fv(scratch.arena, fmt, args); 18 | set_thread_name(string); 19 | va_end(args); 20 | scratch_end(scratch); 21 | } 22 | -------------------------------------------------------------------------------- /src/base/base_markup.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_MARKUP_H 5 | #define BASE_MARKUP_H 6 | 7 | #define RADDBG_MARKUP_IMPLEMENTATION 8 | #define RADDBG_MARKUP_VSNPRINTF raddbg_vsnprintf 9 | #if OS_LINUX 10 | # define RADDBG_MARKUP_STUBS 11 | #endif 12 | #include "lib_raddbg_markup/raddbg_markup.h" 13 | 14 | #if !defined(LAYER_COLOR) 15 | # define LAYER_COLOR 0x404040ff 16 | #endif 17 | 18 | internal void set_thread_name(String8 string); 19 | internal void set_thread_namef(char *fmt, ...); 20 | #define ThreadNameF(...) (set_thread_namef(__VA_ARGS__), raddbg_thread_color_u32(LAYER_COLOR)) 21 | 22 | #endif // BASE_MARKUP_H 23 | -------------------------------------------------------------------------------- /src/base/base_profile.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #if PROFILE_SPALL 5 | internal inline void 6 | spall_begin(char *fmt, ...) 7 | { 8 | if(spall_buffer.data == 0) 9 | { 10 | spall_buffer.length = MB(1); 11 | spall_buffer.data = os_reserve(spall_buffer.length); 12 | os_commit(spall_buffer.data, spall_buffer.length); 13 | spall_buffer_init(&spall_profile, &spall_buffer); 14 | } 15 | if(spall_pid == 0) 16 | { 17 | spall_pid = os_get_process_info()->pid; 18 | } 19 | if(spall_tid == 0) 20 | { 21 | spall_tid = os_tid(); 22 | } 23 | Temp scratch = scratch_begin(0, 0); 24 | va_list args; 25 | va_start(args, fmt); 26 | String8 string = push_str8fv(scratch.arena, fmt, args); 27 | spall_buffer_begin_ex(&spall_profile, &spall_buffer, string.str, string.size, os_now_microseconds(), spall_tid, spall_pid); 28 | va_end(args); 29 | scratch_end(scratch); 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /src/base/base_thread_context.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | // NOTE(allen): Thread Context Functions 6 | 7 | C_LINKAGE thread_static TCTX* tctx_thread_local; 8 | #if !BUILD_SUPPLEMENTARY_UNIT 9 | C_LINKAGE thread_static TCTX* tctx_thread_local = 0; 10 | #endif 11 | 12 | internal void 13 | tctx_init_and_equip(TCTX *tctx) 14 | { 15 | MemoryZeroStruct(tctx); 16 | Arena **arena_ptr = tctx->arenas; 17 | for(U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1) 18 | { 19 | *arena_ptr = arena_alloc(); 20 | } 21 | tctx_thread_local = tctx; 22 | } 23 | 24 | internal void 25 | tctx_release(void) 26 | { 27 | for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1) 28 | { 29 | arena_release(tctx_thread_local->arenas[i]); 30 | } 31 | } 32 | 33 | internal TCTX * 34 | tctx_get_equipped(void) 35 | { 36 | return tctx_thread_local; 37 | } 38 | 39 | internal Arena * 40 | tctx_get_scratch(Arena **conflicts, U64 count) 41 | { 42 | TCTX *tctx = tctx_get_equipped(); 43 | Arena *result = 0; 44 | Arena **arena_ptr = tctx->arenas; 45 | for(U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1) 46 | { 47 | Arena **conflict_ptr = conflicts; 48 | B32 has_conflict = 0; 49 | for(U64 j = 0; j < count; j += 1, conflict_ptr += 1) 50 | { 51 | if(*arena_ptr == *conflict_ptr) 52 | { 53 | has_conflict = 1; 54 | break; 55 | } 56 | } 57 | if(!has_conflict) 58 | { 59 | result = *arena_ptr; 60 | break; 61 | } 62 | } 63 | return result; 64 | } 65 | 66 | internal void 67 | tctx_set_thread_name(String8 string) 68 | { 69 | TCTX *tctx = tctx_get_equipped(); 70 | U64 size = ClampTop(string.size, sizeof(tctx->thread_name)); 71 | MemoryCopy(tctx->thread_name, string.str, size); 72 | tctx->thread_name_size = size; 73 | } 74 | 75 | internal String8 76 | tctx_get_thread_name(void) 77 | { 78 | TCTX *tctx = tctx_get_equipped(); 79 | String8 result = str8(tctx->thread_name, tctx->thread_name_size); 80 | return result; 81 | } 82 | 83 | internal void 84 | tctx_write_srcloc(char *file_name, U64 line_number) 85 | { 86 | TCTX *tctx = tctx_get_equipped(); 87 | tctx->file_name = file_name; 88 | tctx->line_number = line_number; 89 | } 90 | 91 | internal void 92 | tctx_read_srcloc(char **file_name, U64 *line_number) 93 | { 94 | TCTX *tctx = tctx_get_equipped(); 95 | *file_name = tctx->file_name; 96 | *line_number = tctx->line_number; 97 | } 98 | -------------------------------------------------------------------------------- /src/base/base_thread_context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_THREAD_CONTEXT_H 5 | #define BASE_THREAD_CONTEXT_H 6 | 7 | //////////////////////////////// 8 | // NOTE(allen): Thread Context 9 | 10 | typedef struct TCTX TCTX; 11 | struct TCTX 12 | { 13 | Arena *arenas[2]; 14 | 15 | U8 thread_name[32]; 16 | U64 thread_name_size; 17 | 18 | char *file_name; 19 | U64 line_number; 20 | }; 21 | 22 | //////////////////////////////// 23 | // NOTE(allen): Thread Context Functions 24 | 25 | internal void tctx_init_and_equip(TCTX *tctx); 26 | internal void tctx_release(void); 27 | internal TCTX* tctx_get_equipped(void); 28 | 29 | internal Arena* tctx_get_scratch(Arena **conflicts, U64 count); 30 | 31 | internal void tctx_set_thread_name(String8 name); 32 | internal String8 tctx_get_thread_name(void); 33 | 34 | internal void tctx_write_srcloc(char *file_name, U64 line_number); 35 | internal void tctx_read_srcloc(char **file_name, U64 *line_number); 36 | #define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__) 37 | 38 | #define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count))) 39 | #define scratch_end(scratch) temp_end(scratch) 40 | 41 | #endif // BASE_THREAD_CONTEXT_H 42 | -------------------------------------------------------------------------------- /src/coff/coff_enum.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef COFF_ENUM_H 5 | #define COFF_ENUM_H 6 | 7 | internal String8 coff_string_from_time_stamp(Arena *arena, COFF_TimeStamp time_stamp); 8 | internal String8 coff_string_from_comdat_select_type(COFF_ComdatSelectType type); 9 | internal String8 coff_string_from_machine_type(COFF_MachineType machine); 10 | internal String8 coff_string_from_flags(Arena *arena, COFF_FileHeaderFlags flags); 11 | internal String8 coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags); 12 | internal String8 coff_string_from_resource_memory_flags(Arena *arena, COFF_ResourceMemoryFlags flags); 13 | internal String8 coff_string_from_import_header_type(COFF_ImportType type); 14 | internal String8 coff_string_from_sym_dtype(COFF_SymDType x); 15 | internal String8 coff_string_from_sym_type(COFF_SymType x); 16 | internal String8 coff_string_from_sym_storage_class(COFF_SymStorageClass x); 17 | internal String8 coff_string_from_weak_ext_type(COFF_WeakExtType x); 18 | internal String8 coff_string_from_reloc_x86(COFF_Reloc_X86 x); 19 | internal String8 coff_string_from_reloc_x64(COFF_Reloc_X64 x); 20 | internal String8 coff_string_from_reloc_arm(COFF_Reloc_Arm x); 21 | internal String8 coff_string_from_reloc_arm64(COFF_Reloc_Arm64 x); 22 | internal String8 coff_string_from_reloc(COFF_MachineType machine, COFF_RelocType x); 23 | 24 | internal COFF_MachineType coff_machine_from_string(String8 string); 25 | internal COFF_ImportType coff_import_header_type_from_string(String8 name); 26 | 27 | #endif // COFF_ENUM_H 28 | -------------------------------------------------------------------------------- /src/ctrl/ctrl_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #undef LAYER_COLOR 5 | #define LAYER_COLOR 0x969696ff 6 | 7 | #include "ctrl_core.c" 8 | -------------------------------------------------------------------------------- /src/dbg_engine/dbg_engine_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "dbg_engine_core.c" 5 | -------------------------------------------------------------------------------- /src/dbg_engine/dbg_engine_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DBG_ENGINE_INC_H 5 | #define DBG_ENGINE_INC_H 6 | 7 | #include "dbg_engine_core.h" 8 | 9 | #endif // DBG_ENGINE_INC_H 10 | -------------------------------------------------------------------------------- /src/dbg_engine/generated/dbg_engine.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | -------------------------------------------------------------------------------- /src/dbg_engine/generated/dbg_engine.meta.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | #ifndef DBG_ENGINE_META_H 7 | #define DBG_ENGINE_META_H 8 | 9 | typedef enum D_CmdKind 10 | { 11 | D_CmdKind_Null, 12 | D_CmdKind_LaunchAndRun, 13 | D_CmdKind_LaunchAndStepInto, 14 | D_CmdKind_Kill, 15 | D_CmdKind_KillAll, 16 | D_CmdKind_Detach, 17 | D_CmdKind_Continue, 18 | D_CmdKind_StepIntoInst, 19 | D_CmdKind_StepOverInst, 20 | D_CmdKind_StepIntoLine, 21 | D_CmdKind_StepOverLine, 22 | D_CmdKind_StepOut, 23 | D_CmdKind_Halt, 24 | D_CmdKind_SoftHaltRefresh, 25 | D_CmdKind_SetThreadIP, 26 | D_CmdKind_RunToLine, 27 | D_CmdKind_Run, 28 | D_CmdKind_Restart, 29 | D_CmdKind_StepInto, 30 | D_CmdKind_StepOver, 31 | D_CmdKind_FreezeThread, 32 | D_CmdKind_ThawThread, 33 | D_CmdKind_FreezeProcess, 34 | D_CmdKind_ThawProcess, 35 | D_CmdKind_FreezeMachine, 36 | D_CmdKind_ThawMachine, 37 | D_CmdKind_FreezeLocalMachine, 38 | D_CmdKind_ThawLocalMachine, 39 | D_CmdKind_FreezeEntity, 40 | D_CmdKind_ThawEntity, 41 | D_CmdKind_SetEntityColor, 42 | D_CmdKind_SetEntityName, 43 | D_CmdKind_Attach, 44 | D_CmdKind_COUNT, 45 | } D_CmdKind; 46 | 47 | global B32 DEV_simulate_lag = 0; 48 | global B32 DEV_draw_ui_text_pos = 0; 49 | global B32 DEV_draw_ui_focus_debug = 0; 50 | global B32 DEV_draw_ui_box_heatmap = 0; 51 | global B32 DEV_eval_compiler_tooltips = 0; 52 | global B32 DEV_eval_watch_key_tooltips = 0; 53 | global B32 DEV_cmd_context_tooltips = 0; 54 | global B32 DEV_updating_indicator = 0; 55 | struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] = 56 | { 57 | {&DEV_simulate_lag, str8_lit_comp("simulate_lag")}, 58 | {&DEV_draw_ui_text_pos, str8_lit_comp("draw_ui_text_pos")}, 59 | {&DEV_draw_ui_focus_debug, str8_lit_comp("draw_ui_focus_debug")}, 60 | {&DEV_draw_ui_box_heatmap, str8_lit_comp("draw_ui_box_heatmap")}, 61 | {&DEV_eval_compiler_tooltips, str8_lit_comp("eval_compiler_tooltips")}, 62 | {&DEV_eval_watch_key_tooltips, str8_lit_comp("eval_watch_key_tooltips")}, 63 | {&DEV_cmd_context_tooltips, str8_lit_comp("cmd_context_tooltips")}, 64 | {&DEV_updating_indicator, str8_lit_comp("updating_indicator")}, 65 | }; 66 | #endif // DBG_ENGINE_META_H 67 | -------------------------------------------------------------------------------- /src/demon/demon_core.mdesk: -------------------------------------------------------------------------------- 1 | //////////////////////////////// 2 | //~ rjf: Event Kind Tables 3 | 4 | @table(name) 5 | DMN_EventKindTable: 6 | { 7 | {Null} 8 | {Error} 9 | {HandshakeComplete} 10 | {CreateProcess} 11 | {ExitProcess} 12 | {CreateThread} 13 | {ExitThread} 14 | {LoadModule} 15 | {UnloadModule} 16 | {Breakpoint} 17 | {Trap} 18 | {SingleStep} 19 | {Exception} 20 | {Halt} 21 | {Memory} 22 | {DebugString} 23 | {SetThreadName} 24 | {SetThreadColor} 25 | {SetBreakpoint} 26 | {UnsetBreakpoint} 27 | } 28 | 29 | @table(name) 30 | DMN_ErrorKindTable: 31 | { 32 | {Null} 33 | {NotAttached} 34 | {UnexpectedFailure} 35 | {InvalidHandle} 36 | } 37 | 38 | @table(name) 39 | DMN_MemoryEventKindTable: 40 | { 41 | {Null} 42 | {Commit} 43 | {Reserve} 44 | {Decommit} 45 | {Release} 46 | } 47 | 48 | @table(name) 49 | DMN_ExceptionKindTable: 50 | { 51 | {Null} 52 | {MemoryRead} 53 | {MemoryWrite} 54 | {MemoryExecute} 55 | {CppThrow} 56 | } 57 | 58 | //////////////////////////////// 59 | //~ rjf: Generators 60 | 61 | @enum DMN_EventKind: 62 | { 63 | @expand(DMN_EventKindTable a) `$(a.name)`, 64 | COUNT 65 | } 66 | 67 | @data(String8) dmn_event_kind_string_table: 68 | { 69 | @expand(DMN_EventKindTable a) `str8_lit_comp("$(a.name)")` 70 | } 71 | 72 | @enum DMN_ErrorKind: 73 | { 74 | @expand(DMN_ErrorKindTable a) `$(a.name)`, 75 | COUNT 76 | } 77 | 78 | @enum DMN_MemoryEventKind: 79 | { 80 | @expand(DMN_MemoryEventKindTable a) `$(a.name)`, 81 | COUNT 82 | } 83 | 84 | @enum DMN_ExceptionKind: 85 | { 86 | @expand(DMN_ExceptionKindTable a) `$(a.name)`, 87 | COUNT 88 | } 89 | 90 | @data(String8) dmn_exception_kind_string_table: 91 | { 92 | @expand(DMN_ExceptionKindTable a) `str8_lit_comp("$(a.name)")` 93 | } 94 | -------------------------------------------------------------------------------- /src/demon/demon_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "demon/demon_core.c" 5 | 6 | #if OS_WINDOWS 7 | # include "demon/win32/demon_core_win32.c" 8 | #elif OS_LINUX 9 | # include "demon/linux/demon_core_linux.c" 10 | #else 11 | # error Demon layer backend not defined for this operating system. 12 | #endif 13 | -------------------------------------------------------------------------------- /src/demon/demon_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DEMON_INC_H 5 | #define DEMON_INC_H 6 | 7 | #include "demon/demon_core.h" 8 | 9 | #if OS_WINDOWS 10 | # include "demon/win32/demon_core_win32.h" 11 | #elif OS_LINUX 12 | # include "demon/linux/demon_core_linux.h" 13 | #else 14 | # error Demon layer backend not defined for this operating system. 15 | #endif 16 | 17 | #endif // DEMON_INC_H 18 | -------------------------------------------------------------------------------- /src/demon/generated/demon.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | C_LINKAGE_BEGIN 7 | String8 dmn_event_kind_string_table[20] = 8 | { 9 | str8_lit_comp("Null"), 10 | str8_lit_comp("Error"), 11 | str8_lit_comp("HandshakeComplete"), 12 | str8_lit_comp("CreateProcess"), 13 | str8_lit_comp("ExitProcess"), 14 | str8_lit_comp("CreateThread"), 15 | str8_lit_comp("ExitThread"), 16 | str8_lit_comp("LoadModule"), 17 | str8_lit_comp("UnloadModule"), 18 | str8_lit_comp("Breakpoint"), 19 | str8_lit_comp("Trap"), 20 | str8_lit_comp("SingleStep"), 21 | str8_lit_comp("Exception"), 22 | str8_lit_comp("Halt"), 23 | str8_lit_comp("Memory"), 24 | str8_lit_comp("DebugString"), 25 | str8_lit_comp("SetThreadName"), 26 | str8_lit_comp("SetThreadColor"), 27 | str8_lit_comp("SetBreakpoint"), 28 | str8_lit_comp("UnsetBreakpoint"), 29 | }; 30 | 31 | String8 dmn_exception_kind_string_table[5] = 32 | { 33 | str8_lit_comp("Null"), 34 | str8_lit_comp("MemoryRead"), 35 | str8_lit_comp("MemoryWrite"), 36 | str8_lit_comp("MemoryExecute"), 37 | str8_lit_comp("CppThrow"), 38 | }; 39 | 40 | C_LINKAGE_END 41 | 42 | -------------------------------------------------------------------------------- /src/demon/generated/demon.meta.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | #ifndef DEMON_META_H 7 | #define DEMON_META_H 8 | 9 | typedef enum DMN_EventKind 10 | { 11 | DMN_EventKind_Null, 12 | DMN_EventKind_Error, 13 | DMN_EventKind_HandshakeComplete, 14 | DMN_EventKind_CreateProcess, 15 | DMN_EventKind_ExitProcess, 16 | DMN_EventKind_CreateThread, 17 | DMN_EventKind_ExitThread, 18 | DMN_EventKind_LoadModule, 19 | DMN_EventKind_UnloadModule, 20 | DMN_EventKind_Breakpoint, 21 | DMN_EventKind_Trap, 22 | DMN_EventKind_SingleStep, 23 | DMN_EventKind_Exception, 24 | DMN_EventKind_Halt, 25 | DMN_EventKind_Memory, 26 | DMN_EventKind_DebugString, 27 | DMN_EventKind_SetThreadName, 28 | DMN_EventKind_SetThreadColor, 29 | DMN_EventKind_SetBreakpoint, 30 | DMN_EventKind_UnsetBreakpoint, 31 | DMN_EventKind_COUNT, 32 | } DMN_EventKind; 33 | 34 | typedef enum DMN_ErrorKind 35 | { 36 | DMN_ErrorKind_Null, 37 | DMN_ErrorKind_NotAttached, 38 | DMN_ErrorKind_UnexpectedFailure, 39 | DMN_ErrorKind_InvalidHandle, 40 | DMN_ErrorKind_COUNT, 41 | } DMN_ErrorKind; 42 | 43 | typedef enum DMN_MemoryEventKind 44 | { 45 | DMN_MemoryEventKind_Null, 46 | DMN_MemoryEventKind_Commit, 47 | DMN_MemoryEventKind_Reserve, 48 | DMN_MemoryEventKind_Decommit, 49 | DMN_MemoryEventKind_Release, 50 | DMN_MemoryEventKind_COUNT, 51 | } DMN_MemoryEventKind; 52 | 53 | typedef enum DMN_ExceptionKind 54 | { 55 | DMN_ExceptionKind_Null, 56 | DMN_ExceptionKind_MemoryRead, 57 | DMN_ExceptionKind_MemoryWrite, 58 | DMN_ExceptionKind_MemoryExecute, 59 | DMN_ExceptionKind_CppThrow, 60 | DMN_ExceptionKind_COUNT, 61 | } DMN_ExceptionKind; 62 | 63 | C_LINKAGE_BEGIN 64 | extern String8 dmn_event_kind_string_table[20]; 65 | extern String8 dmn_exception_kind_string_table[5]; 66 | 67 | C_LINKAGE_END 68 | 69 | #endif // DEMON_META_H 70 | -------------------------------------------------------------------------------- /src/demon/linux/demon_core_linux.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DEMON_CORE_LINUX_H 5 | #define DEMON_CORE_LINUX_H 6 | 7 | #endif // DEMON_CORE_LINUX_H 8 | -------------------------------------------------------------------------------- /src/draw/draw.mdesk: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | @table(name, name_lower, type, default_init) 5 | DR_StackTable: 6 | { 7 | {Tex2DSampleKind tex2d_sample_kind R_Tex2DSampleKind `R_Tex2DSampleKind_Nearest` } 8 | {XForm2D xform2d Mat3x3F32 `{1, 0, 0, 0, 1, 0, 0, 0, 1}` } 9 | {Clip clip Rng2F32 `{0}` } 10 | {Transparency transparency F32 `0` } 11 | } 12 | 13 | @gen 14 | { 15 | @expand(DR_StackTable a) `typedef struct DR_$(a.name)Node DR_$(a.name)Node; struct DR_$(a.name)Node {DR_$(a.name)Node *next; $(a.type) v;};`; 16 | } 17 | 18 | @gen 19 | { 20 | `#define DR_BucketStackDecls struct{\\`; 21 | @expand(DR_StackTable a) `DR_$(a.name)Node *top_$(a.name_lower);\\`; 22 | `}`; 23 | } 24 | 25 | @gen 26 | { 27 | @expand(DR_StackTable a) `read_only global DR_$(a.name)Node dr_nil_$(a.name_lower) = {0, $(a.default_init)};`; 28 | } 29 | 30 | @gen 31 | { 32 | `#define DR_BucketStackInits(b) do{\\`; 33 | @expand(DR_StackTable a) `(b)->top_$(a.name_lower) = &dr_nil_$(a.name_lower);\\`; 34 | `}while(0)`; 35 | } 36 | 37 | @gen 38 | { 39 | `#if 0`; 40 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_push_$(a.name_lower)($(a.type) v);`; 41 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_pop_$(a.name_lower)(void);`; 42 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_top_$(a.name_lower)(void);`; 43 | `#endif`; 44 | } 45 | 46 | @gen @c_file 47 | { 48 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_push_$(a.name_lower)($(a.type) v) {DR_StackPushImpl($(a.name), $(a.name_lower), $(a.type), v);}`; 49 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_pop_$(a.name_lower)(void) {DR_StackPopImpl($(a.name), $(a.name_lower), $(a.type));}`; 50 | @expand(DR_StackTable a) `internal $(a.type) $(=>35) dr_top_$(a.name_lower)(void) {DR_StackTopImpl($(a.name), $(a.name_lower), $(a.type));}`; 51 | } 52 | 53 | @gen 54 | { 55 | `#if 0`; 56 | @expand(DR_StackTable a) `#define DR_$(a.name)Scope(v) $(=>35) DeferLoop(dr_push_$(a.name_lower)(v), dr_pop_$(a.name_lower)())`; 57 | `#endif`; 58 | } 59 | -------------------------------------------------------------------------------- /src/draw/generated/draw.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | internal R_Tex2DSampleKind dr_push_tex2d_sample_kind(R_Tex2DSampleKind v) {DR_StackPushImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind, v);} 7 | internal Mat3x3F32 dr_push_xform2d(Mat3x3F32 v) {DR_StackPushImpl(XForm2D, xform2d, Mat3x3F32, v);} 8 | internal Rng2F32 dr_push_clip(Rng2F32 v) {DR_StackPushImpl(Clip, clip, Rng2F32, v);} 9 | internal F32 dr_push_transparency(F32 v) {DR_StackPushImpl(Transparency, transparency, F32, v);} 10 | internal R_Tex2DSampleKind dr_pop_tex2d_sample_kind(void) {DR_StackPopImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind);} 11 | internal Mat3x3F32 dr_pop_xform2d(void) {DR_StackPopImpl(XForm2D, xform2d, Mat3x3F32);} 12 | internal Rng2F32 dr_pop_clip(void) {DR_StackPopImpl(Clip, clip, Rng2F32);} 13 | internal F32 dr_pop_transparency(void) {DR_StackPopImpl(Transparency, transparency, F32);} 14 | internal R_Tex2DSampleKind dr_top_tex2d_sample_kind(void) {DR_StackTopImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind);} 15 | internal Mat3x3F32 dr_top_xform2d(void) {DR_StackTopImpl(XForm2D, xform2d, Mat3x3F32);} 16 | internal Rng2F32 dr_top_clip(void) {DR_StackTopImpl(Clip, clip, Rng2F32);} 17 | internal F32 dr_top_transparency(void) {DR_StackTopImpl(Transparency, transparency, F32);} 18 | -------------------------------------------------------------------------------- /src/draw/generated/draw.meta.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | #ifndef DRAW_META_H 7 | #define DRAW_META_H 8 | 9 | typedef struct DR_Tex2DSampleKindNode DR_Tex2DSampleKindNode; struct DR_Tex2DSampleKindNode {DR_Tex2DSampleKindNode *next; R_Tex2DSampleKind v;}; 10 | typedef struct DR_XForm2DNode DR_XForm2DNode; struct DR_XForm2DNode {DR_XForm2DNode *next; Mat3x3F32 v;}; 11 | typedef struct DR_ClipNode DR_ClipNode; struct DR_ClipNode {DR_ClipNode *next; Rng2F32 v;}; 12 | typedef struct DR_TransparencyNode DR_TransparencyNode; struct DR_TransparencyNode {DR_TransparencyNode *next; F32 v;}; 13 | #define DR_BucketStackDecls struct{\ 14 | DR_Tex2DSampleKindNode *top_tex2d_sample_kind;\ 15 | DR_XForm2DNode *top_xform2d;\ 16 | DR_ClipNode *top_clip;\ 17 | DR_TransparencyNode *top_transparency;\ 18 | } 19 | read_only global DR_Tex2DSampleKindNode dr_nil_tex2d_sample_kind = {0, R_Tex2DSampleKind_Nearest}; 20 | read_only global DR_XForm2DNode dr_nil_xform2d = {0, {1, 0, 0, 0, 1, 0, 0, 0, 1}}; 21 | read_only global DR_ClipNode dr_nil_clip = {0, {0}}; 22 | read_only global DR_TransparencyNode dr_nil_transparency = {0, 0}; 23 | #define DR_BucketStackInits(b) do{\ 24 | (b)->top_tex2d_sample_kind = &dr_nil_tex2d_sample_kind;\ 25 | (b)->top_xform2d = &dr_nil_xform2d;\ 26 | (b)->top_clip = &dr_nil_clip;\ 27 | (b)->top_transparency = &dr_nil_transparency;\ 28 | }while(0) 29 | #if 0 30 | internal R_Tex2DSampleKind dr_push_tex2d_sample_kind(R_Tex2DSampleKind v); 31 | internal Mat3x3F32 dr_push_xform2d(Mat3x3F32 v); 32 | internal Rng2F32 dr_push_clip(Rng2F32 v); 33 | internal F32 dr_push_transparency(F32 v); 34 | internal R_Tex2DSampleKind dr_pop_tex2d_sample_kind(void); 35 | internal Mat3x3F32 dr_pop_xform2d(void); 36 | internal Rng2F32 dr_pop_clip(void); 37 | internal F32 dr_pop_transparency(void); 38 | internal R_Tex2DSampleKind dr_top_tex2d_sample_kind(void); 39 | internal Mat3x3F32 dr_top_xform2d(void); 40 | internal Rng2F32 dr_top_clip(void); 41 | internal F32 dr_top_transparency(void); 42 | #endif 43 | #if 0 44 | #define DR_Tex2DSampleKindScope(v) DeferLoop(dr_push_tex2d_sample_kind(v), dr_pop_tex2d_sample_kind()) 45 | #define DR_XForm2DScope(v) DeferLoop(dr_push_xform2d(v), dr_pop_xform2d()) 46 | #define DR_ClipScope(v) DeferLoop(dr_push_clip(v), dr_pop_clip()) 47 | #define DR_TransparencyScope(v) DeferLoop(dr_push_transparency(v), dr_pop_transparency()) 48 | #endif 49 | #endif // DRAW_META_H 50 | -------------------------------------------------------------------------------- /src/dwarf/dwarf_coff.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal B32 5 | dw_is_dwarf_present_coff_section_table(String8 raw_image, 6 | String8 string_table, 7 | U64 section_count, 8 | COFF_SectionHeader *section_table) 9 | { 10 | B32 is_dwarf_present = 0; 11 | 12 | for (U64 i = 0; i < section_count; ++i) { 13 | COFF_SectionHeader *header = §ion_table[i]; 14 | String8 name = coff_name_from_section_header(string_table, header); 15 | 16 | DW_SectionKind s = dw_section_kind_from_string(name); 17 | if (s == DW_Section_Null) { 18 | s = dw_section_dwo_kind_from_string(name); 19 | } 20 | 21 | is_dwarf_present = s != DW_Section_Null; 22 | if (is_dwarf_present) { 23 | break; 24 | } 25 | } 26 | 27 | return is_dwarf_present; 28 | } 29 | 30 | internal DW_Input 31 | dw_input_from_coff_section_table(Arena *arena, 32 | String8 raw_image, 33 | String8 string_table, 34 | U64 section_count, 35 | COFF_SectionHeader *section_table) 36 | { 37 | DW_Input input = {0}; 38 | B32 sect_status[ArrayCount(input.sec)] = {0}; 39 | 40 | for (U64 i = 0; i < section_count; ++i) { 41 | COFF_SectionHeader *header = §ion_table[i]; 42 | Rng1U64 raw_data_range = rng_1u64(header->foff, header->foff + header->fsize); 43 | String8 name = coff_name_from_section_header(string_table, header); 44 | 45 | DW_SectionKind s = dw_section_kind_from_string(name); 46 | B32 is_dwo = 0; 47 | if (s == DW_Section_Null) { 48 | s = dw_section_dwo_kind_from_string(name); 49 | is_dwo = 1; 50 | } 51 | 52 | if (s != DW_Section_Null) { 53 | if (sect_status[s]) { 54 | Assert(!"too many debug sections with identical name, picking first"); 55 | } else { 56 | sect_status[s] = 1; 57 | DW_Section *d = &input.sec[s]; 58 | d->name = push_str8_copy(arena, name); 59 | d->data = str8_substr(raw_image, raw_data_range); 60 | d->is_dwo = is_dwo; 61 | } 62 | } 63 | } 64 | 65 | return input; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/dwarf/dwarf_coff.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DWARF_COFF_H 5 | #define DWARF_COFF_H 6 | 7 | internal DW_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, String8 string_table, U64 section_count, COFF_SectionHeader *section_table); 8 | 9 | #endif // DWARF_COFF_H 10 | 11 | -------------------------------------------------------------------------------- /src/dwarf/dwarf_elf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DWARF_ELF_H 5 | #define DWARF_ELF_H 6 | 7 | internal DW_Input dw_input_from_elf_section_table(Arena *arena, String8 raw_image, ELF_BinInfo *bin); 8 | 9 | #endif // DWARF_ELF_H 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/dwarf/dwarf_enum.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef DWARF_ENUM_H 5 | #define DWARF_ENUM_H 6 | 7 | internal String8 dw_string_from_expr_op(Arena *arena, DW_Version ver, DW_Ext ext, DW_ExprOp op); 8 | internal String8 dw_string_from_tag_kind(Arena *arena, DW_TagKind kind); 9 | internal String8 dw_string_from_attrib_kind(Arena *arena, DW_Version ver, DW_Ext ext, DW_AttribKind kind); 10 | internal String8 dw_string_from_form_kind(Arena *arena, DW_Version ver, DW_FormKind kind); 11 | internal String8 dw_string_access_kind(Arena *arena, DW_AccessKind kind); 12 | 13 | //internal String8 dw_string_from_register(Arena *arena, Arch arch, U64 reg_id); 14 | 15 | #endif // DWARF_ENUM_H 16 | 17 | -------------------------------------------------------------------------------- /src/dwarf/dwarf_notes.txt: -------------------------------------------------------------------------------- 1 | --- DWARF NOTES --------------------------------------------------------------- 2 | 3 | DWARF V4 Spec: http://www.dwarfstd.org/doc/DWARF4.pdf 4 | DWARF V5 Spec: http://www.dwarfstd.org/doc/DWARF5.pdf 5 | 6 | ------------------------------------------------------------------------------- 7 | 8 | $ (2021/04/30) On .debug_pubtypes, .debug_pubnames, and .debug_names: 9 | 10 | .debug_pubtypes and .debug_pubnames are tables that map from a string (the name 11 | of a type or function respectively) to an offset into .debug_info, which is the 12 | offset of the Debug Information Entry (DIE, in DWARF terminology) of the info 13 | associated with the string. THESE TWO SECTIONS ARE OPTIONAL. They don't show up 14 | in every DWARF-holding file, and so they cannot be relied upon as acceleration 15 | structures. But we're going to support parsing them, to make things a bit nicer 16 | in cases where they are present. DWARF doesn't have much in the way of acceler- 17 | ation structures built in, so our rationale is that we should take anything we 18 | can get to make the format a bit more in some subset of the possible cases. 19 | 20 | .debug_names is a DWARF V5 section that is intended to replace .debug_pubtypes 21 | and .debug_pubnames. However, even in cases when DWARF V5 is produced at the 22 | time of writing this, we have not found .debug_names sections being produced. 23 | We did not exhaustively test all compilers and configurations, but it seems 24 | that it is not well-supported at all by major compilers, and there's a very low 25 | probability that a user will have that section, so our current thinking is 26 | that there's no point in supporting it right now. 27 | 28 | ------------------------------------------------------------------------------- 29 | 30 | $ (2021/04/30) On producing DWARF V5 with Clang: 31 | 32 | https://lists.llvm.org/pipermail/llvm-dev/2018-August/125068.html 33 | 34 | By default it looks like (at the time of writing this) that Clang, by default, 35 | will produce DWARF V4. To produce DWARF V5, however, you can use the -gdwarf-5 36 | option. Even when that option is used, it seems that some features of V5 are 37 | not used (for example, .debug_names). 38 | 39 | The above link also says that this will produce .debug_names, but it doesn't as 40 | of Clang 10. 41 | 42 | ------------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /src/elf/elf_parse.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef ELF_PARSE_H 5 | #define ELF_PARSE_H 6 | 7 | //////////////////////////////// 8 | 9 | typedef struct ELF_BinInfo 10 | { 11 | ELF_Hdr64 hdr; 12 | Rng1U64 sh_name_range; 13 | } ELF_BinInfo; 14 | 15 | typedef struct ELF_Shdr64Array 16 | { 17 | U64 count; 18 | ELF_Shdr64 *v; 19 | } ELF_Shdr64Array; 20 | 21 | typedef struct ELF_GnuDebugLink 22 | { 23 | String8 path; 24 | U32 checksum; 25 | } ELF_GnuDebugLink; 26 | 27 | //////////////////////////////// 28 | 29 | internal B32 elf_check_magic(String8 data); 30 | internal ELF_BinInfo elf_bin_from_data(String8 data); 31 | 32 | internal ELF_Shdr64Array elf_shdr64_array_from_bin(Arena *arena, String8 raw_data, ELF_Hdr64 *hdr); 33 | internal String8 elf_name_from_shdr64(String8 raw_data, ELF_Hdr64 *hdr, Rng1U64 sh_name_range, ELF_Shdr64 *shdr); 34 | internal U64 elf_base_addr_from_bin(ELF_Hdr64 *hdr); 35 | 36 | #endif // ELF_PARSE_H 37 | -------------------------------------------------------------------------------- /src/eval/eval_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "eval/eval_core.c" 5 | #include "eval/eval_types.c" 6 | #include "eval/eval_parse.c" 7 | #include "eval/eval_ir.c" 8 | #include "eval/eval_interpret.c" 9 | -------------------------------------------------------------------------------- /src/eval/eval_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef EVAL_INC_H 5 | #define EVAL_INC_H 6 | 7 | #include "eval/eval_core.h" 8 | #include "eval/eval_types.h" 9 | #include "eval/eval_parse.h" 10 | #include "eval/eval_ir.h" 11 | #include "eval/eval_interpret.h" 12 | 13 | #endif // EVAL_INC_H 14 | -------------------------------------------------------------------------------- /src/eval/eval_interpret.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef EVAL_INTERPRET_H 5 | #define EVAL_INTERPRET_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Interpretation Context 9 | 10 | typedef struct E_InterpretCtx E_InterpretCtx; 11 | struct E_InterpretCtx 12 | { 13 | void *space_rw_user_data; 14 | E_SpaceRWFunction *space_read; 15 | E_SpaceRWFunction *space_write; 16 | E_Space primary_space; 17 | Arch reg_arch; 18 | E_Space reg_space; 19 | U64 reg_unwind_count; 20 | U64 *module_base; 21 | U64 *frame_base; 22 | U64 *tls_base; 23 | }; 24 | 25 | //////////////////////////////// 26 | //~ rjf: Globals 27 | 28 | thread_static E_InterpretCtx *e_interpret_ctx = 0; 29 | 30 | //////////////////////////////// 31 | //~ rjf: Context Selection Functions (Selection Required For All Subsequent APIs) 32 | 33 | internal void e_select_interpret_ctx(E_InterpretCtx *ctx, RDI_Parsed *primary_rdi, U64 ip_voff); 34 | 35 | //////////////////////////////// 36 | //~ rjf: Space Reading Helpers 37 | 38 | internal U64 e_space_gen(E_Space space); 39 | internal B32 e_space_read(E_Space space, void *out, Rng1U64 range); 40 | internal B32 e_space_write(E_Space space, void *in, Rng1U64 range); 41 | 42 | //////////////////////////////// 43 | //~ rjf: Interpretation Functions 44 | 45 | internal E_Interpretation e_interpret(String8 bytecode); 46 | 47 | #endif // EVAL_INTERPRET_H 48 | -------------------------------------------------------------------------------- /src/eval/eval_parse.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef EVAL_PARSE_H 5 | #define EVAL_PARSE_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Tokenization Functions 9 | 10 | #define e_token_at_it(it, arr) (((arr)->v <= (it) && (it) < (arr)->v+(arr)->count) ? (*(it)) : e_token_zero()) 11 | internal E_Token e_token_zero(void); 12 | internal void e_token_chunk_list_push(Arena *arena, E_TokenChunkList *list, U64 chunk_size, E_Token *token); 13 | internal E_TokenArray e_token_array_from_chunk_list(Arena *arena, E_TokenChunkList *list); 14 | internal E_TokenArray e_token_array_from_text(Arena *arena, String8 text); 15 | internal E_TokenArray e_token_array_make_first_opl(E_Token *first, E_Token *opl); 16 | 17 | //////////////////////////////// 18 | //~ rjf: Expression Tree Building Functions 19 | 20 | internal E_Expr *e_push_expr(Arena *arena, E_ExprKind kind, Rng1U64 range); 21 | internal void e_expr_insert_child(E_Expr *parent, E_Expr *prev, E_Expr *child); 22 | internal void e_expr_push_child(E_Expr *parent, E_Expr *child); 23 | internal void e_expr_remove_child(E_Expr *parent, E_Expr *child); 24 | internal E_Expr *e_expr_ref(Arena *arena, E_Expr *ref); 25 | internal E_Expr *e_expr_copy(Arena *arena, E_Expr *src); 26 | internal void e_expr_list_push(Arena *arena, E_ExprList *list, E_Expr *expr); 27 | 28 | //////////////////////////////// 29 | //~ rjf: Expression Tree -> String Conversions 30 | 31 | internal void e_append_strings_from_expr(Arena *arena, E_Expr *expr, String8 parent_expr_string, String8List *out); 32 | internal String8 e_string_from_expr(Arena *arena, E_Expr *expr, String8 parent_expr_string); 33 | 34 | //////////////////////////////// 35 | //~ rjf: Parsing Functions 36 | 37 | internal E_TypeKey e_leaf_type_from_name(String8 name); 38 | internal E_TypeKey e_type_key_from_expr(E_Expr *expr); 39 | internal E_Parse e_push_type_parse_from_text_tokens(Arena *arena, String8 text, E_TokenArray tokens); 40 | internal E_Parse e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray tokens, S64 max_precedence, U64 max_chain_count); 41 | internal E_Parse e_push_parse_from_string(Arena *arena, String8 text); 42 | 43 | #endif // EVAL_PARSE_H 44 | -------------------------------------------------------------------------------- /src/eval_visualization/eval_visualization_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "eval_visualization_core.c" 5 | -------------------------------------------------------------------------------- /src/eval_visualization/eval_visualization_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef EVAL_VISUALIZATION_INC_H 5 | #define EVAL_VISUALIZATION_INC_H 6 | 7 | #include "eval_visualization_core.h" 8 | 9 | #endif // EVAL_VISUALIZATION_INC_H 10 | -------------------------------------------------------------------------------- /src/font_provider/font_provider.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Basic Type Functions 6 | 7 | internal FP_Handle 8 | fp_handle_zero(void) 9 | { 10 | FP_Handle result = {0}; 11 | return result; 12 | } 13 | 14 | internal B32 15 | fp_handle_match(FP_Handle a, FP_Handle b) 16 | { 17 | return (a.u64[0] == b.u64[0] && a.u64[1] == b.u64[1]); 18 | } 19 | -------------------------------------------------------------------------------- /src/font_provider/font_provider.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef FONT_PROVIDER_H 5 | #define FONT_PROVIDER_H 6 | 7 | #define fp_hook C_LINKAGE 8 | 9 | //////////////////////////////// 10 | //~ rjf: Types 11 | 12 | typedef U32 FP_RasterFlags; 13 | enum 14 | { 15 | FP_RasterFlag_Smooth = (1<<0), 16 | FP_RasterFlag_Hinted = (1<<1), 17 | }; 18 | 19 | typedef struct FP_Handle FP_Handle; 20 | struct FP_Handle 21 | { 22 | U64 u64[2]; 23 | }; 24 | 25 | typedef struct FP_Metrics FP_Metrics; 26 | struct FP_Metrics 27 | { 28 | F32 design_units_per_em; 29 | F32 ascent; 30 | F32 descent; 31 | F32 line_gap; 32 | F32 capital_height; 33 | }; 34 | 35 | typedef struct FP_RasterResult FP_RasterResult; 36 | struct FP_RasterResult 37 | { 38 | Vec2S16 atlas_dim; 39 | void *atlas; 40 | F32 advance; 41 | }; 42 | 43 | //////////////////////////////// 44 | //~ rjf: Basic Type Functions 45 | 46 | internal FP_Handle fp_handle_zero(void); 47 | internal B32 fp_handle_match(FP_Handle a, FP_Handle b); 48 | 49 | //////////////////////////////// 50 | //~ rjf: Backend Hooks 51 | 52 | fp_hook void fp_init(void); 53 | fp_hook FP_Handle fp_font_open(String8 path); 54 | fp_hook FP_Handle fp_font_open_from_static_data_string(String8 *data_ptr); 55 | fp_hook void fp_font_close(FP_Handle handle); 56 | fp_hook FP_Metrics fp_metrics_from_font(FP_Handle font); 57 | fp_hook NO_ASAN FP_RasterResult fp_raster(Arena *arena, FP_Handle font, F32 size, FP_RasterFlags flags, String8 string); 58 | 59 | #endif // FONT_PROVIDER_H 60 | -------------------------------------------------------------------------------- /src/font_provider/font_provider_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "font_provider.c" 5 | 6 | #if FP_BACKEND == FP_BACKEND_DWRITE 7 | # include "dwrite/font_provider_dwrite.c" 8 | #elif FP_BACKEND == FP_BACKEND_FREETYPE 9 | # include "freetype/font_provider_freetype.c" 10 | #else 11 | # error Font provider backend not specified. 12 | #endif 13 | -------------------------------------------------------------------------------- /src/font_provider/font_provider_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef FONT_PROVIDER_INC_H 5 | #define FONT_PROVIDER_INC_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Backend Constants 9 | 10 | #define FP_BACKEND_DWRITE 1 11 | #define FP_BACKEND_FREETYPE 2 12 | 13 | //////////////////////////////// 14 | //~ rjf: Decide On Backend 15 | 16 | #if !defined(FP_BACKEND) 17 | # if OS_WINDOWS 18 | # define FP_BACKEND FP_BACKEND_DWRITE 19 | # elif OS_LINUX 20 | # define FP_BACKEND FP_BACKEND_FREETYPE 21 | # endif 22 | #endif 23 | 24 | //////////////////////////////// 25 | //~ rjf: Main Includes 26 | 27 | #include "font_provider.h" 28 | 29 | //////////////////////////////// 30 | //~ rjf: Backend Includes 31 | 32 | #if FP_BACKEND == FP_BACKEND_DWRITE 33 | # include "dwrite/font_provider_dwrite.h" 34 | #elif FP_BACKEND == FP_BACKEND_FREETYPE 35 | # include "freetype/font_provider_freetype.h" 36 | #else 37 | # error Font provider backend not specified. 38 | #endif 39 | 40 | #endif // FONT_PROVIDER_INC_H 41 | -------------------------------------------------------------------------------- /src/font_provider/freetype/font_provider_freetype.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef FONT_PROVIDER_FREETYPE_H 5 | #define FONT_PROVIDER_FREETYPE_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Freetype Includes 9 | 10 | #undef internal 11 | #include 12 | #include FT_FREETYPE_H 13 | #include FT_GLYPH_H 14 | #define internal static 15 | 16 | //////////////////////////////// 17 | //~ rjf: State Types 18 | 19 | typedef struct FP_FT_Font FP_FT_Font; 20 | struct FP_FT_Font 21 | { 22 | FT_Face face; 23 | }; 24 | 25 | typedef struct FP_FT_State FP_FT_State; 26 | struct FP_FT_State 27 | { 28 | Arena *arena; 29 | FT_Library library; 30 | }; 31 | 32 | //////////////////////////////// 33 | //~ rjf: Globals 34 | 35 | global FP_FT_State *fp_ft_state = 0; 36 | 37 | //////////////////////////////// 38 | //~ rjf: Helpers 39 | 40 | internal FP_FT_Font fp_ft_font_from_handle(FP_Handle handle); 41 | internal FP_Handle fp_ft_handle_from_font(FP_FT_Font font); 42 | 43 | #endif // FONT_PROVIDER_FREETYPE_H 44 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_arena.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal String8 5 | push_cstr(Arena *arena, String8 str) 6 | { 7 | U64 buffer_size = str.size + 1; 8 | U8 *buffer = push_array_no_zero(arena, U8, buffer_size); 9 | MemoryCopy(buffer, str.str, str.size); 10 | buffer[str.size] = 0; 11 | String8 result = str8(buffer, buffer_size); 12 | return result; 13 | } 14 | 15 | internal U32 * 16 | push_u32(Arena *arena, U32 value) 17 | { 18 | U32 *result = push_array_no_zero(arena, U32, 1); 19 | *result = value; 20 | return result; 21 | } 22 | 23 | internal U64 * 24 | push_u64(Arena *arena, U64 value) 25 | { 26 | U64 *result = push_array_no_zero(arena, U64, 1); 27 | *result = value; 28 | return result; 29 | } 30 | 31 | internal U32 * 32 | push_array_copy_u32(Arena *arena, U32 *v, U64 count) 33 | { 34 | U32 *result = push_array_no_zero(arena, U32, count); 35 | MemoryCopyTyped(result, v, count); 36 | return result; 37 | } 38 | 39 | internal U64 * 40 | push_array_copy_u64(Arena *arena, U64 *v, U64 count) 41 | { 42 | U64 *result = push_array_no_zero(arena, U64, count); 43 | MemoryCopyTyped(result, v, count); 44 | return result; 45 | } 46 | 47 | internal U64 ** 48 | push_matrix_u64(Arena *arena, U64 rows, U64 columns) 49 | { 50 | U64 **result = push_array_no_zero(arena, U64 *, rows); 51 | for (U64 row_idx = 0; row_idx < rows; row_idx += 1) { 52 | result[row_idx] = push_array(arena, U64, columns); 53 | } 54 | return result; 55 | } 56 | 57 | internal Arena ** 58 | alloc_fixed_size_arena_array(Arena *arena, U64 count, U64 res, U64 cmt) 59 | { 60 | U64 data_size = sizeof(count) + sizeof(Arena *) * count; 61 | U8 *data = push_array_no_zero(arena, U8, data_size); 62 | U64 *count_ptr = (U64 *)data; 63 | Arena **arr = (Arena **)(count_ptr + 1); 64 | *count_ptr = count; 65 | 66 | ArenaParams params = {0}; 67 | params.reserve_size = res; 68 | params.commit_size = cmt; 69 | 70 | for (U64 i = 0; i < count; i += 1) { 71 | Arena *fixed_arena = arena_alloc_(¶ms); 72 | arr[i] = fixed_arena; 73 | } 74 | 75 | return arr; 76 | } 77 | 78 | internal void 79 | release_arena_array(Arena **arr) 80 | { 81 | U64 *count_ptr = (U64 *)arr - 1; 82 | U64 count = *count_ptr; 83 | for (U64 i = 0; i < count; i += 1) { 84 | arena_release(arr[i]); 85 | arr[i] = 0; 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal U32 * push_u32(Arena *arena, U32 value); 7 | internal U64 * push_u64(Arena *arena, U64 value); 8 | internal U32 * push_array_copy_u32(Arena *arena, U32 *v, U64 count); 9 | internal U64 * push_array_copy_u64(Arena *arena, U64 *v, U64 count); 10 | internal U64 ** push_matrix_u64(Arena *arena, U64 rows, U64 columns); 11 | internal String8 push_cstr(Arena *arena, String8 str); 12 | 13 | internal Arena ** alloc_fixed_size_arena_array(Arena *arena, U64 count, U64 res, U64 cmt); 14 | internal void release_arena_array(Arena **arr); 15 | 16 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_arrays.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef struct U64Node 7 | { 8 | struct U64Node *next; 9 | U64 data; 10 | } U64Node; 11 | 12 | typedef struct U64List 13 | { 14 | U64 count; 15 | U64Node *first; 16 | U64Node *last; 17 | } U64List; 18 | 19 | typedef struct VoidNode 20 | { 21 | struct VoidNode *next; 22 | void *v; 23 | } VoidNode; 24 | 25 | //////////////////////////////// 26 | 27 | internal U64Node * u64_list_push(Arena *arena, U64List *list, U64 data); 28 | internal void u64_list_concat_in_place(U64List *list, U64List *to_concat); 29 | internal U64Array u64_array_from_list(Arena *arena, U64List *list); 30 | 31 | internal U64Array u64_array_remove_duplicates(Arena *arena, U64Array in); 32 | 33 | internal void u32_array_sort(U64 count, U32 *v); 34 | internal void u64_array_sort(U64 count, U64 *v); 35 | internal B32 u32_array_compare(U32Array a, U32Array b); 36 | 37 | internal U64 sum_array_u64(U64 count, U64 *v); 38 | internal U64 max_array_u64(U64 count, U64 *v); 39 | internal U64 min_array_u64(U64 count, U64 *v); 40 | 41 | internal void counts_to_offsets_array_u32(U64 count, U32 *arr); 42 | internal void counts_to_offsets_array_u64(U64 count, U64 *arr); 43 | 44 | internal U32 * offsets_from_counts_array_u32(Arena *arena, U32 *v, U64 count); 45 | internal U64 * offsets_from_counts_array_u64(Arena *arena, U64 *v, U64 count); 46 | 47 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_bit_array.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal U32Array bit_array_init32(Arena *arena, U64 word_count); 7 | internal U64 bit_array_scan_left_to_right32(U32Array bit_array, U64 lo, U64 hi, B32 state); 8 | internal U64 bit_array_scan_right_to_left32(U32Array bit_array, U64 lo, U64 hi, B32 state); 9 | internal Rng1U64 bit_array_scan_left_to_right32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count); 10 | internal Rng1U64 bit_array_scan_right_to_left32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count); 11 | internal B32 byte_scan_right_to_left(U8 *start, U8 *opl, U8 byte, U64 *offset_out); 12 | internal U64 bit_array_find_next_unset_bit32(U32Array bit_array); 13 | internal U64 bit_array_find_next_set_bit32(U32Array bit_array); 14 | internal void bit_array_set_bit32(U32Array bit_array, U64 idx, B32 state); 15 | internal void bit_array_set_bit_range32(U32Array bit_array, Rng1U64 range, B32 state); 16 | internal U32 bit_array_get_bit32(U32Array bit_array, U64 idx); 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_blake3.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | #if defined(__clang__) && defined(__x86_64__) 7 | # if defined(__IMMINTRIN_H) 8 | # error "include this header before immintrin.h / x86intrin.h / intrin.h" 9 | # endif 10 | # pragma clang diagnostic push 11 | # pragma clang diagnostic ignored "-Wreserved-macro-identifier" 12 | # pragma push_macro("__AVX__") 13 | # pragma push_macro("__AVX2__") 14 | # pragma push_macro("__SSE4_1__") 15 | # pragma push_macro("__AVX512F__") 16 | # pragma push_macro("__AVX512VL__") 17 | # define __AVX__ 1 18 | # define __AVX2__ 1 19 | # define __SSE4_1__ 1 20 | # define __AVX512F__ 1 21 | # define __AVX512VL__ 1 22 | # include 23 | # pragma pop_macro("__AVX512VL__") 24 | # pragma pop_macro("__AVX512F__") 25 | # pragma pop_macro("__SSE4_1__") 26 | # pragma pop_macro("__AVX2__") 27 | # pragma pop_macro("__AVX__") 28 | # pragma clang diagnostic pop 29 | #endif 30 | 31 | #include "third_party/blake3/c/blake3.h" 32 | 33 | static void 34 | blake3(void* out, size_t outlen, void* in, size_t inlen) 35 | { 36 | blake3_hasher hasher; 37 | blake3_hasher_init(&hasher); 38 | blake3_hasher_update(&hasher, in, inlen); 39 | blake3_hasher_finalize(&hasher, (uint8_t*)out, outlen); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_blake3_asm.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "../third_party_ext/blake3/blake3_portable.c" 5 | 6 | #if defined(__aarch64__) || defined(_M_ARM64) 7 | #include "../third_party_ext/blake3/blake3_neon.c" 8 | #endif 9 | 10 | #include "../third_party_ext/blake3/blake3_dispatch.c" 11 | #include "../third_party_ext/blake3/blake3.c" 12 | 13 | #pragma comment (lib, "blake3") 14 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_blake3_asm.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_BLAKE3_H 5 | #define BASE_BLAKE3_H 6 | 7 | #include "../third_party_ext/blake3/blake3.h" 8 | 9 | static void 10 | blake3(void* out, size_t outlen, void* in, size_t inlen) 11 | { 12 | blake3_hasher hasher; 13 | blake3_hasher_init(&hasher); 14 | blake3_hasher_update(&hasher, in, inlen); 15 | blake3_hasher_finalize(&hasher, (uint8_t*)out, outlen); 16 | } 17 | 18 | #endif // BASE_BLAKE3_H 19 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_crc32.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal U32 update_crc32(U32 crc, U8 *ptr, U64 size); 7 | internal U32 crc32_from_string(String8 string); 8 | 9 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "base_core.c" 5 | #include "base_strings.c" 6 | #include "base_arena.c" 7 | #include "base_arrays.c" 8 | #include "base_bit_array.c" 9 | #include "base_crc32.c" 10 | #include "base_md5.c" 11 | 12 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | #include "base_core.h" 7 | #include "base_strings.h" 8 | #include "base_arena.h" 9 | #include "base_arrays.h" 10 | #include "base_blake3.h" 11 | #include "base_bit_array.h" 12 | #include "base_crc32.h" 13 | #include "base_md5.h" 14 | 15 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_md5.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal MD5Hash 5 | md5_hash_from_string(String8 data) 6 | { 7 | MD5_CTX ctx; MD5_Init(&ctx); 8 | MD5_Update(&ctx, (void*)data.str, safe_cast_u32(data.size)); 9 | MD5Hash hash; MD5_Final((unsigned char*)&hash, &ctx); 10 | return hash; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_md5.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef struct MD5Hash 7 | { 8 | U8 value[16]; 9 | } MD5Hash; 10 | 11 | internal MD5Hash md5_hash_from_string(String8 data); 12 | 13 | -------------------------------------------------------------------------------- /src/linker/base_ext/base_strings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | #define MemoryCopyStr8(dst, s) MemoryCopy(dst, (s).str, (s).size) 7 | 8 | internal int str8_compar(String8 a, String8 b, B32 ignore_case); 9 | internal int str8_compar_ignore_case(const void *a, const void *b); 10 | internal int str8_compar_case_sensitive(const void *a, const void *b); 11 | 12 | #define str8_list_push_struct(a,l,d) str8_list_push_raw(a, l, d, sizeof(*d)) 13 | internal String8Node * str8_list_push_raw(Arena *arena, String8List *list, void *data_ptr, U64 data_size); 14 | internal U64 str8_list_push_pad(Arena *arena, String8List *list, U64 offset, U64 align); 15 | internal U64 str8_list_push_pad_front(Arena *arena, String8List *list, U64 offset, U64 align); 16 | internal String8List str8_list_arr_concat(String8List *v, U64 count); 17 | internal String8Node * str8_list_push_many(Arena *arena, String8List *list, U64 count); 18 | 19 | // TODO: remove 20 | internal String8Node * str8_list_pop_front(String8List *list); 21 | 22 | internal U64 hash_from_str8(String8 string); 23 | 24 | -------------------------------------------------------------------------------- /src/linker/lnk_cmd_line.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef struct LNK_CmdOption 7 | { 8 | struct LNK_CmdOption *next; 9 | String8 string; 10 | String8List value_strings; 11 | } LNK_CmdOption; 12 | 13 | typedef struct LNK_CmdLine 14 | { 15 | U64 option_count; 16 | LNK_CmdOption *first_option; 17 | LNK_CmdOption *last_option; 18 | String8List input_list; 19 | } LNK_CmdLine; 20 | 21 | internal String8List lnk_arg_list_parse_windows_rules(Arena *arena, String8 string); 22 | internal LNK_CmdLine lnk_cmd_line_parse_windows_rules(Arena *arena, String8List arg_list); 23 | internal LNK_CmdOption * lnk_cmd_line_option_from_string(LNK_CmdLine cmd_line, String8 string); 24 | internal B32 lnk_cmd_line_has_option_string(LNK_CmdLine cmd_line, String8 string); 25 | internal B32 lnk_cmd_line_has_option(LNK_CmdLine cmd_line, char *string); 26 | 27 | internal LNK_CmdOption * lnk_cmd_line_push_option(Arena *arena, LNK_CmdLine *cmd_line, char *string, char *value); 28 | internal LNK_CmdOption * lnk_cmd_line_push_option_if_not_present(Arena *arena, LNK_CmdLine *cmd_line, char *string, char *value); 29 | 30 | internal String8List lnk_unwrap_rsp(Arena *arena, String8List arg_list); 31 | 32 | internal String8List lnk_data_from_cmd_line(Arena *arena, LNK_CmdLine cmd_line); 33 | 34 | -------------------------------------------------------------------------------- /src/linker/lnk_export_table.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef struct LNK_Export 7 | { 8 | struct LNK_Export *next; 9 | String8 name; 10 | LNK_Symbol *symbol; 11 | U32 id; 12 | U16 ordinal; 13 | COFF_ImportType type; 14 | B32 is_private; 15 | } LNK_Export; 16 | 17 | typedef struct LNK_ExportList 18 | { 19 | U64 count; 20 | LNK_Export *first; 21 | LNK_Export *last; 22 | } LNK_ExportList; 23 | 24 | typedef struct LNK_ExportArray 25 | { 26 | U64 count; 27 | LNK_Export *v; 28 | } LNK_ExportArray; 29 | 30 | typedef struct LNK_ExportTable 31 | { 32 | Arena *arena; 33 | HashTable *name_export_ht; 34 | HashTable *noname_export_ht; 35 | U64 voff_size; 36 | U64 max_ordinal; 37 | B8 *is_ordinal_used; 38 | } LNK_ExportTable; 39 | 40 | internal LNK_ExportTable * lnk_export_table_alloc(void); 41 | internal void lnk_export_table_release(LNK_ExportTable **exptab_ptr); 42 | internal LNK_Export * lnk_export_table_search(LNK_ExportTable *exptab, String8 name); 43 | internal void lnk_collect_exports_from_def_files(LNK_ExportTable *exptab, String8List path_list); 44 | internal void lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 image_name, COFF_MachineType machine); 45 | internal void lnk_collect_exports_from_obj_directives(LNK_ExportTable *exptab, LNK_ObjList obj_list, LNK_SymbolTable *symtab); 46 | 47 | -------------------------------------------------------------------------------- /src/linker/lnk_io.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //////////////////////////////// 4 | 5 | typedef struct 6 | { 7 | String8Array path_arr; 8 | String8Array data_arr; 9 | OS_Handle *handle_arr; 10 | U64 *size_arr; 11 | U64 *off_arr; 12 | U8 *buffer; 13 | } LNK_DiskReader; 14 | 15 | //////////////////////////////// 16 | // Shared File API 17 | 18 | shared_function int lnk_open_file_read(char *path, uint64_t path_size, void *handle_buffer, uint64_t handle_buffer_max); 19 | shared_function int lnk_open_file_write(char *path, uint64_t path_size, void *handle_buffer, uint64_t handle_buffer_max); 20 | shared_function void lnk_close_file(void *raw_handle); 21 | shared_function uint64_t lnk_size_from_file(void *raw_handle); 22 | shared_function uint64_t lnk_read_file(void *raw_handle, void *buffer, uint64_t buffer_max); 23 | shared_function uint64_t lnk_write_file(void *raw_handle, uint64_t offset, void *buffer, uint64_t buffer_size); 24 | 25 | //////////////////////////////// 26 | 27 | internal String8List lnk_file_search(Arena *arena, String8List dir_list, String8 file_path); 28 | 29 | internal OS_Handle lnk_file_open_with_rename_permissions(String8 path); 30 | internal B32 lnk_file_set_delete_on_close(OS_Handle handle, B32 delete_file); 31 | internal B32 lnk_file_rename(OS_Handle handle, String8 new_name); 32 | 33 | internal String8 lnk_read_data_from_file_path(Arena *arena, String8 path); 34 | internal String8Array lnk_read_data_from_file_path_parallel(TP_Context *tp, Arena *arena, String8Array path_arr); 35 | 36 | internal void lnk_write_data_list_to_file_path(String8 path, String8 temp_path, String8List list); 37 | internal void lnk_write_data_to_file_path(String8 path, String8 temp_path, String8 data); 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/linker/lnk_log.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal void 5 | lnk_set_log_status(LNK_LogType type, B32 is_enabled) 6 | { 7 | g_log_status[type] = is_enabled; 8 | } 9 | 10 | internal B32 11 | lnk_get_log_status(LNK_LogType type) 12 | { 13 | B32 status = g_log_status[type]; 14 | return status; 15 | } 16 | 17 | internal void 18 | lnk_log(LNK_LogType type, char *fmt, ...) 19 | { 20 | B32 is_log_enabled = g_log_status[type]; 21 | if (is_log_enabled) { 22 | Temp scratch = scratch_begin(0,0); 23 | va_list args; 24 | va_start(args, fmt); 25 | String8 string = push_str8fv(scratch.arena, fmt, args); 26 | fprintf(stdout, "%.*s\n", str8_varg(string)); 27 | va_end(args); 28 | scratch_end(scratch); 29 | } 30 | } 31 | 32 | internal LNK_LogType 33 | lnk_log_type_from_string(String8 string) 34 | { 35 | static struct { 36 | char *name; 37 | LNK_LogType type; 38 | } map[] = { 39 | "Null", LNK_Log_Null, 40 | "Debug", LNK_Log_Debug, 41 | "InputObj", LNK_Log_InputObj, 42 | "InputLib", LNK_Log_InputLib, 43 | "IO_Read", LNK_Log_IO_Read, 44 | "IO_Write", LNK_Log_IO_Write, 45 | "SizeBreakdown", LNK_Log_SizeBreakdown, 46 | "LinkStats", LNK_Log_LinkStats, 47 | "Timers", LNK_Log_Timers, 48 | }; 49 | Assert(ArrayCount(map) == LNK_Log_Count); 50 | 51 | for (U64 i = 0; i < ArrayCount(map); ++i) { 52 | if (str8_match(str8_cstring(map[i].name), string, StringMatchFlag_CaseInsensitive)) { 53 | return map[i].type; 54 | } 55 | } 56 | 57 | return LNK_Log_Null; 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/linker/lnk_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef enum 7 | { 8 | LNK_Log_Null, 9 | LNK_Log_Debug, 10 | LNK_Log_InputObj, 11 | LNK_Log_InputLib, 12 | LNK_Log_IO_Read, 13 | LNK_Log_IO_Write, 14 | LNK_Log_SizeBreakdown, 15 | LNK_Log_LinkStats, 16 | LNK_Log_Timers, 17 | LNK_Log_Count 18 | } LNK_LogType; 19 | 20 | internal void set_log_level(LNK_LogType type, B32 is_enabled); 21 | internal B32 lnk_get_log_status(LNK_LogType type); 22 | internal void lnk_log(LNK_LogType type, char *fmt, ...); 23 | 24 | internal LNK_LogType lnk_log_type_from_string(String8 string); 25 | 26 | -------------------------------------------------------------------------------- /src/linker/lnk_reloc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef enum 7 | { 8 | LNK_Reloc_NULL, 9 | LNK_Reloc_ADDR_16, 10 | LNK_Reloc_ADDR_32, 11 | LNK_Reloc_ADDR_64, 12 | LNK_Reloc_CHUNK_SIZE_FILE_16, 13 | LNK_Reloc_CHUNK_SIZE_FILE_32, 14 | LNK_Reloc_CHUNK_SIZE_VIRT_32, 15 | LNK_Reloc_FILE_ALIGN_32, 16 | LNK_Reloc_FILE_OFF_15, 17 | LNK_Reloc_FILE_OFF_32, 18 | LNK_Reloc_FILE_OFF_64, 19 | LNK_Reloc_REL32, 20 | LNK_Reloc_REL32_1, 21 | LNK_Reloc_REL32_2, 22 | LNK_Reloc_REL32_3, 23 | LNK_Reloc_REL32_4, 24 | LNK_Reloc_REL32_5, 25 | LNK_Reloc_SECT_REL, 26 | LNK_Reloc_SECT_IDX, 27 | LNK_Reloc_VIRT_ALIGN_32, 28 | LNK_Reloc_VIRT_OFF_32, 29 | } LNK_RelocType; 30 | 31 | typedef struct LNK_Reloc 32 | { 33 | struct LNK_Reloc *next; 34 | LNK_Chunk *chunk; 35 | LNK_RelocType type; 36 | U64 apply_off; 37 | struct LNK_Symbol *symbol; 38 | } LNK_Reloc; 39 | 40 | typedef struct LNK_RelocList 41 | { 42 | U64 count; 43 | LNK_Reloc *first; 44 | LNK_Reloc *last; 45 | } LNK_RelocList; 46 | 47 | internal LNK_Reloc * lnk_reloc_list_reserve(Arena *arena, LNK_RelocList *list, U64 count); 48 | internal LNK_Reloc * lnk_reloc_list_push(Arena *arena, LNK_RelocList *list); 49 | internal LNK_RelocList lnk_reloc_list_copy(Arena *arena, LNK_RelocList *list); 50 | internal void lnk_reloc_list_concat_in_place(LNK_RelocList *list, LNK_RelocList *to_concat); 51 | internal void lnk_reloc_list_concat_in_place_arr(LNK_RelocList *list, LNK_RelocList *arr, U64 count); 52 | internal LNK_RelocList ** lnk_make_reloc_list_arr_arr(Arena *arena, U64 slot_count, U64 per_count); 53 | internal LNK_Reloc ** lnk_reloc_array_from_list(Arena *arena, LNK_RelocList list); 54 | internal LNK_RelocType lnk_ext_reloc_type_from_coff(COFF_MachineType machine, U32 type); 55 | internal U32 lnk_ext_reloc_type_to_coff(COFF_MachineType machine, LNK_RelocType type); 56 | 57 | -------------------------------------------------------------------------------- /src/linker/lnk_timer.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | global LNK_Timer g_timers[LNK_Timer_Count]; 5 | 6 | internal void 7 | lnk_timer_begin(LNK_TimerType timer) 8 | { 9 | g_timers[timer].begin = os_now_microseconds(); 10 | } 11 | 12 | internal void 13 | lnk_timer_end(LNK_TimerType timer) 14 | { 15 | g_timers[timer].end = os_now_microseconds(); 16 | } 17 | 18 | internal String8 19 | lnk_string_from_timer_type(LNK_TimerType type) 20 | { 21 | switch (type) { 22 | case LNK_Timer_Image: return str8_lit("Image"); 23 | case LNK_Timer_Pdb: return str8_lit("PDB"); 24 | case LNK_Timer_Rdi: return str8_lit("RDI"); 25 | case LNK_Timer_Lib: return str8_lit("Lib"); 26 | case LNK_Timer_Debug: return str8_lit("Debug"); 27 | default: InvalidPath; 28 | } 29 | return str8_zero(); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/linker/lnk_timer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef enum LNK_TimerType 7 | { 8 | LNK_Timer_Image, 9 | LNK_Timer_Pdb, 10 | LNK_Timer_Rdi, 11 | LNK_Timer_Lib, 12 | LNK_Timer_Debug, 13 | LNK_Timer_Count 14 | } LNK_TimerType; 15 | 16 | typedef struct LNK_Timer 17 | { 18 | U64 begin; 19 | U64 end; 20 | } LNK_Timer; 21 | 22 | internal void lnk_timer_begin(LNK_TimerType timer); 23 | internal void lnk_timer_end(LNK_TimerType timer); 24 | 25 | -------------------------------------------------------------------------------- /src/linker/pdb_ext/pdb.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal U32 5 | pdb_hash_udt(CV_UDTInfo udt_info, String8 data) 6 | { 7 | B32 is_fwdref = !!(udt_info.props & CV_TypeProp_FwdRef); 8 | B32 is_scoped = !!(udt_info.props & CV_TypeProp_Scoped); 9 | B32 has_unique_name = !!(udt_info.props & CV_TypeProp_HasUniqueName); 10 | B32 is_anon = has_unique_name && cv_is_udt_name_anon(udt_info.name); 11 | 12 | U32 hash = 0; 13 | // dbi/tpi.cpp:1918 14 | if (!is_fwdref && !is_scoped && !is_anon) { 15 | hash = pdb_hash_v1(udt_info.name); 16 | } 17 | // dbi/tpi.cpp:1937 18 | else if (!is_fwdref && has_unique_name && is_scoped && !is_anon) { 19 | hash = pdb_hash_v1(udt_info.unique_name); 20 | } 21 | // dbi/tpi.cpp 1338 22 | else { 23 | hash = pdb_hash_v1(data); 24 | } 25 | 26 | return hash; 27 | } 28 | 29 | internal U32 30 | pdb_crc32_from_string(String8 string) 31 | { 32 | return ~update_crc32(~0, string.str, string.size); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/linker/pdb_ext/pdb.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal U32 pdb_hash_udt(CV_UDTInfo udt_info, String8 data); 7 | internal U32 pdb_crc32_from_string(String8 string); 8 | -------------------------------------------------------------------------------- /src/linker/pdb_ext/pdb_helpers.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal U64 5 | pdb_read_bit_vector_string(String8 data, U64 offset, U32Array *bits_out) 6 | { 7 | U64 cursor = offset; 8 | 9 | U32 word_count = 0; 10 | cursor += str8_deserial_read_struct(data, cursor, &word_count); 11 | 12 | U64 word_data_read_size = word_count * sizeof(U32); 13 | String8 word_data = str8(0,0); 14 | cursor += str8_deserial_read_block(data, cursor, word_data_read_size, &word_data); 15 | 16 | if (word_data.size == word_data_read_size) { 17 | bits_out->count = word_count; 18 | bits_out->v = (U32*)word_data.str; 19 | } else { 20 | bits_out->count = 0; 21 | bits_out->v = 0; 22 | } 23 | 24 | U64 read_size = cursor - offset; 25 | return read_size; 26 | } 27 | 28 | internal U64 29 | pdb_read_bit_vector_msf(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, U32Array *bits_out) 30 | { 31 | // peek word count 32 | MSF_UInt pos = msf_stream_get_pos(msf, sn); 33 | U32 word_count = msf_stream_read_u32(msf, sn); 34 | msf_stream_seek(msf, sn, pos); 35 | 36 | // read out header + packed words 37 | U64 buffer_size = sizeof(word_count) + word_count * sizeof(U32); 38 | U8 *buffer = push_array(arena, U8, buffer_size); 39 | MSF_UInt read_size = msf_stream_read(msf, sn, buffer, buffer_size); 40 | Assert(read_size == buffer_size); 41 | 42 | // parse words 43 | U64 parse_size = pdb_read_bit_vector_string(str8(buffer, buffer_size), 0, bits_out); 44 | return parse_size; 45 | } 46 | 47 | internal B32 48 | pdb_write_bit_vector(MSF_Context *msf, MSF_StreamNumber sn, B32 *flag_array, U64 flag_count) 49 | { 50 | B32 is_write_ok = 0; 51 | 52 | U32 word_size = sizeof(U32); 53 | U32 bits_per_word = MSF_BITS_PER_CHAR * word_size; 54 | U32 word_count = (flag_count + MSF_BITS_PER_CHAR) / MSF_BITS_PER_CHAR; 55 | 56 | is_write_ok = msf_stream_write_struct(msf, sn, &word_count); 57 | if (is_write_ok) { 58 | for (U64 iword = 0, iflag = 0; iword < word_count; ++iword) { 59 | U32 word = 0; 60 | 61 | for (U64 iflag_opl = Min(flag_count, iflag + MSF_BITS_PER_CHAR); iflag < iflag_opl; ++iflag) { 62 | if (flag_array[iflag]) { 63 | word |= 1 << (iflag % bits_per_word); 64 | } 65 | } 66 | 67 | is_write_ok = msf_stream_write_struct(msf, sn, &word); 68 | if (!is_write_ok) { 69 | break; 70 | } 71 | } 72 | } 73 | 74 | return is_write_ok; 75 | } 76 | 77 | internal U64 78 | pdb_get_bit_vector_size(U32 bucket_count) 79 | { 80 | U32 word_size = sizeof(U32); 81 | U32 word_count = (bucket_count + MSF_BITS_PER_CHAR) / MSF_BITS_PER_CHAR; 82 | 83 | U64 result = 0; 84 | result += sizeof(word_count); 85 | result += word_size * word_count; 86 | 87 | return result; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/linker/pdb_ext/pdb_helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal U32 pdb_hash_v1(String8 data); 7 | internal U32 pdb_hash_udt(CV_UDTInfo udt_info, String8 data); 8 | 9 | internal U64 pdb_read_bit_vector_string(String8 data, U64 offset, U32Array *bits_out); 10 | internal U64 pdb_read_bit_vector_msf(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, U32Array *bits_out); 11 | internal B32 pdb_write_bit_vector(MSF_Context *msf, MSF_StreamNumber sn, B32 *flag_array, U64 flag_count); 12 | internal U64 pdb_get_bit_vector_size(U32 bucket_count); 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi.c: -------------------------------------------------------------------------------- 1 | internal String8 2 | rdi_string_from_name_map_kind(RDI_NameMapKind kind) 3 | { 4 | String8 result = {0}; 5 | switch(kind) 6 | { 7 | default:{}break; 8 | #define X(name) case RDI_NameMapKind_##name:{result = str8_lit(#name);}break; 9 | RDI_NameMapKind_XList 10 | #undef X 11 | } 12 | return result; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | internal String8 rdi_string_from_name_map_kind(RDI_NameMapKind kind); 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi_coff.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal RDI_Arch 5 | rdi_arch_from_coff_machine(COFF_MachineType machine) 6 | { 7 | switch (machine) { 8 | case COFF_MachineType_X86: return RDI_Arch_X86; 9 | case COFF_MachineType_X64: return RDI_Arch_X64; 10 | 11 | case COFF_MachineType_Unknown: 12 | case COFF_MachineType_Am33: 13 | case COFF_MachineType_Arm: 14 | case COFF_MachineType_Arm64: 15 | case COFF_MachineType_ArmNt: 16 | case COFF_MachineType_Ebc: 17 | case COFF_MachineType_Ia64: 18 | case COFF_MachineType_M32R: 19 | case COFF_MachineType_Mips16: 20 | case COFF_MachineType_MipsFpu: 21 | case COFF_MachineType_MipsFpu16: 22 | case COFF_MachineType_PowerPc: 23 | case COFF_MachineType_PowerPcFp: 24 | case COFF_MachineType_R4000: 25 | case COFF_MachineType_RiscV32: 26 | case COFF_MachineType_RiscV64: 27 | case COFF_MachineType_Sh3: 28 | case COFF_MachineType_Sh3Dsp: 29 | case COFF_MachineType_Sh4: 30 | case COFF_MachineType_Sh5: 31 | case COFF_MachineType_Thumb: 32 | case COFF_MachineType_WceMipsV2: 33 | NotImplemented; 34 | default: 35 | return RDI_Arch_NULL; 36 | } 37 | } 38 | 39 | internal RDI_BinarySectionFlags 40 | rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags) 41 | { 42 | RDI_BinarySectionFlags result = 0; 43 | if (flags & COFF_SectionFlag_MemRead) { 44 | result |= RDI_BinarySectionFlag_Read; 45 | } 46 | if (flags & COFF_SectionFlag_MemWrite) { 47 | result |= RDI_BinarySectionFlag_Write; 48 | } 49 | if (flags & COFF_SectionFlag_MemExecute) { 50 | result |= RDI_BinarySectionFlag_Execute; 51 | } 52 | return result; 53 | } 54 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi_coff.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal RDI_Arch rdi_arch_from_coff_machine(COFF_MachineType machine); 7 | 8 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi_cv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | internal RDI_Arch rdi_arch_from_cv_arch(CV_Arch arch); 7 | internal RDI_Language rdi_language_from_cv_language(CV_Language language); 8 | internal RDI_TypeModifierFlags rdi_type_modifier_flags_from_cv_pointer_attribs(CV_PointerAttribs attribs); 9 | internal RDI_TypeKind rdi_type_kind_from_cv_basic_type(CV_BasicType basic_type); 10 | internal RDI_RegCode rdi_reg_code_from_cv(CV_Arch arch, CV_Reg reg); 11 | 12 | internal RDI_ChecksumKind rdi_checksum_from_cv_c13(CV_C13ChecksumKind kind); 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/linker/rdi/rdi_overrides.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef U8 RDI_U8; 4 | typedef U16 RDI_U16; 5 | typedef U32 RDI_U32; 6 | typedef U64 RDI_U64; 7 | typedef S8 RDI_S8; 8 | typedef S16 RDI_S16; 9 | typedef S32 RDI_S32; 10 | typedef S64 RDI_S64; 11 | 12 | #define RDI_PROC internal 13 | #define RDIM_MEMSET_OVERRIDE 14 | #define rdim_memset MemorySet 15 | 16 | #define RDIM_MEMCPY_OVERRIDE 17 | #define rdim_memcpy MemoryCopy 18 | 19 | #define rdim_vsnprintf raddbg_vsnprintf 20 | 21 | -------------------------------------------------------------------------------- /src/linker/thread_pool/thread_pool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | #define THREAD_POOL_TASK_FUNC(name) void name(Arena *arena, U64 worker_id, U64 task_id, void *raw_task) 7 | typedef THREAD_POOL_TASK_FUNC(TP_TaskFunc); 8 | 9 | typedef struct TP_Arena 10 | { 11 | U64 count; 12 | Arena **v; 13 | } TP_Arena; 14 | 15 | typedef struct TP_Temp 16 | { 17 | U64 count; 18 | Temp *v; 19 | } TP_Temp; 20 | 21 | typedef struct TP_Worker 22 | { 23 | U64 id; 24 | struct TP_Context *pool; 25 | OS_Handle handle; 26 | } TP_Worker; 27 | 28 | typedef struct TP_Context 29 | { 30 | B32 is_live; 31 | OS_Handle exec_semaphore; 32 | OS_Handle task_semaphore; 33 | OS_Handle main_semaphore; 34 | 35 | U32 worker_count; 36 | TP_Worker *worker_arr; 37 | 38 | TP_Arena *task_arena; 39 | TP_TaskFunc *task_func; 40 | void *task_data; 41 | U64 task_count; 42 | U64 task_done; 43 | S64 task_left; 44 | } TP_Context; 45 | 46 | internal TP_Context * tp_alloc(Arena *arena, U32 worker_count, U32 max_worker_count, String8 name); 47 | internal void tp_release(TP_Context *pool); 48 | internal TP_Arena * tp_arena_alloc(TP_Context *pool); 49 | internal void tp_arena_release(TP_Arena **arena_ptr); 50 | internal TP_Temp tp_temp_begin(TP_Arena *arena); 51 | internal void tp_temp_end(TP_Temp temp); 52 | internal void tp_for_parallel(TP_Context *pool, TP_Arena *arena, U64 task_count, TP_TaskFunc *task_func, void *task_data); 53 | internal Rng1U64 * tp_divide_work(Arena *arena, U64 item_count, U32 worker_count); 54 | 55 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_ARENA_H 5 | #define BASE_ARENA_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Constants 9 | 10 | #define ARENA_HEADER_SIZE 128 11 | 12 | //////////////////////////////// 13 | //~ rjf: Types 14 | 15 | typedef U64 ArenaFlags; 16 | enum 17 | { 18 | ArenaFlag_NoChain = (1<<0), 19 | ArenaFlag_LargePages = (1<<1), 20 | }; 21 | 22 | typedef struct ArenaParams ArenaParams; 23 | struct ArenaParams 24 | { 25 | ArenaFlags flags; 26 | U64 reserve_size; 27 | U64 commit_size; 28 | void *optional_backing_buffer; 29 | }; 30 | 31 | typedef struct Arena Arena; 32 | struct Arena 33 | { 34 | Arena *prev; // previous arena in chain 35 | Arena *current; // current arena in chain 36 | ArenaFlags flags; 37 | U64 cmt_size; 38 | U64 res_size; 39 | U64 base_pos; 40 | U64 pos; 41 | U64 cmt; 42 | U64 res; 43 | #if ARENA_FREE_LIST 44 | U64 free_size; 45 | Arena *free_last; 46 | #endif 47 | }; 48 | StaticAssert(sizeof(Arena) <= ARENA_HEADER_SIZE, arena_header_size_check); 49 | 50 | typedef struct Temp Temp; 51 | struct Temp 52 | { 53 | Arena *arena; 54 | U64 pos; 55 | }; 56 | 57 | //////////////////////////////// 58 | //~ rjf: Global Defaults 59 | 60 | global U64 arena_default_reserve_size = MB(64); 61 | global U64 arena_default_commit_size = KB(64); 62 | global ArenaFlags arena_default_flags = 0; 63 | 64 | //////////////////////////////// 65 | //~ rjf: Arena Functions 66 | 67 | //- rjf: arena creation/destruction 68 | internal Arena *arena_alloc_(ArenaParams *params); 69 | #define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, __VA_ARGS__}) 70 | internal void arena_release(Arena *arena); 71 | 72 | //- rjf: arena push/pop/pos core functions 73 | internal void *arena_push(Arena *arena, U64 size, U64 align); 74 | internal U64 arena_pos(Arena *arena); 75 | internal void arena_pop_to(Arena *arena, U64 pos); 76 | 77 | //- rjf: arena push/pop helpers 78 | internal void arena_clear(Arena *arena); 79 | internal void arena_pop(Arena *arena, U64 amt); 80 | 81 | //- rjf: temporary arena scopes 82 | internal Temp temp_begin(Arena *arena); 83 | internal void temp_end(Temp temp); 84 | 85 | //- rjf: push helper macros 86 | #define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align)) 87 | #define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T)*(c)) 88 | #define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T))) 89 | #define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T))) 90 | 91 | #endif // BASE_ARENA_H 92 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_command_line.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_COMMAND_LINE_H 5 | #define BASE_COMMAND_LINE_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Parsed Command Line Types 9 | 10 | typedef struct CmdLineOpt CmdLineOpt; 11 | struct CmdLineOpt 12 | { 13 | CmdLineOpt *next; 14 | CmdLineOpt *hash_next; 15 | U64 hash; 16 | String8 string; 17 | String8List value_strings; 18 | String8 value_string; 19 | }; 20 | 21 | typedef struct CmdLineOptList CmdLineOptList; 22 | struct CmdLineOptList 23 | { 24 | U64 count; 25 | CmdLineOpt *first; 26 | CmdLineOpt *last; 27 | }; 28 | 29 | typedef struct CmdLine CmdLine; 30 | struct CmdLine 31 | { 32 | String8 exe_name; 33 | CmdLineOptList options; 34 | String8List inputs; 35 | U64 option_table_size; 36 | CmdLineOpt **option_table; 37 | U64 argc; 38 | char **argv; 39 | }; 40 | 41 | //////////////////////////////// 42 | //~ NOTE(rjf): Command Line Option Parsing 43 | 44 | internal U64 cmd_line_hash_from_string(String8 string); 45 | internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string); 46 | internal CmdLineOpt* cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string); 47 | internal void cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var); 48 | internal CmdLineOpt* cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List values); 49 | internal CmdLine cmd_line_from_string_list(Arena *arena, String8List arguments); 50 | internal CmdLineOpt* cmd_line_opt_from_string(CmdLine *cmd_line, String8 name); 51 | internal String8List cmd_line_strings(CmdLine *cmd_line, String8 name); 52 | internal String8 cmd_line_string(CmdLine *cmd_line, String8 name); 53 | internal B32 cmd_line_has_flag(CmdLine *cmd_line, String8 name); 54 | internal B32 cmd_line_has_argument(CmdLine *cmd_line, String8 name); 55 | 56 | #endif // BASE_COMMAND_LINE_H 57 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_entry_point.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_ENTRY_POINT_H 5 | #define BASE_ENTRY_POINT_H 6 | 7 | internal void main_thread_base_entry_point(int argc, char **argv); 8 | internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params); 9 | internal U64 update_tick_idx(void); 10 | internal B32 update(void); 11 | 12 | #endif // BASE_ENTRY_POINT_H 13 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Base Includes 6 | 7 | #undef MARKUP_LAYER_COLOR 8 | #define MARKUP_LAYER_COLOR 0.20f, 0.60f, 0.80f 9 | 10 | #include "metagen_base_core.c" 11 | #include "metagen_base_profile.c" 12 | #include "metagen_base_arena.c" 13 | #include "metagen_base_math.c" 14 | #include "metagen_base_strings.c" 15 | #include "metagen_base_thread_context.c" 16 | #include "metagen_base_command_line.c" 17 | #include "metagen_base_markup.c" 18 | #include "metagen_base_meta.c" 19 | #include "metagen_base_log.c" 20 | #include "metagen_base_entry_point.c" 21 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_INC_H 5 | #define BASE_INC_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Base Includes 9 | 10 | #include "metagen_base_context_cracking.h" 11 | 12 | #include "metagen_base_core.h" 13 | #include "metagen_base_profile.h" 14 | #include "metagen_base_arena.h" 15 | #include "metagen_base_math.h" 16 | #include "metagen_base_strings.h" 17 | #include "metagen_base_thread_context.h" 18 | #include "metagen_base_command_line.h" 19 | #include "metagen_base_markup.h" 20 | #include "metagen_base_meta.h" 21 | #include "metagen_base_log.h" 22 | #include "metagen_base_entry_point.h" 23 | 24 | #endif // BASE_INC_H 25 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_log.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Globals/Thread-Locals 6 | 7 | C_LINKAGE thread_static Log *log_active; 8 | #if !BUILD_SUPPLEMENTARY_UNIT 9 | C_LINKAGE thread_static Log *log_active = 0; 10 | #endif 11 | 12 | //////////////////////////////// 13 | //~ rjf: Log Creation/Selection 14 | 15 | internal Log * 16 | log_alloc(void) 17 | { 18 | Arena *arena = arena_alloc(); 19 | Log *log = push_array(arena, Log, 1); 20 | log->arena = arena; 21 | return log; 22 | } 23 | 24 | internal void 25 | log_release(Log *log) 26 | { 27 | arena_release(log->arena); 28 | } 29 | 30 | internal void 31 | log_select(Log *log) 32 | { 33 | log_active = log; 34 | } 35 | 36 | //////////////////////////////// 37 | //~ rjf: Log Building/Clearing 38 | 39 | internal void 40 | log_msg(LogMsgKind kind, String8 string) 41 | { 42 | if(log_active != 0 && log_active->top_scope != 0) 43 | { 44 | String8 string_copy = push_str8_copy(log_active->arena, string); 45 | str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy); 46 | } 47 | } 48 | 49 | internal void 50 | log_msgf(LogMsgKind kind, char *fmt, ...) 51 | { 52 | if(log_active != 0) 53 | { 54 | Temp scratch = scratch_begin(0, 0); 55 | va_list args; 56 | va_start(args, fmt); 57 | String8 string = push_str8fv(scratch.arena, fmt, args); 58 | log_msg(kind, string); 59 | va_end(args); 60 | scratch_end(scratch); 61 | } 62 | } 63 | 64 | //////////////////////////////// 65 | //~ rjf: Log Scopes 66 | 67 | internal void 68 | log_scope_begin(void) 69 | { 70 | if(log_active != 0) 71 | { 72 | U64 pos = arena_pos(log_active->arena); 73 | LogScope *scope = push_array(log_active->arena, LogScope, 1); 74 | scope->pos = pos; 75 | SLLStackPush(log_active->top_scope, scope); 76 | } 77 | } 78 | 79 | internal LogScopeResult 80 | log_scope_end(Arena *arena) 81 | { 82 | LogScopeResult result = {0}; 83 | if(log_active != 0) 84 | { 85 | LogScope *scope = log_active->top_scope; 86 | if(scope != 0) 87 | { 88 | SLLStackPop(log_active->top_scope); 89 | if(arena != 0) 90 | { 91 | for EachEnumVal(LogMsgKind, kind) 92 | { 93 | Temp scratch = scratch_begin(&arena, 1); 94 | String8 result_unindented = str8_list_join(scratch.arena, &scope->strings[kind], 0); 95 | result.strings[kind] = indented_from_string(arena, result_unindented); 96 | scratch_end(scratch); 97 | } 98 | } 99 | arena_pop_to(log_active->arena, scope->pos); 100 | } 101 | } 102 | return result; 103 | } 104 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_LOG_H 5 | #define BASE_LOG_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Log Types 9 | 10 | typedef enum LogMsgKind 11 | { 12 | LogMsgKind_Info, 13 | LogMsgKind_UserError, 14 | LogMsgKind_COUNT 15 | } 16 | LogMsgKind; 17 | 18 | typedef struct LogScope LogScope; 19 | struct LogScope 20 | { 21 | LogScope *next; 22 | U64 pos; 23 | String8List strings[LogMsgKind_COUNT]; 24 | }; 25 | 26 | typedef struct LogScopeResult LogScopeResult; 27 | struct LogScopeResult 28 | { 29 | String8 strings[LogMsgKind_COUNT]; 30 | }; 31 | 32 | typedef struct Log Log; 33 | struct Log 34 | { 35 | Arena *arena; 36 | LogScope *top_scope; 37 | }; 38 | 39 | //////////////////////////////// 40 | //~ rjf: Log Creation/Selection 41 | 42 | internal Log *log_alloc(void); 43 | internal void log_release(Log *log); 44 | internal void log_select(Log *log); 45 | 46 | //////////////////////////////// 47 | //~ rjf: Log Building 48 | 49 | internal void log_msg(LogMsgKind kind, String8 string); 50 | internal void log_msgf(LogMsgKind kind, char *fmt, ...); 51 | #define log_info(s) log_msg(LogMsgKind_Info, (s)) 52 | #define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__) 53 | #define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) 54 | #define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__) 55 | 56 | #define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) 57 | #define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) 58 | 59 | //////////////////////////////// 60 | //~ rjf: Log Scopes 61 | 62 | internal void log_scope_begin(void); 63 | internal LogScopeResult log_scope_end(Arena *arena); 64 | 65 | #endif // BASE_LOG_H 66 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_markup.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal void 5 | set_thread_name(String8 string) 6 | { 7 | ProfThreadName("%.*s", str8_varg(string)); 8 | os_set_thread_name(string); 9 | } 10 | 11 | internal void 12 | set_thread_namef(char *fmt, ...) 13 | { 14 | Temp scratch = scratch_begin(0, 0); 15 | va_list args; 16 | va_start(args, fmt); 17 | String8 string = push_str8fv(scratch.arena, fmt, args); 18 | set_thread_name(string); 19 | va_end(args); 20 | scratch_end(scratch); 21 | } 22 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_markup.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_MARKUP_H 5 | #define BASE_MARKUP_H 6 | 7 | internal void set_thread_name(String8 string); 8 | internal void set_thread_namef(char *fmt, ...); 9 | #define ThreadNameF(...) (set_thread_namef(__VA_ARGS__)) 10 | #define ThreadName(str) (set_thread_name(str)) 11 | 12 | #endif // BASE_MARKUP_H 13 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_profile.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_thread_context.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | // NOTE(allen): Thread Context Functions 6 | 7 | C_LINKAGE thread_static TCTX* tctx_thread_local; 8 | #if !BUILD_SUPPLEMENTARY_UNIT 9 | C_LINKAGE thread_static TCTX* tctx_thread_local = 0; 10 | #endif 11 | 12 | internal void 13 | tctx_init_and_equip(TCTX *tctx){ 14 | MemoryZeroStruct(tctx); 15 | Arena **arena_ptr = tctx->arenas; 16 | for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){ 17 | *arena_ptr = arena_alloc(); 18 | } 19 | tctx_thread_local = tctx; 20 | } 21 | 22 | internal void 23 | tctx_release(void) 24 | { 25 | for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1) 26 | { 27 | arena_release(tctx_thread_local->arenas[i]); 28 | } 29 | } 30 | 31 | internal TCTX* 32 | tctx_get_equipped(void){ 33 | return(tctx_thread_local); 34 | } 35 | 36 | internal Arena* 37 | tctx_get_scratch(Arena **conflicts, U64 count){ 38 | TCTX *tctx = tctx_get_equipped(); 39 | 40 | Arena *result = 0; 41 | Arena **arena_ptr = tctx->arenas; 42 | for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){ 43 | Arena **conflict_ptr = conflicts; 44 | B32 has_conflict = 0; 45 | for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){ 46 | if (*arena_ptr == *conflict_ptr){ 47 | has_conflict = 1; 48 | break; 49 | } 50 | } 51 | if (!has_conflict){ 52 | result = *arena_ptr; 53 | break; 54 | } 55 | } 56 | 57 | return(result); 58 | } 59 | 60 | internal void 61 | tctx_set_thread_name(String8 string){ 62 | TCTX *tctx = tctx_get_equipped(); 63 | U64 size = ClampTop(string.size, sizeof(tctx->thread_name)); 64 | MemoryCopy(tctx->thread_name, string.str, size); 65 | tctx->thread_name_size = size; 66 | } 67 | 68 | internal String8 69 | tctx_get_thread_name(void){ 70 | TCTX *tctx = tctx_get_equipped(); 71 | String8 result = str8(tctx->thread_name, tctx->thread_name_size); 72 | return(result); 73 | } 74 | 75 | internal void 76 | tctx_write_srcloc(char *file_name, U64 line_number){ 77 | TCTX *tctx = tctx_get_equipped(); 78 | tctx->file_name = file_name; 79 | tctx->line_number = line_number; 80 | } 81 | 82 | internal void 83 | tctx_read_srcloc(char **file_name, U64 *line_number){ 84 | TCTX *tctx = tctx_get_equipped(); 85 | *file_name = tctx->file_name; 86 | *line_number = tctx->line_number; 87 | } 88 | -------------------------------------------------------------------------------- /src/metagen/metagen_base/metagen_base_thread_context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef BASE_THREAD_CONTEXT_H 5 | #define BASE_THREAD_CONTEXT_H 6 | 7 | //////////////////////////////// 8 | // NOTE(allen): Thread Context 9 | 10 | typedef struct TCTX TCTX; 11 | struct TCTX 12 | { 13 | Arena *arenas[2]; 14 | 15 | U8 thread_name[32]; 16 | U64 thread_name_size; 17 | 18 | char *file_name; 19 | U64 line_number; 20 | }; 21 | 22 | //////////////////////////////// 23 | // NOTE(allen): Thread Context Functions 24 | 25 | internal void tctx_init_and_equip(TCTX *tctx); 26 | internal void tctx_release(void); 27 | internal TCTX* tctx_get_equipped(void); 28 | 29 | internal Arena* tctx_get_scratch(Arena **conflicts, U64 countt); 30 | 31 | internal void tctx_set_thread_name(String8 name); 32 | internal String8 tctx_get_thread_name(void); 33 | 34 | internal void tctx_write_srcloc(char *file_name, U64 line_number); 35 | internal void tctx_read_srcloc(char **file_name, U64 *line_number); 36 | #define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__) 37 | 38 | #define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count))) 39 | #define scratch_end(scratch) temp_end(scratch) 40 | 41 | #endif // BASE_THREAD_CONTEXT_H 42 | -------------------------------------------------------------------------------- /src/metagen/metagen_os/metagen_os_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "metagen/metagen_os/core/metagen_os_core.c" 5 | 6 | #if OS_WINDOWS 7 | # include "metagen/metagen_os/core/win32/metagen_os_core_win32.c" 8 | #elif OS_LINUX 9 | # include "metagen/metagen_os/core/linux/metagen_os_core_linux.c" 10 | #else 11 | # error OS core layer not implemented for this operating system. 12 | #endif 13 | -------------------------------------------------------------------------------- /src/metagen/metagen_os/metagen_os_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef OS_INC_H 5 | #define OS_INC_H 6 | 7 | #if !defined(OS_FEATURE_GRAPHICAL) 8 | # define OS_FEATURE_GRAPHICAL 0 9 | #endif 10 | 11 | #include "metagen/metagen_os/core/metagen_os_core.h" 12 | 13 | #if OS_WINDOWS 14 | # include "metagen/metagen_os/core/win32/metagen_os_core_win32.h" 15 | #elif OS_LINUX 16 | # include "metagen/metagen_os/core/linux/metagen_os_core_linux.h" 17 | #else 18 | # error OS core layer not implemented for this operating system. 19 | #endif 20 | 21 | #endif // OS_INC_H 22 | -------------------------------------------------------------------------------- /src/msf/msf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal B32 5 | msf_check_magic_20(String8 data) 6 | { 7 | B32 is_msf = data.size >= sizeof(msf_msf20_magic) && str8_match(data, str8_lit(msf_msf20_magic), StringMatchFlag_RightSideSloppy); 8 | return is_msf; 9 | } 10 | 11 | internal B32 12 | msf_check_magic_70(String8 data) 13 | { 14 | B32 is_msf = data.size >= sizeof(msf_msf70_magic) && str8_match(data, str8_lit(msf_msf70_magic), StringMatchFlag_RightSideSloppy); 15 | return is_msf; 16 | } 17 | -------------------------------------------------------------------------------- /src/msf/msf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef MSF_H 5 | #define MSF_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: MSF Format Types 9 | 10 | #define MSF_UINT_MAX max_U32 11 | typedef U32 MSF_UInt; 12 | typedef S32 MSF_Int; 13 | 14 | #define MSF_BITS_PER_CHAR 8 15 | #define MSF_BITS_PER_WORD (sizeof(MSF_UInt) * MSF_BITS_PER_CHAR) 16 | 17 | #define MSF_PN_MAX MSF_UINT_MAX 18 | typedef MSF_UInt MSF_PageNumber; 19 | #define MSF_MIN_PAGE_SIZE 512 20 | #define MSF_MAX_PAGE_SIZE 32768 21 | 22 | #define MSF_MAX_STREAM_SIZE MSF_INT_MAX 23 | #define MSF_DELETED_STREAM_STAMP MSF_UINT_MAX 24 | #define MSF_STREAM_NUMBER_MAX max_U16 25 | #define MSF_INVALID_STREAM_NUMBER MSF_STREAM_NUMBER_MAX 26 | typedef U16 MSF_StreamNumber; 27 | 28 | static char msf_msf20_magic[] = "Microsoft C/C++ program database 2.00\r\n\x1aJG\0\0"; 29 | static char msf_msf70_magic[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0"; 30 | 31 | typedef struct MSF_Header20 MSF_Header20; 32 | struct MSF_Header20 33 | { 34 | U8 magic[sizeof(msf_msf20_magic)]; 35 | U32 page_size; 36 | U16 active_fpm; 37 | U16 page_count; 38 | U32 stream_table_size; 39 | U32 unknown; 40 | U16 root_pn; 41 | }; 42 | 43 | typedef struct MSF_Header70 MSF_Header70; 44 | struct MSF_Header70 45 | { 46 | U8 magic[sizeof(msf_msf70_magic)]; 47 | MSF_UInt page_size; 48 | MSF_PageNumber active_fpm; 49 | MSF_PageNumber page_count; 50 | MSF_UInt stream_table_size; 51 | MSF_UInt unknown; // always set to zero (used to be stream table page number, see SI_PERSIST in msf.cpp) 52 | MSF_PageNumber root_pn; 53 | }; 54 | 55 | //////////////////////////////// 56 | 57 | internal B32 msf_check_magic_20(String8 data); 58 | internal B32 msf_check_magic_70(String8 data); 59 | 60 | #endif // MSF_H 61 | -------------------------------------------------------------------------------- /src/msf/msf_parse.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef MSF_PARSE_H 5 | #define MSF_PARSE_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: MSF Parser Helper Types 9 | 10 | typedef struct MSF_RawStream MSF_RawStream; 11 | struct MSF_RawStream 12 | { 13 | U64 size; 14 | U64 page_count; 15 | union { 16 | U32 *page_indices_u32; 17 | U16 *page_indices_u16; 18 | } u; 19 | }; 20 | 21 | typedef struct MSF_RawStreamTable MSF_RawStreamTable; 22 | struct MSF_RawStreamTable 23 | { 24 | U64 total_page_count; 25 | U64 index_size; 26 | U64 page_size; 27 | U64 stream_count; 28 | MSF_RawStream *streams; 29 | }; 30 | 31 | typedef struct MSF_Parsed MSF_Parsed; 32 | struct MSF_Parsed 33 | { 34 | String8 *streams; 35 | U64 stream_count; 36 | U64 page_size; 37 | U64 page_count; 38 | }; 39 | 40 | //////////////////////////////// 41 | //~ rjf: MSF Parser Functions 42 | 43 | internal MSF_RawStreamTable* msf_raw_stream_table_from_data(Arena *arena, String8 msf_data); 44 | internal String8 msf_data_from_stream_number(Arena *arena, String8 msf_data, MSF_RawStreamTable *st, MSF_StreamNumber sn); 45 | internal MSF_Parsed* msf_parsed_from_data(Arena *arena, String8 msf_data); 46 | internal String8 msf_data_from_stream(MSF_Parsed *msf, MSF_StreamNumber sn); 47 | 48 | #endif // MSF_PARSE_H 49 | -------------------------------------------------------------------------------- /src/msvc_crt/msvc_crt_enum.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal String8 5 | mscrt_string_from_eh_adjectives(Arena *arena, MSCRT_EhHandlerTypeFlags adjectives) 6 | { 7 | Temp scratch = scratch_begin(&arena, 1); 8 | String8List adj_list = {0}; 9 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsConst) { 10 | str8_list_pushf(scratch.arena, &adj_list, "Const"); 11 | } 12 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsVolatile) { 13 | str8_list_pushf(scratch.arena, &adj_list, "Volatile"); 14 | } 15 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsUnaligned) { 16 | str8_list_pushf(scratch.arena, &adj_list, "Unaligned"); 17 | } 18 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsReference) { 19 | str8_list_pushf(scratch.arena, &adj_list, "Reference"); 20 | } 21 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsResumable) { 22 | str8_list_pushf(scratch.arena, &adj_list, "Resumable"); 23 | } 24 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsStdDotDot) { 25 | str8_list_pushf(scratch.arena, &adj_list, "StdDotDot"); 26 | } 27 | if (adjectives & MSCRT_EhHandlerTypeFlag_IsComplusEH) { 28 | str8_list_pushf(scratch.arena, &adj_list, "ComplusEH"); 29 | } 30 | String8 result = str8_list_join(arena, &adj_list, &(StringJoin){.sep=str8_lit(", ")}); 31 | scratch_end(scratch); 32 | return result; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/msvc_crt/msvc_crt_enum.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef MSVC_CRT_ENUM_H 5 | #define MSVC_CRT_ENUM_H 6 | 7 | internal String8 mscrt_string_from_eh_adjectives(Arena *arena, MSCRT_EhHandlerTypeFlags adjectives); 8 | 9 | #endif // MSVC_CRT_ENUM_H 10 | -------------------------------------------------------------------------------- /src/mule/inline_body.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | bias = (bias^x)&7; 5 | x -= bias; 6 | x *= 2; 7 | x *= x; 8 | x += bias; -------------------------------------------------------------------------------- /src/mule/mule_c.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | /* 5 | * Program to run in debugger organized to provide tests for 6 | * single threaded stepping, breakpoints, evaluation. 7 | */ 8 | 9 | //////////////////////////////// 10 | // NOTE(allen): Complex Types 11 | 12 | #include 13 | 14 | void 15 | c_type_coverage_eval_tests(void){ 16 | #if _WIN32 17 | _Fcomplex x = _FCbuild(0.f, 1.f); 18 | _Dcomplex y = _Cbuild(0.f, -1.f); 19 | 20 | #else 21 | float complex x = 0.f + 1.f*I; 22 | double complex y = 0.0 - 1.0*I; 23 | 24 | #endif 25 | } 26 | 27 | //////////////////////////////// 28 | // NOTE(allen): Reuse Type Names From Another Module 29 | 30 | #include 31 | 32 | typedef struct Basics{ 33 | double a; 34 | float b; 35 | unsigned long long c; 36 | long long d; 37 | unsigned int e; 38 | int f; 39 | unsigned short g; 40 | short h; 41 | unsigned char i; 42 | char j; 43 | 44 | int z; 45 | } Basics; 46 | 47 | typedef struct Basics_Stdint{ 48 | double x1; 49 | float x2; 50 | uint64_t x3; 51 | int64_t x4; 52 | uint32_t x5; 53 | int32_t x6; 54 | uint16_t x7; 55 | int16_t x8; 56 | uint8_t x9; 57 | int8_t x0; 58 | } Basics_Stdint; 59 | 60 | typedef struct Pair{ 61 | int i; 62 | float f; 63 | } Pair; 64 | 65 | void 66 | c_versions_of_same_types(void){ 67 | Basics basics = { 1.5f, 1.50000000000001, -1, 1, -2, 2, -4, 4, -8, 8, }; 68 | Basics_Stdint basics_stdint = { 1.5f, 1.50000000000001, -1, 1, -2, 2, -4, 4, -8, 8, }; 69 | Pair memory_[] = { 70 | {100, 1.f}, 71 | {101, 2.f}, 72 | {102, 4.f}, 73 | {103, 8.f}, 74 | {104, 16.f}, 75 | {105, 32.f}, 76 | }; 77 | 78 | int x = memory_[3].i + basics.f; 79 | } 80 | 81 | //////////////////////////////// 82 | //~ NOTE(rjf): Bitfields 83 | 84 | typedef struct TypeWithBitfield TypeWithBitfield; 85 | struct TypeWithBitfield 86 | { 87 | int v : 14; 88 | int w : 4; 89 | int x : 32; 90 | int y : 4; 91 | int z : 10; 92 | }; 93 | 94 | typedef struct BitfieldType64 BitfieldType64; 95 | struct BitfieldType64 96 | { 97 | uint64_t size : 63; 98 | uint64_t is_free : 1; 99 | }; 100 | 101 | void 102 | c_type_with_bitfield_usage(void) 103 | { 104 | TypeWithBitfield b = {0}; 105 | b.v = 100; 106 | b.w = 6; 107 | b.x = 434512; 108 | b.y = 7; 109 | b.z = 12; 110 | int x = (b.v + b.x); 111 | int y = (b.y - b.z); 112 | int z = (b.w) + 5; 113 | BitfieldType64 b64 = {0}; 114 | b64.size = 524288; 115 | b64.is_free = 1; 116 | int abc = 0; 117 | } 118 | -------------------------------------------------------------------------------- /src/mule/mule_c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | /* 5 | * Program to run in debugger organized to provide tests for 6 | * single threaded stepping, breakpoints, evaluation. 7 | */ 8 | 9 | void c_type_coverage_eval_tests(void); 10 | void c_type_with_bitfield_usage(void); -------------------------------------------------------------------------------- /src/mule/mule_hotload_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | int lib_loaded = 0; 7 | HANDLE lib = {0}; 8 | FILETIME lib_last_filetime = {0}; 9 | int (*get_number)(void) = 0; 10 | for(;;) 11 | { 12 | //- rjf: hot-load dll 13 | { 14 | HANDLE file = CreateFileA("mule_hotload_module.dll", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 15 | FILETIME modified = {0}; 16 | if(GetFileTime(file, 0, 0, &modified) && 17 | CompareFileTime(&lib_last_filetime, &modified) == -1) 18 | { 19 | for(int reloaded = 0; !reloaded;) 20 | { 21 | if(lib_loaded) 22 | { 23 | FreeLibrary(lib); 24 | lib_loaded = 0; 25 | } 26 | BOOL copy_worked = CopyFile("mule_hotload_module.dll", "mule_hotload_module_temp.dll", 0); 27 | lib = LoadLibraryA("mule_hotload_module_temp.dll"); 28 | if(lib != INVALID_HANDLE_VALUE) 29 | { 30 | reloaded = 1; 31 | lib_last_filetime = modified; 32 | get_number = (int(*)(void))GetProcAddress(lib, "get_number"); 33 | lib_loaded = 1; 34 | } 35 | } 36 | } 37 | CloseHandle(file); 38 | } 39 | int number = get_number(); 40 | printf("got a number: %i\n", number); 41 | if(number == 0) 42 | { 43 | break; 44 | } 45 | Sleep(1000); 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/mule/mule_hotload_module_main.c: -------------------------------------------------------------------------------- 1 | __declspec(dllexport) int 2 | get_number(void) 3 | { 4 | int sum = 0; 5 | for(int i = 0; i < 100; i += 1) 6 | { 7 | sum += i; 8 | sum += i; 9 | sum += 1; 10 | } 11 | sum = 1000; 12 | return sum; 13 | } 14 | -------------------------------------------------------------------------------- /src/mule/mule_inline.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | /* 5 | ** Make sure we have an inlined function 6 | */ 7 | 8 | #if defined(_MSC_VER) 9 | # define FORCE_INLINE __forceinline 10 | #elif defined(__clang__) || defined(__GNUC__) 11 | # define FORCE_INLINE __attribute__((always_inline)) 12 | #else 13 | # error need force inline for this compiler 14 | #endif 15 | 16 | //////////////////////////////// 17 | // NOTE(allen): Inline Stepping 18 | 19 | unsigned int fixed_frac_bits = 5; 20 | static unsigned int bias = 7; 21 | 22 | static FORCE_INLINE unsigned int 23 | fixed_mul(unsigned int a, unsigned int b){ 24 | unsigned int c = (((a - bias)*(b - bias)) >> fixed_frac_bits) + bias; 25 | return(c); 26 | } 27 | 28 | static FORCE_INLINE unsigned int 29 | multi_file_inlinesite(unsigned int x){ 30 | // force compiler to generate annotations for code that's inside another file 31 | #include "inline_body.cpp" 32 | return x >> fixed_frac_bits; 33 | } 34 | 35 | static unsigned int test_value = 0; 36 | 37 | unsigned int 38 | inline_stepping_tests(void){ 39 | bias = 15; 40 | 41 | // NOTE(nick): Interesting that CL does not generate inline site symbols in order of apperance here unlike clang. 42 | 43 | // CL: 44 | // BinaryAnnotations: CodeLengthAndCodeOffset d 0 45 | // BinaryAnnotation Length: 4 bytes (1 bytes padding) 46 | // 47 | // Clang: 48 | // BinaryAnnotations: LineOffset 1 CodeLength d 49 | // BinaryAnnotation Length: 4 bytes (0 bytes padding) 50 | unsigned int x = fixed_mul(5001, 7121); 51 | 52 | // CL: 53 | // BinaryAnnotations: CodeOffsetAndLineOffset d File 0 CodeOffsetAndLineOffset 22 LineOffset 1e 54 | // CodeLengthAndCodeOffset 2 3 55 | // BinaryAnnotation Length: 12 bytes (1 bytes padding) 56 | // 57 | // Clang: 58 | // BinaryAnnotations: File 18 LineOffset ffffffe6 CodeOffset d CodeOffsetAndLineOffset 22 59 | // File 0 LineOffset 1e CodeOffset 3 CodeLength 2 60 | // BinaryAnnotation Length: 16 bytes (0 bytes padding) 61 | unsigned int z = multi_file_inlinesite(x); 62 | return(z); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/mule/mule_module.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #if _WIN32 5 | #define export_function extern "C" __declspec(dllexport) 6 | #else 7 | #define export_function extern "C" 8 | #endif 9 | 10 | #if _WIN32 11 | # define thread_var __declspec(thread) 12 | #else 13 | # define thread_var __thread 14 | #endif 15 | 16 | typedef struct OnlyInModule OnlyInModule; 17 | struct OnlyInModule 18 | { 19 | int x; 20 | int y; 21 | int z; 22 | char *name; 23 | }; 24 | 25 | typedef struct Basics Basics; 26 | struct Basics 27 | { 28 | int a; 29 | int b; 30 | int c; 31 | int d; 32 | }; 33 | 34 | static OnlyInModule only_in_module_global = 35 | { 36 | 1, 2, 3, "foobar", 37 | }; 38 | 39 | thread_var float tls_a = 1.015625f; 40 | thread_var int tls_b = -100; 41 | 42 | export_function void 43 | dll_tls_eval_test(void) 44 | { 45 | tls_a *= 1.5f; 46 | tls_b *= -2; 47 | only_in_module_global.x += 1; 48 | only_in_module_global.y += 2; 49 | only_in_module_global.z += 3; 50 | } 51 | 52 | export_function void 53 | dll_type_eval_tests(void) 54 | { 55 | Basics basics1 = {1, 2, 3, 4}; 56 | Basics basics2 = {4, 5, 6, 7}; 57 | OnlyInModule only_in_module = {123, 456, 789, "this type is only in the module!"}; 58 | int x = 0; 59 | (void)x; 60 | } 61 | -------------------------------------------------------------------------------- /src/mule/mule_o2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | static int important_s32 = 0; 5 | static float important_f32 = 0; 6 | 7 | #if _WIN32 8 | #include 9 | #endif 10 | 11 | static void 12 | do_something_with_intermediate_values(void) 13 | { 14 | static int another_important_s32 = 0; 15 | static float another_important_f32 = 0; 16 | 17 | another_important_s32 = (int)important_f32; 18 | another_important_f32 = (float)important_s32; 19 | 20 | #if _WIN32 21 | char buffer[256] = "Hello, World!\n"; 22 | buffer[0] += important_s32 + another_important_s32; 23 | buffer[1] += (int)another_important_f32 * important_f32; 24 | OutputDebugStringA(buffer); 25 | #endif 26 | } 27 | 28 | static void 29 | store_important_s32(int *ptr) 30 | { 31 | important_s32 = *ptr; 32 | } 33 | 34 | static void 35 | store_important_f32(float *ptr) 36 | { 37 | important_f32 = *ptr; 38 | } 39 | 40 | void 41 | optimized_build_eval_tests(void) 42 | { 43 | int simple_sum = 0; 44 | for(int i = 0; i < 10000; i += 1) 45 | { 46 | simple_sum += i; 47 | } 48 | store_important_s32(&simple_sum); 49 | 50 | do_something_with_intermediate_values(); 51 | 52 | static struct {float x, y;} vec2s[] = 53 | { 54 | { 10.f, 76.f }, 55 | { 40.f, 50.f }, 56 | { -230.f, 20.f }, 57 | { 27.f, 27.f }, 58 | { 57.f, -57.f }, 59 | { -37.f, 97.f }, 60 | { 99.f, 67.f }, 61 | { 99.f, 37.f }, 62 | { 99.f, 57.f }, 63 | }; 64 | { 65 | struct{float x, y;}sum = {0}; 66 | int count = sizeof(vec2s)/sizeof(vec2s[0]); 67 | for(int i = 0; i < count; i += 1) 68 | { 69 | sum.x += vec2s[i].x; 70 | sum.y += vec2s[i].y; 71 | } 72 | struct{float x, y;}avg = {sum.x/count, sum.y/count}; 73 | float f32 = avg.x * avg.y; 74 | store_important_f32(&f32); 75 | } 76 | 77 | do_something_with_intermediate_values(); 78 | 79 | int factorial = 1; 80 | for(int i = 10; i > 0; i -= 1) 81 | { 82 | factorial *= i; 83 | } 84 | store_important_s32(&factorial); 85 | 86 | do_something_with_intermediate_values(); 87 | } 88 | 89 | //////////////////////////////// 90 | // NOTE(allen): Struct Parameters Eval 91 | 92 | struct OptimizedBasics{ 93 | char a; 94 | unsigned char b; 95 | short c; 96 | unsigned short d; 97 | int e; 98 | unsigned int f; 99 | long long g; 100 | unsigned long long h; 101 | float i; 102 | double j; 103 | }; 104 | 105 | static void 106 | optimized_struct_parameter_helper(int *ptr, OptimizedBasics basics) 107 | { 108 | basics.a += *ptr; 109 | basics.a += 1; 110 | basics.a += 1; 111 | } 112 | 113 | void 114 | optimized_struct_parameters_eval_tests(void) 115 | { 116 | int x = 10; 117 | OptimizedBasics basics = {-1, 1, -2, 2, -4, 4, -8, 8, 1.5f, 1.50000000000001}; 118 | optimized_struct_parameter_helper(&x, basics); 119 | } 120 | -------------------------------------------------------------------------------- /src/mule/mule_peb_trample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mule_peb_trample_reload.c" 4 | 5 | static void 6 | HideModuleFromWindowsReload(HMODULE ModuleToFlush) 7 | { 8 | /* NOTE(casey): Normally you cannot "reload" an executable module with the same name, 9 | because Windows checks a linked list of loaded modules and assumes that if 10 | it's already loaded, it doesn't need to reload it, even though it may have to because 11 | it has changed on disk. 12 | 13 | This solution to that problem comes from some excellent spelunking by Martins Mozeiko, 14 | who figured out that you could overwrite the filenames Windows stores in your process's 15 | loaded module table, thus thwarting the Windows filename check against loaded modules, 16 | allowing you to reload an existing module that has changed without requiring it to 17 | have a different filename! 18 | */ 19 | 20 | PEB *Peb = (PEB *)__readgsqword(offsetof(TEB, ProcessEnvironmentBlock)); 21 | LIST_ENTRY *Head = &Peb->Ldr->InMemoryOrderModuleList; 22 | for(LIST_ENTRY *Entry = Head->Flink; 23 | Entry != Head; 24 | Entry = Entry->Flink) 25 | { 26 | LDR_DATA_TABLE_ENTRY *Mod = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); 27 | if(Mod->DllBase == ModuleToFlush) 28 | { 29 | ZeroMemory(Mod->FullDllName.Buffer, Mod->FullDllName.Length); 30 | Mod->DllBase = 0; 31 | break; 32 | } 33 | } 34 | } 35 | 36 | int main(int argument_count, char **arguments) 37 | { 38 | char *exe_name = arguments[0]; 39 | HANDLE last_module = GetModuleHandle(0); 40 | int (*loop_iteration_function)(int it) = (int (*)(int))GetProcAddress(last_module, "loop_iteration"); 41 | FILETIME last_filetime = {0}; 42 | int should_exit = 0; 43 | for(int it = 0; !should_exit; it += 1) 44 | { 45 | int result = loop_iteration_function(it); 46 | printf("%i\n", result); 47 | Sleep(50); 48 | FILETIME current_filetime = {0}; 49 | HANDLE current_exe_file = CreateFile(exe_name, 0, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 50 | GetFileTime(current_exe_file, 0, 0, ¤t_filetime); 51 | CloseHandle(current_exe_file); 52 | if(it != 0 && CompareFileTime(&last_filetime, ¤t_filetime) < 0) 53 | { 54 | HideModuleFromWindowsReload(last_module); 55 | last_module = LoadLibrary(arguments[0]); 56 | loop_iteration_function = (int (*)(int))GetProcAddress(last_module, "loop_iteration"); 57 | } 58 | last_filetime = current_filetime; 59 | } 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /src/mule/mule_peb_trample_reload.c: -------------------------------------------------------------------------------- 1 | __declspec(dllexport) int 2 | loop_iteration(int it) 3 | { 4 | //return 111; 5 | #if 1 6 | int sum = 0; 7 | for(int i = 0; i < 1000; i += 1) 8 | { 9 | sum += it*i; 10 | } 11 | return sum; 12 | #endif 13 | } 14 | -------------------------------------------------------------------------------- /src/mutable_text/mutable_text.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef MUTABLE_TEXT_H 5 | #define MUTABLE_TEXT_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Cache Types 9 | 10 | typedef struct MTX_Node MTX_Node; 11 | struct MTX_Node 12 | { 13 | MTX_Node *next; 14 | MTX_Node *prev; 15 | U128 key; 16 | }; 17 | 18 | typedef struct MTX_Slot MTX_Slot; 19 | struct MTX_Slot 20 | { 21 | MTX_Node *first; 22 | MTX_Node *last; 23 | }; 24 | 25 | typedef struct MTX_Stripe MTX_Stripe; 26 | struct MTX_Stripe 27 | { 28 | Arena *arena; 29 | MTX_Node *free_node; 30 | OS_Handle rw_mutex; 31 | }; 32 | 33 | //////////////////////////////// 34 | //~ rjf: Mutation Thread Types 35 | 36 | typedef struct MTX_Op MTX_Op; 37 | struct MTX_Op 38 | { 39 | Rng1U64 range; 40 | String8 replace; 41 | }; 42 | 43 | typedef struct MTX_MutThread MTX_MutThread; 44 | struct MTX_MutThread 45 | { 46 | U64 ring_size; 47 | U8 *ring_base; 48 | U64 ring_read_pos; 49 | U64 ring_write_pos; 50 | OS_Handle cv; 51 | OS_Handle mutex; 52 | OS_Handle thread; 53 | }; 54 | 55 | //////////////////////////////// 56 | //~ rjf: Shared State 57 | 58 | typedef struct MTX_Shared MTX_Shared; 59 | struct MTX_Shared 60 | { 61 | Arena *arena; 62 | 63 | // rjf: buffer cache 64 | U64 slots_count; 65 | U64 stripes_count; 66 | MTX_Slot *slots; 67 | MTX_Stripe *stripes; 68 | 69 | // rjf: mut threads 70 | U64 mut_threads_count; 71 | MTX_MutThread *mut_threads; 72 | }; 73 | 74 | //////////////////////////////// 75 | //~ rjf: Globals 76 | 77 | global MTX_Shared *mtx_shared = 0; 78 | 79 | //////////////////////////////// 80 | //~ rjf: Main Layer Initialization 81 | 82 | internal void mtx_init(void); 83 | 84 | //////////////////////////////// 85 | //~ rjf: Buffer Operations 86 | 87 | internal void mtx_push_op(HS_Key buffer_key, MTX_Op op); 88 | 89 | //////////////////////////////// 90 | //~ rjf: Mutation Threads 91 | 92 | internal void mtx_enqueue_op(MTX_MutThread *thread, HS_Key buffer_key, MTX_Op op); 93 | internal void mtx_dequeue_op(Arena *arena, MTX_MutThread *thread, HS_Key *buffer_key_out, MTX_Op *op_out); 94 | internal void mtx_mut_thread__entry_point(void *p); 95 | 96 | #endif // MUTABLE_TEXT_H 97 | -------------------------------------------------------------------------------- /src/os/core/linux/os_core_linux_old.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef LINUX_H 5 | #define LINUX_H 6 | 7 | //////////////////////////////// 8 | //~ NOTE(allen): Get all these linux includes 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | //////////////////////////////// 27 | //~ NOTE(allen): File Iterator 28 | 29 | struct LNX_FileIter{ 30 | int fd; 31 | DIR *dir; 32 | }; 33 | StaticAssert(sizeof(Member(OS_FileIter, memory)) >= sizeof(LNX_FileIter), file_iter_memory_size); 34 | 35 | //////////////////////////////// 36 | //~ NOTE(allen): Threading Entities 37 | 38 | enum LNX_EntityKind{ 39 | LNX_EntityKind_Null, 40 | LNX_EntityKind_Thread, 41 | LNX_EntityKind_Mutex, 42 | LNX_EntityKind_ConditionVariable, 43 | }; 44 | 45 | struct LNX_Entity{ 46 | LNX_Entity *next; 47 | LNX_EntityKind kind; 48 | volatile U32 reference_mask; 49 | union{ 50 | struct{ 51 | OS_ThreadFunctionType *func; 52 | void *ptr; 53 | pthread_t handle; 54 | } thread; 55 | pthread_mutex_t mutex; 56 | pthread_cond_t cond; 57 | }; 58 | }; 59 | 60 | //////////////////////////////// 61 | //~ NOTE(allen): Safe Call Chain 62 | 63 | struct LNX_SafeCallChain{ 64 | LNX_SafeCallChain *next; 65 | OS_ThreadFunctionType *fail_handler; 66 | void *ptr; 67 | }; 68 | 69 | //////////////////////////////// 70 | //~ NOTE(allen): Helpers 71 | 72 | internal B32 lnx_write_list_to_file_descriptor(int fd, String8List list); 73 | 74 | internal void lnx_date_time_from_tm(DateTime *out, struct tm *in, U32 msec); 75 | internal void lnx_tm_from_date_time(struct tm *out, DateTime *in); 76 | internal void lnx_dense_time_from_timespec(DenseTime *out, struct timespec *in); 77 | internal void lnx_file_properties_from_stat(FileProperties *out, struct stat *in); 78 | 79 | internal String8 lnx_string_from_signal(int signum); 80 | internal String8 lnx_string_from_errno(int error_number); 81 | 82 | internal LNX_Entity* lnx_alloc_entity(LNX_EntityKind kind); 83 | internal void lnx_free_entity(LNX_Entity *entity); 84 | internal void* lnx_thread_base(void *ptr); 85 | 86 | internal void lnx_safe_call_sig_handler(int); 87 | 88 | #endif //LINUX_H 89 | -------------------------------------------------------------------------------- /src/os/gfx/linux/os_gfx_linux.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef OS_GFX_LINUX_H 5 | #define OS_GFX_LINUX_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Includes 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | //////////////////////////////// 18 | //~ rjf: Window State 19 | 20 | typedef struct OS_LNX_Window OS_LNX_Window; 21 | struct OS_LNX_Window 22 | { 23 | OS_LNX_Window *next; 24 | OS_LNX_Window *prev; 25 | Window window; 26 | XIC xic; 27 | XID counter_xid; 28 | U64 counter_value; 29 | }; 30 | 31 | //////////////////////////////// 32 | //~ rjf: State Bundle 33 | 34 | typedef struct OS_LNX_GfxState OS_LNX_GfxState; 35 | struct OS_LNX_GfxState 36 | { 37 | Arena *arena; 38 | Display *display; 39 | XIM xim; 40 | OS_LNX_Window *first_window; 41 | OS_LNX_Window *last_window; 42 | OS_LNX_Window *free_window; 43 | Atom wm_delete_window_atom; 44 | Atom wm_sync_request_atom; 45 | Atom wm_sync_request_counter_atom; 46 | Cursor cursors[OS_Cursor_COUNT]; 47 | OS_Cursor last_set_cursor; 48 | OS_GfxInfo gfx_info; 49 | }; 50 | 51 | //////////////////////////////// 52 | //~ rjf: Globals 53 | 54 | global OS_LNX_GfxState *os_lnx_gfx_state = 0; 55 | 56 | //////////////////////////////// 57 | //~ rjf: Helpers 58 | 59 | internal OS_LNX_Window *os_lnx_window_from_x11window(Window window); 60 | 61 | #endif // OS_GFX_LINUX_H 62 | -------------------------------------------------------------------------------- /src/os/gfx/stub/os_gfx_stub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef OS_GFX_STUB_H 5 | #define OS_GFX_STUB_H 6 | 7 | #endif // OS_GFX_STUB_H 8 | -------------------------------------------------------------------------------- /src/os/os_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "os/core/os_core.c" 5 | #if OS_FEATURE_GRAPHICAL 6 | # include "os/gfx/os_gfx.c" 7 | #endif 8 | 9 | #if OS_WINDOWS 10 | # include "os/core/win32/os_core_win32.c" 11 | #elif OS_LINUX 12 | # include "os/core/linux/os_core_linux.c" 13 | #else 14 | # error OS core layer not implemented for this operating system. 15 | #endif 16 | 17 | #if OS_FEATURE_GRAPHICAL 18 | # if OS_GFX_STUB 19 | # include "os/gfx/stub/os_gfx_stub.c" 20 | # elif OS_WINDOWS 21 | # include "os/gfx/win32/os_gfx_win32.c" 22 | # elif OS_LINUX 23 | # include "os/gfx/linux/os_gfx_linux.c" 24 | # else 25 | # error OS graphical layer not implemented for this operating system. 26 | # endif 27 | #endif 28 | -------------------------------------------------------------------------------- /src/os/os_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef OS_INC_H 5 | #define OS_INC_H 6 | 7 | #if !defined(OS_FEATURE_GRAPHICAL) 8 | # define OS_FEATURE_GRAPHICAL 0 9 | #endif 10 | 11 | #if !defined(OS_GFX_STUB) 12 | # define OS_GFX_STUB 0 13 | #endif 14 | 15 | #include "os/core/os_core.h" 16 | #if OS_FEATURE_GRAPHICAL 17 | # include "os/gfx/os_gfx.h" 18 | #endif 19 | 20 | #if OS_WINDOWS 21 | # include "os/core/win32/os_core_win32.h" 22 | #elif OS_LINUX 23 | # include "os/core/linux/os_core_linux.h" 24 | #else 25 | # error OS core layer not implemented for this operating system. 26 | #endif 27 | 28 | #if OS_FEATURE_GRAPHICAL 29 | # if OS_GFX_STUB 30 | # include "os/gfx/stub/os_gfx_stub.h" 31 | # elif OS_WINDOWS 32 | # include "os/gfx/win32/os_gfx_win32.h" 33 | # elif OS_LINUX 34 | # include "os/gfx/linux/os_gfx_linux.h" 35 | # else 36 | # error OS graphical layer not implemented for this operating system. 37 | # endif 38 | #endif 39 | 40 | #endif // OS_INC_H 41 | -------------------------------------------------------------------------------- /src/path/path.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef PATH_H 5 | #define PATH_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Relative <-> Absolute Path 9 | 10 | internal String8 path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src); 11 | internal String8 path_absolute_dst_from_relative_dst_src(Arena *arena, String8 dst, String8 src); 12 | 13 | //////////////////////////////// 14 | //~ rjf: Path Normalization 15 | 16 | internal String8List path_normalized_list_from_string(Arena *arena, String8 path, PathStyle *style_out); 17 | internal String8 path_normalized_from_string(Arena *arena, String8 path); 18 | internal B32 path_match_normalized(String8 left, String8 right); 19 | 20 | //////////////////////////////// 21 | //~ rjf: Basic Helpers 22 | 23 | internal PathStyle path_style_from_string(String8 string); 24 | internal String8 string_from_path_style(PathStyle style); 25 | internal String8 path_separator_string_from_style(PathStyle style); 26 | internal StringMatchFlags path_match_flags_from_os(OperatingSystem os); 27 | internal String8 path_convert_slashes(Arena *arena, String8 path, PathStyle path_style); 28 | internal String8 path_replace_file_extension(Arena *arena, String8 file_name, String8 ext); 29 | 30 | #endif //PATH_H 31 | -------------------------------------------------------------------------------- /src/pdb/pdb.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal U32 5 | pdb_hash_v1(String8 string) 6 | { 7 | U32 result = 0; 8 | U8 *ptr = string.str; 9 | U8 *opl = ptr + (string.size&(~3)); 10 | for(; ptr < opl; ptr += 4) 11 | { 12 | result ^= *(U32*)ptr; 13 | } 14 | if((string.size&2) != 0) 15 | { 16 | result ^= *(U16*)ptr; ptr += 2; 17 | } 18 | if((string.size&1) != 0) 19 | { 20 | result ^= *ptr; 21 | } 22 | result |= 0x20202020; 23 | result ^= (result >> 11); 24 | result ^= (result >> 16); 25 | return result; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/pdb/pdb_stringize.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ PDB Stringize Functions 6 | 7 | internal void 8 | pdb_stringize_tpi_hash(Arena *arena, String8List *out, PDB_TpiHashParsed *hash){ 9 | U32 bucket_count = hash->bucket_count; 10 | str8_list_pushf(arena, out, "bucket_count=%u\n\n", bucket_count); 11 | for (U32 i = 0; i < bucket_count; i += 1){ 12 | if (hash->buckets[i] != 0){ 13 | str8_list_pushf(arena, out, "bucket[%u]:\n", i); 14 | for (PDB_TpiHashBlock *block = hash->buckets[i]; 15 | block != 0; 16 | block = block->next){ 17 | U32 local_count = block->local_count; 18 | CV_TypeId *itype_ptr = block->itypes; 19 | for (U32 j = 0; j < local_count; j += 1, itype_ptr += 1){ 20 | str8_list_pushf(arena, out, " %u\n", *itype_ptr); 21 | } 22 | } 23 | str8_list_push(arena, out, str8_lit("\n")); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/pdb/pdb_stringize.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef PDB_STRINGIZE_H 5 | #define PDB_STRINGIZE_H 6 | 7 | //////////////////////////////// 8 | //~ PDB Stringize Functions 9 | 10 | internal void pdb_stringize_tpi_hash(Arena *arena, String8List *out, PDB_TpiHashParsed *hash); 11 | 12 | #endif // PDB_STRINGIZE_H 13 | -------------------------------------------------------------------------------- /src/pe/dos_program.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2024 Epic Games Tools 2 | ; Licensed under the MIT license (https://opensource.org/license/mit/) 3 | ; $ c:\devel\projects\bin\win32\nasm src\pe\dos_program.asm -fbin -o dos_program.bin 4 | 5 | BITS 16 6 | 7 | SEGMENT CODE 8 | push cs ; copy psp segment address to ds 9 | pop ds 10 | mov dx, msg ; set print string 11 | mov ah, 9h ; print to stdout 12 | int 21h 13 | mov ax, 0x4c01 ; terminate with return code 1 in al 14 | int 0x21 15 | 16 | msg: DB "This program cannot be run in DOS mode.$",0 17 | ALIGN 8, DB 18 | -------------------------------------------------------------------------------- /src/radcon/radcon.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADCON_H 5 | #define RADCON_H 6 | 7 | typedef U32 RC_Flags; 8 | enum 9 | { 10 | RC_Flag_Strings = (1 << 0), 11 | RC_Flag_IndexRuns = (1 << 1), 12 | RC_Flag_BinarySections = (1 << 2), 13 | RC_Flag_Units = (1 << 3), 14 | RC_Flag_Procedures = (1 << 4), 15 | RC_Flag_GlobalVariables = (1 << 5), 16 | RC_Flag_ThreadVariables = (1 << 6), 17 | RC_Flag_Scopes = (1 << 7), 18 | RC_Flag_Locals = (1 << 8), 19 | RC_Flag_Types = (1 << 9), 20 | RC_Flag_UDTs = (1 << 10), 21 | RC_Flag_LineInfo = (1 << 11), 22 | RC_Flag_GlobalVariableNameMap = (1 << 12), 23 | RC_Flag_ThreadVariableNameMap = (1 << 13), 24 | RC_Flag_ProcedureNameMap = (1 << 14), 25 | RC_Flag_TypeNameMap = (1 << 15), 26 | RC_Flag_LinkNameProcedureNameMap= (1 << 16), 27 | RC_Flag_NormalSourcePathNameMap = (1 << 17), 28 | RC_Flag_Compress = (1 << 18), 29 | RC_Flag_StrictDwarfParse = (1 << 19), 30 | RC_Flag_Deterministic = (1 << 20), 31 | RC_Flag_CheckPdbGuid = (1 << 21), 32 | RC_Flag_CheckElfChecksum = (1 << 22), 33 | RC_Flag_All = 0xffffffff, 34 | }; 35 | 36 | typedef enum 37 | { 38 | RC_Driver_Null, 39 | RC_Driver_Dwarf, 40 | RC_Driver_Pdb, 41 | } RC_Driver; 42 | 43 | typedef struct RC_Context 44 | { 45 | ImageType image; 46 | RC_Driver driver; 47 | String8 image_name; 48 | String8 image_data; 49 | String8 debug_name; 50 | String8 debug_data; 51 | String8 out_name; 52 | RC_Flags flags; 53 | Guid guid; 54 | ELF_GnuDebugLink debug_link; 55 | String8List errors; 56 | } RC_Context; 57 | 58 | //////////////////////////////// 59 | 60 | internal RC_Context rc_context_from_cmd_line(Arena *arena, CmdLine *cmdl); 61 | internal String8List rc_run(Arena *arena, RC_Context *rc); 62 | internal String8 rc_rdi_from_cmd_line(Arena *arena, CmdLine *cmdl); 63 | internal void rc_main(CmdLine *cmdl); 64 | 65 | #endif // RADCON_H 66 | 67 | -------------------------------------------------------------------------------- /src/radcon/radcon_coff.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal RDI_Arch 5 | c2r_rdi_arch_from_coff_machine(COFF_MachineType machine) 6 | { 7 | switch (machine) { 8 | case COFF_MachineType_X86: return RDI_Arch_X86; 9 | case COFF_MachineType_X64: return RDI_Arch_X64; 10 | 11 | case COFF_MachineType_Unknown: 12 | case COFF_MachineType_Am33: 13 | case COFF_MachineType_Arm: 14 | case COFF_MachineType_Arm64: 15 | case COFF_MachineType_ArmNt: 16 | case COFF_MachineType_Ebc: 17 | case COFF_MachineType_Ia64: 18 | case COFF_MachineType_M32R: 19 | case COFF_MachineType_Mips16: 20 | case COFF_MachineType_MipsFpu: 21 | case COFF_MachineType_MipsFpu16: 22 | case COFF_MachineType_PowerPc: 23 | case COFF_MachineType_PowerPcFp: 24 | case COFF_MachineType_R4000: 25 | case COFF_MachineType_RiscV32: 26 | case COFF_MachineType_RiscV64: 27 | case COFF_MachineType_Sh3: 28 | case COFF_MachineType_Sh3Dsp: 29 | case COFF_MachineType_Sh4: 30 | case COFF_MachineType_Sh5: 31 | case COFF_MachineType_Thumb: 32 | case COFF_MachineType_WceMipsV2: 33 | NotImplemented; 34 | default: 35 | return RDI_Arch_NULL; 36 | } 37 | } 38 | 39 | internal RDI_BinarySectionFlags 40 | c2r_rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags) 41 | { 42 | RDI_BinarySectionFlags result = 0; 43 | if(flags & COFF_SectionFlag_MemRead) 44 | { 45 | result |= RDI_BinarySectionFlag_Read; 46 | } 47 | if(flags & COFF_SectionFlag_MemWrite) 48 | { 49 | result |= RDI_BinarySectionFlag_Write; 50 | } 51 | if(flags & COFF_SectionFlag_MemExecute) 52 | { 53 | result |= RDI_BinarySectionFlag_Execute; 54 | } 55 | return(result); 56 | } 57 | 58 | internal RDIM_BinarySectionList 59 | c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab) 60 | { 61 | ProfBeginFunction(); 62 | 63 | RDIM_BinarySectionList binary_sections = {0}; 64 | 65 | for (U64 isec = 0; isec < sectab_count; ++isec) { 66 | COFF_SectionHeader *coff_sec = §ab[isec]; 67 | RDIM_BinarySection *sec = rdim_binary_section_list_push(arena, &binary_sections); 68 | 69 | sec->name = coff_name_from_section_header(string_table, coff_sec); 70 | sec->flags = c2r_rdi_binary_section_flags_from_coff_section_flags(coff_sec->flags); 71 | sec->voff_first = coff_sec->voff; 72 | sec->voff_opl = coff_sec->voff + coff_sec->vsize; 73 | sec->foff_first = coff_sec->foff; 74 | sec->foff_opl = coff_sec->foff + coff_sec->fsize; 75 | } 76 | 77 | ProfEnd(); 78 | return binary_sections; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/radcon/radcon_coff.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADCON_COFF_H 5 | #define RADCON_COFF_H 6 | 7 | internal RDI_Arch c2r_rdi_arch_from_coff_machine(COFF_MachineType machine); 8 | internal RDI_BinarySectionFlags c2r_rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags); 9 | internal RDIM_BinarySectionList c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab); 10 | 11 | #endif // RADCON_COFF_H 12 | 13 | -------------------------------------------------------------------------------- /src/radcon/radcon_cv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //////////////////////////////// 4 | //~ rjf: CodeView => RDI Canonical Conversions 5 | 6 | internal RDI_Arch cv2r_rdi_arch_from_cv_arch(CV_Arch arch); 7 | internal RDI_RegCode cv2r_rdi_reg_code_from_cv_reg_code(RDI_Arch arch, CV_Reg reg_code); 8 | internal RDI_Language cv2r_rdi_language_from_cv_language(CV_Language language); 9 | internal RDI_RegCode cv2r_reg_code_from_arch_encoded_fp_reg(RDI_Arch arch, CV_EncodedFramePtrReg encoded_reg); 10 | internal RDI_TypeKind cv2r_rdi_type_kind_from_cv_basic_type(CV_BasicType basic_type); 11 | -------------------------------------------------------------------------------- /src/radcon/radcon_dwarf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADCON_DWARF_H 5 | #define RADCON_DWARF_H 6 | 7 | typedef struct D2R_TypeTable 8 | { 9 | HashTable *ht; 10 | RDIM_TypeChunkList *types; 11 | U64 type_chunk_cap; 12 | RDIM_Type *varg_type; 13 | } D2R_TypeTable; 14 | 15 | typedef struct D2R_TagNode 16 | { 17 | struct D2R_TagNode *next; 18 | DW_TagNode *cur_node; 19 | RDIM_Type *type; 20 | RDIM_Scope *scope; 21 | } D2R_TagNode; 22 | 23 | typedef struct D2R_CompUnitContribMap 24 | { 25 | U64 count; 26 | U64 *info_off_arr; 27 | RDIM_Rng1U64List *voff_range_arr; 28 | } D2R_CompUnitContribMap; 29 | 30 | //////////////////////////////// 31 | 32 | internal RDIM_BakeParams * d2r_convert(Arena *arena, RDIM_LocalState *local_state, RC_Context *in); 33 | 34 | //////////////////////////////// 35 | 36 | internal RDI_Language rdi_language_from_dw_language(DW_Language v); 37 | internal RDI_RegCodeX86 rdi_reg_from_dw_reg_x86(DW_RegX86 v); 38 | internal B32 rdi_reg_from_dw_reg_x64(DW_RegX64 v, RDI_RegCodeX64 *code_out, U64 *off_out, U64 *size_out); 39 | internal B32 rdi_reg_from_dw_reg(Arch arch, DW_Reg v, RDI_RegCode *code_out, U64 *off_out, U64 *size_out); 40 | 41 | #endif // RADCON_DWARF_H 42 | 43 | -------------------------------------------------------------------------------- /src/radcon/radcon_elf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | internal RDIM_BinarySectionList 5 | e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs) 6 | { 7 | RDIM_BinarySectionList result = {0}; 8 | return result; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/radcon/radcon_elf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADCON_ELF_H 5 | #define RADCON_ELF_H 6 | 7 | internal RDIM_BinarySectionList e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs); 8 | 9 | #endif // RADCON_ELF_H 10 | -------------------------------------------------------------------------------- /src/radcon/radcon_main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #define BUILD_TITLE "Epic Games Tools (R) RAD Debug Info Converter" 5 | #define BUILD_CONSOLE_INTERFACE 1 6 | 7 | //////////////////////////////// 8 | // Third Party 9 | 10 | #include "third_party/rad_lzb_simple/rad_lzb_simple.h" 11 | #include "third_party/rad_lzb_simple/rad_lzb_simple.c" 12 | #define XXH_STATIC_LINKING_ONLY 13 | #include "third_party/xxHash/xxhash.c" 14 | #include "third_party/xxHash/xxhash.h" 15 | #define SINFL_IMPLEMENTATION 16 | #include "third_party/sinfl/sinfl.h" 17 | #include "third_party/radsort/radsort.h" 18 | 19 | //////////////////////////////// 20 | // RDI Format Library 21 | 22 | #include "lib_rdi_format/rdi_format.h" 23 | #include "lib_rdi_format/rdi_format.c" 24 | 25 | //////////////////////////////// 26 | // Headers 27 | 28 | #include "base/base_inc.h" 29 | #include "os/os_inc.h" 30 | #include "async/async.h" 31 | #include "path/path.h" 32 | #include "rdi_make/rdi_make_local.h" 33 | #include "linker/hash_table.h" 34 | #include "coff/coff.h" 35 | #include "coff/coff_parse.h" 36 | #include "pe/pe.h" 37 | #include "elf/elf.h" 38 | #include "elf/elf_parse.h" 39 | #include "codeview/codeview.h" 40 | #include "codeview/codeview_parse.h" 41 | #include "dwarf/dwarf.h" 42 | #include "dwarf/dwarf_parse.h" 43 | #include "dwarf/dwarf_coff.h" 44 | #include "dwarf/dwarf_elf.h" 45 | #include "msf/msf.h" 46 | #include "msf/msf_parse.h" 47 | #include "pdb/pdb.h" 48 | #include "pdb/pdb_parse.h" 49 | #include "pdb/pdb_stringize.h" 50 | #include "radcon.h" 51 | #include "radcon_coff.h" 52 | #include "radcon_elf.h" 53 | #include "radcon_cv.h" 54 | #include "radcon_dwarf.h" 55 | #include "radcon_pdb.h" 56 | 57 | //////////////////////////////// 58 | // Implementations 59 | 60 | #include "base/base_inc.c" 61 | #include "os/os_inc.c" 62 | #include "async/async.c" 63 | #include "path/path.c" 64 | #include "rdi_make/rdi_make_local.c" 65 | #include "linker/hash_table.c" 66 | #include "coff/coff.c" 67 | #include "coff/coff_parse.c" 68 | #include "pe/pe.c" 69 | #include "elf/elf.c" 70 | #include "elf/elf_parse.c" 71 | #include "codeview/codeview.c" 72 | #include "codeview/codeview_parse.c" 73 | #include "msf/msf.c" 74 | #include "msf/msf_parse.c" 75 | #include "pdb/pdb.c" 76 | #include "pdb/pdb_parse.c" 77 | #include "pdb/pdb_stringize.c" 78 | #include "dwarf/dwarf.c" 79 | #include "dwarf/dwarf_parse.c" 80 | #include "dwarf/dwarf_coff.c" 81 | #include "dwarf/dwarf_elf.c" 82 | #include "radcon.c" 83 | #include "radcon_coff.c" 84 | #include "radcon_elf.c" 85 | #include "radcon_cv.c" 86 | #include "radcon_dwarf.c" 87 | #include "radcon_pdb.c" 88 | 89 | //////////////////////////////// 90 | 91 | internal void 92 | entry_point(CmdLine *cmdl) 93 | { 94 | rc_main(cmdl); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/raddbg/raddbg_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "raddbg_core.c" 5 | #include "raddbg_eval.c" 6 | #include "raddbg_widgets.c" 7 | #include "raddbg_views.c" 8 | #include "raddbg_legacy_config.c" 9 | -------------------------------------------------------------------------------- /src/raddbg/raddbg_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADDBG_INC_H 5 | #define RADDBG_INC_H 6 | 7 | #include "raddbg_core.h" 8 | #include "raddbg_eval.h" 9 | #include "raddbg_widgets.h" 10 | #include "raddbg_views.h" 11 | #include "raddbg_legacy_config.h" 12 | 13 | #endif // RADDBG_INC_H 14 | -------------------------------------------------------------------------------- /src/raddbg/raddbg_legacy_config.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RADDBG_LEGACY_CONFIG_H 5 | #define RADDBG_LEGACY_CONFIG_H 6 | 7 | internal RD_CfgList rd_cfg_tree_list_from_string__pre_0_9_16(Arena *arena, String8 file_path, String8 data); 8 | 9 | #endif // RADDBG_LEGACY_CONFIG_H 10 | -------------------------------------------------------------------------------- /src/rdi_format/rdi_format_local.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "lib_rdi_format/rdi_format.c" 5 | #include "lib_rdi_format/rdi_format_parse.c" 6 | 7 | internal void 8 | rdi_decompress_parsed(U8 *decompressed_data, U64 decompressed_size, RDI_Parsed *og_rdi) 9 | { 10 | // rjf: copy header 11 | RDI_Header *src_header = (RDI_Header *)og_rdi->raw_data; 12 | RDI_Header *dst_header = (RDI_Header *)decompressed_data; 13 | { 14 | MemoryCopy(dst_header, src_header, sizeof(RDI_Header)); 15 | } 16 | 17 | // rjf: copy & adjust sections for decompressed version 18 | if(og_rdi->sections_count != 0) 19 | { 20 | RDI_Section *dsec_base = (RDI_Section *)(decompressed_data + dst_header->data_section_off); 21 | MemoryCopy(dsec_base, (U8 *)og_rdi->raw_data + src_header->data_section_off, sizeof(RDI_Section) * og_rdi->sections_count); 22 | U64 off = dst_header->data_section_off + sizeof(RDI_Section) * og_rdi->sections_count; 23 | off += 7; 24 | off -= off%8; 25 | for(U64 idx = 0; idx < og_rdi->sections_count; idx += 1) 26 | { 27 | dsec_base[idx].encoding = RDI_SectionEncoding_Unpacked; 28 | dsec_base[idx].off = off; 29 | dsec_base[idx].encoded_size = dsec_base[idx].unpacked_size; 30 | off += dsec_base[idx].unpacked_size; 31 | off += 7; 32 | off -= off%8; 33 | } 34 | } 35 | 36 | // rjf: decompress sections into new decompressed file buffer 37 | if(og_rdi->sections_count != 0) 38 | { 39 | RDI_Section *src_first = og_rdi->sections; 40 | RDI_Section *dst_first = (RDI_Section *)(decompressed_data + dst_header->data_section_off); 41 | RDI_Section *src_opl = src_first + og_rdi->sections_count; 42 | RDI_Section *dst_opl = dst_first + og_rdi->sections_count; 43 | for(RDI_Section *src = src_first, *dst = dst_first; 44 | src < src_opl && dst < dst_opl; 45 | src += 1, dst += 1) 46 | { 47 | rr_lzb_simple_decode((U8*)og_rdi->raw_data + src->off, src->encoded_size, 48 | decompressed_data + dst->off, dst->unpacked_size); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/rdi_format/rdi_format_local.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RDI_FORMAT_LOCAL_H 5 | #define RDI_FORMAT_LOCAL_H 6 | 7 | #include "lib_rdi_format/rdi_format.h" 8 | #include "lib_rdi_format/rdi_format_parse.h" 9 | 10 | internal void rdi_decompress_parsed(U8 *decompressed_data, U64 decompressed_size, RDI_Parsed *og_rdi); 11 | 12 | #endif // RDI_FORMAT_LOCAL_H 13 | -------------------------------------------------------------------------------- /src/rdi_from_dwarf/rdi_from_dwarf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #pragma once 5 | 6 | typedef U64 D2R_ConvertFlags; 7 | enum 8 | { 9 | #define X(t,n,k) D2R_ConvertFlag_##t = (1ull << RDI_SectionKind_##t), 10 | RDI_SectionKind_XList 11 | #undef X 12 | D2R_ConvertFlag_StrictParse, 13 | }; 14 | 15 | typedef struct D2R_User2Convert 16 | { 17 | String8 input_exe_name; 18 | String8 input_exe_data; 19 | String8 input_debug_name; 20 | String8 input_debug_data; 21 | String8 output_name; 22 | D2R_ConvertFlags flags; 23 | String8List errors; 24 | } D2R_User2Convert; 25 | 26 | typedef struct D2R_TypeTable 27 | { 28 | HashTable *ht; 29 | RDIM_TypeChunkList *types; 30 | U64 type_chunk_cap; 31 | RDIM_Type *void_type; 32 | RDIM_Type *varg_type; 33 | } D2R_TypeTable; 34 | 35 | typedef struct D2R_TagNode 36 | { 37 | struct D2R_TagNode *next; 38 | DW_TagNode *cur_node; 39 | RDIM_Type *type; 40 | RDIM_Scope *scope; 41 | } D2R_TagNode; 42 | 43 | typedef struct D2R_CompUnitContribMap 44 | { 45 | U64 count; 46 | U64 *info_off_arr; 47 | RDIM_Rng1U64List *voff_range_arr; 48 | } D2R_CompUnitContribMap; 49 | 50 | //////////////////////////////// 51 | // Command Line -> Conversion Inputs 52 | 53 | internal D2R_User2Convert * d2r_user2convert_from_cmdln(Arena *arena, CmdLine *cmdline); 54 | 55 | //////////////////////////////// 56 | // Top-Level Conversion Entry Point 57 | 58 | internal RDIM_BakeParams * d2r_convert (Arena *arena, D2R_User2Convert *in); 59 | internal RDIM_BakeResults d2r_bake (RDIM_LocalState *state, RDIM_BakeParams *in); 60 | internal RDIM_SerializedSectionBundle d2r_compress(Arena *arena, RDIM_SerializedSectionBundle in); 61 | 62 | //////////////////////////////// 63 | // Enum Conversion 64 | 65 | internal RDI_Language rdi_language_from_dw_language(DW_Language v); 66 | internal RDI_RegCodeX86 rdi_reg_from_dw_reg_x86(DW_RegX86 v); 67 | internal B32 rdi_reg_from_dw_reg_x64(DW_RegX64 v, RDI_RegCodeX64 *code_out, U64 *off_out, U64 *size_out); 68 | internal B32 rdi_reg_from_dw_reg(Arch arch, DW_Reg v, RDI_RegCode *code_out, U64 *off_out, U64 *size_out); 69 | 70 | -------------------------------------------------------------------------------- /src/regs/rdi/generated/regs_rdi.meta.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | #ifndef REGS_RDI_META_H 7 | #define REGS_RDI_META_H 8 | 9 | #endif // REGS_RDI_META_H 10 | -------------------------------------------------------------------------------- /src/regs/rdi/regs_rdi.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #include "regs/rdi/generated/regs_rdi.meta.c" 5 | -------------------------------------------------------------------------------- /src/regs/rdi/regs_rdi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef REGS_RDI_H 5 | #define REGS_RDI_H 6 | 7 | internal RDI_RegCode regs_rdi_code_from_arch_reg_code(Arch arch, REGS_RegCode code); 8 | internal REGS_RegCode regs_reg_code_from_arch_rdi_code(Arch arch, RDI_RegCode reg); 9 | 10 | #endif //REGS_RDI_H 11 | -------------------------------------------------------------------------------- /src/regs/rdi/regs_rdi.mdesk: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: RADDBG Converter Helper Implementation Generators 6 | 7 | @gen @c_file 8 | { 9 | `internal RDI_RegCode regs_rdi_code_from_arch_reg_code(Arch arch, REGS_RegCode code)`; 10 | `{`; 11 | `RDI_RegCode result = 0;`; 12 | `switch(arch)`; 13 | `{`; 14 | `default:{}break;`; 15 | `case Arch_x64:`; 16 | `{`; 17 | `switch(code)` 18 | `{`; 19 | `default:{}break;`; 20 | @expand(REGS_RegTableX64 a) `case REGS_RegCodeX64_$(a.name):{result = RDI_RegCodeX64_$(a.name);}break;`; 21 | `}`; 22 | `}break;`; 23 | `case Arch_x86:`; 24 | `{`; 25 | `switch(code)` 26 | `{`; 27 | `default:{}break;`; 28 | @expand(REGS_RegTableX86 a) `case REGS_RegCodeX86_$(a.name):{result = RDI_RegCodeX86_$(a.name);}break;`; 29 | `}`; 30 | `}break;`; 31 | `}`; 32 | `return result;`; 33 | `}`; 34 | } 35 | 36 | @gen @c_file 37 | { 38 | `internal REGS_RegCode regs_reg_code_from_arch_rdi_code(Arch arch, RDI_RegCode code)`; 39 | `{`; 40 | `REGS_RegCode result = 0;`; 41 | `switch(arch)`; 42 | `{`; 43 | `default:{}break;`; 44 | `case Arch_x64:`; 45 | `{`; 46 | `switch(code)` 47 | `{`; 48 | `default:{}break;`; 49 | @expand(REGS_RegTableX64 a) `case RDI_RegCodeX64_$(a.name):{result = REGS_RegCodeX64_$(a.name);}break;`; 50 | `}`; 51 | `}break;`; 52 | `case Arch_x86:`; 53 | `{`; 54 | `switch(code)` 55 | `{`; 56 | `default:{}break;`; 57 | @expand(REGS_RegTableX86 a) `case RDI_RegCodeX86_$(a.name):{result = REGS_RegCodeX86_$(a.name);}break;`; 58 | `}`; 59 | `}break;`; 60 | `}`; 61 | `return result;`; 62 | `}`; 63 | } 64 | -------------------------------------------------------------------------------- /src/regs/regs.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Generated Code 6 | 7 | #include "regs/generated/regs.meta.c" 8 | 9 | //////////////////////////////// 10 | //~ rjf: Helpers 11 | 12 | internal U64 13 | regs_rip_from_arch_block(Arch arch, void *block) 14 | { 15 | U64 result = 0; 16 | if(block != 0) switch(arch) 17 | { 18 | default:{}break; 19 | case Arch_x64:{result = ((REGS_RegBlockX64 *)block)->rip.u64;}break; 20 | case Arch_x86:{result = (U64)((REGS_RegBlockX86 *)block)->eip.u32;}break; 21 | } 22 | return result; 23 | } 24 | 25 | internal U64 26 | regs_rsp_from_arch_block(Arch arch, void *block) 27 | { 28 | U64 result = 0; 29 | if(block != 0) switch(arch) 30 | { 31 | default:{}break; 32 | case Arch_x64:{result = ((REGS_RegBlockX64 *)block)->rsp.u64;}break; 33 | case Arch_x86:{result = (U64)((REGS_RegBlockX86 *)block)->esp.u32;}break; 34 | } 35 | return result; 36 | } 37 | 38 | internal void 39 | regs_arch_block_write_rip(Arch arch, void *block, U64 rip) 40 | { 41 | if(block != 0) switch(arch) 42 | { 43 | default:{}break; 44 | case Arch_x64:{((REGS_RegBlockX64 *)block)->rip.u64 = rip;}break; 45 | case Arch_x86:{((REGS_RegBlockX86 *)block)->eip.u32 = (U32)rip;}break; 46 | } 47 | } 48 | 49 | internal void 50 | regs_arch_block_write_rsp(Arch arch, void *block, U64 rsp) 51 | { 52 | if(block != 0) switch(arch) 53 | { 54 | default:{}break; 55 | case Arch_x64:{((REGS_RegBlockX64 *)block)->rsp.u64 = rsp;}break; 56 | case Arch_x86:{((REGS_RegBlockX86 *)block)->esp.u32 = (U32)rsp;}break; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/regs/regs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef REGS_H 5 | #define REGS_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Register Usage Kinds 9 | 10 | typedef enum REGS_UsageKind 11 | { 12 | REGS_UsageKind_Normal, 13 | REGS_UsageKind_Vector, 14 | } 15 | REGS_UsageKind; 16 | 17 | //////////////////////////////// 18 | //~ rjf: Register Types 19 | 20 | typedef U8 REGS_RegCode; 21 | typedef U8 REGS_AliasCode; 22 | 23 | typedef union REGS_Reg16 REGS_Reg16; 24 | union REGS_Reg16 25 | { 26 | U8 v[2]; 27 | U16 u16; 28 | }; 29 | 30 | typedef union REGS_Reg32 REGS_Reg32; 31 | union REGS_Reg32 32 | { 33 | U8 v[4]; 34 | U32 u32; 35 | F32 f32; 36 | }; 37 | 38 | typedef union REGS_Reg64 REGS_Reg64; 39 | union REGS_Reg64 40 | { 41 | U8 v[8]; 42 | U64 u64; 43 | F64 f64; 44 | }; 45 | 46 | #pragma pack(push, 1) 47 | typedef struct REGS_Reg80 REGS_Reg80; 48 | struct REGS_Reg80 49 | { 50 | U64 int1_frac63; 51 | U16 sign1_exp15; 52 | }; 53 | #pragma pack(pop) 54 | 55 | typedef union REGS_Reg128 REGS_Reg128; 56 | union REGS_Reg128 57 | { 58 | U8 v[16]; 59 | U32 u32[4]; 60 | F32 f32[4]; 61 | U64 u64[2]; 62 | F64 f64[2]; 63 | }; 64 | 65 | typedef union REGS_Reg256 REGS_Reg256; 66 | union REGS_Reg256 67 | { 68 | U8 v[32]; 69 | U32 u32[8]; 70 | F32 f32[8]; 71 | U64 u64[4]; 72 | F64 f64[4]; 73 | }; 74 | 75 | typedef union REGS_Reg512 REGS_Reg512; 76 | union REGS_Reg512 77 | { 78 | U8 v[64]; 79 | U32 u32[16]; 80 | F32 f32[16]; 81 | U64 u64[8]; 82 | F64 f64[8]; 83 | }; 84 | 85 | //////////////////////////////// 86 | //~ rjf: Register Slicing Types 87 | 88 | typedef struct REGS_Rng REGS_Rng; 89 | struct REGS_Rng 90 | { 91 | U16 byte_off; 92 | U16 byte_size; 93 | }; 94 | 95 | typedef struct REGS_Slice REGS_Slice; 96 | struct REGS_Slice 97 | { 98 | U16 code; 99 | U8 byte_off; 100 | U8 byte_size; 101 | }; 102 | 103 | //////////////////////////////// 104 | //~ rjf: Generated Code 105 | 106 | #include "regs/generated/regs.meta.h" 107 | 108 | //////////////////////////////// 109 | //~ rjf: Helpers 110 | 111 | internal U64 regs_block_size_from_arch(Arch arch); 112 | internal U64 regs_reg_code_count_from_arch(Arch arch); 113 | internal U64 regs_alias_code_count_from_arch(Arch arch); 114 | internal String8 *regs_reg_code_string_table_from_arch(Arch arch); 115 | internal String8 *regs_alias_code_string_table_from_arch(Arch arch); 116 | internal REGS_Rng *regs_reg_code_rng_table_from_arch(Arch arch); 117 | internal REGS_Slice *regs_alias_code_slice_table_from_arch(Arch arch); 118 | internal REGS_UsageKind *regs_reg_code_usage_kind_table_from_arch(Arch arch); 119 | internal REGS_UsageKind *regs_alias_code_usage_kind_table_from_arch(Arch arch); 120 | internal U64 regs_rip_from_arch_block(Arch arch, void *block); 121 | internal U64 regs_rsp_from_arch_block(Arch arch, void *block); 122 | internal void regs_arch_block_write_rip(Arch arch, void *block, U64 rip); 123 | internal void regs_arch_block_write_rsp(Arch arch, void *block, U64 rsp); 124 | 125 | #endif // REGS_H 126 | -------------------------------------------------------------------------------- /src/render/d3d11/generated/render_d3d11.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | C_LINKAGE_BEGIN 7 | String8* r_d3d11_g_vshad_kind_source_table[5] = 8 | { 9 | &r_d3d11_g_rect_shader_src, 10 | &r_d3d11_g_blur_shader_src, 11 | &r_d3d11_g_mesh_shader_src, 12 | &r_d3d11_g_geo3dcomposite_shader_src, 13 | &r_d3d11_g_finalize_shader_src, 14 | }; 15 | 16 | String8 r_d3d11_g_vshad_kind_source_name_table[5] = 17 | { 18 | str8_lit_comp("r_d3d11_g_rect_shader_src"), 19 | str8_lit_comp("r_d3d11_g_blur_shader_src"), 20 | str8_lit_comp("r_d3d11_g_mesh_shader_src"), 21 | str8_lit_comp("r_d3d11_g_geo3dcomposite_shader_src"), 22 | str8_lit_comp("r_d3d11_g_finalize_shader_src"), 23 | }; 24 | 25 | D3D11_INPUT_ELEMENT_DESC * r_d3d11_g_vshad_kind_elements_ptr_table[5] = 26 | { 27 | r_d3d11_g_rect_ilay_elements, 28 | 0, 29 | r_d3d11_g_mesh_ilay_elements, 30 | 0, 31 | 0, 32 | }; 33 | 34 | U64 r_d3d11_g_vshad_kind_elements_count_table[5] = 35 | { 36 | ArrayCount(r_d3d11_g_rect_ilay_elements) , 37 | 0, 38 | ArrayCount(r_d3d11_g_mesh_ilay_elements) , 39 | 0, 40 | 0, 41 | }; 42 | 43 | String8* r_d3d11_g_pshad_kind_source_table[5] = 44 | { 45 | &r_d3d11_g_rect_shader_src, 46 | &r_d3d11_g_blur_shader_src, 47 | &r_d3d11_g_mesh_shader_src, 48 | &r_d3d11_g_geo3dcomposite_shader_src, 49 | &r_d3d11_g_finalize_shader_src, 50 | }; 51 | 52 | String8 r_d3d11_g_pshad_kind_source_name_table[5] = 53 | { 54 | str8_lit_comp("r_d3d11_g_rect_shader_src"), 55 | str8_lit_comp("r_d3d11_g_blur_shader_src"), 56 | str8_lit_comp("r_d3d11_g_mesh_shader_src"), 57 | str8_lit_comp("r_d3d11_g_geo3dcomposite_shader_src"), 58 | str8_lit_comp("r_d3d11_g_finalize_shader_src"), 59 | }; 60 | 61 | U64 r_d3d11_g_uniform_type_kind_size_table[3] = 62 | { 63 | sizeof(R_D3D11_Uniforms_Rect), 64 | sizeof(R_D3D11_Uniforms_Blur), 65 | sizeof(R_D3D11_Uniforms_Mesh), 66 | }; 67 | 68 | C_LINKAGE_END 69 | 70 | -------------------------------------------------------------------------------- /src/render/generated/render.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | C_LINKAGE_BEGIN 7 | String8 r_tex2d_format_display_string_table[9] = 8 | { 9 | str8_lit_comp("R8"), 10 | str8_lit_comp("RG8"), 11 | str8_lit_comp("RGBA8"), 12 | str8_lit_comp("BGRA8"), 13 | str8_lit_comp("R16"), 14 | str8_lit_comp("RGBA16"), 15 | str8_lit_comp("R32"), 16 | str8_lit_comp("RG32"), 17 | str8_lit_comp("RGBA32"), 18 | }; 19 | 20 | U8 r_tex2d_format_bytes_per_pixel_table[9] = 21 | { 22 | 1, 23 | 2, 24 | 4, 25 | 4, 26 | 2, 27 | 8, 28 | 4, 29 | 8, 30 | 16, 31 | }; 32 | 33 | String8 r_resource_kind_display_string_table[3] = 34 | { 35 | str8_lit_comp("Static"), 36 | str8_lit_comp("Dynamic"), 37 | str8_lit_comp("Stream "), 38 | }; 39 | 40 | String8 r_tex2d_sample_kind_display_string_table[2] = 41 | { 42 | str8_lit_comp("Nearest"), 43 | str8_lit_comp("Linear"), 44 | }; 45 | 46 | String8 r_pass_kind_display_string_table[3] = 47 | { 48 | str8_lit_comp("UI"), 49 | str8_lit_comp("Blur"), 50 | str8_lit_comp("Geo3D"), 51 | }; 52 | 53 | U8 r_pass_kind_batch_table[3] = 54 | { 55 | 1, 56 | 0, 57 | 1, 58 | }; 59 | 60 | U64 r_pass_kind_params_size_table[3] = 61 | { 62 | sizeof(R_PassParams_UI), 63 | sizeof(R_PassParams_Blur), 64 | sizeof(R_PassParams_Geo3D), 65 | }; 66 | 67 | C_LINKAGE_END 68 | 69 | -------------------------------------------------------------------------------- /src/render/generated/render.meta.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | #ifndef RENDER_META_H 7 | #define RENDER_META_H 8 | 9 | typedef enum R_Tex2DFormat 10 | { 11 | R_Tex2DFormat_R8, 12 | R_Tex2DFormat_RG8, 13 | R_Tex2DFormat_RGBA8, 14 | R_Tex2DFormat_BGRA8, 15 | R_Tex2DFormat_R16, 16 | R_Tex2DFormat_RGBA16, 17 | R_Tex2DFormat_R32, 18 | R_Tex2DFormat_RG32, 19 | R_Tex2DFormat_RGBA32, 20 | R_Tex2DFormat_COUNT, 21 | } R_Tex2DFormat; 22 | 23 | typedef enum R_ResourceKind 24 | { 25 | R_ResourceKind_Static, 26 | R_ResourceKind_Dynamic, 27 | R_ResourceKind_Stream, 28 | R_ResourceKind_COUNT, 29 | } R_ResourceKind; 30 | 31 | typedef enum R_Tex2DSampleKind 32 | { 33 | R_Tex2DSampleKind_Nearest, 34 | R_Tex2DSampleKind_Linear, 35 | R_Tex2DSampleKind_COUNT, 36 | } R_Tex2DSampleKind; 37 | 38 | typedef enum R_GeoTopologyKind 39 | { 40 | R_GeoTopologyKind_Lines, 41 | R_GeoTopologyKind_LineStrip, 42 | R_GeoTopologyKind_Triangles, 43 | R_GeoTopologyKind_TriangleStrip, 44 | R_GeoTopologyKind_COUNT, 45 | } R_GeoTopologyKind; 46 | 47 | typedef enum R_PassKind 48 | { 49 | R_PassKind_UI, 50 | R_PassKind_Blur, 51 | R_PassKind_Geo3D, 52 | R_PassKind_COUNT, 53 | } R_PassKind; 54 | 55 | C_LINKAGE_BEGIN 56 | extern String8 r_tex2d_format_display_string_table[9]; 57 | extern U8 r_tex2d_format_bytes_per_pixel_table[9]; 58 | extern String8 r_resource_kind_display_string_table[3]; 59 | extern String8 r_tex2d_sample_kind_display_string_table[2]; 60 | extern String8 r_pass_kind_display_string_table[3]; 61 | extern U8 r_pass_kind_batch_table[3]; 62 | 63 | C_LINKAGE_END 64 | 65 | #endif // RENDER_META_H 66 | -------------------------------------------------------------------------------- /src/render/opengl/generated/render_opengl.meta.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- GENERATED CODE 5 | 6 | C_LINKAGE_BEGIN 7 | String8 r_ogl_shader_kind_name_table[2] = 8 | { 9 | str8_lit_comp("rect"), 10 | str8_lit_comp("blur"), 11 | }; 12 | 13 | String8 * r_ogl_shader_kind_vshad_src_table[2] = 14 | { 15 | &r_ogl_rect_vshad_src, 16 | &r_ogl_blur_vshad_src, 17 | }; 18 | 19 | String8 * r_ogl_shader_kind_pshad_src_table[2] = 20 | { 21 | &r_ogl_rect_pshad_src, 22 | &r_ogl_blur_pshad_src, 23 | }; 24 | 25 | R_OGL_AttributeArray r_ogl_shader_kind_input_attributes_table[2] = 26 | { 27 | { r_ogl_rect_input_attributes, ArrayCount(r_ogl_rect_input_attributes) }, 28 | { 0, }, 29 | }; 30 | 31 | R_OGL_AttributeArray r_ogl_shader_kind_output_attributes_table[2] = 32 | { 33 | { r_ogl_single_color_output_attributes, ArrayCount(r_ogl_single_color_output_attributes) }, 34 | { r_ogl_single_color_output_attributes, ArrayCount(r_ogl_single_color_output_attributes) }, 35 | }; 36 | 37 | C_LINKAGE_END 38 | 39 | -------------------------------------------------------------------------------- /src/render/opengl/linux/egl/render_opengl_linux_egl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_OPENGL_LINUX_EGL_H 5 | #define RENDER_OPENGL_LINUX_EGL_H 6 | 7 | #define glTexImage3D glTexImage3D__static 8 | #define glTexSubImage3D glTexSubImage3D__static 9 | #define glActiveTexture glActiveTexture__static 10 | #include 11 | #include 12 | #undef glTexImage3D 13 | #undef glTexSubImage3D 14 | #undef glActiveTexture 15 | 16 | typedef struct R_OGL_LNX_Window R_OGL_LNX_Window; 17 | struct R_OGL_LNX_Window 18 | { 19 | R_OGL_LNX_Window *next; 20 | EGLSurface *surface; 21 | }; 22 | 23 | typedef struct R_OGL_LNX_State R_OGL_LNX_State; 24 | struct R_OGL_LNX_State 25 | { 26 | Arena *arena; 27 | EGLDisplay *display; 28 | EGLConfig config; 29 | EGLContext *context; 30 | R_OGL_LNX_Window *free_window; 31 | }; 32 | 33 | global R_OGL_LNX_State *r_ogl_lnx_state = 0; 34 | 35 | #endif // RENDER_OPENGL_LINUX_EGL_H 36 | -------------------------------------------------------------------------------- /src/render/opengl/linux/glx/render_opengl_linux_glx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_OPENGL_LINUX_GLX_H 5 | #define RENDER_OPENGL_LINUX_GLX_H 6 | 7 | #define glTexImage3D glTexImage3D__static 8 | #define glTexSubImage3D glTexSubImage3D__static 9 | #define glActiveTexture glActiveTexture__static 10 | #include 11 | #include 12 | #undef glTexImage3D 13 | #undef glTexSubImage3D 14 | #undef glActiveTexture 15 | 16 | #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 17 | #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 18 | #define GLX_CONTEXT_FLAGS_ARB 0x2094 19 | #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 20 | #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 21 | typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); 22 | 23 | global GLXContext r_ogl_lnx_ctx = 0; 24 | 25 | #endif // RENDER_OPENGL_LINUX_GLX_H 26 | -------------------------------------------------------------------------------- /src/render/opengl/linux/render_opengl_linux.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Backend Includes 6 | 7 | #if R_OPENGL_LINUX_BACKEND == R_OPENGL_LINUX_BACKEND_GLX 8 | # include "glx/render_opengl_linux_glx.c" 9 | #elif R_OPENGL_LINUX_BACKEND == R_OPENGL_LINUX_BACKEND_EGL 10 | # include "egl/render_opengl_linux_egl.c" 11 | #else 12 | # error Linux OpenGL backend not specified. 13 | #endif 14 | -------------------------------------------------------------------------------- /src/render/opengl/linux/render_opengl_linux.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_OPENGL_LINUX_H 5 | #define RENDER_OPENGL_LINUX_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Backend Constants 9 | 10 | #define R_OPENGL_LINUX_BACKEND_GLX 0 11 | #define R_OPENGL_LINUX_BACKEND_EGL 1 12 | 13 | //////////////////////////////// 14 | //~ rjf: Decide On Backend 15 | 16 | #if !defined(R_OPENGL_LINUX_BACKEND) 17 | # define R_OPENGL_LINUX_BACKEND R_OPENGL_LINUX_BACKEND_EGL 18 | #endif 19 | 20 | //////////////////////////////// 21 | //~ rjf: Backend Includes 22 | 23 | #if R_OPENGL_LINUX_BACKEND == R_OPENGL_LINUX_BACKEND_GLX 24 | # include "glx/render_opengl_linux_glx.h" 25 | #elif R_OPENGL_LINUX_BACKEND == R_OPENGL_LINUX_BACKEND_EGL 26 | # include "egl/render_opengl_linux_egl.h" 27 | #else 28 | # error Linux OpenGL backend not specified. 29 | #endif 30 | 31 | #endif // RENDER_OPENGL_LINUX_H 32 | -------------------------------------------------------------------------------- /src/render/opengl/win32/render_opengl_win32.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_OPENGL_WIN32_H 5 | #define RENDER_OPENGL_WIN32_H 6 | 7 | #include 8 | #pragma comment(lib, "opengl32") 9 | 10 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 11 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 12 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 13 | #define WGL_PIXEL_TYPE_ARB 0x2013 14 | #define WGL_COLOR_BITS_ARB 0x2014 15 | #define WGL_DEPTH_BITS_ARB 0x2022 16 | #define WGL_STENCIL_BITS_ARB 0x2023 17 | #define WGL_TYPE_RGBA_ARB 0x202B 18 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 19 | 20 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 21 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 22 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 23 | 24 | typedef BOOL WINAPI FNWGLCHOOSEPIXELFORMATARBPROC(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 25 | typedef HGLRC WINAPI FNWGLCREATECONTEXTATTRIBSARBPROC(HDC hDC, HGLRC hShareContext, const int *attribList); 26 | typedef BOOL WINAPI FNWGLSWAPINTERVALEXTPROC(int interval); 27 | 28 | FNWGLCHOOSEPIXELFORMATARBPROC *wglChoosePixelFormatARB; 29 | FNWGLCREATECONTEXTATTRIBSARBPROC *wglCreateContextAttribsARB; 30 | FNWGLSWAPINTERVALEXTPROC *wglSwapIntervalEXT; 31 | 32 | global HGLRC r_ogl_w32_hglrc = 0; 33 | 34 | #endif // RENDER_OPENGL_WIN32_H 35 | -------------------------------------------------------------------------------- /src/render/render_core.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Generated Code 6 | 7 | #include "generated/render.meta.c" 8 | 9 | //////////////////////////////// 10 | //~ rjf: Helpers 11 | 12 | internal Mat4x4F32 13 | r_sample_channel_map_from_tex2dformat(R_Tex2DFormat fmt) 14 | { 15 | Mat4x4F32 result = 16 | { 17 | { 18 | {1, 0, 0, 0}, 19 | {0, 1, 0, 0}, 20 | {0, 0, 1, 0}, 21 | {0, 0, 0, 1}, 22 | } 23 | }; 24 | switch(fmt) 25 | { 26 | default:{}break; 27 | case R_Tex2DFormat_R8: 28 | { 29 | MemoryZeroArray(result.v[0]); 30 | result.v[0][0] = result.v[0][1] = result.v[0][2] = result.v[0][3] = 1.f; 31 | }break; 32 | } 33 | return result; 34 | } 35 | 36 | //////////////////////////////// 37 | //~ rjf: Basic Type Functions 38 | 39 | internal R_Handle 40 | r_handle_zero(void) 41 | { 42 | R_Handle handle = {0}; 43 | return handle; 44 | } 45 | 46 | internal B32 47 | r_handle_match(R_Handle a, R_Handle b) 48 | { 49 | return MemoryMatchStruct(&a, &b); 50 | } 51 | 52 | //////////////////////////////// 53 | //~ rjf: Batch Type Functions 54 | 55 | internal R_BatchList 56 | r_batch_list_make(U64 instance_size) 57 | { 58 | R_BatchList list = {0}; 59 | list.bytes_per_inst = instance_size; 60 | return list; 61 | } 62 | 63 | internal void * 64 | r_batch_list_push_inst(Arena *arena, R_BatchList *list, U64 batch_inst_cap) 65 | { 66 | void *inst = 0; 67 | { 68 | R_BatchNode *n = list->last; 69 | if(n == 0 || n->v.byte_count+list->bytes_per_inst > n->v.byte_cap) 70 | { 71 | n = push_array(arena, R_BatchNode, 1); 72 | n->v.byte_cap = batch_inst_cap*list->bytes_per_inst; 73 | n->v.v = push_array_no_zero(arena, U8, n->v.byte_cap); 74 | SLLQueuePush(list->first, list->last, n); 75 | list->batch_count += 1; 76 | } 77 | inst = n->v.v + n->v.byte_count; 78 | n->v.byte_count += list->bytes_per_inst; 79 | list->byte_count += list->bytes_per_inst; 80 | } 81 | return inst; 82 | } 83 | 84 | //////////////////////////////// 85 | //~ rjf: Pass Type Functions 86 | 87 | internal R_Pass * 88 | r_pass_from_kind(Arena *arena, R_PassList *list, R_PassKind kind) 89 | { 90 | R_PassNode *n = list->last; 91 | if(!r_pass_kind_batch_table[kind]) 92 | { 93 | n = 0; 94 | } 95 | if(n == 0 || n->v.kind != kind) 96 | { 97 | n = push_array(arena, R_PassNode, 1); 98 | SLLQueuePush(list->first, list->last, n); 99 | list->count += 1; 100 | n->v.kind = kind; 101 | n->v.params = push_array(arena, U8, r_pass_kind_params_size_table[kind]); 102 | } 103 | return &n->v; 104 | } 105 | -------------------------------------------------------------------------------- /src/render/render_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #undef LAYER_COLOR 5 | #define LAYER_COLOR 0xc22121ff 6 | 7 | #include "render_core.c" 8 | 9 | #if R_BACKEND == R_BACKEND_STUB 10 | # include "stub/render_stub.c" 11 | #elif R_BACKEND == R_BACKEND_D3D11 12 | # include "d3d11/render_d3d11.c" 13 | #elif R_BACKEND == R_BACKEND_OPENGL 14 | # include "opengl/render_opengl.c" 15 | #else 16 | # error Renderer backend not specified. 17 | #endif 18 | -------------------------------------------------------------------------------- /src/render/render_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_INC_H 5 | #define RENDER_INC_H 6 | 7 | //////////////////////////////// 8 | //~ rjf: Backend Constants 9 | 10 | #define R_BACKEND_STUB 0 11 | #define R_BACKEND_D3D11 1 12 | #define R_BACKEND_OPENGL 2 13 | 14 | //////////////////////////////// 15 | //~ rjf: Decide On Backend 16 | 17 | #if !defined(R_BACKEND) && OS_WINDOWS 18 | # define R_BACKEND R_BACKEND_D3D11 19 | #elif !defined(R_BACKEND) && OS_LINUX 20 | # define R_BACKEND R_BACKEND_OPENGL 21 | #endif 22 | 23 | //////////////////////////////// 24 | //~ rjf: Main Includes 25 | 26 | #include "render_core.h" 27 | 28 | //////////////////////////////// 29 | //~ rjf: Backend Includes 30 | 31 | #if R_BACKEND == R_BACKEND_STUB 32 | # include "stub/render_stub.h" 33 | #elif R_BACKEND == R_BACKEND_D3D11 34 | # include "d3d11/render_d3d11.h" 35 | #elif R_BACKEND == R_BACKEND_OPENGL 36 | # include "opengl/render_opengl.h" 37 | #else 38 | # error Renderer backend not specified. 39 | #endif 40 | 41 | #endif // RENDER_INC_H 42 | -------------------------------------------------------------------------------- /src/render/stub/render_stub.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //- rjf: top-level layer initialization 5 | 6 | r_hook void 7 | r_init(CmdLine *cmdln) 8 | { 9 | } 10 | 11 | //- rjf: window setup/teardown 12 | 13 | r_hook R_Handle 14 | r_window_equip(OS_Handle window) 15 | { 16 | R_Handle handle = {0}; 17 | handle.u64[0] = 1; 18 | return handle; 19 | } 20 | 21 | r_hook void 22 | r_window_unequip(OS_Handle window, R_Handle window_equip) 23 | { 24 | } 25 | 26 | //- rjf: textures 27 | 28 | r_hook R_Handle 29 | r_tex2d_alloc(R_ResourceKind kind, Vec2S32 size, R_Tex2DFormat format, void *data) 30 | { 31 | R_Handle handle = {0}; 32 | handle.u64[0] = 1; 33 | return handle; 34 | } 35 | 36 | r_hook void 37 | r_tex2d_release(R_Handle texture) 38 | { 39 | } 40 | 41 | r_hook R_ResourceKind 42 | r_kind_from_tex2d(R_Handle texture) 43 | { 44 | return R_ResourceStatic; 45 | } 46 | 47 | r_hook Vec2S32 48 | r_size_from_tex2d(R_Handle texture) 49 | { 50 | return v2s32(1, 1); 51 | } 52 | 53 | r_hook R_Tex2DFormat 54 | r_format_from_tex2d(R_Handle texture) 55 | { 56 | return R_Tex2DFormat_RGBA8; 57 | } 58 | 59 | r_hook void 60 | r_fill_tex2d_region(R_Handle texture, Rng2S32 subrect, void *data) 61 | { 62 | } 63 | 64 | //- rjf: buffers 65 | 66 | r_hook R_Handle 67 | r_buffer_alloc(R_ResourceKind kind, U64 size, void *data) 68 | { 69 | R_Handle handle = {0}; 70 | handle.u64[0] = 1; 71 | return handle; 72 | } 73 | 74 | r_hook void 75 | r_buffer_release(R_Handle buffer) 76 | { 77 | } 78 | 79 | //- rjf: frame markers 80 | 81 | r_hook void 82 | r_begin_frame(void) 83 | { 84 | } 85 | 86 | r_hook void 87 | r_end_frame(void) 88 | { 89 | } 90 | 91 | r_hook void 92 | r_window_begin_frame(OS_Handle window, R_Handle window_equip) 93 | { 94 | } 95 | 96 | r_hook void 97 | r_window_end_frame(OS_Handle window, R_Handle window_equip) 98 | { 99 | } 100 | 101 | //- rjf: render pass submission 102 | 103 | r_hook void 104 | r_window_submit(OS_Handle window, R_Handle window_equip, R_PassList *passes) 105 | { 106 | } 107 | -------------------------------------------------------------------------------- /src/render/stub/render_stub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef RENDER_STUB_H 5 | #define RENDER_STUB_H 6 | 7 | #endif // RENDER_STUB_H 8 | -------------------------------------------------------------------------------- /src/scratch/convertperf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Build Options 6 | 7 | #define BUILD_TITLE "convertperf" 8 | 9 | //////////////////////////////// 10 | //~ rjf: Includes 11 | 12 | //- rjf: [lib] 13 | #include "third_party/rad_lzb_simple/rad_lzb_simple.h" 14 | #include "third_party/rad_lzb_simple/rad_lzb_simple.c" 15 | 16 | //- rjf: [h] 17 | #include "base/base_inc.h" 18 | #include "os/os_inc.h" 19 | #include "path/path.h" 20 | #include "async/async.h" 21 | #include "rdi_format/rdi_format_local.h" 22 | #include "dbgi/dbgi.h" 23 | 24 | //- rjf: [c] 25 | #include "base/base_inc.c" 26 | #include "os/os_inc.c" 27 | #include "path/path.c" 28 | #include "async/async.c" 29 | #include "rdi_format/rdi_format_local.c" 30 | #include "dbgi/dbgi.c" 31 | 32 | //////////////////////////////// 33 | //~ rjf: Entry Points 34 | 35 | internal void 36 | entry_point(CmdLine *cmdline) 37 | { 38 | Arena *arena = arena_alloc(); 39 | String8 list_path = str8_list_first(&cmdline->inputs); 40 | String8 list_data = os_data_from_file_path(arena, list_path); 41 | U8 splits[] = {'\n'}; 42 | String8List lines = str8_split(arena, list_data, splits, ArrayCount(splits), 0); 43 | OS_HandleList processes = {0}; 44 | String8Node *processes_first_path_n = 0; 45 | U64 limit = 64; 46 | U64 idx = 0; 47 | for(String8Node *n = lines.first; n != 0; n = n->next) 48 | { 49 | String8 dll_path = n->string; 50 | ProfScope("kick off %.*s", str8_varg(dll_path)) 51 | { 52 | String8 dll_path_no_ext = str8_chop_last_dot(dll_path); 53 | String8 dll_name = str8_skip_last_slash(dll_path_no_ext); 54 | String8 pdb_path = push_str8f(arena, "%S.pdb", dll_path_no_ext); 55 | String8 rdi_path = push_str8f(arena, "dump/%S.rdi", dll_name); 56 | OS_Handle handle = os_cmd_line_launchf("raddbg --convert --pdb:%S --out:%S", pdb_path, rdi_path); 57 | os_handle_list_push(arena, &processes, handle); 58 | if(processes_first_path_n == 0) 59 | { 60 | processes_first_path_n = n; 61 | } 62 | idx += 1; 63 | } 64 | if(idx >= limit) 65 | { 66 | String8Node *line_n = processes_first_path_n; 67 | for(OS_HandleNode *n = processes.first; n != 0; n = n->next, line_n = line_n->next) 68 | { 69 | ProfScope("join %.*s", str8_varg(line_n->string)) 70 | { 71 | os_process_join(n->v, max_U64); 72 | } 73 | } 74 | idx = 0; 75 | MemoryZeroStruct(&processes); 76 | processes_first_path_n = 0; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/scratch/debugstringperf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DWORD thread_entry_point(void *p) 4 | { 5 | for(int i = 0; i < 100000; i += 1) 6 | { 7 | OutputDebugString("this is a test\n"); 8 | } 9 | return 0; 10 | } 11 | 12 | int main(int argc, char **argv) 13 | { 14 | HANDLE threads[] = 15 | { 16 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 17 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 18 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 19 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 20 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 21 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 22 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 23 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 24 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 25 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 26 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 27 | CreateThread(0, 0, thread_entry_point, 0, 0, 0), 28 | }; 29 | for(int i = 0; i < sizeof(threads)/sizeof(threads[0]); i += 1) 30 | { 31 | WaitForSingleObject(threads[i], INFINITE); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/scratch/eval_scratch.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Includes 6 | 7 | //- rjf: [h] 8 | #include "base/base_inc.h" 9 | #include "os/os_inc.h" 10 | #include "rdi_format/rdi_format_local.h" 11 | #include "regs/regs.h" 12 | #include "regs/rdi/regs_rdi.h" 13 | #include "eval/eval_inc.h" 14 | 15 | //- rjf: [c] 16 | #include "base/base_inc.c" 17 | #include "os/os_inc.c" 18 | #include "rdi_format/rdi_format_local.c" 19 | #include "regs/regs.c" 20 | #include "regs/rdi/regs_rdi.c" 21 | #include "eval/eval_inc.c" 22 | 23 | //////////////////////////////// 24 | //~ rjf: Entry Point 25 | 26 | internal void 27 | entry_point(CmdLine *cmdline) 28 | { 29 | Arena *arena = arena_alloc(); 30 | E_TypeCtx *type_ctx = push_array(arena, E_TypeCtx, 1); 31 | e_select_type_ctx(type_ctx); 32 | E_ParseCtx *parse_ctx = push_array(arena, E_ParseCtx, 1); 33 | e_select_parse_ctx(parse_ctx); 34 | E_IRCtx *ir_ctx = push_array(arena, E_IRCtx, 1); 35 | e_select_ir_ctx(ir_ctx); 36 | E_InterpretCtx *interpret_ctx = push_array(arena, E_InterpretCtx, 1); 37 | e_select_interpret_ctx(interpret_ctx, 0, 0); 38 | String8 exprs[] = 39 | { 40 | str8_lit("123"), 41 | str8_lit("1 + 2"), 42 | str8_lit("foo"), 43 | str8_lit("foo(bar)"), 44 | str8_lit("foo(bar(baz))"), 45 | }; 46 | for EachElement(idx, exprs) 47 | { 48 | String8 debug_string = e_debug_log_from_expr_string(arena, exprs[idx]); 49 | raddbg_log("%S", debug_string); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/scratch/textperf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | //////////////////////////////// 5 | //~ rjf: Build Options 6 | 7 | #define BUILD_TITLE "textperf" 8 | #define OS_FEATURE_GRAPHICAL 1 9 | 10 | //////////////////////////////// 11 | //~ rjf: Includes 12 | 13 | //- rjf: [h] 14 | #include "base/base_inc.h" 15 | #include "os/os_inc.h" 16 | #include "render/render_inc.h" 17 | #include "font_provider/font_provider_inc.h" 18 | #include "font_cache/font_cache.h" 19 | #include "draw/draw.h" 20 | 21 | //- rjf: [c] 22 | #include "base/base_inc.c" 23 | #include "os/os_inc.c" 24 | #include "render/render_inc.c" 25 | #include "font_provider/font_provider_inc.c" 26 | #include "font_cache/font_cache.c" 27 | #include "draw/draw.c" 28 | 29 | //////////////////////////////// 30 | //~ rjf: Globals 31 | 32 | global OS_Handle os_window = {0}; 33 | global R_Handle r_window = {0}; 34 | 35 | //////////////////////////////// 36 | //~ rjf: Entry Points 37 | 38 | internal B32 39 | frame(void) 40 | { 41 | ProfBeginFunction(); 42 | B32 quit = 0; 43 | Temp scratch = scratch_begin(0, 0); 44 | OS_EventList events = os_get_events(scratch.arena, 0); 45 | for(OS_Event *evt = events.first; evt != 0; evt = evt->next) 46 | { 47 | if(evt->kind == OS_EventKind_WindowClose) 48 | { 49 | quit = 1; 50 | break; 51 | } 52 | } 53 | r_begin_frame(); 54 | dr_begin_frame(fnt_tag_zero()); 55 | r_window_begin_frame(os_window, r_window); 56 | DR_Bucket *bucket = dr_bucket_make(); 57 | DR_BucketScope(bucket) ProfScope("draw") 58 | { 59 | Vec2F32 mouse = os_mouse_from_window(os_window); 60 | FNT_Tag font = fnt_tag_from_path(str8_lit("C:/devel/raddebugger/data/Inconsolata-Regular.ttf")); 61 | for(F32 x = 0; x < 500; x += 5.f) 62 | { 63 | for(F32 y = 0; y < 500; y += 5.f) 64 | { 65 | dr_text(font, 16.f, 0, 0, FNT_RasterFlag_Smooth|FNT_RasterFlag_Hinted, v2f32(30 + x + mouse.x, 30 + y + mouse.y), v4f32(1, 1, 1, 1), str8_lit("This is a test.")); 66 | } 67 | } 68 | } 69 | r_window_submit(os_window, r_window, &bucket->passes); 70 | r_window_end_frame(os_window, r_window); 71 | r_end_frame(); 72 | scratch_end(scratch); 73 | ProfEnd(); 74 | return quit; 75 | } 76 | 77 | internal void 78 | entry_point(CmdLine *cmdline) 79 | { 80 | os_window = os_window_open(r2f32p(0, 0, 1600, 900), OS_WindowFlag_UseDefaultPosition, str8_lit("textperf")); 81 | r_window = r_window_equip(os_window); 82 | os_window_first_paint(os_window); 83 | for(;!update();); 84 | } 85 | -------------------------------------------------------------------------------- /src/third_party/blake3/asm/blake3.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE3_H 2 | #define BLAKE3_H 3 | 4 | #include 5 | #include 6 | 7 | #if !defined(BLAKE3_API) 8 | # if defined(_WIN32) || defined(__CYGWIN__) 9 | # if defined(BLAKE3_DLL) 10 | # if defined(BLAKE3_DLL_EXPORTS) 11 | # define BLAKE3_API __declspec(dllexport) 12 | # else 13 | # define BLAKE3_API __declspec(dllimport) 14 | # endif 15 | # define BLAKE3_PRIVATE 16 | # else 17 | # define BLAKE3_API 18 | # define BLAKE3_PRIVATE 19 | # endif 20 | # elif __GNUC__ >= 4 21 | # define BLAKE3_API __attribute__((visibility("default"))) 22 | # define BLAKE3_PRIVATE __attribute__((visibility("hidden"))) 23 | # else 24 | # define BLAKE3_API 25 | # define BLAKE3_PRIVATE 26 | # endif 27 | #endif 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #define BLAKE3_VERSION_STRING "1.5.0" 34 | #define BLAKE3_KEY_LEN 32 35 | #define BLAKE3_OUT_LEN 32 36 | #define BLAKE3_BLOCK_LEN 64 37 | #define BLAKE3_CHUNK_LEN 1024 38 | #define BLAKE3_MAX_DEPTH 54 39 | 40 | // This struct is a private implementation detail. It has to be here because 41 | // it's part of blake3_hasher below. 42 | typedef struct { 43 | uint32_t cv[8]; 44 | uint64_t chunk_counter; 45 | uint8_t buf[BLAKE3_BLOCK_LEN]; 46 | uint8_t buf_len; 47 | uint8_t blocks_compressed; 48 | uint8_t flags; 49 | } blake3_chunk_state; 50 | 51 | typedef struct { 52 | uint32_t key[8]; 53 | blake3_chunk_state chunk; 54 | uint8_t cv_stack_len; 55 | // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example, 56 | // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk 57 | // requires a 4th entry, rather than merging everything down to 1, because we 58 | // don't know whether more input is coming. This is different from how the 59 | // reference implementation does things. 60 | uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN]; 61 | } blake3_hasher; 62 | 63 | BLAKE3_API const char *blake3_version(void); 64 | BLAKE3_API void blake3_hasher_init(blake3_hasher *self); 65 | BLAKE3_API void blake3_hasher_init_keyed(blake3_hasher *self, 66 | const uint8_t key[BLAKE3_KEY_LEN]); 67 | BLAKE3_API void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context); 68 | BLAKE3_API void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context, 69 | size_t context_len); 70 | BLAKE3_API void blake3_hasher_update(blake3_hasher *self, const void *input, 71 | size_t input_len); 72 | BLAKE3_API void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out, 73 | size_t out_len); 74 | BLAKE3_API void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, 75 | uint8_t *out, size_t out_len); 76 | BLAKE3_API void blake3_hasher_reset(blake3_hasher *self); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* BLAKE3_H */ 83 | -------------------------------------------------------------------------------- /src/third_party/blake3/c/blake3.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE3_H 2 | #define BLAKE3_H 3 | 4 | #include 5 | #include 6 | 7 | #if !defined(BLAKE3_API) 8 | # if defined(_WIN32) || defined(__CYGWIN__) 9 | # if defined(BLAKE3_DLL) 10 | # if defined(BLAKE3_DLL_EXPORTS) 11 | # define BLAKE3_API __declspec(dllexport) 12 | # else 13 | # define BLAKE3_API __declspec(dllimport) 14 | # endif 15 | # define BLAKE3_PRIVATE 16 | # else 17 | # define BLAKE3_API 18 | # define BLAKE3_PRIVATE 19 | # endif 20 | # elif __GNUC__ >= 4 21 | # define BLAKE3_API __attribute__((visibility("default"))) 22 | # define BLAKE3_PRIVATE __attribute__((visibility("hidden"))) 23 | # else 24 | # define BLAKE3_API 25 | # define BLAKE3_PRIVATE 26 | # endif 27 | #endif 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #define BLAKE3_VERSION_STRING "1.5.0" 34 | #define BLAKE3_KEY_LEN 32 35 | #define BLAKE3_OUT_LEN 32 36 | #define BLAKE3_BLOCK_LEN 64 37 | #define BLAKE3_CHUNK_LEN 1024 38 | #define BLAKE3_MAX_DEPTH 54 39 | 40 | // This struct is a private implementation detail. It has to be here because 41 | // it's part of blake3_hasher below. 42 | typedef struct { 43 | uint32_t cv[8]; 44 | uint64_t chunk_counter; 45 | uint8_t buf[BLAKE3_BLOCK_LEN]; 46 | uint8_t buf_len; 47 | uint8_t blocks_compressed; 48 | uint8_t flags; 49 | } blake3_chunk_state; 50 | 51 | typedef struct { 52 | uint32_t key[8]; 53 | blake3_chunk_state chunk; 54 | uint8_t cv_stack_len; 55 | // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example, 56 | // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk 57 | // requires a 4th entry, rather than merging everything down to 1, because we 58 | // don't know whether more input is coming. This is different from how the 59 | // reference implementation does things. 60 | uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN]; 61 | } blake3_hasher; 62 | 63 | BLAKE3_API const char *blake3_version(void); 64 | BLAKE3_API void blake3_hasher_init(blake3_hasher *self); 65 | BLAKE3_API void blake3_hasher_init_keyed(blake3_hasher *self, 66 | const uint8_t key[BLAKE3_KEY_LEN]); 67 | BLAKE3_API void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context); 68 | BLAKE3_API void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context, 69 | size_t context_len); 70 | BLAKE3_API void blake3_hasher_update(blake3_hasher *self, const void *input, 71 | size_t input_len); 72 | BLAKE3_API void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out, 73 | size_t out_len); 74 | BLAKE3_API void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, 75 | uint8_t *out, size_t out_len); 76 | BLAKE3_API void blake3_hasher_reset(blake3_hasher *self); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* BLAKE3_H */ 83 | -------------------------------------------------------------------------------- /src/third_party/md5/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | extern void MD5_Init(MD5_CTX *ctx); 42 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/third_party/xxHash/LICENSE: -------------------------------------------------------------------------------- 1 | xxHash Library 2 | Copyright (c) 2012-2021 Yann Collet 3 | All rights reserved. 4 | 5 | BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, this 14 | list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /src/third_party/xxHash/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Security updates are applied only to the latest release. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. 10 | 11 | Please disclose it at [security advisory](https://github.com/Cyan4973/xxHash/security/advisories/new). 12 | 13 | This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure. 14 | -------------------------------------------------------------------------------- /src/third_party/xxHash/doc/README.md: -------------------------------------------------------------------------------- 1 | xxHash Specification 2 | ======================= 3 | 4 | This directory contains material defining the xxHash algorithm. 5 | It's described in [this specification document](xxhash_spec.md). 6 | 7 | The algorithm is also be illustrated by a [simple educational library](https://github.com/easyaspi314/xxhash-clean), 8 | written by @easyaspi314 and designed for readability 9 | (as opposed to the reference library which is designed for speed). 10 | -------------------------------------------------------------------------------- /src/third_party/xxHash/xxh3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xxHash - Extremely Fast Hash algorithm 3 | * Development source file for `xxh3` 4 | * Copyright (C) 2019-2021 Yann Collet 5 | * 6 | * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are 10 | * met: 11 | * 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above 15 | * copyright notice, this list of conditions and the following disclaimer 16 | * in the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * You can contact the author at: 32 | * - xxHash homepage: https://www.xxhash.com 33 | * - xxHash source repository: https://github.com/Cyan4973/xxHash 34 | */ 35 | 36 | /* 37 | * Note: This file used to host the source code of XXH3_* variants. 38 | * during the development period. 39 | * The source code is now properly integrated within xxhash.h. 40 | * 41 | * xxh3.h is no longer useful, 42 | * but it is still provided for compatibility with source code 43 | * which used to include it directly. 44 | * 45 | * Programs are now highly discouraged to include xxh3.h. 46 | * Include `xxhash.h` instead, which is the officially supported interface. 47 | * 48 | * In the future, xxh3.h will start to generate warnings, then errors, 49 | * then it will be removed from source package and from include directory. 50 | */ 51 | 52 | /* Simulate the same impact as including the old xxh3.h source file */ 53 | 54 | #define XXH_INLINE_ALL 55 | #include "xxhash.h" 56 | -------------------------------------------------------------------------------- /src/third_party/xxHash/xxhash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xxHash - Extremely Fast Hash algorithm 3 | * Copyright (C) 2012-2021 Yann Collet 4 | * 5 | * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following disclaimer 15 | * in the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * You can contact the author at: 31 | * - xxHash homepage: https://www.xxhash.com 32 | * - xxHash source repository: https://github.com/Cyan4973/xxHash 33 | */ 34 | 35 | 36 | /* 37 | * xxhash.c instantiates functions defined in xxhash.h 38 | */ 39 | 40 | #define XXH_STATIC_LINKING_ONLY /* access advanced declarations */ 41 | #define XXH_IMPLEMENTATION /* access definitions */ 42 | 43 | #include "xxhash.h" 44 | -------------------------------------------------------------------------------- /src/ui/ui_inc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #undef LAYER_COLOR 5 | #define LAYER_COLOR 0xb5438dff 6 | 7 | #include "ui_core.c" 8 | #include "ui_basic_widgets.c" 9 | -------------------------------------------------------------------------------- /src/ui/ui_inc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Epic Games Tools 2 | // Licensed under the MIT license (https://opensource.org/license/mit/) 3 | 4 | #ifndef UI_INC_H 5 | #define UI_INC_H 6 | 7 | #include "ui_core.h" 8 | #include "ui_basic_widgets.h" 9 | 10 | #endif // UI_INC_H 11 | --------------------------------------------------------------------------------