From 4b68967fbee82da7f8cc0016895a2bdb3cc8cd0f Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 12 Feb 2024 14:29:24 -0800 Subject: [PATCH] raddbg format stuff -> raddbgi; partial naming/organization over raddbgi_cons --- README.md | 20 +- build.bat | 6 +- project.4coder | 14 +- src/base/base_types.h | 1 + src/raddbg/raddbg_main.cpp | 50 +- .../raddbgi_cons.c} | 3662 +++++++++-------- .../raddbgi_cons.h} | 1213 +++--- .../dwarf/raddbgi_dwarf.c} | 0 .../dwarf/raddbgi_dwarf.h} | 0 .../dwarf/raddbgi_dwarf_stringize.c} | 0 .../dwarf/raddbgi_dwarf_stringize.h} | 0 .../dwarf/raddbgi_elf.c} | 0 .../dwarf/raddbgi_elf.h} | 0 .../dwarf/raddbgi_from_dwarf.c} | 23 +- .../dwarf/raddbgi_from_dwarf.h} | 0 .../pdb/raddbgi_codeview.c} | 0 .../pdb/raddbgi_codeview.h} | 0 .../pdb/raddbgi_codeview_conversion.c} | 0 .../pdb/raddbgi_codeview_conversion.h} | 0 .../pdb/raddbgi_codeview_stringize.c} | 0 .../pdb/raddbgi_codeview_stringize.h} | 0 .../pdb/raddbgi_coff.h} | 0 .../pdb/raddbgi_coff_conversion.c} | 0 .../pdb/raddbgi_coff_conversion.h} | 0 .../pdb/raddbgi_from_pdb.c} | 5 - .../pdb/raddbgi_from_pdb.h} | 0 .../pdb/raddbgi_from_pdb_main.c} | 42 +- .../pdb/raddbgi_msf.c} | 0 .../pdb/raddbgi_msf.h} | 0 .../pdb/raddbgi_pdb.c} | 0 .../pdb/raddbgi_pdb.h} | 0 .../pdb/raddbgi_pdb_stringize.c} | 0 .../pdb/raddbgi_pdb_stringize.h} | 0 .../raddbgi_dump.c} | 14 +- .../raddbgi_dump.h} | 0 .../raddbgi_stringize.c} | 0 .../raddbgi_stringize.h} | 0 .../raddbgi_format.c} | 0 .../raddbgi_format.h} | 0 .../raddbgi_format_parse.c} | 0 .../raddbgi_format_parse.h} | 0 .../generated/regs_raddbgi.meta.c} | 0 .../generated/regs_raddbgi.meta.h} | 0 .../regs_raddbg.c => raddbgi/regs_raddbgi.c} | 2 +- .../regs_raddbg.h => raddbgi/regs_raddbgi.h} | 0 .../regs_raddbgi.mc} | 0 src/scratch/look_at_raddbg.c | 8 +- 47 files changed, 2589 insertions(+), 2471 deletions(-) rename src/{raddbg_cons/raddbg_cons.c => raddbgi_cons/raddbgi_cons.c} (71%) rename src/{raddbg_cons/raddbg_cons.h => raddbgi_cons/raddbgi_cons.h} (58%) rename src/{raddbg_convert/dwarf/raddbg_dwarf.c => raddbgi_convert/dwarf/raddbgi_dwarf.c} (100%) rename src/{raddbg_convert/dwarf/raddbg_dwarf.h => raddbgi_convert/dwarf/raddbgi_dwarf.h} (100%) rename src/{raddbg_convert/dwarf/raddbg_dwarf_stringize.c => raddbgi_convert/dwarf/raddbgi_dwarf_stringize.c} (100%) rename src/{raddbg_convert/dwarf/raddbg_dwarf_stringize.h => raddbgi_convert/dwarf/raddbgi_dwarf_stringize.h} (100%) rename src/{raddbg_convert/dwarf/raddbg_elf.c => raddbgi_convert/dwarf/raddbgi_elf.c} (100%) rename src/{raddbg_convert/dwarf/raddbg_elf.h => raddbgi_convert/dwarf/raddbgi_elf.h} (100%) rename src/{raddbg_convert/dwarf/raddbg_from_dwarf.c => raddbgi_convert/dwarf/raddbgi_from_dwarf.c} (98%) rename src/{raddbg_convert/dwarf/raddbg_from_dwarf.h => raddbgi_convert/dwarf/raddbgi_from_dwarf.h} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview.c => raddbgi_convert/pdb/raddbgi_codeview.c} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview.h => raddbgi_convert/pdb/raddbgi_codeview.h} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview_conversion.c => raddbgi_convert/pdb/raddbgi_codeview_conversion.c} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview_conversion.h => raddbgi_convert/pdb/raddbgi_codeview_conversion.h} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview_stringize.c => raddbgi_convert/pdb/raddbgi_codeview_stringize.c} (100%) rename src/{raddbg_convert/pdb/raddbg_codeview_stringize.h => raddbgi_convert/pdb/raddbgi_codeview_stringize.h} (100%) rename src/{raddbg_convert/pdb/raddbg_coff.h => raddbgi_convert/pdb/raddbgi_coff.h} (100%) rename src/{raddbg_convert/pdb/raddbg_coff_conversion.c => raddbgi_convert/pdb/raddbgi_coff_conversion.c} (100%) rename src/{raddbg_convert/pdb/raddbg_coff_conversion.h => raddbgi_convert/pdb/raddbgi_coff_conversion.h} (100%) rename src/{raddbg_convert/pdb/raddbg_from_pdb.c => raddbgi_convert/pdb/raddbgi_from_pdb.c} (99%) rename src/{raddbg_convert/pdb/raddbg_from_pdb.h => raddbgi_convert/pdb/raddbgi_from_pdb.h} (100%) rename src/{raddbg_convert/pdb/raddbg_from_pdb_main.c => raddbgi_convert/pdb/raddbgi_from_pdb_main.c} (76%) rename src/{raddbg_convert/pdb/raddbg_msf.c => raddbgi_convert/pdb/raddbgi_msf.c} (100%) rename src/{raddbg_convert/pdb/raddbg_msf.h => raddbgi_convert/pdb/raddbgi_msf.h} (100%) rename src/{raddbg_convert/pdb/raddbg_pdb.c => raddbgi_convert/pdb/raddbgi_pdb.c} (100%) rename src/{raddbg_convert/pdb/raddbg_pdb.h => raddbgi_convert/pdb/raddbgi_pdb.h} (100%) rename src/{raddbg_convert/pdb/raddbg_pdb_stringize.c => raddbgi_convert/pdb/raddbgi_pdb_stringize.c} (100%) rename src/{raddbg_convert/pdb/raddbg_pdb_stringize.h => raddbgi_convert/pdb/raddbgi_pdb_stringize.h} (100%) rename src/{raddbg_dump/raddbg_dump.c => raddbgi_dump/raddbgi_dump.c} (98%) rename src/{raddbg_dump/raddbg_dump.h => raddbgi_dump/raddbgi_dump.h} (100%) rename src/{raddbg_dump/raddbg_stringize.c => raddbgi_dump/raddbgi_stringize.c} (100%) rename src/{raddbg_dump/raddbg_stringize.h => raddbgi_dump/raddbgi_stringize.h} (100%) rename src/{raddbg_format/raddbg_format.c => raddbgi_format/raddbgi_format.c} (100%) rename src/{raddbg_format/raddbg_format.h => raddbgi_format/raddbgi_format.h} (100%) rename src/{raddbg_format/raddbg_format_parse.c => raddbgi_format/raddbgi_format_parse.c} (100%) rename src/{raddbg_format/raddbg_format_parse.h => raddbgi_format/raddbgi_format_parse.h} (100%) rename src/regs/{raddbg/generated/regs_raddbg.meta.c => raddbgi/generated/regs_raddbgi.meta.c} (100%) rename src/regs/{raddbg/generated/regs_raddbg.meta.h => raddbgi/generated/regs_raddbgi.meta.h} (100%) rename src/regs/{raddbg/regs_raddbg.c => raddbgi/regs_raddbgi.c} (67%) rename src/regs/{raddbg/regs_raddbg.h => raddbgi/regs_raddbgi.h} (100%) rename src/regs/{raddbg/regs_raddbg.mc => raddbgi/regs_raddbgi.mc} (100%) diff --git a/README.md b/README.md index 1af8fc83..93647aae 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ simply deserialize the PDBs). It is much slower for much larger projects at the moment, but we expect this will vastly improve overtime. The RADDBG format is currently specified in code, in the files within the -`src/raddbg_format` folder. The other relevant folders for working with the +`src/raddbgi_format` folder. The other relevant folders for working with the format are: -- `raddbg_cons`: The RADDBG construction layer, for constructing RADDBG files. -- `raddbg_convert`: Our implementation of PDB-to-RADDBG (and an in-progress +- `raddbgi_cons`: The RADDBG construction layer, for making RADDBG debug info. +- `raddbgi_convert`: Our implementation of PDB-to-RADDBG (and an in-progress implementation of a DWARF-to-RADDBG) conversion. -- `raddbg_dump`: Code for textually dumping information from RADDBG files. +- `raddbgi_dump`: Code for textually dumping information from RADDBG files. ## Development Setup Instructions @@ -288,15 +288,15 @@ A list of the layers in the codebase and their associated namespaces is below: - `raddbg` (no namespace): The layer which ties everything together for the main graphical debugger. Not much "meat", just drives `df`, implements command line options, and so on. -- `raddbg_cons` (`CONS_`): Implements an API for constructing files of the - RADDBG debug info file format. -- `raddbg_dump` (`DUMP_`): A dumper utility program for dumping textualizations - of RADDBG debug info files. -- `raddbg_format` (`RADDBG_`): Standalone types and helper functions for the - RADDBG debug info file format. Does not depend on `base`. - `raddbg_markup` (`RADDBG_`): Standalone header file for marking up user programs to work with various features in the `raddbg` debugger. Does not depend on `base`. +- `raddbgi_cons` (`CONS_`): Implements an API for constructing files of the + RADDBG debug info file format. +- `raddbgi_dump` (`DUMP_`): A dumper utility program for dumping + textualizations of RADDBG debug info files. +- `raddbgi_format` (`RADDBG_`): Standalone types and helper functions for the + RADDBG debug info file format. Does not depend on `base`. - `regs` (`REGS_`): Types, helper functions, and metadata for registers on supported architectures. Used in reading/writing registers in `demon`, or in looking up register metadata. diff --git a/build.bat b/build.bat index 8f00468b..79d3fb91 100644 --- a/build.bat +++ b/build.bat @@ -99,9 +99,9 @@ if not "%no_meta%"=="1" ( :: --- Build Everything (@build_targets) -------------------------------------- pushd build if "%raddbg%"=="1" %compile% %gfx% ..\src\raddbg\raddbg_main.cpp %compile_link% %out%raddbg.exe || exit /b 1 -if "%raddbg_from_pdb%"=="1" %compile% ..\src\raddbg_convert\pdb\raddbg_from_pdb_main.c %compile_link% %out%raddbg_from_pdb.exe || exit /b 1 -if "%raddbg_from_dwarf%"=="1" %compile% ..\src\raddbg_convert\dwarf\raddbg_from_dwarf.c %compile_link% %out%raddbg_from_dwarf.exe || exit /b 1 -if "%raddbg_dump%"=="1" %compile% ..\src\raddbg_dump\raddbg_dump.c %compile_link% %out%raddbg_dump.exe || exit /b 1 +if "%raddbgi_from_pdb%"=="1" %compile% ..\src\raddbgi_convert\pdb\raddbgi_from_pdb_main.c %compile_link% %out%raddbgi_from_pdb.exe || exit /b 1 +if "%raddbgi_from_dwarf%"=="1" %compile% ..\src\raddbgi_convert\dwarf\raddbgi_from_dwarf.c %compile_link% %out%raddbgi_from_dwarf.exe || exit /b 1 +if "%raddbgi_dump%"=="1" %compile% ..\src\raddbgi_dump\raddbgi_dump.c %compile_link% %out%raddbgi_dump.exe || exit /b 1 if "%ryan_scratch%"=="1" %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe || exit /b 1 if "%cpp_tests%"=="1" %compile% ..\src\scratch\i_hate_c_plus_plus.cpp %compile_link% %out%cpp_tests.exe || exit /b 1 if "%look_at_raddbg%"=="1" %compile% ..\src\scratch\look_at_raddbg.c %compile_link% %out%look_at_raddbg.exe || exit /b 1 diff --git a/project.4coder b/project.4coder index 6fdeb145..1a4474d3 100644 --- a/project.4coder +++ b/project.4coder @@ -56,7 +56,7 @@ commands = }, .rjf_f2 = { - .win = "build raddbg_from_pdb telemetry release", + .win = "build raddbgi_from_pdb telemetry release", .linux = "", .out = "*compilation*", .footer_panel = true, @@ -74,7 +74,7 @@ commands = }, .rjf_f4 = { - .win = "build raddbg_from_pdb && pushd build && raddbg_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --dump:table_diagnostics && popd", + .win = "build raddbgi_from_pdb && pushd build && raddbg_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --dump:table_diagnostics && popd", .linux = "", .out = "*compilation*", .footer_panel = true, @@ -83,7 +83,7 @@ commands = }, .rjf_f5 = { - .win = "pushd build && raddbg_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --capture && popd", + .win = "pushd build && raddbgi_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --capture && popd", .linux = "", .out = "*compilation*", .footer_panel = true, @@ -108,18 +108,18 @@ commands = .save_dirty_files = true, .cursor_at_end = false, }, - .build_raddbg_from_pdb = + .build_raddbgi_from_pdb = { - .win = "build raddbg_from_pdb", + .win = "build raddbgi_from_pdb", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .build_raddbg_dump = + .build_raddbgi_dump = { - .win = "build raddbg_dump", + .win = "build raddbgi_dump", .linux = "", .out = "*compilation*", .footer_panel = true, diff --git a/src/base/base_types.h b/src/base/base_types.h index bdc6a916..3ed2cba6 100644 --- a/src/base/base_types.h +++ b/src/base/base_types.h @@ -102,6 +102,7 @@ #define AssertIff(a,b) Assert(!!(a) == !!(b)) #define InvalidPath Assert(!"Invalid Path!") #define NotImplemented Assert(!"Not Implemented!") +#define NoOp ((void)0) #define StaticAssert(C,ID) global U8 Glue(ID,__LINE__)[(C)?1:-1] diff --git a/src/raddbg/raddbg_main.cpp b/src/raddbg/raddbg_main.cpp index 922c3c2f..5334c154 100644 --- a/src/raddbg/raddbg_main.cpp +++ b/src/raddbg/raddbg_main.cpp @@ -15,20 +15,20 @@ #include "txti/txti.h" #include "coff/coff.h" #include "pe/pe.h" -#include "raddbg_format/raddbg_format.h" -#include "raddbg_format/raddbg_format_parse.h" -#include "raddbg_cons/raddbg_cons.h" -#include "raddbg_convert/pdb/raddbg_coff.h" -#include "raddbg_convert/pdb/raddbg_codeview.h" -#include "raddbg_convert/pdb/raddbg_msf.h" -#include "raddbg_convert/pdb/raddbg_pdb.h" -#include "raddbg_convert/pdb/raddbg_coff_conversion.h" -#include "raddbg_convert/pdb/raddbg_codeview_conversion.h" -#include "raddbg_convert/pdb/raddbg_from_pdb.h" -#include "raddbg_convert/pdb/raddbg_codeview_stringize.h" -#include "raddbg_convert/pdb/raddbg_pdb_stringize.h" +#include "raddbgi_format/raddbgi_format.h" +#include "raddbgi_format/raddbgi_format_parse.h" +#include "raddbgi_cons/raddbgi_cons.h" +#include "raddbgi_convert/pdb/raddbgi_coff.h" +#include "raddbgi_convert/pdb/raddbgi_codeview.h" +#include "raddbgi_convert/pdb/raddbgi_msf.h" +#include "raddbgi_convert/pdb/raddbgi_pdb.h" +#include "raddbgi_convert/pdb/raddbgi_coff_conversion.h" +#include "raddbgi_convert/pdb/raddbgi_codeview_conversion.h" +#include "raddbgi_convert/pdb/raddbgi_from_pdb.h" +#include "raddbgi_convert/pdb/raddbgi_codeview_stringize.h" +#include "raddbgi_convert/pdb/raddbgi_pdb_stringize.h" #include "regs/regs.h" -#include "regs/raddbg/regs_raddbg.h" +#include "regs/raddbgi/regs_raddbgi.h" #include "type_graph/type_graph.h" #include "dbgi/dbgi.h" #include "demon/demon_inc.h" @@ -57,19 +57,19 @@ #include "txti/txti.c" #include "coff/coff.c" #include "pe/pe.c" -#include "raddbg_format/raddbg_format.c" -#include "raddbg_format/raddbg_format_parse.c" -#include "raddbg_cons/raddbg_cons.c" -#include "raddbg_convert/pdb/raddbg_msf.c" -#include "raddbg_convert/pdb/raddbg_codeview.c" -#include "raddbg_convert/pdb/raddbg_pdb.c" -#include "raddbg_convert/pdb/raddbg_coff_conversion.c" -#include "raddbg_convert/pdb/raddbg_codeview_conversion.c" -#include "raddbg_convert/pdb/raddbg_codeview_stringize.c" -#include "raddbg_convert/pdb/raddbg_pdb_stringize.c" -#include "raddbg_convert/pdb/raddbg_from_pdb.c" +#include "raddbgi_format/raddbgi_format.c" +#include "raddbgi_format/raddbgi_format_parse.c" +#include "raddbgi_cons/raddbgi_cons.c" +#include "raddbgi_convert/pdb/raddbgi_msf.c" +#include "raddbgi_convert/pdb/raddbgi_codeview.c" +#include "raddbgi_convert/pdb/raddbgi_pdb.c" +#include "raddbgi_convert/pdb/raddbgi_coff_conversion.c" +#include "raddbgi_convert/pdb/raddbgi_codeview_conversion.c" +#include "raddbgi_convert/pdb/raddbgi_codeview_stringize.c" +#include "raddbgi_convert/pdb/raddbgi_pdb_stringize.c" +#include "raddbgi_convert/pdb/raddbgi_from_pdb.c" #include "regs/regs.c" -#include "regs/raddbg/regs_raddbg.c" +#include "regs/raddbgi/regs_raddbgi.c" #include "type_graph/type_graph.c" #include "dbgi/dbgi.c" #include "demon/demon_inc.c" diff --git a/src/raddbg_cons/raddbg_cons.c b/src/raddbgi_cons/raddbgi_cons.c similarity index 71% rename from src/raddbg_cons/raddbg_cons.c rename to src/raddbgi_cons/raddbgi_cons.c index c4dd67ae..90266a26 100644 --- a/src/raddbg_cons/raddbg_cons.c +++ b/src/raddbgi_cons/raddbgi_cons.c @@ -2,11 +2,378 @@ // Licensed under the MIT license (https://opensource.org/license/mit/) //////////////////////////////// -//- "Public Facing" Cons API +//~ rjf: API Implementation Helper Macros + +#define cons_require(root, b32, else_code, error_msg) do { if(!(b32)) {cons_error((root), (error_msg));} else { else_code; } }while(0) +#define cons_requiref(root, b32, else_code, fmt, ...) do { if(!(b32)) {cons_errorf((root), (fmt), __VA_ARGS__);} else { else_code; } }while(0) + +//////////////////////////////// +//~ rjf: Basic Type Helpers + +//- rjf: type lists + +static void +cons_type_list_push(Arena *arena, CONS_TypeList *list, CONS_Type *type) +{ + CONS_TypeNode *node = push_array(arena, CONS_TypeNode, 1); + SLLQueuePush(list->first, list->last, node); + list->count += 1; + node->type = type; +} + +//- rjf: bytecode lists + +static void +cons_bytecode_push_op(Arena *arena, CONS_EvalBytecode *bytecode, RADDBG_EvalOp op, U64 p) +{ + U8 ctrlbits = raddbg_eval_opcode_ctrlbits[op]; + U32 p_size = RADDBG_DECODEN_FROM_CTRLBITS(ctrlbits); + + CONS_EvalBytecodeOp *node = push_array(arena, CONS_EvalBytecodeOp, 1); + node->op = op; + node->p_size = p_size; + node->p = p; + + SLLQueuePush(bytecode->first_op, bytecode->last_op, node); + bytecode->op_count += 1; + bytecode->encoded_size += 1 + p_size; +} + +static void +cons_bytecode_push_uconst(Arena *arena, CONS_EvalBytecode *bytecode, U64 x) +{ + if(x <= 0xFF) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU8, x); + } + else if(x <= 0xFFFF) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU16, x); + } + else if(x <= 0xFFFFFFFF) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU32, x); + } + else + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU64, x); + } +} + +static void +cons_bytecode_push_sconst(Arena *arena, CONS_EvalBytecode *bytecode, S64 x) +{ + if(-0x80 <= x && x <= 0x7F) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU8, (U64)x); + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 8); + } + else if(-0x8000 <= x && x <= 0x7FFF) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU16, (U64)x); + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 16); + } + else if(-0x80000000ll <= x && x <= 0x7FFFFFFFll) + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU32, (U64)x); + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 32); + } + else + { + cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU64, (U64)x); + } +} + +static void +cons_bytecode_concat_in_place(CONS_EvalBytecode *left_dst, CONS_EvalBytecode *right_destroyed) +{ + if(right_destroyed->first_op != 0) + { + if(left_dst->first_op == 0) + { + MemoryCopyStruct(left_dst, right_destroyed); + } + else + { + left_dst->last_op = right_destroyed->last_op; + left_dst->op_count += right_destroyed->op_count; + left_dst->encoded_size += right_destroyed->encoded_size; + } + MemoryZeroStruct(right_destroyed); + } +} + +//- rjf: sortable range sorting + +static CONS__SortKey* +cons__sort_key_array(Arena *arena, CONS__SortKey *keys, U64 count) +{ + // This sort is designed to take advantage of lots of pre-existing sorted ranges. + // Most line info is already sorted or close to already sorted. + // Similarly most vmap data has lots of pre-sorted ranges. etc. etc. + // Also - this sort should be a "stable" sort. In the use case of sorting vmap + // ranges, we want to be able to rely on order, so it needs to be preserved here. + + ProfBegin("cons__sort_key_array"); + Temp scratch = scratch_begin(&arena, 1); + CONS__SortKey *result = 0; + + if(count <= 1) + { + result = keys; + } + else + { + CONS__OrderedRange *ranges_first = 0; + CONS__OrderedRange *ranges_last = 0; + U64 range_count = 0; + { + U64 pos = 0; + for(;pos < count;) + { + // identify ordered range + U64 first = pos; + U64 opl = pos + 1; + for(; opl < count && keys[opl - 1].key <= keys[opl].key; opl += 1); + + // generate an ordered range node + CONS__OrderedRange *new_range = push_array(scratch.arena, CONS__OrderedRange, 1); + SLLQueuePush(ranges_first, ranges_last, new_range); + range_count += 1; + new_range->first = first; + new_range->opl = opl; + + // update pos + pos = opl; + } + } + + if(range_count == 1) + { + result = keys; + } + else + { + CONS__SortKey *keys_swap = push_array_no_zero(arena, CONS__SortKey, count); + CONS__SortKey *src = keys; + CONS__SortKey *dst = keys_swap; + CONS__OrderedRange *src_ranges = ranges_first; + CONS__OrderedRange *dst_ranges = 0; + CONS__OrderedRange *dst_ranges_last = 0; + + for(;;) + { + // begin a pass + for(;;) + { + // end pass when out of ranges + if(src_ranges == 0) + { + break; + } + + // get first range + CONS__OrderedRange *range1 = src_ranges; + SLLStackPop(src_ranges); + + // if this range is the whole array, we are done + if(range1->first == 0 && range1->opl == count) + { + result = src; + goto sort_done; + } + + // if there is not a second range, save this range for next time and end this pass + if(src_ranges == 0) + { + U64 first = range1->first; + MemoryCopy(dst + first, src + first, sizeof(*src)*(range1->opl - first)); + SLLQueuePush(dst_ranges, dst_ranges_last, range1); + break; + } + + // get second range + CONS__OrderedRange *range2 = src_ranges; + SLLStackPop(src_ranges); + + Assert(range1->opl == range2->first); + + // merge these ranges + U64 jd = range1->first; + U64 j1 = range1->first; + U64 j1_opl = range1->opl; + U64 j2 = range2->first; + U64 j2_opl = range2->opl; + for(;;) + { + if(src[j1].key <= src[j2].key) + { + MemoryCopy(dst + jd, src + j1, sizeof(*src)); + j1 += 1; + jd += 1; + if(j1 >= j1_opl) + { + break; + } + } + else + { + MemoryCopy(dst + jd, src + j2, sizeof(*src)); + j2 += 1; + jd += 1; + if(j2 >= j2_opl) + { + break; + } + } + } + if(j1 < j1_opl) + { + MemoryCopy(dst + jd, src + j1, sizeof(*src)*(j1_opl - j1)); + } + else + { + MemoryCopy(dst + jd, src + j2, sizeof(*src)*(j2_opl - j2)); + } + + // save this as one range + range1->opl = range2->opl; + SLLQueuePush(dst_ranges, dst_ranges_last, range1); + } + + // end pass by swapping buffers and range nodes + Swap(CONS__SortKey*, src, dst); + src_ranges = dst_ranges; + dst_ranges = 0; + dst_ranges_last = 0; + } + } + } + sort_done:; + +#if 0 + // assert sortedness + for(U64 i = 1; i < count; i += 1){ + Assert(result[i - 1].key <= result[i].key); + } +#endif + + scratch_end(scratch); + ProfEnd(); + + return result; +} + +//////////////////////////////// +//~ rjf: Auxiliary Data Structure Functions + +//- rjf: u64 -> ptr map + +static void +cons__u64toptr_init(Arena *arena, CONS__U64ToPtrMap *map, U64 bucket_count) +{ + Assert(IsPow2OrZero(bucket_count) && bucket_count > 0); + map->buckets = push_array(arena, CONS__U64ToPtrNode*, bucket_count); + map->buckets_count = bucket_count; +} + +static void +cons__u64toptr_lookup(CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup_out) +{ + U64 bucket_idx = hash&(map->buckets_count - 1); + CONS__U64ToPtrNode *check_node = map->buckets[bucket_idx]; + for(;check_node != 0; check_node = check_node->next){ + for(U32 k = 0; k < ArrayCount(check_node->key); k += 1){ + if(check_node->ptr[k] == 0){ + lookup_out->fill_node = check_node; + lookup_out->fill_k = k; + break; + } + else if(check_node->key[k] == key){ + lookup_out->match = check_node->ptr[k]; + break; + } + } + } +} + +static void +cons__u64toptr_insert(Arena *arena, CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup, void *ptr) +{ + if(lookup->fill_node != 0) + { + CONS__U64ToPtrNode *node = lookup->fill_node; + U32 k = lookup->fill_k; + node->key[k] = key; + node->ptr[k] = ptr; + } + else + { + U64 bucket_idx = hash&(map->buckets_count - 1); + + CONS__U64ToPtrNode *node = push_array(arena, CONS__U64ToPtrNode, 1); + SLLStackPush(map->buckets[bucket_idx], node); + node->key[0] = key; + node->ptr[0] = ptr; + + lookup->fill_node = node; + lookup->fill_k = 0; + + map->pair_count += 1; + map->bucket_collision_count += (node->next != 0); + } +} + +//- rjf: string8 -> ptr map + +static void +cons__str8toptr_init(Arena *arena, CONS__Str8ToPtrMap *map, U64 bucket_count) +{ + map->buckets_count = bucket_count; + map->buckets = push_array(arena, CONS__Str8ToPtrNode*, map->buckets_count); +} + +static void* +cons__str8toptr_lookup(CONS__Str8ToPtrMap *map, String8 key, U64 hash) +{ + void *result = 0; + U64 bucket_idx = hash%map->buckets_count; + for(CONS__Str8ToPtrNode *node = map->buckets[bucket_idx]; + node != 0; + node = node->next) + { + if(node->hash == hash && str8_match(node->key, key, 0)) + { + result = node->ptr; + break; + } + } + return result; +} + +static void +cons__str8toptr_insert(Arena *arena, CONS__Str8ToPtrMap *map, String8 key, U64 hash, void *ptr) +{ + U64 bucket_idx = hash%map->buckets_count; + + CONS__Str8ToPtrNode *node = push_array(arena, CONS__Str8ToPtrNode, 1); + SLLStackPush(map->buckets[bucket_idx], node); + + node->key = push_str8_copy(arena, key); + node->hash = hash; + node->ptr = ptr; + map->bucket_collision_count += (node->next != 0); + map->pair_count += 1; +} + +//////////////////////////////// +//~ rjf: Loose Debug Info Construction (Anything -> Loose) Functions + +//- rjf: root creation -//- init static CONS_Root* -cons_root_new(CONS_RootParams *params){ +cons_root_new(CONS_RootParams *params) +{ Arena *arena = arena_alloc__sized(GB(64), MB(64)); CONS_Root *result = push_array(arena, CONS_Root, 1); result->arena = arena; @@ -54,462 +421,60 @@ cons_root_new(CONS_RootParams *params){ #undef BKTCOUNT } - return(result); + return result; } static void -cons_root_release(CONS_Root *root){ +cons_root_release(CONS_Root *root) +{ arena_release(root->arena); } -//- baking -static void -cons_bake_file(Arena *arena, CONS_Root *root, String8List *out){ - ProfBegin("cons_bake_file"); - str8_serial_begin(arena, out); - - // setup cons helpers - CONS__DSections dss = {0}; - cons__dsection(arena, &dss, 0, 0, RADDBG_DataSectionTag_NULL); - - CONS__BakeParams bctx_params = {0}; - { - bctx_params.strings_bucket_count = u64_up_to_pow2(root->symbol_map.pair_count*8); - bctx_params.idx_runs_bucket_count = u64_up_to_pow2(root->symbol_map.pair_count*8); - } - CONS__BakeCtx *bctx = cons__bake_ctx_begin(&bctx_params); - - //////////////////////////////// - // MAIN PART: allocating and filling out sections of the file - - // top level info - RADDBG_TopLevelInfo *tli = push_array(arena, RADDBG_TopLevelInfo, 1); - { - CONS_TopLevelInfo *cons_tli = &root->top_level_info; - tli->architecture = cons_tli->architecture; - tli->exe_name_string_idx = cons__string(bctx, cons_tli->exe_name); - tli->exe_hash = cons_tli->exe_hash; - tli->voff_max = cons_tli->voff_max; - } - cons__dsection(arena, &dss, tli, sizeof(*tli), RADDBG_DataSectionTag_TopLevelInfo); - - // binary sections array - { - U32 count = root->binary_section_count; - RADDBG_BinarySection *sections = push_array(arena, RADDBG_BinarySection, count); - RADDBG_BinarySection *dsec = sections; - for (CONS_BinarySection *ssec = root->binary_section_first; - ssec != 0; - ssec = ssec->next, dsec += 1){ - dsec->name_string_idx = cons__string(bctx, ssec->name); - dsec->flags = ssec->flags; - dsec->voff_first = ssec->voff_first; - dsec->voff_opl = ssec->voff_opl; - dsec->foff_first = ssec->foff_first; - dsec->foff_opl = ssec->foff_opl; - } - cons__dsection(arena, &dss, sections, sizeof(*sections)*count, RADDBG_DataSectionTag_BinarySections); - } - - // units array - // * pass for per-unit information including: - // * top-level unit information - // * combining line info for whole unit - { - U32 count = root->unit_count; - RADDBG_Unit *units = push_array(arena, RADDBG_Unit, count); - RADDBG_Unit *dunit = units; - for (CONS_Unit *sunit = root->unit_first; - sunit != 0; - sunit = sunit->next_order, dunit += 1){ - // strings & paths - U32 unit_name = cons__string(bctx, sunit->unit_name); - U32 cmp_name = cons__string(bctx, sunit->compiler_name); - - U32 src_path = cons__paths_idx_from_path(bctx, sunit->source_file); - U32 obj_path = cons__paths_idx_from_path(bctx, sunit->object_file); - U32 archive_path = cons__paths_idx_from_path(bctx, sunit->archive_file); - U32 build_path = cons__paths_idx_from_path(bctx, sunit->build_path); - - dunit->unit_name_string_idx = unit_name; - dunit->compiler_name_string_idx = cmp_name; - dunit->source_file_path_node = src_path; - dunit->object_file_path_node = obj_path; - dunit->archive_file_path_node = archive_path; - dunit->build_path_node = build_path; - dunit->language = sunit->language; - - // line info (voff -> file*line*col) - CONS_LineSequenceNode *first_seq = sunit->line_seq_first; - CONS__UnitLinesCombined *lines = cons__unit_combine_lines(arena, bctx, first_seq); - - U32 line_count = lines->line_count; - if (line_count > 0){ - dunit->line_info_voffs_data_idx = - cons__dsection(arena, &dss, lines->voffs, sizeof(U64)*(line_count + 1), - RADDBG_DataSectionTag_LineInfoVoffs); - dunit->line_info_data_idx = - cons__dsection(arena, &dss, lines->lines, sizeof(RADDBG_Line)*line_count, - RADDBG_DataSectionTag_LineInfoData); - if (lines->cols != 0){ - dunit->line_info_col_data_idx = - cons__dsection(arena, &dss, lines->cols, sizeof(RADDBG_Column)*line_count, - RADDBG_DataSectionTag_LineInfoColumns); - } - dunit->line_info_count = line_count; - } - } - - cons__dsection(arena, &dss, units, sizeof(*units)*count, RADDBG_DataSectionTag_Units); - } - - // source file line info baking - // * pass for "source_combine_line" for each source file - - // * can only be run after a pass that does "unit_combine_lines" for each unit. - for (CONS__SrcNode *src_node = bctx->tree->src_first; - src_node != 0; - src_node = src_node->next){ - CONS__LineMapFragment *first_fragment = src_node->first_fragment; - CONS__SrcLinesCombined *lines = cons__source_combine_lines(arena, first_fragment); - U32 line_count = lines->line_count; - - if (line_count > 0){ - src_node->line_map_count = line_count; - - src_node->line_map_nums_data_idx = - cons__dsection(arena, &dss, lines->line_nums, sizeof(*lines->line_nums)*line_count, - RADDBG_DataSectionTag_LineMapNumbers); - - src_node->line_map_range_data_idx = - cons__dsection(arena, &dss, lines->line_ranges, sizeof(*lines->line_ranges)*(line_count + 1), - RADDBG_DataSectionTag_LineMapRanges); - - src_node->line_map_voff_data_idx = - cons__dsection(arena, &dss, lines->voffs, sizeof(*lines->voffs)*lines->voff_count, - RADDBG_DataSectionTag_LineMapVoffs); - } - } - - // source file name mapping - { - CONS__NameMap* map = cons__name_map_for_kind(root, RADDBG_NameMapKind_NormalSourcePaths); - for (CONS__SrcNode *src_node = bctx->tree->src_first; - src_node != 0; - src_node = src_node->next){ - if (src_node->idx != 0){ - cons__name_map_add_pair(root, map, src_node->normal_full_path, src_node->idx); - } - } - } - - // unit vmap baking - { - CONS__VMap *vmap = cons__vmap_from_unit_ranges(arena, - root->unit_vmap_range_first, - root->unit_vmap_range_count); - - U64 vmap_size = sizeof(*vmap->vmap)*(vmap->count + 1); - cons__dsection(arena, &dss, vmap->vmap, vmap_size, RADDBG_DataSectionTag_UnitVmap); - } - - // type info baking - { - CONS__TypeData *types = cons__type_data_combine(arena, root, bctx); - - U64 type_nodes_size = sizeof(*types->type_nodes)*types->type_node_count; - cons__dsection(arena, &dss, types->type_nodes, type_nodes_size, RADDBG_DataSectionTag_TypeNodes); - - U64 udt_size = sizeof(*types->udts)*types->udt_count; - cons__dsection(arena, &dss, types->udts, udt_size, RADDBG_DataSectionTag_UDTs); - - U64 member_size = sizeof(*types->members)*types->member_count; - cons__dsection(arena, &dss, types->members, member_size, RADDBG_DataSectionTag_Members); - - U64 enum_member_size = sizeof(*types->enum_members)*types->enum_member_count; - cons__dsection(arena, &dss, types->enum_members, enum_member_size, RADDBG_DataSectionTag_EnumMembers); - } - - // symbol info baking - { - CONS__SymbolData *symbol_data = cons__symbol_data_combine(arena, root, bctx); - - U64 global_variables_size = - sizeof(*symbol_data->global_variables)*symbol_data->global_variable_count; - cons__dsection(arena, &dss, symbol_data->global_variables, global_variables_size, - RADDBG_DataSectionTag_GlobalVariables); - - CONS__VMap *global_vmap = symbol_data->global_vmap; - U64 global_vmap_size = sizeof(*global_vmap->vmap)*(global_vmap->count + 1); - cons__dsection(arena, &dss, global_vmap->vmap, global_vmap_size, - RADDBG_DataSectionTag_GlobalVmap); - - U64 thread_variables_size = - sizeof(*symbol_data->thread_variables)*symbol_data->thread_variable_count; - cons__dsection(arena, &dss, symbol_data->thread_variables, thread_variables_size, - RADDBG_DataSectionTag_ThreadVariables); - - U64 procedures_size = sizeof(*symbol_data->procedures)*symbol_data->procedure_count; - cons__dsection(arena, &dss, symbol_data->procedures, procedures_size, - RADDBG_DataSectionTag_Procedures); - - U64 scopes_size = sizeof(*symbol_data->scopes)*symbol_data->scope_count; - cons__dsection(arena, &dss, symbol_data->scopes, scopes_size, RADDBG_DataSectionTag_Scopes); - - U64 scope_voffs_size = sizeof(*symbol_data->scope_voffs)*symbol_data->scope_voff_count; - cons__dsection(arena, &dss, symbol_data->scope_voffs, scope_voffs_size, - RADDBG_DataSectionTag_ScopeVoffData); - - CONS__VMap *scope_vmap = symbol_data->scope_vmap; - U64 scope_vmap_size = sizeof(*scope_vmap->vmap)*(scope_vmap->count + 1); - cons__dsection(arena, &dss, scope_vmap->vmap, scope_vmap_size, RADDBG_DataSectionTag_ScopeVmap); - - U64 local_size = sizeof(*symbol_data->locals)*symbol_data->local_count; - cons__dsection(arena, &dss, symbol_data->locals, local_size, RADDBG_DataSectionTag_Locals); - - U64 location_blocks_size = - sizeof(*symbol_data->location_blocks)*symbol_data->location_block_count; - cons__dsection(arena, &dss, symbol_data->location_blocks, location_blocks_size, - RADDBG_DataSectionTag_LocationBlocks); - - U64 location_data_size = symbol_data->location_data_size; - cons__dsection(arena, &dss, symbol_data->location_data, location_data_size, - RADDBG_DataSectionTag_LocationData); - } - - // name map baking - { - U32 name_map_count = 0; - for (U32 i = 0; i < RADDBG_NameMapKind_COUNT; i += 1){ - if (root->name_maps[i] != 0){ - name_map_count += 1; - } - } - - RADDBG_NameMap *name_maps = push_array(arena, RADDBG_NameMap, name_map_count); - - RADDBG_NameMap *name_map_ptr = name_maps; - for (U32 i = 0; i < RADDBG_NameMapKind_COUNT; i += 1){ - CONS__NameMap *map = root->name_maps[i]; - if (map != 0){ - CONS__NameMapBaked *baked = cons__name_map_bake(arena, root, bctx, map); - - name_map_ptr->kind = i; - name_map_ptr->bucket_data_idx = - cons__dsection(arena, &dss, baked->buckets, sizeof(*baked->buckets)*baked->bucket_count, - RADDBG_DataSectionTag_NameMapBuckets); - name_map_ptr->node_data_idx = - cons__dsection(arena, &dss, baked->nodes, sizeof(*baked->nodes)*baked->node_count, - RADDBG_DataSectionTag_NameMapNodes); - name_map_ptr += 1; - } - } - - cons__dsection(arena, &dss, name_maps, sizeof(*name_maps)*name_map_count, - RADDBG_DataSectionTag_NameMaps); - } - - //////////////////////////////// - // LATE PART: baking loose structures and creating final layout - - // generate data sections for file paths - { - U32 count = bctx->tree->count; - RADDBG_FilePathNode *nodes = push_array(arena, RADDBG_FilePathNode, count); - - RADDBG_FilePathNode *out_node = nodes; - for (CONS__PathNode *node = bctx->tree->first; - node != 0; - node = node->next_order, out_node += 1){ - out_node->name_string_idx = cons__string(bctx, node->name); - if (node->parent != 0){ - out_node->parent_path_node = node->parent->idx; - } - if (node->first_child != 0){ - out_node->first_child = node->first_child->idx; - } - if (node->next_sibling != 0){ - out_node->next_sibling = node->next_sibling->idx; - } - if (node->src_file != 0){ - out_node->source_file_idx = node->src_file->idx; - } - } - - cons__dsection(arena, &dss, nodes, sizeof(*nodes)*count, RADDBG_DataSectionTag_FilePathNodes); - } - - // generate data sections for files - { - U32 count = bctx->tree->src_count; - RADDBG_SourceFile *src_files = push_array(arena, RADDBG_SourceFile, count); - - RADDBG_SourceFile *out_src_file = src_files; - for (CONS__SrcNode *node = bctx->tree->src_first; - node != 0; - node = node->next, out_src_file += 1){ - out_src_file->file_path_node_idx = node->path_node->idx; - out_src_file->normal_full_path_string_idx = cons__string(bctx, node->normal_full_path); - out_src_file->line_map_nums_data_idx = node->line_map_nums_data_idx; - out_src_file->line_map_range_data_idx = node->line_map_range_data_idx; - out_src_file->line_map_count = node->line_map_count; - out_src_file->line_map_voff_data_idx = node->line_map_voff_data_idx; - } - - cons__dsection(arena, &dss, src_files, sizeof(*src_files)*count, RADDBG_DataSectionTag_SourceFiles); - } - - // generate data sections for strings - { - U32 *str_offs = push_array_no_zero(arena, U32, bctx->strs.count + 1); - - U32 off_cursor = 0; - { - U32 *off_ptr = str_offs; - *off_ptr = 0; - off_ptr += 1; - for (CONS__StringNode *node = bctx->strs.order_first; - node != 0; - node = node->order_next){ - off_cursor += node->str.size; - *off_ptr = off_cursor; - off_ptr += 1; - } - } - - U8 *buf = push_array(arena, U8, off_cursor); - { - U8 *ptr = buf; - for (CONS__StringNode *node = bctx->strs.order_first; - node != 0; - node = node->order_next){ - MemoryCopy(ptr, node->str.str, node->str.size); - ptr += node->str.size; - } - } - - cons__dsection(arena, &dss, str_offs, sizeof(*str_offs)*(bctx->strs.count + 1), - RADDBG_DataSectionTag_StringTable); - cons__dsection(arena, &dss, buf, off_cursor, RADDBG_DataSectionTag_StringData); - } - - // generate data sections for index runs - { - U32 *idx_data = push_array_no_zero(arena, U32, bctx->idxs.idx_count); - - { - U32 *out_ptr = idx_data; - U32 *opl = out_ptr + bctx->idxs.idx_count; - CONS__IdxRunNode *node = bctx->idxs.order_first; - for (;node != 0 && out_ptr < opl; - node = node->order_next){ - MemoryCopy(out_ptr, node->idx_run, sizeof(*node->idx_run)*node->count); - out_ptr += node->count; - } - Assert(out_ptr == opl); - } - - cons__dsection(arena, &dss, idx_data, sizeof(*idx_data)*bctx->idxs.idx_count, - RADDBG_DataSectionTag_IndexRuns); - } - - // layout - // * the header and data section table have to be initialized "out of order" - // * so that the rest of the system can avoid this tricky order-layout interdependence stuff - RADDBG_Header *header = push_array(arena, RADDBG_Header, 1); - RADDBG_DataSection *dstable = push_array(arena, RADDBG_DataSection, dss.count); - str8_serial_push_align(arena, out, 8); - U64 header_off = out->total_size; - str8_list_push(arena, out, str8_struct(header)); - str8_serial_push_align(arena, out, 8); - U64 data_section_off = out->total_size; - str8_list_push(arena, out, str8((U8 *)dstable, sizeof(*dstable)*dss.count)); - { - header->magic = RADDBG_MAGIC_CONSTANT; - header->encoding_version = RADDBG_ENCODING_VERSION; - header->data_section_off = data_section_off; - header->data_section_count = dss.count; - } - { - U64 test_dss_count = 0; - for (CONS__DSectionNode *node = dss.first; - node != 0; - node = node->next){ - test_dss_count += 1; - } - Assert(test_dss_count == dss.count); - - RADDBG_DataSection *ptr = dstable; - for (CONS__DSectionNode *node = dss.first; - node != 0; - node = node->next, ptr += 1){ - U64 data_section_offset = 0; - if(node->size != 0) - { - str8_serial_push_align(arena, out, 8); - data_section_offset = out->total_size; - str8_list_push(arena, out, str8((U8 *)node->data, node->size)); - } - ptr->tag = node->tag; - ptr->encoding = RADDBG_DataSectionEncoding_Unpacked; - ptr->off = data_section_offset; - ptr->encoded_size = node->size; - ptr->unpacked_size = node->size; - } - Assert(ptr == dstable + dss.count); - } - - cons__bake_ctx_release(bctx); - ProfEnd(); -} +//- rjf: error accumulation - -//- errors static void -cons_errorf(CONS_Root *root, char *fmt, ...){ - ProfBeginFunction(); +cons_error(CONS_Root *root, String8 string) +{ CONS_Error *error = push_array(root->arena, CONS_Error, 1); SLLQueuePush(root->errors.first, root->errors.last, error); root->errors.count += 1; - + error->msg = string; +} + +static void +cons_errorf(CONS_Root *root, char *fmt, ...) +{ va_list args; va_start(args, fmt); String8 str = push_str8fv(root->arena, fmt, args); + cons_error(root, str); va_end(args); - - error->msg = str; - ProfEnd(); } static CONS_Error* -cons_get_first_error(CONS_Root *root){ - return(root->errors.first); +cons_get_first_error(CONS_Root *root) +{ + return root->errors.first; } - -//- information declaration - -// top level info +//- rjf: top-level info specification static void -cons_set_top_level_info(CONS_Root *root, CONS_TopLevelInfo *tli){ - if (root->top_level_info_is_set){ - // TODO(allen): API error - } - else{ - MemoryCopyStruct(&root->top_level_info, tli); - root->top_level_info_is_set = 1; - } +cons_set_top_level_info(CONS_Root *root, CONS_TopLevelInfo *tli) +{ + cons_requiref(root, !root->top_level_info_is_set, return, "Top level information set multiple times."); + MemoryCopyStruct(&root->top_level_info, tli); + root->top_level_info_is_set = 1; } -// binary sections +//- rjf: binary section building static void -cons_add_binary_section(CONS_Root *root, String8 name, RADDBG_BinarySectionFlags flags, - U64 voff_first, U64 voff_opl, U64 foff_first, U64 foff_opl){ +cons_add_binary_section(CONS_Root *root, String8 name, RADDBG_BinarySectionFlags flags, U64 voff_first, U64 voff_opl, U64 foff_first, U64 foff_opl) +{ CONS_BinarySection *sec = push_array(root->arena, CONS_BinarySection, 1); SLLQueuePush(root->binary_section_first, root->binary_section_last, sec); root->binary_section_count += 1; - sec->name = name; sec->flags = flags; sec->voff_first = voff_first; @@ -518,49 +483,46 @@ cons_add_binary_section(CONS_Root *root, String8 name, RADDBG_BinarySectionFlags sec->foff_opl = foff_opl; } -// units +//- rjf: unit info building static CONS_Unit* -cons_unit_handle_from_user_id(CONS_Root *root, U64 unit_user_id, U64 unit_user_id_hash){ - ProfBeginFunction(); +cons_unit_handle_from_user_id(CONS_Root *root, U64 unit_user_id, U64 unit_user_id_hash) +{ CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->unit_map, unit_user_id, unit_user_id_hash, &lookup); - CONS_Unit *result = 0; - if (lookup.match != 0){ + if(lookup.match != 0) + { result = (CONS_Unit*)lookup.match; } - else{ + else + { result = push_array(root->arena, CONS_Unit, 1); result->idx = root->unit_count; SLLQueuePush_N(root->unit_first, root->unit_last, result, next_order); root->unit_count += 1; cons__u64toptr_insert(root->arena, &root->unit_map, unit_user_id, unit_user_id, &lookup, result); } - - ProfEnd(); - return(result); + return result; } static void -cons_unit_set_info(CONS_Root *root, CONS_Unit *unit, CONS_UnitInfo *info){ - if (unit->info_is_set){ - // TODO(allen): API error - } - else{ - unit->info_is_set = 1; - unit->unit_name = push_str8_copy(root->arena, info->unit_name); - unit->compiler_name = push_str8_copy(root->arena, info->compiler_name); - unit->source_file = push_str8_copy(root->arena, info->source_file); - unit->object_file = push_str8_copy(root->arena, info->object_file); - unit->archive_file = push_str8_copy(root->arena, info->archive_file); - unit->build_path = push_str8_copy(root->arena, info->build_path); - unit->language = info->language; - } +cons_unit_set_info(CONS_Root *root, CONS_Unit *unit, CONS_UnitInfo *info) +{ + cons_requiref(root, !unit->info_is_set, return, "Unit information set multiple times."); + unit->info_is_set = 1; + unit->unit_name = push_str8_copy(root->arena, info->unit_name); + unit->compiler_name = push_str8_copy(root->arena, info->compiler_name); + unit->source_file = push_str8_copy(root->arena, info->source_file); + unit->object_file = push_str8_copy(root->arena, info->object_file); + unit->archive_file = push_str8_copy(root->arena, info->archive_file); + unit->build_path = push_str8_copy(root->arena, info->build_path); + unit->language = info->language; } static void -cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, CONS_LineSequence *line_sequence){ +cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, CONS_LineSequence *line_sequence) +{ CONS_LineSequenceNode *node = push_array(root->arena, CONS_LineSequenceNode, 1); SLLQueuePush(unit->line_seq_first, unit->line_seq_last, node); unit->line_seq_count += 1; @@ -573,7 +535,8 @@ cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, CONS_LineSequence node->line_seq.line_nums = push_array(root->arena, U32, line_sequence->line_count); MemoryCopy(node->line_seq.line_nums, line_sequence->line_nums, sizeof(U32)*line_sequence->line_count); - if (line_sequence->col_nums != 0){ + if(line_sequence->col_nums != 0) + { node->line_seq.col_nums = push_array(root->arena, U16, line_sequence->line_count); MemoryCopy(node->line_seq.col_nums, line_sequence->col_nums, sizeof(U16)*line_sequence->line_count); } @@ -582,496 +545,166 @@ cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, CONS_LineSequence } static void -cons_unit_vmap_add_range(CONS_Root *root, CONS_Unit *unit, U64 first, U64 opl){ +cons_unit_vmap_add_range(CONS_Root *root, CONS_Unit *unit, U64 first, U64 opl) +{ CONS_UnitVMapRange *node = push_array(root->arena, CONS_UnitVMapRange, 1); SLLQueuePush(root->unit_vmap_range_first, root->unit_vmap_range_last, node); root->unit_vmap_range_count += 1; - node->unit = unit; node->first = first; node->opl = opl; } -// types +//- rjf: type info lookups/reservations static CONS_Type* -cons_type_from_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash){ +cons_type_from_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash) +{ CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->type_from_id_map, type_user_id, type_user_id_hash, &lookup); - CONS_Type *result = (CONS_Type*)lookup.match; - return(result); + return result; } static CONS_Reservation* -cons_type_reserve_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash){ - ProfBeginFunction(); +cons_type_reserve_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash) +{ + CONS_Reservation *result = 0; CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->type_from_id_map, type_user_id, type_user_id_hash, &lookup); - - CONS_Reservation *result = 0; - if (lookup.match == 0){ + if(lookup.match == 0) + { cons__u64toptr_insert(root->arena, &root->type_from_id_map, type_user_id, type_user_id_hash, &lookup, root->nil_type); void **slot = &lookup.fill_node->ptr[lookup.fill_k]; result = (CONS_Reservation*)slot; } - - ProfEnd(); - return(result); + return result; } static void -cons_type_fill_id(CONS_Root *root, CONS_Reservation *res, CONS_Type *type){ - if (res != 0 && type != 0){ +cons_type_fill_id(CONS_Root *root, CONS_Reservation *res, CONS_Type *type) +{ + if(res != 0 && type != 0) + { *(void**)res = type; } } +//- rjf: nil/singleton types + static B32 -cons_type_is_unhandled_nil(CONS_Root *root, CONS_Type *type){ - B32 result = (type->kind == RADDBG_TypeKind_NULL && - type != &root->handled_nil_type); - return(result); +cons_type_is_unhandled_nil(CONS_Root *root, CONS_Type *type) +{ + B32 result = (type->kind == RADDBG_TypeKind_NULL && type != &root->handled_nil_type); + return result; } static CONS_Type* -cons_type_handled_nil(CONS_Root *root){ - return(&root->handled_nil_type); +cons_type_handled_nil(CONS_Root *root) +{ + return &root->handled_nil_type; } static CONS_Type* -cons_type_nil(CONS_Root *root){ - return(root->nil_type); +cons_type_nil(CONS_Root *root) +{ + return root->nil_type; } static CONS_Type* -cons_type_variadic(CONS_Root *root){ - return(root->variadic_type); +cons_type_variadic(CONS_Root *root) +{ + return root->variadic_type; } -static CONS_Type* -cons_type_basic(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name){ - CONS_Type *result = root->nil_type; - - if (!(RADDBG_TypeKind_FirstBuiltIn <= type_kind && - type_kind <= RADDBG_TypeKind_LastBuiltIn)){ - // TODO(allen): API error - } - else{ - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(type_kind) + name.size; - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "basic" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Basic; - ptr += sizeof(CONS_TypeConstructKind); - // type_kind - MemoryCopy(ptr, &type_kind, sizeof(type_kind)); - ptr += sizeof(type_kind); - // name - MemoryCopy(ptr, name.str, name.size); - ptr += name.size; - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - // calculate size - U32 byte_size = raddbg_size_from_basic_type_kind(type_kind); - if (byte_size == 0xFFFFFFFF){ - byte_size = root->addr_size; - } - - // setup new node - result = cons__type_new(root); - result->kind = type_kind; - result->name = push_str8_copy(root->arena, name); - result->byte_size = byte_size; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - - // save in name map - { - CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); - cons__name_map_add_pair(root, map, result->name, result->idx); - } - } - - scratch_end(scratch); - } - - Assert(result != 0); - return(result); -} +//- rjf: base type info constructors static CONS_Type* -cons_type_modifier(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeModifierFlags flags){ - ProfBeginFunction(); - CONS_Type *result = root->nil_type; - +cons__type_new(CONS_Root *root) +{ + CONS_Type *result = push_array(root->arena, CONS_Type, 1); + result->idx = root->type_count; + SLLQueuePush_N(root->first_type, root->last_type, result, next_order); + root->type_count += 1; + return result; +} + +static CONS_TypeUDT* +cons__type_udt_from_any_type(CONS_Root *root, CONS_Type *type) +{ + if(type->udt == 0) { - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(flags) + sizeof(direct_type->idx); - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "modifier" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Modifier; - ptr += sizeof(CONS_TypeConstructKind); - // flags - MemoryCopy(ptr, &flags, sizeof(flags)); - ptr += sizeof(flags); - // direct_type->idx - MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); - ptr += sizeof(direct_type->idx); - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup new node - result = cons__type_new(root); - result->kind = RADDBG_TypeKind_Modifier; - result->flags = flags; - result->byte_size = direct_type->byte_size; - result->direct_type = direct_type; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); + CONS_TypeUDT *new_udt = push_array(root->arena, CONS_TypeUDT, 1); + new_udt->idx = root->type_udt_count; + SLLQueuePush_N(root->first_udt, root->last_udt, new_udt, next_order); + root->type_udt_count += 1; + new_udt->self_type = type; + type->udt = new_udt; } - - Assert(result != 0); - ProfEnd(); - return(result); + CONS_TypeUDT *result = type->udt; + return result; } +static CONS_TypeUDT* +cons__type_udt_from_record_type(CONS_Root *root, CONS_Type *type) +{ + cons_requiref(root, (type->kind == RADDBG_TypeKind_Struct || + type->kind == RADDBG_TypeKind_Class || + type->kind == RADDBG_TypeKind_Union), + return 0, + "Tried to use non-user-defined-type-kind to create user-defined-type."); + CONS_TypeUDT *result = 0; + result = cons__type_udt_from_any_type(root, type); + return result; +} + +//- rjf: basic/operator type construction helpers + static CONS_Type* -cons_type_bitfield(CONS_Root *root, CONS_Type *direct_type, U32 bit_off, U32 bit_count){ +cons_type_basic(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name) +{ + cons_requiref(root, (RADDBG_TypeKind_FirstBuiltIn <= type_kind && type_kind <= RADDBG_TypeKind_LastBuiltIn), return root->nil_type, "Non-basic type kind passed to construct basic type."); CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + // setup construct buffer + U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(type_kind) + name.size; + U8 *buf = push_array(scratch.arena, U8, buf_size); { - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(direct_type->idx) + sizeof(U32)*2; - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "bitfield" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Bitfield; - ptr += sizeof(CONS_TypeConstructKind); - // direct_type->idx - MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); - ptr += sizeof(direct_type->idx); - // bit_off - MemoryCopy(ptr, &bit_off, sizeof(bit_off)); - ptr += sizeof(bit_off); - // bit_count - MemoryCopy(ptr, &bit_count, sizeof(bit_count)); - ptr += sizeof(bit_count); - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup new node - result = cons__type_new(root); - result->kind = RADDBG_TypeKind_Bitfield; - result->byte_size = direct_type->byte_size; - result->off = bit_off; - result->count = bit_count; - result->direct_type = direct_type; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); + U8 *ptr = buf; + // "basic" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Basic; + ptr += sizeof(CONS_TypeConstructKind); + // type_kind + MemoryCopy(ptr, &type_kind, sizeof(type_kind)); + ptr += sizeof(type_kind); + // name + MemoryCopy(ptr, name.str, name.size); + ptr += name.size; } - Assert(result != 0); - return(result); -} - -static CONS_Type* -cons_type_pointer(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeKind ptr_type_kind){ - ProfBeginFunction(); - CONS_Type *result = root->nil_type; - - if (!(ptr_type_kind == RADDBG_TypeKind_Ptr || - ptr_type_kind == RADDBG_TypeKind_LRef || - ptr_type_kind == RADDBG_TypeKind_RRef)){ - // TODO(allen): API error - } - else{ - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(ptr_type_kind) + sizeof(direct_type->idx); - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "pointer" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Pointer; - ptr += sizeof(CONS_TypeConstructKind); - // type_kind - MemoryCopy(ptr, &ptr_type_kind, sizeof(ptr_type_kind)); - ptr += sizeof(ptr_type_kind); - // direct_type->idx - MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); - ptr += sizeof(direct_type->idx); - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup new node - result = cons__type_new(root); - result->kind = ptr_type_kind; - result->byte_size = root->addr_size; - result->direct_type = direct_type; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); - } - - Assert(result != 0); - ProfEnd(); - return(result); -} - -static CONS_Type* -cons_type_array(CONS_Root *root, CONS_Type *direct_type, U64 count){ - CONS_Type *result = root->nil_type; - + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) { - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = - sizeof(CONS_TypeConstructKind) + sizeof(direct_type->idx) + sizeof(count); - U8 *buf = push_array(scratch.arena, U8, buf_size); + // calculate size + U32 byte_size = raddbg_size_from_basic_type_kind(type_kind); + if(byte_size == 0xFFFFFFFF) { - U8 *ptr = buf; - // "array" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Array; - ptr += sizeof(CONS_TypeConstructKind); - // direct_type->idx - MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); - ptr += sizeof(direct_type->idx); - // count - MemoryCopy(ptr, &count, sizeof(count)); - ptr += sizeof(count); + byte_size = root->addr_size; } - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup new node - result = cons__type_new(root); - result->kind = RADDBG_TypeKind_Array; - result->count = count; - result->direct_type = direct_type; - result->byte_size = direct_type->byte_size*count; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); - } - - Assert(result != 0); - return(result); -} - -static CONS_Type* -cons_type_proc(CONS_Root *root, CONS_Type *return_type, CONS_TypeList *params){ - ProfBeginFunction(); - CONS_Type *result = root->nil_type; - - { - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(return_type->idx)*(1 + params->count); - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "procedure" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Procedure; - ptr += sizeof(CONS_TypeConstructKind); - // ret_type->idx - MemoryCopy(ptr, &return_type->idx, sizeof(return_type->idx)); - ptr += sizeof(return_type->idx); - // (params ...)->idx - for (CONS_TypeNode *node = params->first; - node != 0; - node = node->next){ - MemoryCopy(ptr, &node->type->idx, sizeof(node->type->idx)); - ptr += sizeof(node->type->idx); - } - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup param buffer - CONS_Type **param_types = push_array(root->arena, CONS_Type*, params->count); - { - CONS_Type **ptr = param_types; - for (CONS_TypeNode *node = params->first; - node != 0; - node = node->next){ - *ptr = node->type; - ptr += 1; - } - } - - // setup new node - result = cons__type_new(root); - result->kind = RADDBG_TypeKind_Function; - result->byte_size = root->addr_size; - result->count = params->count; - result->direct_type = return_type; - result->param_types = param_types; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); - } - - Assert(result != 0); - ProfEnd(); - return(result); -} - -static CONS_Type* -cons_type_method(CONS_Root *root, CONS_Type *this_type, CONS_Type *return_type, CONS_TypeList *params){ - ProfBeginFunction(0, 0); - CONS_Type *result = root->nil_type; - - { - Temp scratch = scratch_begin(0, 0); - - // setup construct buffer - U64 buf_size = - sizeof(CONS_TypeConstructKind) + sizeof(return_type->idx)*(2 + params->count); - U8 *buf = push_array(scratch.arena, U8, buf_size); - { - U8 *ptr = buf; - // "method" - *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Method; - ptr += sizeof(CONS_TypeConstructKind); - // ret_type->idx - MemoryCopy(ptr, &return_type->idx, sizeof(return_type->idx)); - ptr += sizeof(return_type->idx); - // this_type->idx - MemoryCopy(ptr, &this_type->idx, sizeof(this_type->idx)); - ptr += sizeof(this_type->idx); - // (params ...)->idx - for (CONS_TypeNode *node = params->first; - node != 0; - node = node->next){ - MemoryCopy(ptr, &node->type->idx, sizeof(node->type->idx)); - ptr += sizeof(node->type->idx); - } - } - - // check for duplicate construct - String8 blob = str8(buf, buf_size); - U64 blob_hash = raddbg_hash(buf, buf_size); - void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); - result = (CONS_Type*)lookup_ptr; - if (result == 0){ - - // setup param buffer - CONS_Type **param_types = push_array(root->arena, CONS_Type*, params->count + 1); - { - CONS_Type **ptr = param_types; - { - *ptr = this_type; - ptr += 1; - } - for (CONS_TypeNode *node = params->first; - node != 0; - node = node->next){ - *ptr = node->type; - ptr += 1; - } - } - - // setup new node - result = cons__type_new(root); - result->kind = RADDBG_TypeKind_Method; - result->byte_size = root->addr_size; - result->count = params->count; - result->direct_type = return_type; - result->param_types = param_types; - - // save in construct map - cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); - } - - scratch_end(scratch); - } - - Assert(result != 0); - ProfEnd(); - return(result); -} - -static CONS_Type* -cons_type_udt(CONS_Root *root, RADDBG_TypeKind record_type_kind, String8 name, U64 size){ - CONS_Type *result = root->nil_type; - - if (!(record_type_kind == RADDBG_TypeKind_Struct || - record_type_kind == RADDBG_TypeKind_Class || - record_type_kind == RADDBG_TypeKind_Union)){ - // TODO(allen): API error - } - else{ + // setup new node result = cons__type_new(root); - result->kind = record_type_kind; - result->byte_size = size; + result->kind = type_kind; result->name = push_str8_copy(root->arena, name); + result->byte_size = byte_size; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); // save in name map { @@ -1080,79 +713,436 @@ cons_type_udt(CONS_Root *root, RADDBG_TypeKind record_type_kind, String8 name, U } } - return(result); + scratch_end(scratch); + Assert(result != 0); + return result; } static CONS_Type* -cons_type_enum(CONS_Root *root, CONS_Type *direct_type, String8 name){ +cons_type_modifier(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeModifierFlags flags) +{ + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(flags) + sizeof(direct_type->idx); + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "modifier" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Modifier; + ptr += sizeof(CONS_TypeConstructKind); + // flags + MemoryCopy(ptr, &flags, sizeof(flags)); + ptr += sizeof(flags); + // direct_type->idx + MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); + ptr += sizeof(direct_type->idx); + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0){ + + // setup new node + result = cons__type_new(root); + result->kind = RADDBG_TypeKind_Modifier; + result->flags = flags; + result->byte_size = direct_type->byte_size; + result->direct_type = direct_type; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +static CONS_Type* +cons_type_bitfield(CONS_Root *root, CONS_Type *direct_type, U32 bit_off, U32 bit_count) +{ + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(direct_type->idx) + sizeof(U32)*2; + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "bitfield" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Bitfield; + ptr += sizeof(CONS_TypeConstructKind); + // direct_type->idx + MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); + ptr += sizeof(direct_type->idx); + // bit_off + MemoryCopy(ptr, &bit_off, sizeof(bit_off)); + ptr += sizeof(bit_off); + // bit_count + MemoryCopy(ptr, &bit_count, sizeof(bit_count)); + ptr += sizeof(bit_count); + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) + { + // setup new node + result = cons__type_new(root); + result->kind = RADDBG_TypeKind_Bitfield; + result->byte_size = direct_type->byte_size; + result->off = bit_off; + result->count = bit_count; + result->direct_type = direct_type; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +static CONS_Type* +cons_type_pointer(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeKind ptr_type_kind) +{ + cons_requiref(root, (ptr_type_kind == RADDBG_TypeKind_Ptr || + ptr_type_kind == RADDBG_TypeKind_LRef || + ptr_type_kind == RADDBG_TypeKind_RRef), + return root->nil_type, + "Non-pointer type kind used to construct pointer type."); + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(ptr_type_kind) + sizeof(direct_type->idx); + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "pointer" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Pointer; + ptr += sizeof(CONS_TypeConstructKind); + // type_kind + MemoryCopy(ptr, &ptr_type_kind, sizeof(ptr_type_kind)); + ptr += sizeof(ptr_type_kind); + // direct_type->idx + MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); + ptr += sizeof(direct_type->idx); + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) + { + // setup new node + result = cons__type_new(root); + result->kind = ptr_type_kind; + result->byte_size = root->addr_size; + result->direct_type = direct_type; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +static CONS_Type* +cons_type_array(CONS_Root *root, CONS_Type *direct_type, U64 count) +{ + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = + sizeof(CONS_TypeConstructKind) + sizeof(direct_type->idx) + sizeof(count); + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "array" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Array; + ptr += sizeof(CONS_TypeConstructKind); + // direct_type->idx + MemoryCopy(ptr, &direct_type->idx, sizeof(direct_type->idx)); + ptr += sizeof(direct_type->idx); + // count + MemoryCopy(ptr, &count, sizeof(count)); + ptr += sizeof(count); + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) + { + // setup new node + result = cons__type_new(root); + result->kind = RADDBG_TypeKind_Array; + result->count = count; + result->direct_type = direct_type; + result->byte_size = direct_type->byte_size*count; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +static CONS_Type* +cons_type_proc(CONS_Root *root, CONS_Type *return_type, struct CONS_TypeList *params) +{ + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = sizeof(CONS_TypeConstructKind) + sizeof(return_type->idx)*(1 + params->count); + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "procedure" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Procedure; + ptr += sizeof(CONS_TypeConstructKind); + // ret_type->idx + MemoryCopy(ptr, &return_type->idx, sizeof(return_type->idx)); + ptr += sizeof(return_type->idx); + // (params ...)->idx + for(CONS_TypeNode *node = params->first; + node != 0; + node = node->next) + { + MemoryCopy(ptr, &node->type->idx, sizeof(node->type->idx)); + ptr += sizeof(node->type->idx); + } + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) + { + // setup param buffer + CONS_Type **param_types = push_array(root->arena, CONS_Type*, params->count); + { + CONS_Type **ptr = param_types; + for(CONS_TypeNode *node = params->first; + node != 0; + node = node->next) + { + *ptr = node->type; + ptr += 1; + } + } + + // setup new node + result = cons__type_new(root); + result->kind = RADDBG_TypeKind_Function; + result->byte_size = root->addr_size; + result->count = params->count; + result->direct_type = return_type; + result->param_types = param_types; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +static CONS_Type* +cons_type_method(CONS_Root *root, CONS_Type *this_type, CONS_Type *return_type, struct CONS_TypeList *params) +{ + CONS_Type *result = root->nil_type; + Temp scratch = scratch_begin(0, 0); + + // setup construct buffer + U64 buf_size = + sizeof(CONS_TypeConstructKind) + sizeof(return_type->idx)*(2 + params->count); + U8 *buf = push_array(scratch.arena, U8, buf_size); + { + U8 *ptr = buf; + // "method" + *(CONS_TypeConstructKind*)ptr = CONS_TypeConstructKind_Method; + ptr += sizeof(CONS_TypeConstructKind); + // ret_type->idx + MemoryCopy(ptr, &return_type->idx, sizeof(return_type->idx)); + ptr += sizeof(return_type->idx); + // this_type->idx + MemoryCopy(ptr, &this_type->idx, sizeof(this_type->idx)); + ptr += sizeof(this_type->idx); + // (params ...)->idx + for(CONS_TypeNode *node = params->first; + node != 0; + node = node->next) + { + MemoryCopy(ptr, &node->type->idx, sizeof(node->type->idx)); + ptr += sizeof(node->type->idx); + } + } + + // check for duplicate construct + String8 blob = str8(buf, buf_size); + U64 blob_hash = raddbg_hash(buf, buf_size); + void *lookup_ptr = cons__str8toptr_lookup(&root->construct_map, blob, blob_hash); + result = (CONS_Type*)lookup_ptr; + if(result == 0) + { + // setup param buffer + CONS_Type **param_types = push_array(root->arena, CONS_Type*, params->count + 1); + { + CONS_Type **ptr = param_types; + { + *ptr = this_type; + ptr += 1; + } + for(CONS_TypeNode *node = params->first; + node != 0; + node = node->next) + { + *ptr = node->type; + ptr += 1; + } + } + + // setup new node + result = cons__type_new(root); + result->kind = RADDBG_TypeKind_Method; + result->byte_size = root->addr_size; + result->count = params->count; + result->direct_type = return_type; + result->param_types = param_types; + + // save in construct map + cons__str8toptr_insert(root->arena, &root->construct_map, blob, blob_hash, result); + } + + scratch_end(scratch); + Assert(result != 0); + return result; +} + +//- rjf: udt type constructors + +static CONS_Type* +cons_type_udt(CONS_Root *root, RADDBG_TypeKind record_type_kind, String8 name, U64 size) +{ + cons_requiref(root, (record_type_kind == RADDBG_TypeKind_Struct || + record_type_kind == RADDBG_TypeKind_Class || + record_type_kind == RADDBG_TypeKind_Union), + return root->nil_type, + "Non-user-defined-type-kind used to create user-defined type."); + + // rjf: make type + CONS_Type *result = cons__type_new(root); + result->kind = record_type_kind; + result->byte_size = size; + result->name = push_str8_copy(root->arena, name); + + // rjf: save in name map + { + CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); + cons__name_map_add_pair(root, map, result->name, result->idx); + } + + return result; +} + +static CONS_Type* +cons_type_enum(CONS_Root *root, CONS_Type *direct_type, String8 name) +{ + // rjf: make type CONS_Type *result = cons__type_new(root); result->kind = RADDBG_TypeKind_Enum; result->byte_size = direct_type->byte_size; result->name = push_str8_copy(root->arena, name); result->direct_type = direct_type; - // save in name map + // rjf: save in name map { CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); cons__name_map_add_pair(root, map, result->name, result->idx); } - return(result); + return result; } static CONS_Type* -cons_type_alias(CONS_Root *root, CONS_Type *direct_type, String8 name){ +cons_type_alias(CONS_Root *root, CONS_Type *direct_type, String8 name) +{ + // rjf: make type CONS_Type *result = cons__type_new(root); result->kind = RADDBG_TypeKind_Alias; result->byte_size = direct_type->byte_size; result->name = push_str8_copy(root->arena, name); result->direct_type = direct_type; + // rjf: save in name map + { + CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); + cons__name_map_add_pair(root, map, result->name, result->idx); + } + + return result; +} + +static CONS_Type* +cons_type_incomplete(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name) +{ + cons_requiref(root, (type_kind == RADDBG_TypeKind_IncompleteStruct || + type_kind == RADDBG_TypeKind_IncompleteClass || + type_kind == RADDBG_TypeKind_IncompleteUnion || + type_kind == RADDBG_TypeKind_IncompleteEnum), + return root->nil_type, + "Non-incomplete-type-kind used to create incomplete type."); + + // rjf: make type + CONS_Type *result = cons__type_new(root); + result->kind = type_kind; + result->name = push_str8_copy(root->arena, name); + // save in name map { CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); cons__name_map_add_pair(root, map, result->name, result->idx); } - return(result); + return result; } -static CONS_Type* -cons_type_incomplete(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name){ - CONS_Type *result = root->nil_type; - - if (!(type_kind == RADDBG_TypeKind_IncompleteStruct || - type_kind == RADDBG_TypeKind_IncompleteClass || - type_kind == RADDBG_TypeKind_IncompleteUnion || - type_kind == RADDBG_TypeKind_IncompleteEnum)){ - // TODO(allen): API error - } - else{ - result = cons__type_new(root); - result->kind = type_kind; - result->name = push_str8_copy(root->arena, name); - - // save in name map - { - CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Types); - cons__name_map_add_pair(root, map, result->name, result->idx); - } - } - - return(result); -} +//- rjf: type member building static void -cons_type_add_member_data_field(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type, U32 off){ +cons_type_add_member_data_field(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type, U32 off) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_DataField; member->name = push_str8_copy(root->arena, name); member->type = mem_type; @@ -1161,16 +1151,15 @@ cons_type_add_member_data_field(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_static_data(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type){ +cons_type_add_member_static_data(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_StaticData; member->name = push_str8_copy(root->arena, name); member->type = mem_type; @@ -1178,16 +1167,15 @@ cons_type_add_member_static_data(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type){ +cons_type_add_member_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_Method; member->name = push_str8_copy(root->arena, name); member->type = mem_type; @@ -1195,10 +1183,11 @@ cons_type_add_member_method(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_static_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type){ +cons_type_add_member_static_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; @@ -1212,16 +1201,15 @@ cons_type_add_member_static_method(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_virtual_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type){ +cons_type_add_member_virtual_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_VirtualMethod; member->name = push_str8_copy(root->arena, name); member->type = mem_type; @@ -1229,16 +1217,15 @@ cons_type_add_member_virtual_method(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_base(CONS_Root *root, CONS_Type *record_type, - CONS_Type *base_type, U32 off){ +cons_type_add_member_base(CONS_Root *root, CONS_Type *record_type, CONS_Type *base_type, U32 off) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_Base; member->type = base_type; member->off = off; @@ -1246,16 +1233,15 @@ cons_type_add_member_base(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_virtual_base(CONS_Root *root, CONS_Type *record_type, - CONS_Type *base_type, U32 vptr_off, U32 vtable_off){ +cons_type_add_member_virtual_base(CONS_Root *root, CONS_Type *record_type, CONS_Type *base_type, U32 vptr_off, U32 vtable_off) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_VirtualBase; member->type = base_type; // TODO(allen): what to do with the two offsets in this case? @@ -1263,214 +1249,185 @@ cons_type_add_member_virtual_base(CONS_Root *root, CONS_Type *record_type, } static void -cons_type_add_member_nested_type(CONS_Root *root, CONS_Type *record_type, - CONS_Type *nested_type){ +cons_type_add_member_nested_type(CONS_Root *root, CONS_Type *record_type, CONS_Type *nested_type) +{ CONS_TypeUDT *udt = cons__type_udt_from_record_type(root, record_type); - if (udt != 0){ + if(udt != 0) + { CONS_TypeMember *member = push_array(root->arena, CONS_TypeMember, 1); SLLQueuePush(udt->first_member, udt->last_member, member); udt->member_count += 1; - root->total_member_count += 1; - member->kind = RADDBG_MemberKind_NestedType; member->type = nested_type; } } static void -cons_type_add_enum_val(CONS_Root *root, CONS_Type *enum_type, String8 name, U64 val){ - if (enum_type->kind != RADDBG_TypeKind_Enum){ - // TODO(allen): API error - } - else{ - CONS_TypeUDT *udt = cons__type_udt_from_any_type(root, enum_type); - +cons_type_add_enum_val(CONS_Root *root, CONS_Type *enum_type, String8 name, U64 val) +{ + cons_requiref(root, (enum_type->kind == RADDBG_TypeKind_Enum), return, "Tried to add enum value to non-enum type."); + CONS_TypeUDT *udt = cons__type_udt_from_any_type(root, enum_type); + if(udt != 0) + { CONS_TypeEnumVal *enum_val = push_array(root->arena, CONS_TypeEnumVal, 1); SLLQueuePush(udt->first_enum_val, udt->last_enum_val, enum_val); udt->enum_val_count += 1; - root->total_enum_val_count += 1; - enum_val->name = push_str8_copy(root->arena, name); enum_val->val = val; } } +//- rjf: type source coordinate specifications static void -cons_type_set_source_coordinates(CONS_Root *root, CONS_Type *defined_type, - String8 source_path, U32 line, U32 col){ - if (!(RADDBG_TypeKind_FirstUserDefined <= defined_type->kind && - defined_type->kind <= RADDBG_TypeKind_LastUserDefined)){ - // TODO(allen): API error - } - else{ - CONS_TypeUDT *udt = cons__type_udt_from_any_type(root, defined_type); - +cons_type_set_source_coordinates(CONS_Root *root, CONS_Type *defined_type, String8 source_path, U32 line, U32 col) +{ + cons_requiref(root, (RADDBG_TypeKind_FirstUserDefined <= defined_type->kind && defined_type->kind <= RADDBG_TypeKind_LastUserDefined), + return, "Tried to add source coordinates to non-user-defined type."); + CONS_TypeUDT *udt = cons__type_udt_from_any_type(root, defined_type); + if(udt != 0) + { udt->source_path = push_str8_copy(root->arena, source_path); udt->line = line; udt->col = col; } } -// type list - -static void -cons_type_list_push(Arena *arena, CONS_TypeList *list, CONS_Type *type){ - CONS_TypeNode *node = push_array(arena, CONS_TypeNode, 1); - SLLQueuePush(list->first, list->last, node); - list->count += 1; - node->type = type; -} - -// symbols +//- rjf: symbol info building static CONS_Symbol* -cons_symbol_handle_from_user_id(CONS_Root *root, U64 symbol_user_id, U64 symbol_user_id_hash){ +cons_symbol_handle_from_user_id(CONS_Root *root, U64 symbol_user_id, U64 symbol_user_id_hash) +{ CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->symbol_map, symbol_user_id, symbol_user_id_hash, &lookup); - CONS_Symbol *result = 0; - if (lookup.match != 0){ + if(lookup.match != 0) + { result = (CONS_Symbol*)lookup.match; } - else{ + else + { result = push_array(root->arena, CONS_Symbol, 1); SLLQueuePush_N(root->first_symbol, root->last_symbol, result, next_order); root->symbol_count += 1; cons__u64toptr_insert(root->arena, &root->symbol_map, symbol_user_id, symbol_user_id_hash, &lookup, result); } - - return(result); + return result; } static void -cons_symbol_set_info(CONS_Root *root, CONS_Symbol *symbol, CONS_SymbolInfo *info){ +cons_symbol_set_info(CONS_Root *root, CONS_Symbol *symbol, CONS_SymbolInfo *info) +{ + // rjf: unpack CONS_SymbolKind kind = info->kind; + CONS_Symbol *container_symbol = info->container_symbol; + CONS_Type *container_type = info->container_type; - if (symbol->kind != CONS_SymbolKind_NULL){ - // TODO(allen): API error + // rjf: requirements + cons_requiref(root, CONS_SymbolKind_NULL == symbol->kind, return, "Symbol information set multiple times."); + cons_requiref(root, CONS_SymbolKind_NULL < info->kind && info->kind < CONS_SymbolKind_COUNT, return, "Invalid symbol kind used to initialize symbol."); + cons_requiref(root, info->type != 0, return, "Invalid type used to initialize symbol."); + cons_requiref(root, info->container_symbol == 0 || info->container_type == 0, container_type = 0, "Symbol initialized with both a containing symbol and containing type, when only one is allowed."); + + // rjf: fill + root->symbol_kind_counts[kind] += 1; + symbol->idx = root->symbol_kind_counts[kind]; + symbol->kind = kind; + symbol->name = push_str8_copy(root->arena, info->name); + symbol->link_name = push_str8_copy(root->arena, info->link_name); + symbol->type = info->type; + symbol->is_extern = info->is_extern; + symbol->offset = info->offset; + symbol->container_symbol = container_symbol; + symbol->container_type = container_type; + + // rjf: set root scope + switch(kind) + { + default:{}break; + case CONS_SymbolKind_GlobalVariable: + case CONS_SymbolKind_ThreadVariable: + { + cons_requiref(root, info->root_scope == 0, NoOp, "Global or thread variable initialized with root scope."); + }break; + case CONS_SymbolKind_Procedure: + { + cons_requiref(root, info->root_scope != 0, NoOp, "Procedure symbol initialized without root scope."); + symbol->root_scope = info->root_scope; + cons__scope_recursive_set_symbol(info->root_scope, symbol); + }break; } - else if (kind == CONS_SymbolKind_NULL || kind >= CONS_SymbolKind_COUNT){ - // TODO(allen): API error - } - else if (info->type == 0){ - // TODO(allen): API error - } - else{ - CONS_Symbol *container_symbol = info->container_symbol; - CONS_Type *container_type = info->container_type; - if (info->container_symbol != 0 && info->container_type != 0){ - // TODO(allen): API error - container_type = 0; - } - - root->symbol_kind_counts[kind] += 1; - symbol->idx = root->symbol_kind_counts[kind]; - - symbol->kind = kind; - symbol->name = push_str8_copy(root->arena, info->name); - symbol->link_name = push_str8_copy(root->arena, info->link_name); - symbol->type = info->type; - symbol->is_extern = info->is_extern; - symbol->offset = info->offset; - symbol->container_symbol = container_symbol; - symbol->container_type = container_type; - - // set root scope - switch (kind){ + + // save name map + { + CONS__NameMap *map = 0; + switch(kind) + { default:{}break; case CONS_SymbolKind_GlobalVariable: + { + map = cons__name_map_for_kind(root, RADDBG_NameMapKind_GlobalVariables); + }break; case CONS_SymbolKind_ThreadVariable: { - if (info->root_scope != 0){ - // TODO(allen): API error - } + map = cons__name_map_for_kind(root, RADDBG_NameMapKind_ThreadVariables); }break; - case CONS_SymbolKind_Procedure: { - if (info->root_scope == 0){ - // TODO(allen): API error - } - else{ - symbol->root_scope = info->root_scope; - cons__scope_recursive_set_symbol(info->root_scope, symbol); - } + map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Procedures); }break; } - - // save name map + if(map != 0) { - CONS__NameMap *map = 0; - switch (kind){ - default:{}break; - case CONS_SymbolKind_GlobalVariable: - { - map = cons__name_map_for_kind(root, RADDBG_NameMapKind_GlobalVariables); - }break; - case CONS_SymbolKind_ThreadVariable: - { - map = cons__name_map_for_kind(root, RADDBG_NameMapKind_ThreadVariables); - }break; - case CONS_SymbolKind_Procedure: - { - map = cons__name_map_for_kind(root, RADDBG_NameMapKind_Procedures); - }break; - } - if(map != 0) - { - cons__name_map_add_pair(root, map, symbol->name, symbol->idx); - } - } - - // save link name map - if (kind == CONS_SymbolKind_Procedure && symbol->link_name.size > 0){ - CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_LinkNameProcedures); - cons__name_map_add_pair(root, map, symbol->link_name, symbol->idx); + cons__name_map_add_pair(root, map, symbol->name, symbol->idx); } } + + // save link name map + if(kind == CONS_SymbolKind_Procedure && symbol->link_name.size > 0) + { + CONS__NameMap *map = cons__name_map_for_kind(root, RADDBG_NameMapKind_LinkNameProcedures); + cons__name_map_add_pair(root, map, symbol->link_name, symbol->idx); + } } -// scopes +//- rjf: scope info building -static CONS_Scope* -cons_scope_handle_from_user_id(CONS_Root *root, U64 scope_user_id, U64 scope_user_id_hash){ +static CONS_Scope * +cons_scope_handle_from_user_id(CONS_Root *root, U64 scope_user_id, U64 scope_user_id_hash) +{ + CONS_Scope *result = 0; CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->scope_map, scope_user_id, scope_user_id_hash, &lookup); - - CONS_Scope *result = 0; - if (lookup.match != 0){ + if(lookup.match != 0) + { result = (CONS_Scope*)lookup.match; } - else{ + else + { result = push_array(root->arena, CONS_Scope, 1); result->idx = root->scope_count; SLLQueuePush_N(root->first_scope, root->last_scope, result, next_order); root->scope_count += 1; cons__u64toptr_insert(root->arena, &root->scope_map, scope_user_id, scope_user_id_hash, &lookup, result); } - - return(result); + return result; } static void -cons_scope_set_parent(CONS_Root *root, CONS_Scope *scope, CONS_Scope *parent){ - if (scope->parent_scope != 0){ - // TODO(allen): API error - } - else if (parent == 0){ - // TODO(allen): API error - } - else{ - scope->symbol = parent->symbol; - scope->parent_scope = parent; - SLLQueuePush_N(parent->first_child, parent->last_child, scope, next_sibling); - } +cons_scope_set_parent(CONS_Root *root, CONS_Scope *scope, CONS_Scope *parent) +{ + cons_requiref(root, scope->parent_scope == 0, return, "Scope parent set multiple times."); + cons_requiref(root, parent != 0, return, "Tried to set invalid parent as scope parent."); + scope->symbol = parent->symbol; + scope->parent_scope = parent; + SLLQueuePush_N(parent->first_child, parent->last_child, scope, next_sibling); } static void -cons_scope_add_voff_range(CONS_Root *root, CONS_Scope *scope, U64 voff_first, U64 voff_opl){ +cons_scope_add_voff_range(CONS_Root *root, CONS_Scope *scope, U64 voff_first, U64 voff_opl) +{ CONS__VOffRange *range = push_array(root->arena, CONS__VOffRange, 1); SLLQueuePush(scope->first_range, scope->last_range, range); scope->range_count += 1; @@ -1480,278 +1437,169 @@ cons_scope_add_voff_range(CONS_Root *root, CONS_Scope *scope, U64 voff_first, U6 root->scope_voff_count += 2; } -// locals +static void +cons__scope_recursive_set_symbol(CONS_Scope *scope, CONS_Symbol *symbol) +{ + scope->symbol = symbol; + for(CONS_Scope *node = scope->first_child; + node != 0; + node = node->next_sibling) + { + cons__scope_recursive_set_symbol(node, symbol); + } +} + +//- rjf: local info building static CONS_Local* -cons_local_handle_from_user_id(CONS_Root *root, U64 local_user_id, U64 local_user_id_hash){ +cons_local_handle_from_user_id(CONS_Root *root, U64 local_user_id, U64 local_user_id_hash) +{ + CONS_Local *result = 0; CONS__U64ToPtrLookup lookup = {0}; cons__u64toptr_lookup(&root->local_map, local_user_id, local_user_id_hash, &lookup); - - CONS_Local *result = 0; - if (lookup.match != 0){ + if(lookup.match != 0) + { result = (CONS_Local*)lookup.match; } - else{ + else + { result = push_array(root->arena, CONS_Local, 1); cons__u64toptr_insert(root->arena, &root->local_map, local_user_id, local_user_id_hash, &lookup, result); } - - return(result); + return result; } static void -cons_local_set_basic_info(CONS_Root *root, CONS_Local *local, CONS_LocalInfo *info){ - if (local->kind != RADDBG_LocalKind_NULL){ - // TODO(allen): API error - } - else if (info->scope == 0){ - // TODO(allen): API error - } - else if (info->kind == RADDBG_LocalKind_NULL || RADDBG_LocalKind_COUNT <= info->kind){ - // TODO(allen): API error - } - else if (info->type == 0){ - // TODO(allen): API error - } - else{ - CONS_Scope *scope = info->scope; - SLLQueuePush(scope->first_local, scope->last_local, local); - scope->local_count += 1; - root->local_count += 1; - local->kind = info->kind; - local->name = push_str8_copy(root->arena, info->name); - local->type = info->type; - } +cons_local_set_basic_info(CONS_Root *root, CONS_Local *local, CONS_LocalInfo *info) +{ + cons_requiref(root, local->kind == RADDBG_LocalKind_NULL, return, "Local information set multiple times."); + cons_requiref(root, info->scope != 0, return, "Tried to set invalid scope as local's containing scope."); + cons_requiref(root, RADDBG_LocalKind_NULL < info->kind && info->kind < RADDBG_LocalKind_COUNT, return, "Invalid local kind."); + cons_requiref(root, info->type != 0, return, "Tried to set invalid type as local's type."); + CONS_Scope *scope = info->scope; + SLLQueuePush(scope->first_local, scope->last_local, local); + scope->local_count += 1; + root->local_count += 1; + local->kind = info->kind; + local->name = push_str8_copy(root->arena, info->name); + local->type = info->type; } static CONS_LocationSet* -cons_location_set_from_local(CONS_Root *root, CONS_Local *local){ +cons_location_set_from_local(CONS_Root *root, CONS_Local *local) +{ CONS_LocationSet *result = local->locset; - if (result == 0){ + if(result == 0) + { local->locset = push_array(root->arena, CONS_LocationSet, 1); result = local->locset; } - return(result); + return result; } +//- rjf: location info building + static void -cons_location_set_add_case(CONS_Root *root, CONS_LocationSet *locset, - U64 voff_first, U64 voff_opl, CONS_Location *location){ +cons_location_set_add_case(CONS_Root *root, CONS_LocationSet *locset, U64 voff_first, U64 voff_opl, CONS_Location *location) +{ CONS__LocationCase *location_case = push_array(root->arena, CONS__LocationCase, 1); SLLQueuePush(locset->first_location_case, locset->last_location_case, location_case); locset->location_case_count += 1; root->location_count += 1; - location_case->voff_first = voff_first; location_case->voff_opl = voff_opl; location_case->location = location; } static CONS_Location* -cons_location_addr_bytecode_stream(CONS_Root *root, CONS_EvalBytecode *bytecode){ +cons_location_addr_bytecode_stream(CONS_Root *root, struct CONS_EvalBytecode *bytecode) +{ CONS_Location *result = push_array(root->arena, CONS_Location, 1); result->kind = RADDBG_LocationKind_AddrBytecodeStream; result->bytecode = *bytecode; - return(result); + return result; } static CONS_Location* -cons_location_val_bytecode_stream(CONS_Root *root, CONS_EvalBytecode *bytecode){ +cons_location_val_bytecode_stream(CONS_Root *root, struct CONS_EvalBytecode *bytecode) +{ CONS_Location *result = push_array(root->arena, CONS_Location, 1); result->kind = RADDBG_LocationKind_ValBytecodeStream; result->bytecode = *bytecode; - return(result); + return result; } static CONS_Location* -cons_location_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset){ +cons_location_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset) +{ CONS_Location *result = push_array(root->arena, CONS_Location, 1); result->kind = RADDBG_LocationKind_AddrRegisterPlusU16; result->register_code = reg_code; result->offset = offset; - return(result); + return result; } static CONS_Location* -cons_location_addr_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset){ +cons_location_addr_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset) +{ CONS_Location *result = push_array(root->arena, CONS_Location, 1); result->kind = RADDBG_LocationKind_AddrAddrRegisterPlusU16; result->register_code = reg_code; result->offset = offset; - return(result); + return result; } static CONS_Location* -cons_location_val_reg(CONS_Root *root, U8 reg_code){ +cons_location_val_reg(CONS_Root *root, U8 reg_code) +{ CONS_Location *result = push_array(root->arena, CONS_Location, 1); result->kind = RADDBG_LocationKind_ValRegister; result->register_code = reg_code; - return(result); + return result; } -// bytecode - -static void -cons_bytecode_push_op(Arena *arena, CONS_EvalBytecode *bytecode, RADDBG_EvalOp op, U64 p){ - U8 ctrlbits = raddbg_eval_opcode_ctrlbits[op]; - U32 p_size = RADDBG_DECODEN_FROM_CTRLBITS(ctrlbits); - - CONS_EvalBytecodeOp *node = push_array(arena, CONS_EvalBytecodeOp, 1); - node->op = op; - node->p_size = p_size; - node->p = p; - - SLLQueuePush(bytecode->first_op, bytecode->last_op, node); - bytecode->op_count += 1; - bytecode->encoded_size += 1 + p_size; -} - -static void -cons_bytecode_push_uconst(Arena *arena, CONS_EvalBytecode *bytecode, U64 x){ - if (x <= 0xFF){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU8, x); - } - else if (x <= 0xFFFF){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU16, x); - } - else if (x <= 0xFFFFFFFF){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU32, x); - } - else{ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU64, x); - } -} - -static void -cons_bytecode_push_sconst(Arena *arena, CONS_EvalBytecode *bytecode, S64 x){ - if (-0x80 <= x && x <= 0x7F){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU8, (U64)x); - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 8); - } - else if (-0x8000 <= x && x <= 0x7FFF){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU16, (U64)x); - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 16); - } - else if (-0x80000000ll <= x && x <= 0x7FFFFFFFll){ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU32, (U64)x); - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_TruncSigned, 32); - } - else{ - cons_bytecode_push_op(arena, bytecode, RADDBG_EvalOp_ConstU64, (U64)x); - } -} - -static void -cons_bytecode_concat_in_place(CONS_EvalBytecode *left_dst, CONS_EvalBytecode *right_destroyed){ - if (right_destroyed->first_op != 0){ - if (left_dst->first_op == 0){ - MemoryCopyStruct(left_dst, right_destroyed); - } - else{ - left_dst->last_op = right_destroyed->last_op; - left_dst->op_count += right_destroyed->op_count; - left_dst->encoded_size += right_destroyed->encoded_size; - } - MemoryZeroStruct(right_destroyed); - } -} - - - -//////////////////////////////// -//- Implementation Helpers - -// types - -static CONS_Type* -cons__type_new(CONS_Root *root){ - ProfBeginFunction(); - CONS_Type *result = push_array(root->arena, CONS_Type, 1); - result->idx = root->type_count; - SLLQueuePush_N(root->first_type, root->last_type, result, next_order); - root->type_count += 1; - ProfEnd(); - return(result); -} - -static CONS_TypeUDT* -cons__type_udt_from_any_type(CONS_Root *root, CONS_Type *type){ - if (type->udt == 0){ - CONS_TypeUDT *new_udt = push_array(root->arena, CONS_TypeUDT, 1); - new_udt->idx = root->type_udt_count; - SLLQueuePush_N(root->first_udt, root->last_udt, new_udt, next_order); - root->type_udt_count += 1; - new_udt->self_type = type; - type->udt = new_udt; - } - CONS_TypeUDT *result = type->udt; - return(result); -} - -static CONS_TypeUDT* -cons__type_udt_from_record_type(CONS_Root *root, CONS_Type *type){ - CONS_TypeUDT *result = 0; - - if (!(type->kind == RADDBG_TypeKind_Struct || - type->kind == RADDBG_TypeKind_Class || - type->kind == RADDBG_TypeKind_Union)){ - // TODO(allen): API error - } - else{ - result = cons__type_udt_from_any_type(root, type); - } - - return(result); -} - -// scopes - -static void -cons__scope_recursive_set_symbol(CONS_Scope *scope, CONS_Symbol *symbol){ - scope->symbol = symbol; - for (CONS_Scope *node = scope->first_child; - node != 0; - node = node->next_sibling){ - cons__scope_recursive_set_symbol(node, symbol); - } -} - -// name maps +//- rjf: name map building static CONS__NameMap* -cons__name_map_for_kind(CONS_Root *root, RADDBG_NameMapKind kind){ +cons__name_map_for_kind(CONS_Root *root, RADDBG_NameMapKind kind) +{ CONS__NameMap *result = 0; - if (kind < RADDBG_NameMapKind_COUNT){ - if (root->name_maps[kind] == 0){ + if(kind < RADDBG_NameMapKind_COUNT) + { + if(root->name_maps[kind] == 0) + { root->name_maps[kind] = push_array(root->arena, CONS__NameMap, 1); root->name_maps[kind]->buckets_count = 16384; root->name_maps[kind]->buckets = push_array(root->arena, CONS__NameMapNode *, root->name_maps[kind]->buckets_count); } result = root->name_maps[kind]; } - return(result); + return result; } static void -cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32 idx){ - +cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32 idx) +{ // hash U64 hash = raddbg_hash(string.str, string.size); U64 bucket_idx = hash%map->buckets_count; // find existing name node CONS__NameMapNode *match = 0; - for (CONS__NameMapNode *node = map->buckets[bucket_idx]; - node != 0; - node = node->bucket_next){ - if (str8_match(string, node->string, 0)){ + for(CONS__NameMapNode *node = map->buckets[bucket_idx]; + node != 0; + node = node->bucket_next) + { + if(str8_match(string, node->string, 0)) + { match = node; break; } } // make name node if necessary - if (match == 0){ + if(match == 0) + { match = push_array(root->arena, CONS__NameMapNode, 1); match->string = push_str8_copy(root->arena, string); SLLStackPush_N(map->buckets[bucket_idx], match, bucket_next); @@ -1762,14 +1610,18 @@ cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32 // find existing idx B32 existing_idx = 0; - for (CONS__NameMapIdxNode *node = match->idx_first; - node != 0; - node = node->next){ - for (U32 i = 0; i < ArrayCount(node->idx); i += 1){ - if (node->idx[i] == 0){ + for(CONS__NameMapIdxNode *node = match->idx_first; + node != 0; + node = node->next) + { + for(U32 i = 0; i < ArrayCount(node->idx); i += 1) + { + if(node->idx[i] == 0) + { break; } - if (node->idx[i] == idx){ + if(node->idx[i] == idx) + { existing_idx = 1; break; } @@ -1777,11 +1629,12 @@ cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32 } // insert new idx if necessary - if (!existing_idx){ + if(!existing_idx) + { CONS__NameMapIdxNode *idx_node = match->idx_last; - U32 insert_i = match->idx_count%ArrayCount(idx_node->idx); - if (insert_i == 0){ + if(insert_i == 0) + { idx_node = push_array(root->arena, CONS__NameMapIdxNode, 1); SLLQueuePush(match->idx_first, match->idx_last, idx_node); } @@ -1789,116 +1642,12 @@ cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32 idx_node->idx[insert_i] = idx; match->idx_count += 1; } - } -// u64 to ptr map +//////////////////////////////// +//~ rjf: Debug Info Baking (Loose -> Tight) Functions -static void -cons__u64toptr_init(Arena *arena, CONS__U64ToPtrMap *map, U64 bucket_count){ - Assert(IsPow2OrZero(bucket_count) && bucket_count > 0); - map->buckets = push_array(arena, CONS__U64ToPtrNode*, bucket_count); - map->buckets_count = bucket_count; -} - -static void -cons__u64toptr_lookup(CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup_out){ - U64 bucket_idx = hash&(map->buckets_count - 1); - CONS__U64ToPtrNode *check_node = map->buckets[bucket_idx]; - for (;check_node != 0; check_node = check_node->next){ - for (U32 k = 0; k < ArrayCount(check_node->key); k += 1){ - if (check_node->ptr[k] == 0){ - lookup_out->fill_node = check_node; - lookup_out->fill_k = k; - break; - } - else if (check_node->key[k] == key){ - lookup_out->match = check_node->ptr[k]; - break; - } - } - } -} - -static void -cons__u64toptr_insert(Arena *arena, CONS__U64ToPtrMap *map, U64 key, U64 hash, - CONS__U64ToPtrLookup *lookup, void *ptr){ - if (lookup->fill_node != 0){ - CONS__U64ToPtrNode *node = lookup->fill_node; - U32 k = lookup->fill_k; - node->key[k] = key; - node->ptr[k] = ptr; - } - else{ - U64 bucket_idx = hash&(map->buckets_count - 1); - - CONS__U64ToPtrNode *node = push_array(arena, CONS__U64ToPtrNode, 1); - SLLStackPush(map->buckets[bucket_idx], node); - node->key[0] = key; - node->ptr[0] = ptr; - - lookup->fill_node = node; - lookup->fill_k = 0; - - map->pair_count += 1; - map->bucket_collision_count += (node->next != 0); - } -} - -// str8 to ptr map - -static void -cons__str8toptr_init(Arena *arena, CONS__Str8ToPtrMap *map, U64 bucket_count) -{ - map->buckets_count = bucket_count; - map->buckets = push_array(arena, CONS__Str8ToPtrNode*, map->buckets_count); -} - -static void* -cons__str8toptr_lookup(CONS__Str8ToPtrMap *map, String8 key, U64 hash){ - void *result = 0; - U64 bucket_idx = hash%map->buckets_count; - for (CONS__Str8ToPtrNode *node = map->buckets[bucket_idx]; - node != 0; - node = node->next){ - if (node->hash == hash && str8_match(node->key, key, 0)){ - result = node->ptr; - break; - } - } - return(result); -} - -static void -cons__str8toptr_insert(Arena *arena, CONS__Str8ToPtrMap *map, String8 key, U64 hash, void *ptr){ - U64 bucket_idx = hash%map->buckets_count; - - CONS__Str8ToPtrNode *node = push_array(arena, CONS__Str8ToPtrNode, 1); - SLLStackPush(map->buckets[bucket_idx], node); - - node->key = push_str8_copy(arena, key); - node->hash = hash; - node->ptr = ptr; - map->bucket_collision_count += (node->next != 0); - map->pair_count += 1; -} - - -//- cons intermediate functions - -static U32 -cons__dsection(Arena *arena, CONS__DSections *dss, void *data, U64 size, RADDBG_DataSectionTag tag){ - U32 result = dss->count; - - CONS__DSectionNode *node = push_array(arena, CONS__DSectionNode, 1); - SLLQueuePush(dss->first, dss->last, node); - node->data = data; - node->size = size; - node->tag = tag; - dss->count += 1; - - return(result); -} +//- rjf: bake context construction static CONS__BakeCtx* cons__bake_ctx_begin(CONS__BakeParams *params) @@ -1914,7 +1663,6 @@ cons__bake_ctx_begin(CONS__BakeParams *params) result->idxs.buckets = push_array(arena, CONS__IdxRunNode *, result->idxs.buckets_count); cons__string(result, str8_lit("")); - cons__idx_run(result, 0, 0); result->tree = push_array(arena, CONS__PathTree, 1); @@ -1927,46 +1675,48 @@ cons__bake_ctx_begin(CONS__BakeParams *params) nil_path_node->src_file = nil_src_node; } - return(result); + return result; } static void -cons__bake_ctx_release(CONS__BakeCtx *bake_ctx){ +cons__bake_ctx_release(CONS__BakeCtx *bake_ctx) +{ arena_release(bake_ctx->arena); } +//- rjf: string baking static U32 -cons__string(CONS__BakeCtx *bctx, String8 str){ +cons__string(CONS__BakeCtx *bctx, String8 str) +{ Arena *arena = bctx->arena; CONS__Strings *strs = &bctx->strs; - U64 hash = raddbg_hash(str.str, str.size); U64 bucket_idx = hash%strs->buckets_count; // look for a match CONS__StringNode *match = 0; - for (CONS__StringNode *node = strs->buckets[bucket_idx]; - node != 0; - node = node->bucket_next){ - if (node->hash == hash && - str8_match(node->str, str, 0)){ + for(CONS__StringNode *node = strs->buckets[bucket_idx]; + node != 0; + node = node->bucket_next) + { + if(node->hash == hash && str8_match(node->str, str, 0)) + { match = node; break; } } // insert new node if no match - if (match == 0){ + if(match == 0) + { CONS__StringNode *node = push_array_no_zero(arena, CONS__StringNode, 1); node->str = push_str8_copy(arena, str); node->hash = hash; node->idx = strs->count; strs->count += 1; - SLLQueuePush_N(strs->order_first, strs->order_last, node, order_next); SLLStackPush_N(strs->buckets[bucket_idx], node, bucket_next); - match = node; strs->bucket_collision_count += (node->bucket_next != 0); } @@ -1974,23 +1724,27 @@ cons__string(CONS__BakeCtx *bctx, String8 str){ // extract idx to return Assert(match != 0); U32 result = match->idx; - - return(result); + return result; } +//- rjf: idx run baking + static U64 -cons__idx_run_hash(U32 *idx_run, U32 count){ +cons__idx_run_hash(U32 *idx_run, U32 count) +{ U64 hash = 5381; U32 *ptr = idx_run; U32 *opl = idx_run + count; - for (; ptr < opl; ptr += 1){ + for(;ptr < opl; ptr += 1) + { hash = ((hash << 5) + hash) + (*ptr); } return(hash); } static U32 -cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count){ +cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count) +{ Arena *arena = bctx->arena; CONS__IdxRuns *idxs = &bctx->idxs; @@ -1999,19 +1753,24 @@ cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count){ // look for a match CONS__IdxRunNode *match = 0; - for (CONS__IdxRunNode *node = idxs->buckets[bucket_idx]; - node != 0; - node = node->bucket_next){ - if (node->hash == hash){ + for(CONS__IdxRunNode *node = idxs->buckets[bucket_idx]; + node != 0; + node = node->bucket_next) + { + if(node->hash == hash) + { S32 is_match = 1; U32 *node_idx = node->idx_run; - for (U32 i = 0; i < count; i += 1){ - if (node_idx[i] != idx_run[i]){ + for(U32 i = 0; i < count; i += 1) + { + if(node_idx[i] != idx_run[i]) + { is_match = 0; break; } } - if (is_match){ + if(is_match) + { match = node; break; } @@ -2019,23 +1778,22 @@ cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count){ } // insert new node if no match - if (match == 0){ + if(match == 0) + { CONS__IdxRunNode *node = push_array_no_zero(arena, CONS__IdxRunNode, 1); U32 *idx_run_copy = push_array_no_zero(arena, U32, count); - for (U32 i = 0; i < count; i += 1){ + for(U32 i = 0; i < count; i += 1) + { idx_run_copy[i] = idx_run[i]; } node->idx_run = idx_run_copy; node->hash = hash; node->count = count; node->first_idx = idxs->idx_count; - idxs->count += 1; idxs->idx_count += count; - SLLQueuePush_N(idxs->order_first, idxs->order_last, node, order_next); SLLStackPush_N(idxs->buckets[bucket_idx], node, bucket_next); - match = node; idxs->bucket_collision_count += (node->bucket_next != 0); } @@ -2043,115 +1801,33 @@ cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count){ // extract idx to return Assert(match != 0); U32 result = match->first_idx; - - return(result); + return result; } -static CONS__PathNode* -cons__paths_new_node(CONS__BakeCtx *bctx){ - CONS__PathTree *tree = bctx->tree; - CONS__PathNode *result = push_array(bctx->arena, CONS__PathNode, 1); - SLLQueuePush_N(tree->first, tree->last, result, next_order); - result->idx = tree->count; - tree->count += 1; - return(result); -} - -static CONS__PathNode* -cons__paths_sub_path(CONS__BakeCtx *bctx, CONS__PathNode *dir, String8 sub_dir){ - // look for existing match - CONS__PathNode *match = 0; - for (CONS__PathNode *node = dir->first_child; - node != 0; - node = node->next_sibling){ - if (str8_match(node->name, sub_dir, StringMatchFlag_CaseInsensitive)){ - match = node; - break; - } - } - - // construct new node if no match - CONS__PathNode *new_node = 0; - if (match == 0){ - new_node = cons__paths_new_node(bctx); - new_node->parent = dir; - SLLQueuePush_N(dir->first_child, dir->last_child, new_node, next_sibling); - new_node->name = push_str8_copy(bctx->arena, sub_dir); - } - - // select result from the two paths - CONS__PathNode *result = match; - if (match == 0){ - result = new_node; - } - - return(result); -} - -static CONS__PathNode* -cons__paths_node_from_path(CONS__BakeCtx *bctx, String8 path){ - CONS__PathNode *node_cursor = &bctx->tree->root; - - U8 *ptr = path.str; - U8 *opl = path.str + path.size; - for (;ptr < opl;){ - // skip past slashes - for (;ptr < opl && (*ptr == '/' || *ptr == '\\'); ptr += 1); - - // save beginning of non-slash range - U8 *range_first = ptr; - - // skip past non-slashes - for (;ptr < opl && !(*ptr == '/' || *ptr == '\\'); ptr += 1); - - // if range is non-empty advance the node cursor - if (range_first < ptr){ - String8 sub_dir = str8_range(range_first, ptr); - node_cursor = cons__paths_sub_path(bctx, node_cursor, sub_dir); - } - } - - CONS__PathNode *result = node_cursor; - return(result); -} +//- rjf: data section baking static U32 -cons__paths_idx_from_path(CONS__BakeCtx *bctx, String8 path){ - CONS__PathNode *node = cons__paths_node_from_path(bctx, path); - U32 result = node->idx; - return(result); +cons__dsection(Arena *arena, CONS__DSections *dss, void *data, U64 size, RADDBG_DataSectionTag tag) +{ + U32 result = dss->count; + CONS__DSectionNode *node = push_array(arena, CONS__DSectionNode, 1); + SLLQueuePush(dss->first, dss->last, node); + node->data = data; + node->size = size; + node->tag = tag; + dss->count += 1; + return result; } -static CONS__SrcNode* -cons__paths_new_src_node(CONS__BakeCtx *bctx){ - CONS__PathTree *tree = bctx->tree; - CONS__SrcNode *result = push_array(bctx->arena, CONS__SrcNode, 1); - SLLQueuePush(tree->src_first, tree->src_last, result); - result->idx = tree->src_count; - tree->src_count += 1; - return(result); -} - -static CONS__SrcNode* -cons__paths_src_node_from_path_node(CONS__BakeCtx *bctx, CONS__PathNode *path_node){ - CONS__SrcNode *result = path_node->src_file; - if (result == 0){ - CONS__SrcNode *new_node = cons__paths_new_src_node(bctx); - new_node->path_node = path_node; - new_node->normal_full_path = cons__normal_string_from_path_node(bctx->arena, path_node); - result = path_node->src_file = new_node; - } - return(result); -} - - -//- cons path helper +//- rjf: paths baking static String8 -cons__normal_string_from_path_node(Arena *arena, CONS__PathNode *node){ +cons__normal_string_from_path_node(Arena *arena, CONS__PathNode *node) +{ Temp scratch = scratch_begin(&arena, 1); String8List list = {0}; - if (node != 0){ + if(node != 0) + { cons__normal_string_from_path_node_build(scratch.arena, node, &list); } StringJoin join = {0}; @@ -2160,177 +1836,140 @@ cons__normal_string_from_path_node(Arena *arena, CONS__PathNode *node){ { U8 *ptr = result.str; U8 *opl = result.str + result.size; - for (; ptr < opl; ptr += 1){ + for(; ptr < opl; ptr += 1) + { U8 c = *ptr; - if ('A' <= c && c <= 'Z') c += 'a' - 'A'; + if('A' <= c && c <= 'Z') { c += 'a' - 'A'; } *ptr = c; } } scratch_end(scratch); - return(result); + return result; } static void -cons__normal_string_from_path_node_build(Arena *arena, CONS__PathNode *node, String8List *out){ - if (node->parent != 0){ +cons__normal_string_from_path_node_build(Arena *arena, CONS__PathNode *node, String8List *out) +{ + // TODO(rjf): why is this recursive... + if(node->parent != 0) + { cons__normal_string_from_path_node_build(arena, node->parent, out); } - if (node->name.size > 0){ + if(node->name.size > 0) + { str8_list_push(arena, out, node->name); } } - -//- cons sort helper - -static CONS__SortKey* -cons__sort_key_array(Arena *arena, CONS__SortKey *keys, U64 count){ - // This sort is designed to take advantage of lots of pre-existing sorted ranges. - // Most line info is already sorted or close to already sorted. - // Similarly most vmap data has lots of pre-sorted ranges. etc. etc. - // Also - this sort should be a "stable" sort. In the use case of sorting vmap - // ranges, we want to be able to rely on order, so it needs to be preserved here. - - ProfBegin("cons__sort_key_array"); - Temp scratch = scratch_begin(&arena, 1); - - CONS__SortKey *result = 0; - - if (count <= 1){ - result = keys; - } - else{ - CONS__OrderedRange *ranges_first = 0; - CONS__OrderedRange *ranges_last = 0; - U64 range_count = 0; - { - U64 pos = 0; - for (;pos < count;){ - // identify ordered range - U64 first = pos; - U64 opl = pos + 1; - for (; opl < count && keys[opl - 1].key <= keys[opl].key; opl += 1); - - // generate an ordered range node - CONS__OrderedRange *new_range = push_array(scratch.arena, CONS__OrderedRange, 1); - SLLQueuePush(ranges_first, ranges_last, new_range); - range_count += 1; - new_range->first = first; - new_range->opl = opl; - - // update pos - pos = opl; - } - } - - if (range_count == 1){ - result = keys; - } - else{ - CONS__SortKey *keys_swap = push_array_no_zero(arena, CONS__SortKey, count); - - CONS__SortKey *src = keys; - CONS__SortKey *dst = keys_swap; - - CONS__OrderedRange *src_ranges = ranges_first; - CONS__OrderedRange *dst_ranges = 0; - CONS__OrderedRange *dst_ranges_last = 0; - - for (;;){ - // begin a pass - for (;;){ - // end pass when out of ranges - if (src_ranges == 0){ - break; - } - - // get first range - CONS__OrderedRange *range1 = src_ranges; - SLLStackPop(src_ranges); - - // if this range is the whole array, we are done - if (range1->first == 0 && range1->opl == count){ - result = src; - goto sort_done; - } - - // if there is not a second range, save this range for next time and end this pass - if (src_ranges == 0){ - U64 first = range1->first; - MemoryCopy(dst + first, src + first, sizeof(*src)*(range1->opl - first)); - SLLQueuePush(dst_ranges, dst_ranges_last, range1); - break; - } - - // get second range - CONS__OrderedRange *range2 = src_ranges; - SLLStackPop(src_ranges); - - Assert(range1->opl == range2->first); - - // merge these ranges - U64 jd = range1->first; - U64 j1 = range1->first; - U64 j1_opl = range1->opl; - U64 j2 = range2->first; - U64 j2_opl = range2->opl; - for (;;){ - if (src[j1].key <= src[j2].key){ - MemoryCopy(dst + jd, src + j1, sizeof(*src)); - j1 += 1; - jd += 1; - if (j1 >= j1_opl){ - break; - } - } - else{ - MemoryCopy(dst + jd, src + j2, sizeof(*src)); - j2 += 1; - jd += 1; - if (j2 >= j2_opl){ - break; - } - } - } - if (j1 < j1_opl){ - MemoryCopy(dst + jd, src + j1, sizeof(*src)*(j1_opl - j1)); - } - else{ - MemoryCopy(dst + jd, src + j2, sizeof(*src)*(j2_opl - j2)); - } - - // save this as one range - range1->opl = range2->opl; - SLLQueuePush(dst_ranges, dst_ranges_last, range1); - } - - // end pass by swapping buffers and range nodes - Swap(CONS__SortKey*, src, dst); - src_ranges = dst_ranges; - dst_ranges = 0; - dst_ranges_last = 0; - } - } - } - sort_done:; - -#if 0 - // assert sortedness - for (U64 i = 1; i < count; i += 1){ - Assert(result[i - 1].key <= result[i].key); - } -#endif - - scratch_end(scratch); - ProfEnd(); - - return(result); +static CONS__PathNode* +cons__paths_new_node(CONS__BakeCtx *bctx) +{ + CONS__PathTree *tree = bctx->tree; + CONS__PathNode *result = push_array(bctx->arena, CONS__PathNode, 1); + SLLQueuePush_N(tree->first, tree->last, result, next_order); + result->idx = tree->count; + tree->count += 1; + return result; } +static CONS__PathNode* +cons__paths_sub_path(CONS__BakeCtx *bctx, CONS__PathNode *dir, String8 sub_dir) +{ + // look for existing match + CONS__PathNode *match = 0; + for(CONS__PathNode *node = dir->first_child; + node != 0; + node = node->next_sibling){ + if(str8_match(node->name, sub_dir, StringMatchFlag_CaseInsensitive)){ + match = node; + break; + } + } + + // construct new node if no match + CONS__PathNode *new_node = 0; + if(match == 0){ + new_node = cons__paths_new_node(bctx); + new_node->parent = dir; + SLLQueuePush_N(dir->first_child, dir->last_child, new_node, next_sibling); + new_node->name = push_str8_copy(bctx->arena, sub_dir); + } + + // select result from the two paths + CONS__PathNode *result = match; + if(match == 0){ + result = new_node; + } + + return result; +} + +static CONS__PathNode* +cons__paths_node_from_path(CONS__BakeCtx *bctx, String8 path) +{ + CONS__PathNode *node_cursor = &bctx->tree->root; + + U8 *ptr = path.str; + U8 *opl = path.str + path.size; + for(;ptr < opl;){ + // skip past slashes + for(;ptr < opl && (*ptr == '/' || *ptr == '\\'); ptr += 1); + + // save beginning of non-slash range + U8 *range_first = ptr; + + // skip past non-slashes + for(;ptr < opl && !(*ptr == '/' || *ptr == '\\'); ptr += 1); + + // if range is non-empty advance the node cursor + if(range_first < ptr){ + String8 sub_dir = str8_range(range_first, ptr); + node_cursor = cons__paths_sub_path(bctx, node_cursor, sub_dir); + } + } + + CONS__PathNode *result = node_cursor; + return result; +} + +static U32 +cons__paths_idx_from_path(CONS__BakeCtx *bctx, String8 path) +{ + CONS__PathNode *node = cons__paths_node_from_path(bctx, path); + U32 result = node->idx; + return result; +} + +static CONS__SrcNode* +cons__paths_new_src_node(CONS__BakeCtx *bctx) +{ + CONS__PathTree *tree = bctx->tree; + CONS__SrcNode *result = push_array(bctx->arena, CONS__SrcNode, 1); + SLLQueuePush(tree->src_first, tree->src_last, result); + result->idx = tree->src_count; + tree->src_count += 1; + return result; +} + +static CONS__SrcNode* +cons__paths_src_node_from_path_node(CONS__BakeCtx *bctx, CONS__PathNode *path_node) +{ + CONS__SrcNode *result = path_node->src_file; + if(result == 0) + { + CONS__SrcNode *new_node = cons__paths_new_src_node(bctx); + new_node->path_node = path_node; + new_node->normal_full_path = cons__normal_string_from_path_node(bctx->arena, path_node); + result = path_node->src_file = new_node; + } + return result; +} + +//- rjf: per-unit line info baking -//- cons intermediate unit line info static CONS__UnitLinesCombined* -cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNode *first_seq){ +cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNode *first_seq) +{ ProfBegin("cons__unit_combine_lines"); Temp scratch = scratch_begin(&arena, 1); @@ -2339,9 +1978,9 @@ cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNod // recs: contains all the source coordinates for a range of voffs U64 line_count = 0; U64 seq_count = 0; - for (CONS_LineSequenceNode *node = first_seq; - node != 0; - node = node->next){ + for(CONS_LineSequenceNode *node = first_seq; + node != 0; + node = node->next){ seq_count += 1; line_count += node->line_seq.line_count; } @@ -2354,23 +1993,23 @@ cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNod CONS__SortKey *key_ptr = line_keys; CONS__LineRec *rec_ptr = line_recs; - for (CONS_LineSequenceNode *node = first_seq; - node != 0; - node = node->next){ + for(CONS_LineSequenceNode *node = first_seq; + node != 0; + node = node->next){ CONS__PathNode *src_path = cons__paths_node_from_path(bctx, node->line_seq.file_name); CONS__SrcNode *src_file = cons__paths_src_node_from_path_node(bctx, src_path); U32 file_id = src_file->idx; U64 node_line_count = node->line_seq.line_count; - for (U64 i = 0; i < node_line_count; i += 1){ + for(U64 i = 0; i < node_line_count; i += 1){ key_ptr->key = node->line_seq.voffs[i]; key_ptr->val = rec_ptr; key_ptr += 1; rec_ptr->file_id = file_id; rec_ptr->line_num = node->line_seq.line_nums[i]; - if (node->line_seq.col_nums != 0){ + if(node->line_seq.col_nums != 0){ rec_ptr->col_first = node->line_seq.col_nums[i*2]; rec_ptr->col_opl = node->line_seq.col_nums[i*2 + 1]; } @@ -2397,13 +2036,13 @@ cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNod U64 *arranged_voffs = push_array_no_zero(arena, U64, key_count + 1); RADDBG_Line *arranged_lines = push_array_no_zero(arena, RADDBG_Line, key_count); - for (U64 i = 0; i < key_count; i += 1){ + for(U64 i = 0; i < key_count; i += 1){ arranged_voffs[i] = sorted_line_keys[i].key; } arranged_voffs[key_count] = ~0ull; - for (U64 i = 0; i < key_count; i += 1){ + for(U64 i = 0; i < key_count; i += 1){ CONS__LineRec *rec = (CONS__LineRec*)sorted_line_keys[i].val; - if (rec != 0){ + if(rec != 0){ arranged_lines[i].file_idx = rec->file_id; arranged_lines[i].line_num = rec->line_num; } @@ -2422,13 +2061,14 @@ cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNod scratch_end(scratch); ProfEnd(); - return(result); + return result; } +//- rjf: per-src line info baking -//- cons intermediate source line info static CONS__SrcLinesCombined* -cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ +cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first) +{ ProfBegin("cons__source_combine_lines"); Temp scratch = scratch_begin(&arena, 1); @@ -2442,16 +2082,16 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ U64 max_line_num = 0; ProfScope("gather line number map") { - for (CONS__LineMapFragment *map_fragment = first; - map_fragment != 0; - map_fragment = map_fragment->next) + for(CONS__LineMapFragment *map_fragment = first; + map_fragment != 0; + map_fragment = map_fragment->next) { CONS_LineSequence *sequence = &map_fragment->sequence->line_seq; U64 *seq_voffs = sequence->voffs; U32 *seq_line_nums = sequence->line_nums; U64 seq_line_count = sequence->line_count; - for (U64 i = 0; i < seq_line_count; i += 1){ + for(U64 i = 0; i < seq_line_count; i += 1){ U32 line_num = seq_line_nums[i]; U64 voff = seq_voffs[i]; U64 line_hash_slot_idx = line_num%line_hash_slots_count; @@ -2463,10 +2103,10 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ // find match CONS__SrcLineMapBucket *match = 0; { - for (CONS__SrcLineMapBucket *node = line_hash_slots[line_hash_slot_idx]; - node != 0; - node = node->hash_next){ - if (node->line_num == line_num){ + for(CONS__SrcLineMapBucket *node = line_hash_slots[line_hash_slot_idx]; + node != 0; + node = node->hash_next){ + if(node->line_num == line_num){ match = node; break; } @@ -2474,7 +2114,7 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ } // introduce new line if no match - if (match == 0){ + if(match == 0){ match = push_array(scratch.arena, CONS__SrcLineMapBucket, 1); SLLQueuePush_N(first_bucket, last_bucket, match, order_next); SLLStackPush_N(line_hash_slots[line_hash_slot_idx], match, hash_next); @@ -2498,9 +2138,9 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ ProfScope("bake sortable keys array") { CONS__SortKey *key_ptr = keys; - for (CONS__SrcLineMapBucket *node = first_bucket; - node != 0; - node = node->order_next, key_ptr += 1){ + for(CONS__SrcLineMapBucket *node = first_bucket; + node != 0; + node = node->order_next, key_ptr += 1){ key_ptr->key = node->line_num; key_ptr->val = node; } @@ -2516,13 +2156,13 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ ProfScope("bake result") { U64 *voff_ptr = voffs; - for (U32 i = 0; i < line_count; i += 1){ + for(U32 i = 0; i < line_count; i += 1){ line_nums[i] = sorted_keys[i].key; line_ranges[i] = (U32)(voff_ptr - voffs); CONS__SrcLineMapBucket *bucket = (CONS__SrcLineMapBucket*)sorted_keys[i].val; - for (CONS__SrcLineMapVoffBlock *node = bucket->first_voff_block; - node != 0; - node = node->next){ + for(CONS__SrcLineMapVoffBlock *node = bucket->first_voff_block; + node != 0; + node = node->next){ *voff_ptr = node->voff; voff_ptr += 1; } @@ -2540,13 +2180,13 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){ scratch_end(scratch); ProfEnd(); - return(result); + return result; } - -//- cons intermediate vmap type +//- rjf: vmap baking static CONS__VMap* -cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey *keys, U64 marker_count){ +cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey *keys, U64 marker_count) +{ Temp scratch = scratch_begin(&arena, 1); // sort markers @@ -2554,7 +2194,7 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * // determine if an extra vmap entry for zero is needed U32 extra_vmap_entry = 0; - if (marker_count > 0 && sorted_keys[0].key != 0){ + if(marker_count > 0 && sorted_keys[0].key != 0){ extra_vmap_entry = 1; } @@ -2566,7 +2206,7 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * { RADDBG_VMapEntry *vmap_ptr = vmap; - if (extra_vmap_entry){ + if(extra_vmap_entry){ vmap_ptr->voff = 0; vmap_ptr->idx = 0; vmap_ptr += 1; @@ -2577,10 +2217,10 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * CONS__SortKey *key_ptr = sorted_keys; CONS__SortKey *key_opl = sorted_keys + marker_count; - for (;key_ptr < key_opl;){ + for(;key_ptr < key_opl;){ // get initial map state from tracker stack U32 initial_idx = max_U32; - if (tracker_stack != 0){ + if(tracker_stack != 0){ initial_idx = tracker_stack->idx; } @@ -2588,14 +2228,14 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * // * we must process _all_ of the changes that apply at this voff before moving on U64 voff = key_ptr->key; - for (;key_ptr < key_opl && key_ptr->key == voff; key_ptr += 1){ + for(;key_ptr < key_opl && key_ptr->key == voff; key_ptr += 1){ CONS__VMapMarker *marker = (CONS__VMapMarker*)key_ptr->val; U32 idx = marker->idx; // push to stack - if (marker->begin_range){ + if(marker->begin_range){ CONS__VMapRangeTracker *new_tracker = tracker_free; - if (new_tracker != 0){ + if(new_tracker != 0){ SLLStackPop(tracker_free); } else{ @@ -2609,16 +2249,16 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * else{ CONS__VMapRangeTracker **ptr_in = &tracker_stack; CONS__VMapRangeTracker *match = 0; - for (CONS__VMapRangeTracker *node = tracker_stack; - node != 0;){ - if (node->idx == idx){ + for(CONS__VMapRangeTracker *node = tracker_stack; + node != 0;){ + if(node->idx == idx){ match = node; break; } ptr_in = &node->next; node = node->next; } - if (match != 0){ + if(match != 0){ *ptr_in = match->next; SLLStackPush(tracker_free, match); } @@ -2627,12 +2267,12 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * // get final map state from tracker stack U32 final_idx = 0; - if (tracker_stack != 0){ + if(tracker_stack != 0){ final_idx = tracker_stack->idx; } // if final is different from initial - emit new vmap entry - if (final_idx != initial_idx){ + if(final_idx != initial_idx){ vmap_ptr->voff = voff; vmap_ptr->idx = final_idx; vmap_ptr += 1; @@ -2652,9 +2292,9 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * RADDBG_VMapEntry *vmap_ptr = vmap; U64 real_idx = 0; - for (U32 i = 0; i < last; i += 1, vmap_ptr += 1){ + for(U32 i = 0; i < last; i += 1, vmap_ptr += 1){ // is this a zero after a real index? - if (vmap_ptr->idx == 0){ + if(vmap_ptr->idx == 0){ vmap_ptr->idx = real_idx; } @@ -2672,11 +2312,11 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * RADDBG_VMapEntry *vmap_opl = vmap + vmap_entry_count_pass_1; RADDBG_VMapEntry *vmap_out = vmap; - for (;vmap_ptr < vmap_opl;){ + for(;vmap_ptr < vmap_opl;){ RADDBG_VMapEntry *vmap_range_first = vmap_ptr; U64 idx = vmap_ptr->idx; vmap_ptr += 1; - for (;vmap_ptr < vmap_opl && vmap_ptr->idx == idx;) vmap_ptr += 1; + for(;vmap_ptr < vmap_opl && vmap_ptr->idx == idx;) vmap_ptr += 1; MemoryCopyStruct(vmap_out, vmap_range_first); vmap_out += 1; } @@ -2691,13 +2331,12 @@ cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey * scratch_end(scratch); - return(result); + return result; } - -//- cons intermediate unit vmap static CONS__VMap* -cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count){ +cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count) +{ Temp scratch = scratch_begin(&arena, 1); // count necessary markers @@ -2710,10 +2349,10 @@ cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count){ { CONS__SortKey *key_ptr = keys; CONS__VMapMarker *marker_ptr = markers; - for (CONS_UnitVMapRange *range = first; - range != 0; - range = range->next){ - if (range->first < range->opl){ + for(CONS_UnitVMapRange *range = first; + range != 0; + range = range->next){ + if(range->first < range->opl){ U32 unit_idx = range->unit->idx; key_ptr->key = range->first; @@ -2735,15 +2374,25 @@ cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count){ // construct vmap CONS__VMap *result = cons__vmap_from_markers(arena, markers, keys, marker_count); - scratch_end(scratch); - - return(result); + return result; +} + +//- rjf: type info baking + +static U32* +cons__idx_run_from_types(Arena *arena, CONS_Type **types, U32 count) +{ + U32 *result = push_array(arena, U32, count); + for(U32 i = 0; i < count; i += 1){ + result[i] = types[i]->idx; + } + return result; } -//- cons intermediate types static CONS__TypeData* -cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ +cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx) +{ ProfBegin("cons__type_data_combine"); Temp scratch = scratch_begin(&arena, 1); @@ -2755,8 +2404,8 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ RADDBG_TypeNode *ptr = type_nodes; RADDBG_TypeNode *opl = ptr + type_count; CONS_Type *loose_type = root->first_type; - for (;loose_type != 0 && ptr < opl; - loose_type = loose_type->next_order, ptr += 1){ + for(;loose_type != 0 && ptr < opl; + loose_type = loose_type->next_order, ptr += 1){ RADDBG_TypeKind kind = loose_type->kind; @@ -2766,12 +2415,12 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ ptr->byte_size = loose_type->byte_size; // built-in - if (RADDBG_TypeKind_FirstBuiltIn <= kind && kind <= RADDBG_TypeKind_LastBuiltIn){ + if(RADDBG_TypeKind_FirstBuiltIn <= kind && kind <= RADDBG_TypeKind_LastBuiltIn){ ptr->built_in.name_string_idx = cons__string(bctx, loose_type->name); } // constructed - else if (RADDBG_TypeKind_FirstConstructed <= kind && kind <= RADDBG_TypeKind_LastConstructed){ + else if(RADDBG_TypeKind_FirstConstructed <= kind && kind <= RADDBG_TypeKind_LastConstructed){ ptr->constructed.direct_type_idx = loose_type->direct_type->idx; switch (kind){ @@ -2801,18 +2450,18 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ } // user-defined - else if (RADDBG_TypeKind_FirstUserDefined <= kind && kind <= RADDBG_TypeKind_LastUserDefined){ + else if(RADDBG_TypeKind_FirstUserDefined <= kind && kind <= RADDBG_TypeKind_LastUserDefined){ ptr->user_defined.name_string_idx = cons__string(bctx, loose_type->name); - if (loose_type->udt != 0){ + if(loose_type->udt != 0){ ptr->user_defined.udt_idx = loose_type->udt->idx; } - if (loose_type->direct_type != 0){ + if(loose_type->direct_type != 0){ ptr->user_defined.direct_type_idx = loose_type->direct_type->idx; } } // bitfield - else if (kind == RADDBG_TypeKind_Bitfield){ + else if(kind == RADDBG_TypeKind_Bitfield){ ptr->bitfield.off = loose_type->off; ptr->bitfield.size = loose_type->count; } @@ -2847,15 +2496,15 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ RADDBG_EnumMember *enum_member_opl = enum_members + enum_member_count; CONS_TypeUDT *loose_udt = root->first_udt; - for (;loose_udt != 0 && ptr < opl; - loose_udt = loose_udt->next_order, ptr += 1){ + for(;loose_udt != 0 && ptr < opl; + loose_udt = loose_udt->next_order, ptr += 1){ ptr->self_type_idx = loose_udt->self_type->idx; Assert(loose_udt->member_count == 0 || loose_udt->enum_val_count == 0); // enum members - if (loose_udt->enum_val_count != 0){ + if(loose_udt->enum_val_count != 0){ ptr->flags |= RADDBG_UserDefinedTypeFlag_EnumMembers; ptr->member_first = (U32)(enum_member_ptr - enum_members); @@ -2863,9 +2512,9 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ U32 local_enum_val_count = loose_udt->enum_val_count; CONS_TypeEnumVal *loose_enum_val = loose_udt->first_enum_val; - for (U32 i = 0; - i < local_enum_val_count; - i += 1, enum_member_ptr += 1, loose_enum_val = loose_enum_val->next){ + for(U32 i = 0; + i < local_enum_val_count; + i += 1, enum_member_ptr += 1, loose_enum_val = loose_enum_val->next){ enum_member_ptr->name_string_idx = cons__string(bctx, loose_enum_val->name); enum_member_ptr->val = loose_enum_val->val; } @@ -2878,9 +2527,9 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ U32 local_member_count = loose_udt->member_count; CONS_TypeMember *loose_member = loose_udt->first_member; - for (U32 i = 0; - i < local_member_count; - i += 1, member_ptr += 1, loose_member = loose_member->next){ + for(U32 i = 0; + i < local_member_count; + i += 1, member_ptr += 1, loose_member = loose_member->next){ member_ptr->kind = loose_member->kind; // TODO(allen): member_ptr->visibility = ; member_ptr->name_string_idx = cons__string(bctx, loose_member->name); @@ -2888,7 +2537,7 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ member_ptr->type_idx = loose_member->type->idx; // TODO(allen): - if (loose_member->kind == RADDBG_MemberKind_Method){ + if(loose_member->kind == RADDBG_MemberKind_Method){ //loose_member_ptr->unit_idx = ; //loose_member_ptr->proc_symbol_idx = ; } @@ -2897,7 +2546,7 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ } U32 file_idx = 0; - if (loose_udt->source_path.size > 0){ + if(loose_udt->source_path.size > 0){ CONS__PathNode *path_node = cons__paths_node_from_path(bctx, loose_udt->source_path); CONS__SrcNode *src_node = cons__paths_src_node_from_path_node(bctx, path_node); file_idx = src_node->idx; @@ -2929,22 +2578,14 @@ cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ scratch_end(scratch); ProfEnd(); - - return(result); + return result; } -static U32* -cons__idx_run_from_types(Arena *arena, CONS_Type **types, U32 count){ - U32 *result = push_array(arena, U32, count); - for (U32 i = 0; i < count; i += 1){ - result[i] = types[i]->idx; - } - return(result); -} +//- rjf: symbol data baking -//- cons serializer for symbols static CONS__SymbolData* -cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ +cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx) +{ ProfBegin("cons__symbol_data_combine"); Temp scratch = scratch_begin(&arena, 1); @@ -2974,9 +2615,9 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ procedure_ptr += 1; // symbol nodes - for (CONS_Symbol *node = root->first_symbol; - node != 0; - node = node->next_order){ + for(CONS_Symbol *node = root->first_symbol; + node != 0; + node = node->next_order){ U32 name_string_idx = cons__string(bctx, node->name); U32 link_name_string_idx = cons__string(bctx, node->link_name); U32 type_idx = node->type->idx; @@ -2984,14 +2625,14 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ RADDBG_LinkFlags link_flags = 0; U32 container_idx = 0; { - if (node->is_extern){ + if(node->is_extern){ link_flags |= RADDBG_LinkFlag_External; } - if (node->container_symbol != 0){ + if(node->container_symbol != 0){ container_idx = node->container_symbol->idx; link_flags |= RADDBG_LinkFlag_ProcScoped; } - else if (node->container_type != 0 && node->container_type->udt != 0){ + else if(node->container_type != 0 && node->container_type->udt != 0){ container_idx = node->container_type->udt->idx; link_flags |= RADDBG_LinkFlag_TypeScoped; } @@ -3052,10 +2693,10 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ CONS__VMapMarker *marker_ptr = markers; // real globals - for (CONS_Symbol *node = root->first_symbol; - node != 0; - node = node->next_order){ - if (node->kind == CONS_SymbolKind_GlobalVariable){ + for(CONS_Symbol *node = root->first_symbol; + node != 0; + node = node->next_order){ + if(node->kind == CONS_SymbolKind_GlobalVariable){ U32 global_idx = node->idx; U64 first = node->offset; @@ -3139,15 +2780,15 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ RADDBG_Local *local_ptr = locals; RADDBG_LocationBlock *location_block_ptr = location_blocks; - for (CONS_Scope *node = root->first_scope; - node != 0; - node = node->next_order, scope_ptr += 1){ + for(CONS_Scope *node = root->first_scope; + node != 0; + node = node->next_order, scope_ptr += 1){ // emit voffs U32 voff_first = (U32)(scope_voff_ptr - scope_voffs); - for (CONS__VOffRange *range = node->first_range; - range != 0; - range = range->next){ + for(CONS__VOffRange *range = node->first_range; + range != 0; + range = range->next){ *scope_voff_ptr = range->voff_first; scope_voff_ptr += 1; *scope_voff_ptr = range->voff_opl; @@ -3158,30 +2799,30 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ // emit locals U32 scope_local_count = node->local_count; U32 scope_local_first = (U32)(local_ptr - locals); - for (CONS_Local *slocal = node->first_local; - slocal != 0; - slocal = slocal->next, local_ptr += 1){ + for(CONS_Local *slocal = node->first_local; + slocal != 0; + slocal = slocal->next, local_ptr += 1){ local_ptr->kind = slocal->kind; local_ptr->name_string_idx = cons__string(bctx, slocal->name); local_ptr->type_idx = slocal->type->idx; CONS_LocationSet *locset = slocal->locset; - if (locset != 0){ + if(locset != 0){ U32 location_first = (U32)(location_block_ptr - location_blocks); U32 location_opl = location_first + locset->location_case_count; local_ptr->location_first = location_first; local_ptr->location_opl = location_opl; - for (CONS__LocationCase *location_case = locset->first_location_case; - location_case != 0; - location_case = location_case->next){ + for(CONS__LocationCase *location_case = locset->first_location_case; + location_case != 0; + location_case = location_case->next){ location_block_ptr->scope_off_first = location_case->voff_first; location_block_ptr->scope_off_opl = location_case->voff_opl; location_block_ptr->location_data_off = location_data.total_size; location_block_ptr += 1; CONS_Location *location = location_case->location; - if (location == 0){ + if(location == 0){ U64 data = 0; str8_serial_push_align(scratch.arena, &location_data, 8); str8_serial_push_data(scratch.arena, &location_data, &data, 1); @@ -3199,9 +2840,9 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ case RADDBG_LocationKind_ValBytecodeStream: { str8_list_push(scratch.arena, &location_data, push_str8_copy(scratch.arena, str8_struct(&location->kind))); - for (CONS_EvalBytecodeOp *op_node = location->bytecode.first_op; - op_node != 0; - op_node = op_node->next){ + for(CONS_EvalBytecodeOp *op_node = location->bytecode.first_op; + op_node != 0; + op_node = op_node->next){ U8 op_data[9]; op_data[0] = op_node->op; MemoryCopy(op_data + 1, &op_node->p, op_node->p_size); @@ -3277,14 +2918,14 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ CONS__SortKey *key_ptr = keys; CONS__VMapMarker *marker_ptr = markers; - for (CONS_Scope *node = root->first_scope; - node != 0; - node = node->next_order){ + for(CONS_Scope *node = root->first_scope; + node != 0; + node = node->next_order){ U32 scope_idx = node->idx; - for (CONS__VOffRange *range = node->first_range; - range != 0; - range = range->next){ + for(CONS__VOffRange *range = node->first_range; + range != 0; + range = range->next){ key_ptr->key = range->voff_first; key_ptr->val = marker_ptr; marker_ptr->idx = scope_idx; @@ -3328,13 +2969,14 @@ cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx){ scratch_end(scratch); ProfEnd(); - return(result); + return result; } -//- cons serializer for name maps +//- rjf: name map baking static CONS__NameMapBaked* -cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__NameMap *map){ +cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__NameMap *map) +{ Temp scratch = scratch_begin(&arena, 1); U32 bucket_count = map->name_count; @@ -3342,9 +2984,9 @@ cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__Na // setup the final bucket layouts CONS__NameMapSemiBucket *sbuckets = push_array(scratch.arena, CONS__NameMapSemiBucket, bucket_count); - for (CONS__NameMapNode *node = map->first; - node != 0; - node = node->order_next){ + for(CONS__NameMapNode *node = map->first; + node != 0; + node = node->order_next){ U64 hash = raddbg_hash(node->string.str, node->string.size); U64 bi = hash%bucket_count; CONS__NameMapSemiNode *snode = push_array(scratch.arena, CONS__NameMapSemiNode, 1); @@ -3361,31 +3003,31 @@ cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__Na { RADDBG_NameMapBucket *bucket_ptr = buckets; RADDBG_NameMapNode *node_ptr = nodes; - for (U32 i = 0; i < bucket_count; i += 1, bucket_ptr += 1){ + for(U32 i = 0; i < bucket_count; i += 1, bucket_ptr += 1){ bucket_ptr->first_node = (U32)(node_ptr - nodes); bucket_ptr->node_count = sbuckets[i].count; - for (CONS__NameMapSemiNode *snode = sbuckets[i].first; - snode != 0; - snode = snode->next){ + for(CONS__NameMapSemiNode *snode = sbuckets[i].first; + snode != 0; + snode = snode->next){ CONS__NameMapNode *node = snode->node; // cons name and index(es) U32 string_idx = cons__string(bctx, node->string); U32 match_count = node->idx_count; U32 idx = 0; - if (match_count == 1){ + if(match_count == 1){ idx = node->idx_first->idx[0]; } else{ Temp temp = temp_begin(scratch.arena); U32 *idx_run = push_array_no_zero(temp.arena, U32, match_count); U32 *idx_ptr = idx_run; - for (CONS__NameMapIdxNode *idxnode = node->idx_first; - idxnode != 0; - idxnode = idxnode->next){ - for (U32 i = 0; i < ArrayCount(idxnode->idx); i += 1){ - if (idxnode->idx[i] == 0){ + for(CONS__NameMapIdxNode *idxnode = node->idx_first; + idxnode != 0; + idxnode = idxnode->next){ + for(U32 i = 0; i < ArrayCount(idxnode->idx); i += 1){ + if(idxnode->idx[i] == 0){ goto dblbreak; } *idx_ptr = idxnode->idx[i]; @@ -3415,5 +3057,407 @@ cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__Na result->nodes = nodes; result->bucket_count = bucket_count; result->node_count = node_count; - return(result); + return result; +} + +//- rjf: top-level baking entry point + +static void +cons_bake_file(Arena *arena, CONS_Root *root, String8List *out) +{ + ProfBeginFunction(); + str8_serial_begin(arena, out); + + // setup cons helpers + CONS__DSections dss = {0}; + cons__dsection(arena, &dss, 0, 0, RADDBG_DataSectionTag_NULL); + + CONS__BakeParams bctx_params = {0}; + { + bctx_params.strings_bucket_count = u64_up_to_pow2(root->symbol_map.pair_count*8); + bctx_params.idx_runs_bucket_count = u64_up_to_pow2(root->symbol_map.pair_count*8); + } + CONS__BakeCtx *bctx = cons__bake_ctx_begin(&bctx_params); + + //////////////////////////////// + // MAIN PART: allocating and filling out sections of the file + + // top level info + RADDBG_TopLevelInfo *tli = push_array(arena, RADDBG_TopLevelInfo, 1); + { + CONS_TopLevelInfo *cons_tli = &root->top_level_info; + tli->architecture = cons_tli->architecture; + tli->exe_name_string_idx = cons__string(bctx, cons_tli->exe_name); + tli->exe_hash = cons_tli->exe_hash; + tli->voff_max = cons_tli->voff_max; + } + cons__dsection(arena, &dss, tli, sizeof(*tli), RADDBG_DataSectionTag_TopLevelInfo); + + // binary sections array + { + U32 count = root->binary_section_count; + RADDBG_BinarySection *sections = push_array(arena, RADDBG_BinarySection, count); + RADDBG_BinarySection *dsec = sections; + for(CONS_BinarySection *ssec = root->binary_section_first; + ssec != 0; + ssec = ssec->next, dsec += 1){ + dsec->name_string_idx = cons__string(bctx, ssec->name); + dsec->flags = ssec->flags; + dsec->voff_first = ssec->voff_first; + dsec->voff_opl = ssec->voff_opl; + dsec->foff_first = ssec->foff_first; + dsec->foff_opl = ssec->foff_opl; + } + cons__dsection(arena, &dss, sections, sizeof(*sections)*count, RADDBG_DataSectionTag_BinarySections); + } + + // units array + // * pass for per-unit information including: + // * top-level unit information + // * combining line info for whole unit + { + U32 count = root->unit_count; + RADDBG_Unit *units = push_array(arena, RADDBG_Unit, count); + RADDBG_Unit *dunit = units; + for(CONS_Unit *sunit = root->unit_first; + sunit != 0; + sunit = sunit->next_order, dunit += 1){ + // strings & paths + U32 unit_name = cons__string(bctx, sunit->unit_name); + U32 cmp_name = cons__string(bctx, sunit->compiler_name); + + U32 src_path = cons__paths_idx_from_path(bctx, sunit->source_file); + U32 obj_path = cons__paths_idx_from_path(bctx, sunit->object_file); + U32 archive_path = cons__paths_idx_from_path(bctx, sunit->archive_file); + U32 build_path = cons__paths_idx_from_path(bctx, sunit->build_path); + + dunit->unit_name_string_idx = unit_name; + dunit->compiler_name_string_idx = cmp_name; + dunit->source_file_path_node = src_path; + dunit->object_file_path_node = obj_path; + dunit->archive_file_path_node = archive_path; + dunit->build_path_node = build_path; + dunit->language = sunit->language; + + // line info (voff -> file*line*col) + CONS_LineSequenceNode *first_seq = sunit->line_seq_first; + CONS__UnitLinesCombined *lines = cons__unit_combine_lines(arena, bctx, first_seq); + + U32 line_count = lines->line_count; + if(line_count > 0){ + dunit->line_info_voffs_data_idx = + cons__dsection(arena, &dss, lines->voffs, sizeof(U64)*(line_count + 1), + RADDBG_DataSectionTag_LineInfoVoffs); + dunit->line_info_data_idx = + cons__dsection(arena, &dss, lines->lines, sizeof(RADDBG_Line)*line_count, + RADDBG_DataSectionTag_LineInfoData); + if(lines->cols != 0){ + dunit->line_info_col_data_idx = + cons__dsection(arena, &dss, lines->cols, sizeof(RADDBG_Column)*line_count, + RADDBG_DataSectionTag_LineInfoColumns); + } + dunit->line_info_count = line_count; + } + } + + cons__dsection(arena, &dss, units, sizeof(*units)*count, RADDBG_DataSectionTag_Units); + } + + // source file line info baking + // * pass for "source_combine_line" for each source file - + // * can only be run after a pass that does "unit_combine_lines" for each unit. + for(CONS__SrcNode *src_node = bctx->tree->src_first; + src_node != 0; + src_node = src_node->next){ + CONS__LineMapFragment *first_fragment = src_node->first_fragment; + CONS__SrcLinesCombined *lines = cons__source_combine_lines(arena, first_fragment); + U32 line_count = lines->line_count; + + if(line_count > 0){ + src_node->line_map_count = line_count; + + src_node->line_map_nums_data_idx = + cons__dsection(arena, &dss, lines->line_nums, sizeof(*lines->line_nums)*line_count, + RADDBG_DataSectionTag_LineMapNumbers); + + src_node->line_map_range_data_idx = + cons__dsection(arena, &dss, lines->line_ranges, sizeof(*lines->line_ranges)*(line_count + 1), + RADDBG_DataSectionTag_LineMapRanges); + + src_node->line_map_voff_data_idx = + cons__dsection(arena, &dss, lines->voffs, sizeof(*lines->voffs)*lines->voff_count, + RADDBG_DataSectionTag_LineMapVoffs); + } + } + + // source file name mapping + { + CONS__NameMap* map = cons__name_map_for_kind(root, RADDBG_NameMapKind_NormalSourcePaths); + for(CONS__SrcNode *src_node = bctx->tree->src_first; + src_node != 0; + src_node = src_node->next){ + if(src_node->idx != 0){ + cons__name_map_add_pair(root, map, src_node->normal_full_path, src_node->idx); + } + } + } + + // unit vmap baking + { + CONS__VMap *vmap = cons__vmap_from_unit_ranges(arena, + root->unit_vmap_range_first, + root->unit_vmap_range_count); + + U64 vmap_size = sizeof(*vmap->vmap)*(vmap->count + 1); + cons__dsection(arena, &dss, vmap->vmap, vmap_size, RADDBG_DataSectionTag_UnitVmap); + } + + // type info baking + { + CONS__TypeData *types = cons__type_data_combine(arena, root, bctx); + + U64 type_nodes_size = sizeof(*types->type_nodes)*types->type_node_count; + cons__dsection(arena, &dss, types->type_nodes, type_nodes_size, RADDBG_DataSectionTag_TypeNodes); + + U64 udt_size = sizeof(*types->udts)*types->udt_count; + cons__dsection(arena, &dss, types->udts, udt_size, RADDBG_DataSectionTag_UDTs); + + U64 member_size = sizeof(*types->members)*types->member_count; + cons__dsection(arena, &dss, types->members, member_size, RADDBG_DataSectionTag_Members); + + U64 enum_member_size = sizeof(*types->enum_members)*types->enum_member_count; + cons__dsection(arena, &dss, types->enum_members, enum_member_size, RADDBG_DataSectionTag_EnumMembers); + } + + // symbol info baking + { + CONS__SymbolData *symbol_data = cons__symbol_data_combine(arena, root, bctx); + + U64 global_variables_size = + sizeof(*symbol_data->global_variables)*symbol_data->global_variable_count; + cons__dsection(arena, &dss, symbol_data->global_variables, global_variables_size, + RADDBG_DataSectionTag_GlobalVariables); + + CONS__VMap *global_vmap = symbol_data->global_vmap; + U64 global_vmap_size = sizeof(*global_vmap->vmap)*(global_vmap->count + 1); + cons__dsection(arena, &dss, global_vmap->vmap, global_vmap_size, + RADDBG_DataSectionTag_GlobalVmap); + + U64 thread_variables_size = + sizeof(*symbol_data->thread_variables)*symbol_data->thread_variable_count; + cons__dsection(arena, &dss, symbol_data->thread_variables, thread_variables_size, + RADDBG_DataSectionTag_ThreadVariables); + + U64 procedures_size = sizeof(*symbol_data->procedures)*symbol_data->procedure_count; + cons__dsection(arena, &dss, symbol_data->procedures, procedures_size, + RADDBG_DataSectionTag_Procedures); + + U64 scopes_size = sizeof(*symbol_data->scopes)*symbol_data->scope_count; + cons__dsection(arena, &dss, symbol_data->scopes, scopes_size, RADDBG_DataSectionTag_Scopes); + + U64 scope_voffs_size = sizeof(*symbol_data->scope_voffs)*symbol_data->scope_voff_count; + cons__dsection(arena, &dss, symbol_data->scope_voffs, scope_voffs_size, + RADDBG_DataSectionTag_ScopeVoffData); + + CONS__VMap *scope_vmap = symbol_data->scope_vmap; + U64 scope_vmap_size = sizeof(*scope_vmap->vmap)*(scope_vmap->count + 1); + cons__dsection(arena, &dss, scope_vmap->vmap, scope_vmap_size, RADDBG_DataSectionTag_ScopeVmap); + + U64 local_size = sizeof(*symbol_data->locals)*symbol_data->local_count; + cons__dsection(arena, &dss, symbol_data->locals, local_size, RADDBG_DataSectionTag_Locals); + + U64 location_blocks_size = + sizeof(*symbol_data->location_blocks)*symbol_data->location_block_count; + cons__dsection(arena, &dss, symbol_data->location_blocks, location_blocks_size, + RADDBG_DataSectionTag_LocationBlocks); + + U64 location_data_size = symbol_data->location_data_size; + cons__dsection(arena, &dss, symbol_data->location_data, location_data_size, + RADDBG_DataSectionTag_LocationData); + } + + // name map baking + { + U32 name_map_count = 0; + for(U32 i = 0; i < RADDBG_NameMapKind_COUNT; i += 1){ + if(root->name_maps[i] != 0){ + name_map_count += 1; + } + } + + RADDBG_NameMap *name_maps = push_array(arena, RADDBG_NameMap, name_map_count); + + RADDBG_NameMap *name_map_ptr = name_maps; + for(U32 i = 0; i < RADDBG_NameMapKind_COUNT; i += 1){ + CONS__NameMap *map = root->name_maps[i]; + if(map != 0){ + CONS__NameMapBaked *baked = cons__name_map_bake(arena, root, bctx, map); + + name_map_ptr->kind = i; + name_map_ptr->bucket_data_idx = + cons__dsection(arena, &dss, baked->buckets, sizeof(*baked->buckets)*baked->bucket_count, + RADDBG_DataSectionTag_NameMapBuckets); + name_map_ptr->node_data_idx = + cons__dsection(arena, &dss, baked->nodes, sizeof(*baked->nodes)*baked->node_count, + RADDBG_DataSectionTag_NameMapNodes); + name_map_ptr += 1; + } + } + + cons__dsection(arena, &dss, name_maps, sizeof(*name_maps)*name_map_count, + RADDBG_DataSectionTag_NameMaps); + } + + //////////////////////////////// + // LATE PART: baking loose structures and creating final layout + + // generate data sections for file paths + { + U32 count = bctx->tree->count; + RADDBG_FilePathNode *nodes = push_array(arena, RADDBG_FilePathNode, count); + + RADDBG_FilePathNode *out_node = nodes; + for(CONS__PathNode *node = bctx->tree->first; + node != 0; + node = node->next_order, out_node += 1){ + out_node->name_string_idx = cons__string(bctx, node->name); + if(node->parent != 0){ + out_node->parent_path_node = node->parent->idx; + } + if(node->first_child != 0){ + out_node->first_child = node->first_child->idx; + } + if(node->next_sibling != 0){ + out_node->next_sibling = node->next_sibling->idx; + } + if(node->src_file != 0){ + out_node->source_file_idx = node->src_file->idx; + } + } + + cons__dsection(arena, &dss, nodes, sizeof(*nodes)*count, RADDBG_DataSectionTag_FilePathNodes); + } + + // generate data sections for files + { + U32 count = bctx->tree->src_count; + RADDBG_SourceFile *src_files = push_array(arena, RADDBG_SourceFile, count); + + RADDBG_SourceFile *out_src_file = src_files; + for(CONS__SrcNode *node = bctx->tree->src_first; + node != 0; + node = node->next, out_src_file += 1){ + out_src_file->file_path_node_idx = node->path_node->idx; + out_src_file->normal_full_path_string_idx = cons__string(bctx, node->normal_full_path); + out_src_file->line_map_nums_data_idx = node->line_map_nums_data_idx; + out_src_file->line_map_range_data_idx = node->line_map_range_data_idx; + out_src_file->line_map_count = node->line_map_count; + out_src_file->line_map_voff_data_idx = node->line_map_voff_data_idx; + } + + cons__dsection(arena, &dss, src_files, sizeof(*src_files)*count, RADDBG_DataSectionTag_SourceFiles); + } + + // generate data sections for strings + { + U32 *str_offs = push_array_no_zero(arena, U32, bctx->strs.count + 1); + + U32 off_cursor = 0; + { + U32 *off_ptr = str_offs; + *off_ptr = 0; + off_ptr += 1; + for(CONS__StringNode *node = bctx->strs.order_first; + node != 0; + node = node->order_next){ + off_cursor += node->str.size; + *off_ptr = off_cursor; + off_ptr += 1; + } + } + + U8 *buf = push_array(arena, U8, off_cursor); + { + U8 *ptr = buf; + for(CONS__StringNode *node = bctx->strs.order_first; + node != 0; + node = node->order_next){ + MemoryCopy(ptr, node->str.str, node->str.size); + ptr += node->str.size; + } + } + + cons__dsection(arena, &dss, str_offs, sizeof(*str_offs)*(bctx->strs.count + 1), + RADDBG_DataSectionTag_StringTable); + cons__dsection(arena, &dss, buf, off_cursor, RADDBG_DataSectionTag_StringData); + } + + // generate data sections for index runs + { + U32 *idx_data = push_array_no_zero(arena, U32, bctx->idxs.idx_count); + + { + U32 *out_ptr = idx_data; + U32 *opl = out_ptr + bctx->idxs.idx_count; + CONS__IdxRunNode *node = bctx->idxs.order_first; + for(;node != 0 && out_ptr < opl; + node = node->order_next){ + MemoryCopy(out_ptr, node->idx_run, sizeof(*node->idx_run)*node->count); + out_ptr += node->count; + } + Assert(out_ptr == opl); + } + + cons__dsection(arena, &dss, idx_data, sizeof(*idx_data)*bctx->idxs.idx_count, + RADDBG_DataSectionTag_IndexRuns); + } + + // layout + // * the header and data section table have to be initialized "out of order" + // * so that the rest of the system can avoid this tricky order-layout interdependence stuff + RADDBG_Header *header = push_array(arena, RADDBG_Header, 1); + RADDBG_DataSection *dstable = push_array(arena, RADDBG_DataSection, dss.count); + str8_serial_push_align(arena, out, 8); + U64 header_off = out->total_size; + str8_list_push(arena, out, str8_struct(header)); + str8_serial_push_align(arena, out, 8); + U64 data_section_off = out->total_size; + str8_list_push(arena, out, str8((U8 *)dstable, sizeof(*dstable)*dss.count)); + { + header->magic = RADDBG_MAGIC_CONSTANT; + header->encoding_version = RADDBG_ENCODING_VERSION; + header->data_section_off = data_section_off; + header->data_section_count = dss.count; + } + { + U64 test_dss_count = 0; + for(CONS__DSectionNode *node = dss.first; + node != 0; + node = node->next){ + test_dss_count += 1; + } + Assert(test_dss_count == dss.count); + + RADDBG_DataSection *ptr = dstable; + for(CONS__DSectionNode *node = dss.first; + node != 0; + node = node->next, ptr += 1){ + U64 data_section_offset = 0; + if(node->size != 0) + { + str8_serial_push_align(arena, out, 8); + data_section_offset = out->total_size; + str8_list_push(arena, out, str8((U8 *)node->data, node->size)); + } + ptr->tag = node->tag; + ptr->encoding = RADDBG_DataSectionEncoding_Unpacked; + ptr->off = data_section_offset; + ptr->encoded_size = node->size; + ptr->unpacked_size = node->size; + } + Assert(ptr == dstable + dss.count); + } + + cons__bake_ctx_release(bctx); + ProfEnd(); } diff --git a/src/raddbg_cons/raddbg_cons.h b/src/raddbgi_cons/raddbgi_cons.h similarity index 58% rename from src/raddbg_cons/raddbg_cons.h rename to src/raddbgi_cons/raddbgi_cons.h index a2c71726..0d024bf4 100644 --- a/src/raddbg_cons/raddbg_cons.h +++ b/src/raddbgi_cons/raddbgi_cons.h @@ -1,109 +1,133 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef RADDBG_CONS_H -#define RADDBG_CONS_H +#ifndef RADDBGI_CONS_H +#define RADDBGI_CONS_H //////////////////////////////// -//- "Public Facing" Cons API +//~ rjf: Error Types -// frequently used opaque types -typedef struct CONS_Root CONS_Root; -typedef struct CONS_Unit CONS_Unit; -typedef struct CONS_Type CONS_Type; -typedef struct CONS_Reservation CONS_Reservation; -typedef struct CONS_Symbol CONS_Symbol; -typedef struct CONS_Scope CONS_Scope; -typedef struct CONS_Local CONS_Local; -typedef struct CONS_LocationSet CONS_LocationSet; -typedef struct CONS_Location CONS_Location; - -typedef struct CONS_TypeNode{ - struct CONS_TypeNode *next; - CONS_Type *type; -} CONS_TypeNode; - -typedef struct CONS_TypeList{ - CONS_TypeNode *first; - CONS_TypeNode *last; - U64 count; -} CONS_TypeList; - -typedef struct CONS_EvalBytecodeOp{ - struct CONS_EvalBytecodeOp *next; - RADDBG_EvalOp op; - U32 p_size; - U64 p; -} CONS_EvalBytecodeOp; - -typedef struct CONS_EvalBytecode{ - CONS_EvalBytecodeOp *first_op; - CONS_EvalBytecodeOp *last_op; - U32 op_count; - U32 encoded_size; -} CONS_EvalBytecode; - -//- init - -typedef struct CONS_RootParams{ - // important to set this correctly so pointer - // types get the correct sizes - U64 addr_size; - - // options to optimize map bucket counts - // * if these are left as zeros a modest default is used instead - U32 bucket_count_units; - U32 bucket_count_symbols; - U32 bucket_count_scopes; - U32 bucket_count_locals; - U32 bucket_count_types; - U64 bucket_count_type_constructs; -} CONS_RootParams; - -static CONS_Root* cons_root_new(CONS_RootParams *params); -static void cons_root_release(CONS_Root *root); - - -//- baking -static void cons_bake_file(Arena *arena, CONS_Root *root, String8List *out); - - -//- errors -typedef struct CONS_Error{ - struct CONS_Error *next; +typedef struct CONS_Error CONS_Error; +struct CONS_Error +{ + CONS_Error *next; String8 msg; -} CONS_Error; +}; -static void cons_errorf(CONS_Root *root, char *fmt, ...); +typedef struct CONS_ErrorList CONS_ErrorList; +struct CONS_ErrorList +{ + CONS_Error *first; + CONS_Error *last; + U64 count; +}; -static CONS_Error* cons_get_first_error(CONS_Root *root); +//////////////////////////////// +//~ rjf: Auxiliary Data Structure Types +//- rjf: u64 -> pointer map +typedef struct CONS__U64ToPtrNode CONS__U64ToPtrNode; +struct CONS__U64ToPtrNode +{ + CONS__U64ToPtrNode *next; + U64 _padding_; + U64 key[1]; + void *ptr[1]; +}; -//- information declaration +typedef struct CONS__U64ToPtrMap CONS__U64ToPtrMap; +struct CONS__U64ToPtrMap +{ + CONS__U64ToPtrNode **buckets; + U64 buckets_count; + U64 bucket_collision_count; + U64 pair_count; +}; -// top level info -typedef struct CONS_TopLevelInfo{ - RADDBG_Arch architecture; - String8 exe_name; - U64 exe_hash; - U64 voff_max; -} CONS_TopLevelInfo; +typedef struct CONS__U64ToPtrLookup CONS__U64ToPtrLookup; +struct CONS__U64ToPtrLookup +{ + void *match; + CONS__U64ToPtrNode *fill_node; + U32 fill_k; +}; -static void cons_set_top_level_info(CONS_Root *root, CONS_TopLevelInfo *tli); +//- rjf: string8 -> pointer map +typedef struct CONS__Str8ToPtrNode CONS__Str8ToPtrNode; +struct CONS__Str8ToPtrNode +{ + struct CONS__Str8ToPtrNode *next; + String8 key; + U64 hash; + void *ptr; +}; -// binary sections -static void cons_add_binary_section(CONS_Root *root, - String8 name, RADDBG_BinarySectionFlags flags, - U64 voff_first, U64 voff_opl, U64 foff_first, - U64 foff_opl); +typedef struct CONS__Str8ToPtrMap CONS__Str8ToPtrMap; +struct CONS__Str8ToPtrMap +{ + CONS__Str8ToPtrNode **buckets; + U64 buckets_count; + U64 bucket_collision_count; + U64 pair_count; +}; +//- rjf: sortable range data structure -// units -static CONS_Unit* cons_unit_handle_from_user_id(CONS_Root *root, U64 unit_user_id, U64 unit_user_id_hash); +typedef struct CONS__SortKey CONS__SortKey; +struct CONS__SortKey +{ + U64 key; + void *val; +}; -typedef struct CONS_UnitInfo{ +typedef struct CONS__OrderedRange CONS__OrderedRange; +struct CONS__OrderedRange +{ + CONS__OrderedRange *next; + U64 first; + U64 opl; +}; + +//////////////////////////////// +//~ rjf: Binary Section Types + +typedef struct CONS_BinarySection CONS_BinarySection; +struct CONS_BinarySection +{ + CONS_BinarySection *next; + String8 name; + RADDBG_BinarySectionFlags flags; + U64 voff_first; + U64 voff_opl; + U64 foff_first; + U64 foff_opl; +}; + +//////////////////////////////// +//~ rjf: Per-Compilation-Unit Info Types + +typedef struct CONS_LineSequence CONS_LineSequence; +struct CONS_LineSequence +{ + String8 file_name; + U64 *voffs; // [line_count + 1] (sorted) + U32 *line_nums; // [line_count] + U16 *col_nums; // [2*line_count] + U64 line_count; +}; + +typedef struct CONS_LineSequenceNode CONS_LineSequenceNode; +struct CONS_LineSequenceNode +{ + CONS_LineSequenceNode *next; + CONS_LineSequence line_seq; +}; + +typedef struct CONS_UnitInfo CONS_UnitInfo; +struct CONS_UnitInfo +{ String8 unit_name; String8 compiler_name; String8 source_file; @@ -111,187 +135,13 @@ typedef struct CONS_UnitInfo{ String8 archive_file; String8 build_path; RADDBG_Language language; -} CONS_UnitInfo; +}; -static void cons_unit_set_info(CONS_Root *root, CONS_Unit *unit, CONS_UnitInfo *info); - -typedef struct CONS_LineSequence{ - String8 file_name; - U64 *voffs; // [line_count + 1] (sorted) - U32 *line_nums; // [line_count] - U16 *col_nums; // [2*line_count] - U64 line_count; -} CONS_LineSequence; - -static void cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, - CONS_LineSequence *line_sequence); - -static void cons_unit_vmap_add_range(CONS_Root *root, CONS_Unit *unit, U64 first, U64 opl); - - -// types -static CONS_Type* cons_type_from_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash); -static CONS_Reservation* cons_type_reserve_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash); -static void cons_type_fill_id(CONS_Root *root, CONS_Reservation *res, CONS_Type *type); - -static B32 cons_type_is_unhandled_nil(CONS_Root *root, CONS_Type *type); - -static CONS_Type* cons_type_handled_nil(CONS_Root *root); -static CONS_Type* cons_type_nil(CONS_Root *root); -static CONS_Type* cons_type_variadic(CONS_Root *root); - -static CONS_Type* cons_type_basic(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name); -static CONS_Type* cons_type_modifier(CONS_Root *root, - CONS_Type *direct_type, RADDBG_TypeModifierFlags flags); -static CONS_Type* cons_type_bitfield(CONS_Root *root, - CONS_Type *direct_type, U32 bit_off, U32 bit_count); -static CONS_Type* cons_type_pointer(CONS_Root *root, - CONS_Type *direct_type, RADDBG_TypeKind ptr_type_kind); -static CONS_Type* cons_type_array(CONS_Root *root, - CONS_Type *direct_type, U64 count); -static CONS_Type* cons_type_proc(CONS_Root *root, - CONS_Type *return_type, struct CONS_TypeList *params); -static CONS_Type* cons_type_method(CONS_Root *root, - CONS_Type *this_type, CONS_Type *return_type, - struct CONS_TypeList *params); - -static CONS_Type* cons_type_udt(CONS_Root *root, - RADDBG_TypeKind record_type_kind, String8 name, U64 size); -static CONS_Type* cons_type_enum(CONS_Root *root, - CONS_Type *direct_type, String8 name); -static CONS_Type* cons_type_alias(CONS_Root *root, - CONS_Type *direct_type, String8 name); -static CONS_Type* cons_type_incomplete(CONS_Root *root, - RADDBG_TypeKind type_kind, String8 name); - -static void cons_type_add_member_data_field(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type, U32 off); -static void cons_type_add_member_static_data(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type); -static void cons_type_add_member_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type); -static void cons_type_add_member_static_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type); -static void cons_type_add_member_virtual_method(CONS_Root *root, CONS_Type *record_type, - String8 name, CONS_Type *mem_type); -static void cons_type_add_member_base(CONS_Root *root, CONS_Type *record_type, - CONS_Type *base_type, U32 off); -static void cons_type_add_member_virtual_base(CONS_Root *root, CONS_Type *record_type, - CONS_Type *base_type, U32 vptr_off, U32 vtable_off); -static void cons_type_add_member_nested_type(CONS_Root *root, CONS_Type *record_type, - CONS_Type *nested_type); - -static void cons_type_add_enum_val(CONS_Root *root, CONS_Type *enum_type, String8 name, U64 val); - -static void cons_type_set_source_coordinates(CONS_Root *root, CONS_Type *defined_type, - String8 source_path, U32 line, U32 col); - -// type list -static void cons_type_list_push(Arena *arena, CONS_TypeList *list, CONS_Type *type); - -// symbols -static CONS_Symbol* cons_symbol_handle_from_user_id(CONS_Root *root, U64 symbol_user_id, U64 symbol_user_id_hash); - -typedef enum{ - CONS_SymbolKind_NULL, - CONS_SymbolKind_GlobalVariable, - CONS_SymbolKind_ThreadVariable, - CONS_SymbolKind_Procedure, - CONS_SymbolKind_COUNT -} CONS_SymbolKind; - -typedef struct CONS_SymbolInfo{ - CONS_SymbolKind kind; - String8 name; - String8 link_name; - CONS_Type *type; - B32 is_extern; - U64 offset; - // TODO(allen): should this actually be "container scope"? - CONS_Symbol *container_symbol; - CONS_Type *container_type; - CONS_Scope *root_scope; -} CONS_SymbolInfo; - -static void cons_symbol_set_info(CONS_Root *root, CONS_Symbol *symbol, CONS_SymbolInfo *info); - -// scopes -static CONS_Scope *cons_scope_handle_from_user_id(CONS_Root *root, U64 scope_user_id, U64 scope_user_id_hash); - -static void cons_scope_set_parent(CONS_Root *root, CONS_Scope *scope, CONS_Scope *parent); -static void cons_scope_add_voff_range(CONS_Root *root, CONS_Scope *scope, U64 voff_first, U64 voff_opl); - -// locals -static CONS_Local* cons_local_handle_from_user_id(CONS_Root *root, U64 local_user_id, U64 local_user_id_hash); - -typedef struct CONS_LocalInfo{ - RADDBG_LocalKind kind; - CONS_Scope *scope; - String8 name; - CONS_Type *type; -} CONS_LocalInfo; - -static void cons_local_set_basic_info(CONS_Root *root, CONS_Local *local, - CONS_LocalInfo *info); - -static CONS_LocationSet* cons_location_set_from_local(CONS_Root *root, CONS_Local *local); - -// locations -static void cons_location_set_add_case(CONS_Root *root, CONS_LocationSet *locset, - U64 voff_min, U64 voff_max, - CONS_Location *location); - -static CONS_Location* cons_location_addr_bytecode_stream(CONS_Root *root, - struct CONS_EvalBytecode *bytecode); -static CONS_Location* cons_location_val_bytecode_stream(CONS_Root *root, - struct CONS_EvalBytecode *bytecode); -static CONS_Location* cons_location_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset); -static CONS_Location* cons_location_addr_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset); -static CONS_Location* cons_location_val_reg(CONS_Root *root, U8 reg_code); - -// bytecode -static void cons_bytecode_push_op(Arena *arena, CONS_EvalBytecode *bytecode, RADDBG_EvalOp op, U64 p); -static void cons_bytecode_push_uconst(Arena *arena, CONS_EvalBytecode *bytecode, U64 x); -static void cons_bytecode_push_sconst(Arena *arena, CONS_EvalBytecode *bytecode, S64 x); -static void cons_bytecode_concat_in_place(CONS_EvalBytecode *left_dst, - CONS_EvalBytecode *right_destroyed); - -//////////////////////////////// -//- Concrete Types & Implementation Helpers - -// NOTE: the user should generally treat these as opaque - -// errors -typedef struct CONS_ErrorList{ - CONS_Error *first; - CONS_Error *last; - U64 count; -} CONS_ErrorList; - - -// binary sections -typedef struct CONS_BinarySection{ - struct CONS_BinarySection *next; - String8 name; - RADDBG_BinarySectionFlags flags; - U64 voff_first; - U64 voff_opl; - U64 foff_first; - U64 foff_opl; -} CONS_BinarySection; - - -// units -typedef struct CONS_LineSequenceNode{ - struct CONS_LineSequenceNode *next; - CONS_LineSequence line_seq; -} CONS_LineSequenceNode; - -typedef struct CONS_Unit{ - struct CONS_Unit *next_order; - +typedef struct CONS_Unit CONS_Unit; +struct CONS_Unit +{ + CONS_Unit *next_order; U32 idx; - B32 info_is_set; String8 unit_name; String8 compiler_name; @@ -300,77 +150,26 @@ typedef struct CONS_Unit{ String8 archive_file; String8 build_path; RADDBG_Language language; - CONS_LineSequenceNode *line_seq_first; CONS_LineSequenceNode *line_seq_last; U64 line_seq_count; - -} CONS_Unit; +}; -typedef struct CONS_UnitVMapRange{ - struct CONS_UnitVMapRange *next; +typedef struct CONS_UnitVMapRange CONS_UnitVMapRange; +struct CONS_UnitVMapRange +{ + CONS_UnitVMapRange *next; CONS_Unit *unit; U64 first; U64 opl; -} CONS_UnitVMapRange; +}; - -// types -typedef struct CONS_Type{ - struct CONS_Type *next_order; - - RADDBG_TypeKind kind; - U32 idx; - U32 byte_size; - U32 flags; - U32 off; - U32 count; - - String8 name; - - struct CONS_Type *direct_type; - struct CONS_Type **param_types; - - struct CONS_TypeUDT *udt; -} CONS_Type; - -typedef struct CONS_TypeMember{ - struct CONS_TypeMember *next; - - RADDBG_MemberKind kind; - String8 name; - CONS_Type *type; - U32 off; -} CONS_TypeMember; - -typedef struct CONS_TypeEnumVal{ - struct CONS_TypeEnumVal *next; - - String8 name; - U64 val; -} CONS_TypeEnumVal; - -typedef struct CONS_TypeUDT{ - struct CONS_TypeUDT *next_order; - - U32 idx; - struct CONS_Type *self_type; - - CONS_TypeMember *first_member; - CONS_TypeMember *last_member; - U64 member_count; - - CONS_TypeEnumVal *first_enum_val; - CONS_TypeEnumVal *last_enum_val; - U64 enum_val_count; - - String8 source_path; - U32 line; - U32 col; -} CONS_TypeUDT; +//////////////////////////////// +//~ rjf: Type Info Types typedef U8 CONS_TypeConstructKind; -enum{ +enum +{ CONS_TypeConstructKind_Basic, CONS_TypeConstructKind_Modifier, CONS_TypeConstructKind_Bitfield, @@ -380,17 +179,107 @@ enum{ CONS_TypeConstructKind_Method, }; -static CONS_Type* cons__type_new(CONS_Root *root); -static CONS_TypeUDT* cons__type_udt_from_any_type(CONS_Root *root, CONS_Type *type); -static CONS_TypeUDT* cons__type_udt_from_record_type(CONS_Root *root, CONS_Type *type); +typedef struct CONS_Reservation CONS_Reservation; +typedef struct CONS_TypeMember CONS_TypeMember; +struct CONS_TypeMember +{ + CONS_TypeMember *next; + RADDBG_MemberKind kind; + String8 name; + struct CONS_Type *type; + U32 off; +}; -// symbols -typedef struct CONS_Symbol{ - struct CONS_Symbol *next_order; - +typedef struct CONS_TypeEnumVal CONS_TypeEnumVal; +struct CONS_TypeEnumVal +{ + CONS_TypeEnumVal *next; + String8 name; + U64 val; +}; + +typedef struct CONS_Type CONS_Type; +struct CONS_Type +{ + CONS_Type *next_order; + RADDBG_TypeKind kind; + U32 idx; + U32 byte_size; + U32 flags; + U32 off; + U32 count; + String8 name; + CONS_Type *direct_type; + CONS_Type **param_types; + struct CONS_TypeUDT *udt; +}; + +typedef struct CONS_TypeUDT CONS_TypeUDT; +struct CONS_TypeUDT +{ + CONS_TypeUDT *next_order; + U32 idx; + CONS_Type *self_type; + CONS_TypeMember *first_member; + CONS_TypeMember *last_member; + U64 member_count; + CONS_TypeEnumVal *first_enum_val; + CONS_TypeEnumVal *last_enum_val; + U64 enum_val_count; + String8 source_path; + U32 line; + U32 col; +}; + +typedef struct CONS_TypeNode CONS_TypeNode; +struct CONS_TypeNode +{ + CONS_TypeNode *next; + CONS_Type *type; +}; + +typedef struct CONS_TypeList CONS_TypeList; +struct CONS_TypeList +{ + CONS_TypeNode *first; + CONS_TypeNode *last; + U64 count; +}; + +//////////////////////////////// +//~ rjf: Symbol Info Types + +typedef enum CONS_SymbolKind +{ + CONS_SymbolKind_NULL, + CONS_SymbolKind_GlobalVariable, + CONS_SymbolKind_ThreadVariable, + CONS_SymbolKind_Procedure, + CONS_SymbolKind_COUNT +} +CONS_SymbolKind; + +typedef struct CONS_SymbolInfo CONS_SymbolInfo; +struct CONS_SymbolInfo +{ + CONS_SymbolKind kind; + String8 name; + String8 link_name; + CONS_Type *type; + B32 is_extern; + U64 offset; + // TODO(allen): should this actually be "container scope"? + struct CONS_Symbol *container_symbol; + CONS_Type *container_type; + struct CONS_Scope *root_scope; +}; + +typedef struct CONS_Symbol CONS_Symbol; +struct CONS_Symbol +{ + CONS_Symbol *next_order; U32 idx; - CONS_SymbolKind kind; String8 name; String8 link_name; @@ -398,156 +287,169 @@ typedef struct CONS_Symbol{ B32 is_extern; B8 offset_is_set; U64 offset; - CONS_Symbol *container_symbol; CONS_Type *container_type; - - CONS_Scope *root_scope; -} CONS_Symbol; + struct CONS_Scope *root_scope; +}; +//////////////////////////////// +//~ rjf: Scope Info Types -// scopes -typedef struct CONS_Local{ - struct CONS_Local *next; +typedef struct CONS_LocalInfo CONS_LocalInfo; +struct CONS_LocalInfo +{ + RADDBG_LocalKind kind; + struct CONS_Scope *scope; + String8 name; + CONS_Type *type; +}; + +typedef struct CONS_Local CONS_Local; +struct CONS_Local +{ + CONS_Local *next; RADDBG_LocalKind kind; String8 name; CONS_Type *type; - CONS_LocationSet *locset; -} CONS_Local; + struct CONS_LocationSet *locset; +}; -typedef struct CONS__VOffRange{ - struct CONS__VOffRange *next; +typedef struct CONS__VOffRange CONS__VOffRange; +struct CONS__VOffRange +{ + CONS__VOffRange *next; U64 voff_first; U64 voff_opl; -} CONS__VOffRange; +}; -typedef struct CONS_Scope{ - struct CONS_Scope *next_order; - +typedef struct CONS_Scope CONS_Scope; +struct CONS_Scope +{ + CONS_Scope *next_order; CONS_Symbol *symbol; CONS_Scope *parent_scope; CONS_Scope *first_child; CONS_Scope *last_child; CONS_Scope *next_sibling; - U64 voff_base; CONS__VOffRange *first_range; CONS__VOffRange *last_range; U32 range_count; - U32 idx; - CONS_Local *first_local; CONS_Local *last_local; U32 local_count; - -} CONS_Scope; +}; -static void cons__scope_recursive_set_symbol(CONS_Scope *scope, CONS_Symbol *symbol); +//////////////////////////////// +//~ rjf: Location Info Types +typedef struct CONS_EvalBytecodeOp CONS_EvalBytecodeOp; +struct CONS_EvalBytecodeOp +{ + CONS_EvalBytecodeOp *next; + RADDBG_EvalOp op; + U32 p_size; + U64 p; +}; -// locations -typedef struct CONS_Location{ +typedef struct CONS_EvalBytecode CONS_EvalBytecode; +struct CONS_EvalBytecode +{ + CONS_EvalBytecodeOp *first_op; + CONS_EvalBytecodeOp *last_op; + U32 op_count; + U32 encoded_size; +}; + +typedef struct CONS_Location CONS_Location; +struct CONS_Location +{ RADDBG_LocationKind kind; U8 register_code; U16 offset; CONS_EvalBytecode bytecode; -} CONS_Location; +}; -typedef struct CONS__LocationCase{ - struct CONS__LocationCase *next; +typedef struct CONS__LocationCase CONS__LocationCase; +struct CONS__LocationCase +{ + CONS__LocationCase *next; U64 voff_first; U64 voff_opl; CONS_Location *location; -} CONS__LocationCase; +}; -typedef struct CONS_LocationSet{ +typedef struct CONS_LocationSet CONS_LocationSet; +struct CONS_LocationSet +{ CONS__LocationCase *first_location_case; CONS__LocationCase *last_location_case; U64 location_case_count; -} CONS_LocationSet; +}; +//////////////////////////////// +//~ rjf: Name Map Types -// name maps -typedef struct CONS__NameMapIdxNode{ - struct CONS__NameMapIdxNode *next; +typedef struct CONS__NameMapIdxNode CONS__NameMapIdxNode; +struct CONS__NameMapIdxNode +{ + CONS__NameMapIdxNode *next; U32 idx[8]; -} CONS__NameMapIdxNode; +}; -typedef struct CONS__NameMapNode{ - struct CONS__NameMapNode *bucket_next; - struct CONS__NameMapNode *order_next; +typedef struct CONS__NameMapNode CONS__NameMapNode; +struct CONS__NameMapNode +{ + CONS__NameMapNode *bucket_next; + CONS__NameMapNode *order_next; String8 string; CONS__NameMapIdxNode *idx_first; CONS__NameMapIdxNode *idx_last; U64 idx_count; -} CONS__NameMapNode; +}; -typedef struct CONS__NameMap{ +typedef struct CONS__NameMap CONS__NameMap; +struct CONS__NameMap +{ CONS__NameMapNode **buckets; U64 buckets_count; U64 bucket_collision_count; CONS__NameMapNode *first; CONS__NameMapNode *last; U64 name_count; -} CONS__NameMap; +}; -static CONS__NameMap* cons__name_map_for_kind(CONS_Root *root, RADDBG_NameMapKind kind); -static void cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, - String8 name, U32 idx); +//////////////////////////////// +//~ rjf: Top-Level Debug Info Types +typedef struct CONS_TopLevelInfo CONS_TopLevelInfo; +struct CONS_TopLevelInfo +{ + RADDBG_Arch architecture; + String8 exe_name; + U64 exe_hash; + U64 voff_max; +}; -// u64 to ptr map -typedef struct CONS__U64ToPtrNode{ - struct CONS__U64ToPtrNode *next; - U64 _padding_; - U64 key[1]; - void *ptr[1]; -} CONS__U64ToPtrNode; +//////////////////////////////// +//~ rjf: Root Construction Bundle Types -typedef struct CONS__U64ToPtrMap{ - CONS__U64ToPtrNode **buckets; - U64 buckets_count; - U64 bucket_collision_count; - U64 pair_count; -} CONS__U64ToPtrMap; +typedef struct CONS_RootParams CONS_RootParams; +struct CONS_RootParams +{ + U64 addr_size; + U32 bucket_count_units; // optional; default chosen if 0 + U32 bucket_count_symbols; // optional; default chosen if 0 + U32 bucket_count_scopes; // optional; default chosen if 0 + U32 bucket_count_locals; // optional; default chosen if 0 + U32 bucket_count_types; // optional; default chosen if 0 + U64 bucket_count_type_constructs; // optional; default chosen if 0 +}; -typedef struct CONS__U64ToPtrLookup{ - void *match; - CONS__U64ToPtrNode *fill_node; - U32 fill_k; -} CONS__U64ToPtrLookup; - -static void cons__u64toptr_init(Arena *arena, CONS__U64ToPtrMap *map, U64 bucket_count); - -static void cons__u64toptr_lookup(CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup_out); -static void cons__u64toptr_insert(Arena *arena, CONS__U64ToPtrMap *map, U64 key, U64 hash, - CONS__U64ToPtrLookup *lookup, void *ptr); - - - -// str8 to ptr map -typedef struct CONS__Str8ToPtrNode{ - struct CONS__Str8ToPtrNode *next; - String8 key; - U64 hash; - void *ptr; -} CONS__Str8ToPtrNode; - -typedef struct CONS__Str8ToPtrMap{ - CONS__Str8ToPtrNode **buckets; - U64 buckets_count; - U64 bucket_collision_count; - U64 pair_count; -} CONS__Str8ToPtrMap; - -static void cons__str8toptr_init(Arena *arena, CONS__Str8ToPtrMap *map, U64 bucket_count); -static void*cons__str8toptr_lookup(CONS__Str8ToPtrMap *map, String8 key, U64 hash); -static void cons__str8toptr_insert(Arena *arena, CONS__Str8ToPtrMap *map, - String8 key, U64 hash, void *ptr); - -// root -struct CONS_Root{ +typedef struct CONS_Root CONS_Root; +struct CONS_Root +{ Arena *arena; CONS_ErrorList errors; @@ -623,50 +525,67 @@ struct CONS_Root{ CONS__Str8ToPtrMap construct_map; }; +//////////////////////////////// +//~ rjf: Baking Phase Types -//- cons intermediate data sections -typedef struct CONS__DSectionNode{ - struct CONS__DSectionNode *next; +//- rjf: bake data section data structure + +typedef struct CONS__DSectionNode CONS__DSectionNode; +struct CONS__DSectionNode +{ + CONS__DSectionNode *next; void *data; U64 size; RADDBG_DataSectionTag tag; -} CONS__DSectionNode; +}; -typedef struct CONS__DSections{ +typedef struct CONS__DSections CONS__DSections; +struct CONS__DSections +{ CONS__DSectionNode *first; CONS__DSectionNode *last; U32 count; -} CONS__DSections; +}; -//- cons intermediate strings -typedef struct CONS__StringNode{ - struct CONS__StringNode *order_next; - struct CONS__StringNode *bucket_next; +//- rjf: bake string data structure + +typedef struct CONS__StringNode CONS__StringNode; +struct CONS__StringNode +{ + CONS__StringNode *order_next; + CONS__StringNode *bucket_next; String8 str; U64 hash; U32 idx; -} CONS__StringNode; +}; -typedef struct CONS__Strings{ +typedef struct CONS__Strings CONS__Strings; +struct CONS__Strings +{ CONS__StringNode *order_first; CONS__StringNode *order_last; CONS__StringNode **buckets; U64 buckets_count; U64 bucket_collision_count; U32 count; -} CONS__Strings; +}; -//- cons intermediate index runs -typedef struct CONS__IdxRunNode{ - struct CONS__IdxRunNode *order_next; - struct CONS__IdxRunNode *bucket_next; +//- rjf: index run baking data structure + +typedef struct CONS__IdxRunNode CONS__IdxRunNode; +struct CONS__IdxRunNode +{ + CONS__IdxRunNode *order_next; + CONS__IdxRunNode *bucket_next; U32 *idx_run; U64 hash; U32 count; U32 first_idx; -} CONS__IdxRunNode; +}; -typedef struct CONS__IdxRuns{ +typedef struct CONS__IdxRuns CONS__IdxRuns; +struct CONS__IdxRuns +{ CONS__IdxRunNode *order_first; CONS__IdxRunNode *order_last; CONS__IdxRunNode **buckets; @@ -674,27 +593,34 @@ typedef struct CONS__IdxRuns{ U64 bucket_collision_count; U32 count; U32 idx_count; -} CONS__IdxRuns; +}; -//- cons intermediate file path tree -typedef struct CONS__PathNode{ - struct CONS__PathNode *next_order; - struct CONS__PathNode *parent; - struct CONS__PathNode *first_child; - struct CONS__PathNode *last_child; - struct CONS__PathNode *next_sibling; +//- rjf: source file & file path baking data structures + +typedef struct CONS__PathNode CONS__PathNode; +struct CONS__PathNode +{ + CONS__PathNode *next_order; + CONS__PathNode *parent; + CONS__PathNode *first_child; + CONS__PathNode *last_child; + CONS__PathNode *next_sibling; String8 name; struct CONS__SrcNode *src_file; U32 idx; -} CONS__PathNode; +}; -typedef struct CONS__LineMapFragment{ - struct CONS__LineMapFragment *next; +typedef struct CONS__LineMapFragment CONS__LineMapFragment; +struct CONS__LineMapFragment +{ + CONS__LineMapFragment *next; CONS_LineSequenceNode *sequence; -} CONS__LineMapFragment; +}; -typedef struct CONS__SrcNode{ - struct CONS__SrcNode *next; +typedef struct CONS__SrcNode CONS__SrcNode; +struct CONS__SrcNode +{ + CONS__SrcNode *next; CONS__PathNode *path_node; U32 idx; @@ -709,9 +635,11 @@ typedef struct CONS__SrcNode{ U32 line_map_range_data_idx; U32 line_map_count; U32 line_map_voff_data_idx; -} CONS__SrcNode; +}; -typedef struct CONS__PathTree{ +typedef struct CONS__PathTree CONS__PathTree; +struct CONS__PathTree +{ CONS__PathNode *first; CONS__PathNode *last; U32 count; @@ -719,130 +647,84 @@ typedef struct CONS__PathTree{ CONS__SrcNode *src_first; CONS__SrcNode *src_last; U32 src_count; -} CONS__PathTree; - -typedef struct CONS__BakeCtx{ - Arena *arena; - CONS__Strings strs; - CONS__IdxRuns idxs; - CONS__PathTree *tree; -} CONS__BakeCtx; - -typedef struct CONS__BakeParams CONS__BakeParams; -struct CONS__BakeParams -{ - U64 strings_bucket_count; - U64 idx_runs_bucket_count; }; -//- cons intermediate functions -static U32 cons__dsection(Arena *arena, CONS__DSections *dss, - void *data, U64 size, RADDBG_DataSectionTag tag); +//- rjf: line info baking data structures -static CONS__BakeCtx* cons__bake_ctx_begin(CONS__BakeParams *params); -static void cons__bake_ctx_release(CONS__BakeCtx *bake_ctx); - -static U32 cons__string(CONS__BakeCtx *bctx, String8 str); - -static U64 cons__idx_run_hash(U32 *idx_run, U32 count); -static U32 cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count); - -static CONS__PathNode* cons__paths_new_node(CONS__BakeCtx *bctx); -static CONS__PathNode* cons__paths_sub_path(CONS__BakeCtx *bctx, CONS__PathNode *dir, String8 sub_dir); -static CONS__PathNode* cons__paths_node_from_path(CONS__BakeCtx *bctx, String8 path); -static U32 cons__paths_idx_from_path(CONS__BakeCtx *bctx, String8 path); - -static CONS__SrcNode* cons__paths_new_src_node(CONS__BakeCtx *bctx); -static CONS__SrcNode* cons__paths_src_node_from_path_node(CONS__BakeCtx *bctx, CONS__PathNode *path); - -//- cons path helper -static String8 cons__normal_string_from_path_node(Arena *arena, CONS__PathNode *node); -static void cons__normal_string_from_path_node_build(Arena *arena, CONS__PathNode *node, - String8List *out); - - -//- cons sort helper -typedef struct CONS__SortKey{ - U64 key; - void *val; -} CONS__SortKey; - -typedef struct CONS__OrderedRange{ - struct CONS__OrderedRange *next; - U64 first; - U64 opl; -} CONS__OrderedRange; - -static CONS__SortKey* cons__sort_key_array(Arena *arena, CONS__SortKey *keys, U64 count); - - -//- cons serializer for unit line info -typedef struct CONS__LineRec{ +typedef struct CONS__LineRec CONS__LineRec; +struct CONS__LineRec +{ U32 file_id; U32 line_num; U16 col_first; U16 col_opl; -} CONS__LineRec; +}; -typedef struct CONS__UnitLinesCombined{ +typedef struct CONS__UnitLinesCombined CONS__UnitLinesCombined; +struct CONS__UnitLinesCombined +{ U64 *voffs; RADDBG_Line *lines; U16 *cols; U32 line_count; -} CONS__UnitLinesCombined; +}; -static CONS__UnitLinesCombined* cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, - CONS_LineSequenceNode *first); - -//- cons serializer for source line info -typedef struct CONS__SrcLinesCombined{ +typedef struct CONS__SrcLinesCombined CONS__SrcLinesCombined; +struct CONS__SrcLinesCombined +{ U32 *line_nums; U32 *line_ranges; U64 *voffs; U32 line_count; U32 voff_count; -} CONS__SrcLinesCombined; +}; -typedef struct CONS__SrcLineMapVoffBlock{ - struct CONS__SrcLineMapVoffBlock *next; +typedef struct CONS__SrcLineMapVoffBlock CONS__SrcLineMapVoffBlock; +struct CONS__SrcLineMapVoffBlock +{ + CONS__SrcLineMapVoffBlock *next; U64 voff; -} CONS__SrcLineMapVoffBlock; +}; -typedef struct CONS__SrcLineMapBucket{ - struct CONS__SrcLineMapBucket *order_next; - struct CONS__SrcLineMapBucket *hash_next; +typedef struct CONS__SrcLineMapBucket CONS__SrcLineMapBucket; +struct CONS__SrcLineMapBucket +{ + CONS__SrcLineMapBucket *order_next; + CONS__SrcLineMapBucket *hash_next; U32 line_num; CONS__SrcLineMapVoffBlock *first_voff_block; CONS__SrcLineMapVoffBlock *last_voff_block; U64 voff_count; -} CONS__SrcLineMapBucket; +}; -static CONS__SrcLinesCombined* cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first); +//- rjf: vmap baking data structure -//- cons serializer for vmap type -typedef struct CONS__VMap{ +typedef struct CONS__VMap CONS__VMap; +struct CONS__VMap +{ RADDBG_VMapEntry *vmap; // [count + 1] U32 count; -} CONS__VMap; +}; -typedef struct CONS__VMapMarker{ +typedef struct CONS__VMapMarker CONS__VMapMarker; +struct CONS__VMapMarker +{ U32 idx; U32 begin_range; -} CONS__VMapMarker; +}; -typedef struct CONS__VMapRangeTracker{ - struct CONS__VMapRangeTracker *next; +typedef struct CONS__VMapRangeTracker CONS__VMapRangeTracker; +struct CONS__VMapRangeTracker +{ + CONS__VMapRangeTracker *next; U32 idx; -} CONS__VMapRangeTracker; +}; -static CONS__VMap* cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey *keys, - U64 marker_count); +//- rjf: type data baking types -//- cons serializer for unit vmap -static CONS__VMap* cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count); - -//- cons serializer for types -typedef struct CONS__TypeData{ +typedef struct CONS__TypeData CONS__TypeData; +struct CONS__TypeData +{ RADDBG_TypeNode *type_nodes; U32 type_node_count; @@ -854,14 +736,13 @@ typedef struct CONS__TypeData{ RADDBG_EnumMember *enum_members; U32 enum_member_count; -} CONS__TypeData; +}; -static CONS__TypeData* cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx); +//- rjf: symbol data baking types -static U32* cons__idx_run_from_types(Arena *arena, CONS_Type **types, U32 count); - -//- cons serializer for symbols -typedef struct CONS__SymbolData{ +typedef struct CONS__SymbolData CONS__SymbolData; +struct CONS__SymbolData +{ RADDBG_GlobalVariable *global_variables; U32 global_variable_count; @@ -889,30 +770,228 @@ typedef struct CONS__SymbolData{ void *location_data; U32 location_data_size; - -} CONS__SymbolData; +}; -static CONS__SymbolData* cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx); +//- rjf: name map baking types -//- cons serializer for name maps -typedef struct CONS__NameMapSemiNode{ - struct CONS__NameMapSemiNode *next; +typedef struct CONS__NameMapSemiNode CONS__NameMapSemiNode; +struct CONS__NameMapSemiNode +{ + CONS__NameMapSemiNode *next; CONS__NameMapNode *node; -} CONS__NameMapSemiNode; +}; -typedef struct CONS__NameMapSemiBucket{ +typedef struct CONS__NameMapSemiBucket CONS__NameMapSemiBucket; +struct CONS__NameMapSemiBucket +{ CONS__NameMapSemiNode *first; CONS__NameMapSemiNode *last; U64 count; -} CONS__NameMapSemiBucket; +}; -typedef struct CONS__NameMapBaked{ +typedef struct CONS__NameMapBaked CONS__NameMapBaked; +struct CONS__NameMapBaked +{ RADDBG_NameMapBucket *buckets; RADDBG_NameMapNode *nodes; U32 bucket_count; U32 node_count; -} CONS__NameMapBaked; +}; +//- rjf: bundle baking context type + +typedef struct CONS__BakeParams CONS__BakeParams; +struct CONS__BakeParams +{ + U64 strings_bucket_count; + U64 idx_runs_bucket_count; +}; + +typedef struct CONS__BakeCtx CONS__BakeCtx; +struct CONS__BakeCtx +{ + Arena *arena; + CONS__Strings strs; + CONS__IdxRuns idxs; + CONS__PathTree *tree; +}; + +//////////////////////////////// +//~ rjf: Basic Type Helpers + +//- rjf: type lists +static void cons_type_list_push(Arena *arena, CONS_TypeList *list, CONS_Type *type); + +//- rjf: bytecode lists +static void cons_bytecode_push_op(Arena *arena, CONS_EvalBytecode *bytecode, RADDBG_EvalOp op, U64 p); +static void cons_bytecode_push_uconst(Arena *arena, CONS_EvalBytecode *bytecode, U64 x); +static void cons_bytecode_push_sconst(Arena *arena, CONS_EvalBytecode *bytecode, S64 x); +static void cons_bytecode_concat_in_place(CONS_EvalBytecode *left_dst, CONS_EvalBytecode *right_destroyed); + +//- rjf: sortable range sorting +static CONS__SortKey* cons__sort_key_array(Arena *arena, CONS__SortKey *keys, U64 count); + +//////////////////////////////// +//~ rjf: Auxiliary Data Structure Functions + +//- rjf: u64 -> ptr map +static void cons__u64toptr_init(Arena *arena, CONS__U64ToPtrMap *map, U64 bucket_count); +static void cons__u64toptr_lookup(CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup_out); +static void cons__u64toptr_insert(Arena *arena, CONS__U64ToPtrMap *map, U64 key, U64 hash, CONS__U64ToPtrLookup *lookup, void *ptr); + +//- rjf: string8 -> ptr map +static void cons__str8toptr_init(Arena *arena, CONS__Str8ToPtrMap *map, U64 bucket_count); +static void*cons__str8toptr_lookup(CONS__Str8ToPtrMap *map, String8 key, U64 hash); +static void cons__str8toptr_insert(Arena *arena, CONS__Str8ToPtrMap *map, String8 key, U64 hash, void *ptr); + +//////////////////////////////// +//~ rjf: Loose Debug Info Construction (Anything -> Loose) Functions + +//- rjf: root creation +static CONS_Root* cons_root_new(CONS_RootParams *params); +static void cons_root_release(CONS_Root *root); + +//- rjf: error accumulation +static void cons_error(CONS_Root *root, String8 string); +static void cons_errorf(CONS_Root *root, char *fmt, ...); +static CONS_Error* cons_get_first_error(CONS_Root *root); + +//- rjf: top-level info specification +static void cons_set_top_level_info(CONS_Root *root, CONS_TopLevelInfo *tli); + +//- rjf: binary section building +static void cons_add_binary_section(CONS_Root *root, + String8 name, RADDBG_BinarySectionFlags flags, + U64 voff_first, U64 voff_opl, U64 foff_first, + U64 foff_opl); + +//- rjf: unit info building +static CONS_Unit* cons_unit_handle_from_user_id(CONS_Root *root, U64 unit_user_id, U64 unit_user_id_hash); +static void cons_unit_set_info(CONS_Root *root, CONS_Unit *unit, CONS_UnitInfo *info); +static void cons_unit_add_line_sequence(CONS_Root *root, CONS_Unit *unit, + CONS_LineSequence *line_sequence); +static void cons_unit_vmap_add_range(CONS_Root *root, CONS_Unit *unit, U64 first, U64 opl); + +//- rjf: type info lookups/reservations +static CONS_Type* cons_type_from_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash); +static CONS_Reservation* cons_type_reserve_id(CONS_Root *root, U64 type_user_id, U64 type_user_id_hash); +static void cons_type_fill_id(CONS_Root *root, CONS_Reservation *res, CONS_Type *type); + +//- rjf: nil/singleton types +static B32 cons_type_is_unhandled_nil(CONS_Root *root, CONS_Type *type); +static CONS_Type* cons_type_handled_nil(CONS_Root *root); +static CONS_Type* cons_type_nil(CONS_Root *root); +static CONS_Type* cons_type_variadic(CONS_Root *root); + +//- rjf: base type info constructors +static CONS_Type* cons__type_new(CONS_Root *root); +static CONS_TypeUDT* cons__type_udt_from_any_type(CONS_Root *root, CONS_Type *type); +static CONS_TypeUDT* cons__type_udt_from_record_type(CONS_Root *root, CONS_Type *type); + +//- rjf: basic/operator type construction helpers +static CONS_Type* cons_type_basic(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name); +static CONS_Type* cons_type_modifier(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeModifierFlags flags); +static CONS_Type* cons_type_bitfield(CONS_Root *root, CONS_Type *direct_type, U32 bit_off, U32 bit_count); +static CONS_Type* cons_type_pointer(CONS_Root *root, CONS_Type *direct_type, RADDBG_TypeKind ptr_type_kind); +static CONS_Type* cons_type_array(CONS_Root *root, CONS_Type *direct_type, U64 count); +static CONS_Type* cons_type_proc(CONS_Root *root, CONS_Type *return_type, struct CONS_TypeList *params); +static CONS_Type* cons_type_method(CONS_Root *root, CONS_Type *this_type, CONS_Type *return_type, struct CONS_TypeList *params); + +//- rjf: udt type constructors +static CONS_Type* cons_type_udt(CONS_Root *root, RADDBG_TypeKind record_type_kind, String8 name, U64 size); +static CONS_Type* cons_type_enum(CONS_Root *root, CONS_Type *direct_type, String8 name); +static CONS_Type* cons_type_alias(CONS_Root *root, CONS_Type *direct_type, String8 name); +static CONS_Type* cons_type_incomplete(CONS_Root *root, RADDBG_TypeKind type_kind, String8 name); + +//- rjf: type member building +static void cons_type_add_member_data_field(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type, U32 off); +static void cons_type_add_member_static_data(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type); +static void cons_type_add_member_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type); +static void cons_type_add_member_static_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type); +static void cons_type_add_member_virtual_method(CONS_Root *root, CONS_Type *record_type, String8 name, CONS_Type *mem_type); +static void cons_type_add_member_base(CONS_Root *root, CONS_Type *record_type, CONS_Type *base_type, U32 off); +static void cons_type_add_member_virtual_base(CONS_Root *root, CONS_Type *record_type, CONS_Type *base_type, U32 vptr_off, U32 vtable_off); +static void cons_type_add_member_nested_type(CONS_Root *root, CONS_Type *record_type, CONS_Type *nested_type); +static void cons_type_add_enum_val(CONS_Root *root, CONS_Type *enum_type, String8 name, U64 val); + +//- rjf: type source coordinate specifications +static void cons_type_set_source_coordinates(CONS_Root *root, CONS_Type *defined_type, String8 source_path, U32 line, U32 col); + +//- rjf: symbol info building +static CONS_Symbol* cons_symbol_handle_from_user_id(CONS_Root *root, U64 symbol_user_id, U64 symbol_user_id_hash); +static void cons_symbol_set_info(CONS_Root *root, CONS_Symbol *symbol, CONS_SymbolInfo *info); + +//- rjf: scope info building +static CONS_Scope *cons_scope_handle_from_user_id(CONS_Root *root, U64 scope_user_id, U64 scope_user_id_hash); +static void cons_scope_set_parent(CONS_Root *root, CONS_Scope *scope, CONS_Scope *parent); +static void cons_scope_add_voff_range(CONS_Root *root, CONS_Scope *scope, U64 voff_first, U64 voff_opl); +static void cons__scope_recursive_set_symbol(CONS_Scope *scope, CONS_Symbol *symbol); + +//- rjf: local info building +static CONS_Local* cons_local_handle_from_user_id(CONS_Root *root, U64 local_user_id, U64 local_user_id_hash); +static void cons_local_set_basic_info(CONS_Root *root, CONS_Local *local, CONS_LocalInfo *info); +static CONS_LocationSet* cons_location_set_from_local(CONS_Root *root, CONS_Local *local); + +//- rjf: location info building +static void cons_location_set_add_case(CONS_Root *root, CONS_LocationSet *locset, U64 voff_first, U64 voff_opl, CONS_Location *location); +static CONS_Location* cons_location_addr_bytecode_stream(CONS_Root *root, struct CONS_EvalBytecode *bytecode); +static CONS_Location* cons_location_val_bytecode_stream(CONS_Root *root, struct CONS_EvalBytecode *bytecode); +static CONS_Location* cons_location_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset); +static CONS_Location* cons_location_addr_addr_reg_plus_u16(CONS_Root *root, U8 reg_code, U16 offset); +static CONS_Location* cons_location_val_reg(CONS_Root *root, U8 reg_code); + +//- rjf: name map building +static CONS__NameMap* cons__name_map_for_kind(CONS_Root *root, RADDBG_NameMapKind kind); +static void cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 name, U32 idx); + +//////////////////////////////// +//~ rjf: Debug Info Baking (Loose -> Tight) Functions + +//- rjf: bake context construction +static CONS__BakeCtx* cons__bake_ctx_begin(CONS__BakeParams *params); +static void cons__bake_ctx_release(CONS__BakeCtx *bake_ctx); + +//- rjf: string baking +static U32 cons__string(CONS__BakeCtx *bctx, String8 str); + +//- rjf: idx run baking +static U64 cons__idx_run_hash(U32 *idx_run, U32 count); +static U32 cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count); + +//- rjf: data section baking +static U32 cons__dsection(Arena *arena, CONS__DSections *dss, void *data, U64 size, RADDBG_DataSectionTag tag); + +//- rjf: paths baking +static String8 cons__normal_string_from_path_node(Arena *arena, CONS__PathNode *node); +static void cons__normal_string_from_path_node_build(Arena *arena, CONS__PathNode *node, String8List *out); +static CONS__PathNode* cons__paths_new_node(CONS__BakeCtx *bctx); +static CONS__PathNode* cons__paths_sub_path(CONS__BakeCtx *bctx, CONS__PathNode *dir, String8 sub_dir); +static CONS__PathNode* cons__paths_node_from_path(CONS__BakeCtx *bctx, String8 path); +static U32 cons__paths_idx_from_path(CONS__BakeCtx *bctx, String8 path); +static CONS__SrcNode* cons__paths_new_src_node(CONS__BakeCtx *bctx); +static CONS__SrcNode* cons__paths_src_node_from_path_node(CONS__BakeCtx *bctx, CONS__PathNode *path_node); + +//- rjf: per-unit line info baking +static CONS__UnitLinesCombined* cons__unit_combine_lines(Arena *arena, CONS__BakeCtx *bctx, CONS_LineSequenceNode *first_seq); + +//- rjf: per-src line info baking +static CONS__SrcLinesCombined* cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first); + +//- rjf: vmap baking +static CONS__VMap* cons__vmap_from_markers(Arena *arena, CONS__VMapMarker *markers, CONS__SortKey *keys, U64 marker_count); +static CONS__VMap* cons__vmap_from_unit_ranges(Arena *arena, CONS_UnitVMapRange *first, U64 count); + +//- rjf: type info baking +static U32* cons__idx_run_from_types(Arena *arena, CONS_Type **types, U32 count); +static CONS__TypeData* cons__type_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx); + +//- rjf: symbol data baking +static CONS__SymbolData* cons__symbol_data_combine(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx); + +//- rjf: name map baking static CONS__NameMapBaked* cons__name_map_bake(Arena *arena, CONS_Root *root, CONS__BakeCtx *bctx, CONS__NameMap *map); -#endif // RADDBG_CONS_H +//- rjf: top-level baking entry point +static void cons_bake_file(Arena *arena, CONS_Root *root, String8List *out); + +#endif // RADDBGI_CONS_H diff --git a/src/raddbg_convert/dwarf/raddbg_dwarf.c b/src/raddbgi_convert/dwarf/raddbgi_dwarf.c similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_dwarf.c rename to src/raddbgi_convert/dwarf/raddbgi_dwarf.c diff --git a/src/raddbg_convert/dwarf/raddbg_dwarf.h b/src/raddbgi_convert/dwarf/raddbgi_dwarf.h similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_dwarf.h rename to src/raddbgi_convert/dwarf/raddbgi_dwarf.h diff --git a/src/raddbg_convert/dwarf/raddbg_dwarf_stringize.c b/src/raddbgi_convert/dwarf/raddbgi_dwarf_stringize.c similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_dwarf_stringize.c rename to src/raddbgi_convert/dwarf/raddbgi_dwarf_stringize.c diff --git a/src/raddbg_convert/dwarf/raddbg_dwarf_stringize.h b/src/raddbgi_convert/dwarf/raddbgi_dwarf_stringize.h similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_dwarf_stringize.h rename to src/raddbgi_convert/dwarf/raddbgi_dwarf_stringize.h diff --git a/src/raddbg_convert/dwarf/raddbg_elf.c b/src/raddbgi_convert/dwarf/raddbgi_elf.c similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_elf.c rename to src/raddbgi_convert/dwarf/raddbgi_elf.c diff --git a/src/raddbg_convert/dwarf/raddbg_elf.h b/src/raddbgi_convert/dwarf/raddbgi_elf.h similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_elf.h rename to src/raddbgi_convert/dwarf/raddbgi_elf.h diff --git a/src/raddbg_convert/dwarf/raddbg_from_dwarf.c b/src/raddbgi_convert/dwarf/raddbgi_from_dwarf.c similarity index 98% rename from src/raddbg_convert/dwarf/raddbg_from_dwarf.c rename to src/raddbgi_convert/dwarf/raddbgi_from_dwarf.c index 76c013bc..2e4aa10f 100644 --- a/src/raddbg_convert/dwarf/raddbg_from_dwarf.c +++ b/src/raddbgi_convert/dwarf/raddbgi_from_dwarf.c @@ -3,30 +3,29 @@ #include "base/base_inc.h" #include "os/os_inc.h" -#include "raddbg_format/raddbg_format.h" -#include "raddbg_cons/raddbg_cons.h" +#include "raddbgi_format/raddbgi_format.h" +#include "raddbgi_cons/raddbgi_cons.h" -#include "raddbg_elf.h" -#include "raddbg_dwarf.h" +#include "raddbgi_elf.h" +#include "raddbgi_dwarf.h" -#include "raddbg_dwarf_stringize.h" +#include "raddbgi_dwarf_stringize.h" -#include "raddbg_from_dwarf.h" +#include "raddbgi_from_dwarf.h" #include "base/base_inc.c" #include "os/os_inc.c" -#include "raddbg_format/raddbg_format.c" -#include "raddbg_cons/raddbg_cons.c" +#include "raddbgi_format/raddbgi_format.c" +#include "raddbgi_cons/raddbgi_cons.c" -#include "raddbg_elf.c" -#include "raddbg_dwarf.c" +#include "raddbgi_elf.c" +#include "raddbgi_dwarf.c" -#include "raddbg_dwarf_stringize.c" +#include "raddbgi_dwarf_stringize.c" // TODO(allen): // [ ] need sample data for .debug_names - //////////////////////////////// //~ Program Parameters Parser diff --git a/src/raddbg_convert/dwarf/raddbg_from_dwarf.h b/src/raddbgi_convert/dwarf/raddbgi_from_dwarf.h similarity index 100% rename from src/raddbg_convert/dwarf/raddbg_from_dwarf.h rename to src/raddbgi_convert/dwarf/raddbgi_from_dwarf.h diff --git a/src/raddbg_convert/pdb/raddbg_codeview.c b/src/raddbgi_convert/pdb/raddbgi_codeview.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview.c rename to src/raddbgi_convert/pdb/raddbgi_codeview.c diff --git a/src/raddbg_convert/pdb/raddbg_codeview.h b/src/raddbgi_convert/pdb/raddbgi_codeview.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview.h rename to src/raddbgi_convert/pdb/raddbgi_codeview.h diff --git a/src/raddbg_convert/pdb/raddbg_codeview_conversion.c b/src/raddbgi_convert/pdb/raddbgi_codeview_conversion.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview_conversion.c rename to src/raddbgi_convert/pdb/raddbgi_codeview_conversion.c diff --git a/src/raddbg_convert/pdb/raddbg_codeview_conversion.h b/src/raddbgi_convert/pdb/raddbgi_codeview_conversion.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview_conversion.h rename to src/raddbgi_convert/pdb/raddbgi_codeview_conversion.h diff --git a/src/raddbg_convert/pdb/raddbg_codeview_stringize.c b/src/raddbgi_convert/pdb/raddbgi_codeview_stringize.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview_stringize.c rename to src/raddbgi_convert/pdb/raddbgi_codeview_stringize.c diff --git a/src/raddbg_convert/pdb/raddbg_codeview_stringize.h b/src/raddbgi_convert/pdb/raddbgi_codeview_stringize.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_codeview_stringize.h rename to src/raddbgi_convert/pdb/raddbgi_codeview_stringize.h diff --git a/src/raddbg_convert/pdb/raddbg_coff.h b/src/raddbgi_convert/pdb/raddbgi_coff.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_coff.h rename to src/raddbgi_convert/pdb/raddbgi_coff.h diff --git a/src/raddbg_convert/pdb/raddbg_coff_conversion.c b/src/raddbgi_convert/pdb/raddbgi_coff_conversion.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_coff_conversion.c rename to src/raddbgi_convert/pdb/raddbgi_coff_conversion.c diff --git a/src/raddbg_convert/pdb/raddbg_coff_conversion.h b/src/raddbgi_convert/pdb/raddbgi_coff_conversion.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_coff_conversion.h rename to src/raddbgi_convert/pdb/raddbgi_coff_conversion.h diff --git a/src/raddbg_convert/pdb/raddbg_from_pdb.c b/src/raddbgi_convert/pdb/raddbgi_from_pdb.c similarity index 99% rename from src/raddbg_convert/pdb/raddbg_from_pdb.c rename to src/raddbgi_convert/pdb/raddbgi_from_pdb.c index fceda14c..18c4be2e 100644 --- a/src/raddbg_convert/pdb/raddbg_from_pdb.c +++ b/src/raddbgi_convert/pdb/raddbgi_from_pdb.c @@ -1407,11 +1407,6 @@ pdbconv_type_cons_leaf_record(PDBCONV_Ctx *ctx, CV_TypeId itype){ U8 *name_ptr = numeric_ptr + size.encoded_size; String8 name = str8_cstring_capped((char*)name_ptr, first + cap); - if(str8_match(name, str8_lit("Foo"), 0)) - { - int x = 0; - } - // incomplete type if (lf_struct->props & CV_TypeProp_FwdRef){ RADDBG_TypeKind type_kind = RADDBG_TypeKind_IncompleteStruct; diff --git a/src/raddbg_convert/pdb/raddbg_from_pdb.h b/src/raddbgi_convert/pdb/raddbgi_from_pdb.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_from_pdb.h rename to src/raddbgi_convert/pdb/raddbgi_from_pdb.h diff --git a/src/raddbg_convert/pdb/raddbg_from_pdb_main.c b/src/raddbgi_convert/pdb/raddbgi_from_pdb_main.c similarity index 76% rename from src/raddbg_convert/pdb/raddbg_from_pdb_main.c rename to src/raddbgi_convert/pdb/raddbgi_from_pdb_main.c index 4a7921a2..be1a992a 100644 --- a/src/raddbg_convert/pdb/raddbg_from_pdb_main.c +++ b/src/raddbgi_convert/pdb/raddbgi_from_pdb_main.c @@ -4,37 +4,37 @@ #include "base/base_inc.h" #include "os/os_inc.h" #include "coff/coff.h" -#include "raddbg_format/raddbg_format.h" -#include "raddbg_cons/raddbg_cons.h" +#include "raddbgi_format/raddbgi_format.h" +#include "raddbgi_cons/raddbgi_cons.h" -#include "raddbg_coff.h" -#include "raddbg_codeview.h" -#include "raddbg_msf.h" -#include "raddbg_pdb.h" -#include "raddbg_coff_conversion.h" -#include "raddbg_codeview_conversion.h" +#include "raddbgi_coff.h" +#include "raddbgi_codeview.h" +#include "raddbgi_msf.h" +#include "raddbgi_pdb.h" +#include "raddbgi_coff_conversion.h" +#include "raddbgi_codeview_conversion.h" -#include "raddbg_codeview_stringize.h" -#include "raddbg_pdb_stringize.h" +#include "raddbgi_codeview_stringize.h" +#include "raddbgi_pdb_stringize.h" -#include "raddbg_from_pdb.h" +#include "raddbgi_from_pdb.h" #include "base/base_inc.c" #include "coff/coff.c" #include "os/os_inc.c" -#include "raddbg_format/raddbg_format.c" -#include "raddbg_cons/raddbg_cons.c" +#include "raddbgi_format/raddbgi_format.c" +#include "raddbgi_cons/raddbgi_cons.c" -#include "raddbg_msf.c" -#include "raddbg_codeview.c" -#include "raddbg_pdb.c" -#include "raddbg_coff_conversion.c" -#include "raddbg_codeview_conversion.c" +#include "raddbgi_msf.c" +#include "raddbgi_codeview.c" +#include "raddbgi_pdb.c" +#include "raddbgi_coff_conversion.c" +#include "raddbgi_codeview_conversion.c" -#include "raddbg_codeview_stringize.c" -#include "raddbg_pdb_stringize.c" +#include "raddbgi_codeview_stringize.c" +#include "raddbgi_pdb_stringize.c" -#include "raddbg_from_pdb.c" +#include "raddbgi_from_pdb.c" int main(int argc, char **argv){ diff --git a/src/raddbg_convert/pdb/raddbg_msf.c b/src/raddbgi_convert/pdb/raddbgi_msf.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_msf.c rename to src/raddbgi_convert/pdb/raddbgi_msf.c diff --git a/src/raddbg_convert/pdb/raddbg_msf.h b/src/raddbgi_convert/pdb/raddbgi_msf.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_msf.h rename to src/raddbgi_convert/pdb/raddbgi_msf.h diff --git a/src/raddbg_convert/pdb/raddbg_pdb.c b/src/raddbgi_convert/pdb/raddbgi_pdb.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_pdb.c rename to src/raddbgi_convert/pdb/raddbgi_pdb.c diff --git a/src/raddbg_convert/pdb/raddbg_pdb.h b/src/raddbgi_convert/pdb/raddbgi_pdb.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_pdb.h rename to src/raddbgi_convert/pdb/raddbgi_pdb.h diff --git a/src/raddbg_convert/pdb/raddbg_pdb_stringize.c b/src/raddbgi_convert/pdb/raddbgi_pdb_stringize.c similarity index 100% rename from src/raddbg_convert/pdb/raddbg_pdb_stringize.c rename to src/raddbgi_convert/pdb/raddbgi_pdb_stringize.c diff --git a/src/raddbg_convert/pdb/raddbg_pdb_stringize.h b/src/raddbgi_convert/pdb/raddbgi_pdb_stringize.h similarity index 100% rename from src/raddbg_convert/pdb/raddbg_pdb_stringize.h rename to src/raddbgi_convert/pdb/raddbgi_pdb_stringize.h diff --git a/src/raddbg_dump/raddbg_dump.c b/src/raddbgi_dump/raddbgi_dump.c similarity index 98% rename from src/raddbg_dump/raddbg_dump.c rename to src/raddbgi_dump/raddbgi_dump.c index 2fa2dc50..1bcd7209 100644 --- a/src/raddbg_dump/raddbg_dump.c +++ b/src/raddbgi_dump/raddbgi_dump.c @@ -3,17 +3,17 @@ #include "base/base_inc.h" #include "os/os_inc.h" -#include "raddbg_format/raddbg_format.h" -#include "raddbg_format/raddbg_format_parse.h" -#include "raddbg_stringize.h" +#include "raddbgi_format/raddbgi_format.h" +#include "raddbgi_format/raddbgi_format_parse.h" +#include "raddbgi_stringize.h" -#include "raddbg_dump.h" +#include "raddbgi_dump.h" #include "base/base_inc.c" #include "os/os_inc.c" -#include "raddbg_format/raddbg_format.c" -#include "raddbg_format/raddbg_format_parse.c" -#include "raddbg_stringize.c" +#include "raddbgi_format/raddbgi_format.c" +#include "raddbgi_format/raddbgi_format_parse.c" +#include "raddbgi_stringize.c" //////////////////////////////// //~ Program Parameters Parser diff --git a/src/raddbg_dump/raddbg_dump.h b/src/raddbgi_dump/raddbgi_dump.h similarity index 100% rename from src/raddbg_dump/raddbg_dump.h rename to src/raddbgi_dump/raddbgi_dump.h diff --git a/src/raddbg_dump/raddbg_stringize.c b/src/raddbgi_dump/raddbgi_stringize.c similarity index 100% rename from src/raddbg_dump/raddbg_stringize.c rename to src/raddbgi_dump/raddbgi_stringize.c diff --git a/src/raddbg_dump/raddbg_stringize.h b/src/raddbgi_dump/raddbgi_stringize.h similarity index 100% rename from src/raddbg_dump/raddbg_stringize.h rename to src/raddbgi_dump/raddbgi_stringize.h diff --git a/src/raddbg_format/raddbg_format.c b/src/raddbgi_format/raddbgi_format.c similarity index 100% rename from src/raddbg_format/raddbg_format.c rename to src/raddbgi_format/raddbgi_format.c diff --git a/src/raddbg_format/raddbg_format.h b/src/raddbgi_format/raddbgi_format.h similarity index 100% rename from src/raddbg_format/raddbg_format.h rename to src/raddbgi_format/raddbgi_format.h diff --git a/src/raddbg_format/raddbg_format_parse.c b/src/raddbgi_format/raddbgi_format_parse.c similarity index 100% rename from src/raddbg_format/raddbg_format_parse.c rename to src/raddbgi_format/raddbgi_format_parse.c diff --git a/src/raddbg_format/raddbg_format_parse.h b/src/raddbgi_format/raddbgi_format_parse.h similarity index 100% rename from src/raddbg_format/raddbg_format_parse.h rename to src/raddbgi_format/raddbgi_format_parse.h diff --git a/src/regs/raddbg/generated/regs_raddbg.meta.c b/src/regs/raddbgi/generated/regs_raddbgi.meta.c similarity index 100% rename from src/regs/raddbg/generated/regs_raddbg.meta.c rename to src/regs/raddbgi/generated/regs_raddbgi.meta.c diff --git a/src/regs/raddbg/generated/regs_raddbg.meta.h b/src/regs/raddbgi/generated/regs_raddbgi.meta.h similarity index 100% rename from src/regs/raddbg/generated/regs_raddbg.meta.h rename to src/regs/raddbgi/generated/regs_raddbgi.meta.h diff --git a/src/regs/raddbg/regs_raddbg.c b/src/regs/raddbgi/regs_raddbgi.c similarity index 67% rename from src/regs/raddbg/regs_raddbg.c rename to src/regs/raddbgi/regs_raddbgi.c index 399ec8d3..b72739f4 100644 --- a/src/regs/raddbg/regs_raddbg.c +++ b/src/regs/raddbgi/regs_raddbgi.c @@ -1,4 +1,4 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#include "regs/raddbg/generated/regs_raddbg.meta.c" +#include "regs/raddbgi/generated/regs_raddbgi.meta.c" diff --git a/src/regs/raddbg/regs_raddbg.h b/src/regs/raddbgi/regs_raddbgi.h similarity index 100% rename from src/regs/raddbg/regs_raddbg.h rename to src/regs/raddbgi/regs_raddbgi.h diff --git a/src/regs/raddbg/regs_raddbg.mc b/src/regs/raddbgi/regs_raddbgi.mc similarity index 100% rename from src/regs/raddbg/regs_raddbg.mc rename to src/regs/raddbgi/regs_raddbgi.mc diff --git a/src/scratch/look_at_raddbg.c b/src/scratch/look_at_raddbg.c index 9e3c7313..ce6d9129 100644 --- a/src/scratch/look_at_raddbg.c +++ b/src/scratch/look_at_raddbg.c @@ -6,10 +6,10 @@ #include #include -#include "raddbg_format/raddbg_format.h" -#include "raddbg_format/raddbg_format_parse.h" -#include "raddbg_format/raddbg_format.c" -#include "raddbg_format/raddbg_format_parse.c" +#include "raddbgi_format/raddbgi_format.h" +#include "raddbgi_format/raddbgi_format_parse.h" +#include "raddbgi_format/raddbgi_format.c" +#include "raddbgi_format/raddbgi_format_parse.c" int main(int argument_count, char **arguments) {