next checkpoint on dwarf cleanup

This commit is contained in:
Ryan Fleury
2025-11-10 16:37:23 -08:00
parent f396b2eaa3
commit 08642d2745
9 changed files with 387 additions and 403 deletions
+20 -20
View File
@@ -611,19 +611,19 @@ typedef enum Arch
Arch_arm64,
Arch_arm32,
Arch_COUNT,
#if ARCH_X64
Arch_CURRENT = Arch_x64,
#elif ARCH_X86
Arch_CURRENT = Arch_x86,
#elif ARCH_ARM64
Arch_CURRENT = Arch_arm64,
#elif ARCH_ARM32
Arch_CURRENT = Arch_arm32,
#else
Arch_CURRENT = Arch_Null,
#endif
}
Arch;
#if ARCH_X64
# define Arch_CURRENT Arch_x64
#elif ARCH_X86
# define Arch_CURRENT Arch_x86
#elif ARCH_ARM64
# define Arch_CURRENT Arch_arm64
#elif ARCH_ARM32
# define Arch_CURRENT Arch_arm32
#else
# define Arch_CURRENT Arch_Null
#endif
typedef enum Compiler
{
@@ -632,17 +632,17 @@ typedef enum Compiler
Compiler_gcc,
Compiler_clang,
Compiler_COUNT,
#if COMPILER_MSVC
Compiler_CURRENT = Compiler_msvc,
#elif COMPILER_GCC
Compiler_CURRENT = Compiler_gcc,
#elif COMPILER_CLANG
Compiler_CURRENT = Compiler_clang,
#else
Compiler_CURRENT = Compiler_Null,
#endif
}
Compiler;
#if COMPILER_MSVC
# define Compiler_CURRENT Compiler_msvc
#elif COMPILER_GCC
# define Compiler_CURRENT Compiler_gcc
#elif COMPILER_CLANG
# define Compiler_CURRENT Compiler_clang
#else
# define Compiler_CURRENT Compiler_Null
#endif
////////////////////////////////
//~ rjf: Text 2D Coordinates & Ranges
+72 -70
View File
@@ -73,10 +73,10 @@ internal U64
dw_reg_count_from_arch(Arch arch)
{
switch (arch) {
default: { NotImplemented; } // fall-through
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Last;
case Arch_x64: return DW_RegX64_Last;
default: { NotImplemented; } // fall-through
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Last;
case Arch_x64: return DW_RegX64_Last;
}
}
@@ -98,10 +98,10 @@ internal U64
dw_sp_from_arch(Arch arch)
{
switch (arch) {
default: NotImplemented;
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Esp;
case Arch_x64: return DW_RegX64_Rsp;
default: NotImplemented;
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Esp;
case Arch_x64: return DW_RegX64_Rsp;
}
}
@@ -278,58 +278,64 @@ internal B32
dw_are_attrib_class_and_form_kind_compatible(DW_Version ver, DW_AttribClass attrib_class, DW_FormKind form_kind)
{
DW_AttribClass compat_flags = dw_attrib_class_from_form_kind(ver, form_kind);
B32 are_compat = (attrib_class & compat_flags) != 0;
B32 are_compat = (attrib_class & compat_flags) != 0;
return are_compat;
}
internal String8
dw_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_L);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_L);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal String8
dw_mach_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_M);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_M);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal String8
dw_dwo_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_D);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_D);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal U64
dw_size_from_format(DW_Format format)
{
U64 result = 0;
switch (format) {
case DW_Format_Null: break;
switch(format)
{
default:{}break;
case DW_Format_32Bit: result = 4; break;
case DW_Format_64Bit: result = 8; break;
default: InvalidPath; break;
}
return result;
}
internal DW_AttribClass
dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib_kind, DW_FormKind form_kind)
dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib_kind, DW_FormKind form_kind)
{
// NOTE(rjf): DWARF's spec specifies two mappings:
// (DW_AttribKind) => List(DW_AttribClass)
@@ -340,14 +346,10 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKin
DW_AttribClass attrib_class = dw_attrib_class_from_attrib(ver, ext, attrib_kind);
DW_AttribClass form_class = dw_attrib_class_from_form_kind(ver, form_kind);
if(relaxed)
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
{
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
{
attrib_class = dw_attrib_class_from_attrib(DW_Version_Last, ext, attrib_kind);
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
}
attrib_class = dw_attrib_class_from_attrib(DW_Version_Last, ext, attrib_kind);
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
}
DW_AttribClass result = DW_AttribClass_Null;
@@ -428,11 +430,11 @@ dw_operand_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _OPER_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -443,11 +445,11 @@ dw_pop_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _POP_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -458,11 +460,11 @@ dw_push_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _PUSH_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -474,7 +476,7 @@ dw_operand_count_from_cfa_opcode(DW_CFA_Opcode opcode)
#define X(_N, _ID, ...) case _ID: { local_persist DW_CFA_OperandType t[] = { DW_CFA_OperandType_Null, __VA_ARGS__ }; return ArrayCount(t)-1; }
DW_CFA_Kind_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -484,21 +486,21 @@ dw_is_cfa_expr_opcode_invalid(DW_ExprOp opcode)
{
B32 is_invalid = 0;
switch (opcode) {
case DW_ExprOp_Addrx:
case DW_ExprOp_Call2:
case DW_ExprOp_Call4:
case DW_ExprOp_CallRef:
case DW_ExprOp_ConstType:
case DW_ExprOp_Constx:
case DW_ExprOp_Convert:
case DW_ExprOp_DerefType:
case DW_ExprOp_RegvalType:
case DW_ExprOp_Reinterpret:
case DW_ExprOp_PushObjectAddress:
case DW_ExprOp_CallFrameCfa: {
is_invalid = 1;
} break;
default: break;
case DW_ExprOp_Addrx:
case DW_ExprOp_Call2:
case DW_ExprOp_Call4:
case DW_ExprOp_CallRef:
case DW_ExprOp_ConstType:
case DW_ExprOp_Constx:
case DW_ExprOp_Convert:
case DW_ExprOp_DerefType:
case DW_ExprOp_RegvalType:
case DW_ExprOp_Reinterpret:
case DW_ExprOp_PushObjectAddress:
case DW_ExprOp_CallFrameCfa: {
is_invalid = 1;
} break;
default: break;
}
return is_invalid;
}
@@ -508,14 +510,14 @@ dw_is_new_row_cfa_opcode(DW_CFA_Opcode opcode)
{
B32 is_new_row_op = 0;
switch (opcode) {
case DW_CFA_SetLoc:
case DW_CFA_AdvanceLoc:
case DW_CFA_AdvanceLoc1:
case DW_CFA_AdvanceLoc2:
case DW_CFA_AdvanceLoc4: {
is_new_row_op = 1;
} break;
default: break;
case DW_CFA_SetLoc:
case DW_CFA_AdvanceLoc:
case DW_CFA_AdvanceLoc1:
case DW_CFA_AdvanceLoc2:
case DW_CFA_AdvanceLoc4: {
is_new_row_op = 1;
} break;
default: break;
}
return is_new_row_op;
}
@@ -527,7 +529,7 @@ dw_operand_types_from_cfa_op(DW_CFA_Opcode opcode)
#define X(_N, _ID, ...) case _ID: { local_persist DW_CFA_OperandType t[] = { DW_CFA_OperandType_Null, __VA_ARGS__ }; return &t[0] + 1; }
DW_CFA_Kind_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -539,9 +541,9 @@ internal String8
dw_string_from_format(DW_Format format)
{
switch (format) {
case DW_Format_Null: return str8_zero();
case DW_Format_32Bit: return str8_lit("DWARF32");
case DW_Format_64Bit: return str8_lit("DWARF64");
case DW_Format_Null: return str8_zero();
case DW_Format_32Bit: return str8_lit("DWARF32");
case DW_Format_64Bit: return str8_lit("DWARF64");
}
return str8_zero();
}
@@ -824,7 +826,7 @@ dw_string_from_cfa_opcode(DW_CFA_Opcode opcode)
#define X(_NAME, _ID, ...) case _ID: return str8_lit(Stringify(_NAME));
DW_CFA_Kind_XList(X)
#undef X
default: InvalidPath; break;
default: InvalidPath; break;
}
return str8_zero();
}
+1 -1
View File
@@ -1782,7 +1782,7 @@ internal U64 dw_size_from_format(DW_Format format);
////////////////////////////////
internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib, DW_FormKind form_kind);
internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib, DW_FormKind form_kind);
internal U64 dw_pick_default_lower_bound(DW_Language lang);
+4 -20
View File
@@ -1,13 +1,6 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64
dw_hash_from_string(String8 string)
{
XXH64_hash_t hash64 = XXH3_64bits(string.str, string.size);
return hash64;
}
internal U64
str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out)
{
@@ -58,20 +51,16 @@ str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out)
U64 cursor = off;
for(;;)
{
U8 byte = 0;
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
break;
@@ -93,19 +82,16 @@ str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out)
U64 cursor = off;
for(;;)
{
U8 byte;
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
if(shift < sizeof(value) * 8 && (byte & 0x40u) != 0)
@@ -1678,7 +1664,7 @@ dw_interp_loclists_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form)
internal DW_AttribClass
dw_value_class_from_attrib(DW_CompUnit *cu, DW_Attrib *attrib)
{
return dw_pick_attrib_value_class(cu->version, cu->ext, cu->relaxed, attrib->attrib_kind, attrib->form_kind);
return dw_pick_attrib_value_class(cu->version, cu->ext, attrib->attrib_kind, attrib->form_kind);
}
internal String8
@@ -2163,7 +2149,6 @@ dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U6
U64 low_pc = dw_interp_address(address_size, max_U64, addr_lu, low_pc_attrib->form_kind, low_pc_attrib->form);
// fill out compile unit
cu.relaxed = relaxed;
cu.ext = DW_Ext_All;
cu.kind = unit_kind;
cu.version = version;
@@ -3027,7 +3012,6 @@ dw_parsed_line_table_from_data(Arena *arena, String8 unit_data, DW_Input *input,
//
// See the DWARF V4 spec (June 10, 2010), page 122.
error = 1;
// AssertAlways(!"UNHANDLED DEFINE FILE!!!");
}break;
case DW_ExtOpcode_SetDiscriminator:
@@ -3103,7 +3087,7 @@ dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_Sect
String8 string = {0};
cursor += str8_deserial_read_cstr(section_data, cursor, &string);
U64 hash = dw_hash_from_string(string);
U64 hash = u64_hash_from_str8(string);
U64 bucket_idx = hash % names_table.size;
DW_PubStringsBucket *bucket = push_array(arena, DW_PubStringsBucket, 1);
+94 -82
View File
@@ -4,54 +4,59 @@
#ifndef DWARF_PARSE_H
#define DWARF_PARSE_H
typedef struct DW_Section
typedef struct DW_Section DW_Section;
struct DW_Section
{
String8 name;
String8 data;
B32 is_dwo;
} DW_Section;
};
typedef struct DW_Input
typedef struct DW_Input DW_Input;
struct DW_Input
{
DW_Section sec[DW_Section_Count];
DW_Section sup[DW_Section_Count];
} DW_Input;
};
typedef struct DW_ListUnit
typedef struct DW_ListUnit DW_ListUnit;
struct DW_ListUnit
{
DW_Version version;
U64 address_size;
U64 segment_selector_size;
U64 entry_size;
String8 entries;
} DW_ListUnit;
U64 address_size;
U64 segment_selector_size;
U64 entry_size;
String8 entries;
};
typedef struct DW_ListUnitInput
typedef struct DW_ListUnitInput DW_ListUnitInput;
struct DW_ListUnitInput
{
U64 addr_count;
U64 str_offset_count;
U64 rnglist_count;
U64 loclist_count;
Rng1U64Array addr_ranges;
Rng1U64Array str_offset_ranges;
Rng1U64Array rnglist_ranges;
Rng1U64Array loclist_ranges;
DW_ListUnit *addrs;
DW_ListUnit *str_offsets;
DW_ListUnit *rnglists;
DW_ListUnit *loclists;
} DW_ListUnitInput;
U64 addr_count;
U64 str_offset_count;
U64 rnglist_count;
U64 loclist_count;
Rng1U64Array addr_ranges;
Rng1U64Array str_offset_ranges;
Rng1U64Array rnglist_ranges;
Rng1U64Array loclist_ranges;
DW_ListUnit *addrs;
DW_ListUnit *str_offsets;
DW_ListUnit *rnglists;
DW_ListUnit *loclists;
};
typedef struct DW_AbbrevTableEntry
typedef struct DW_AbbrevTableEntry DW_AbbrevTableEntry;
struct DW_AbbrevTableEntry
{
U64 id;
U64 off;
} DW_AbbrevTableEntry;
};
typedef struct DW_AbbrevTable DW_AbbrevTable;
struct DW_AbbrevTable
{
U64 count;
U64 count;
DW_AbbrevTableEntry *entries;
};
@@ -63,7 +68,8 @@ typedef enum DW_AbbrevKind
DW_Abbrev_AttribSequenceEnd,
DW_Abbrev_DIEBegin,
DW_Abbrev_DIEEnd,
} DW_AbbrevKind;
}
DW_AbbrevKind;
typedef U32 DW_AbbrevFlags;
enum
@@ -72,14 +78,15 @@ enum
DW_AbbrevFlag_HasChildren = (1 << 1),
};
typedef struct DW_Abbrev
typedef struct DW_Abbrev DW_Abbrev;
struct DW_Abbrev
{
DW_AbbrevKind kind;
U64 sub_kind;
U64 id;
U64 const_value;
DW_AbbrevKind kind;
U64 sub_kind;
U64 id;
U64 const_value;
DW_AbbrevFlags flags;
} DW_Abbrev;
};
typedef union DW_Form
{
@@ -100,71 +107,80 @@ typedef union DW_Form
U64 rnglistx;
U64 ptr;
U64 implicit_const;
} DW_Form;
}
DW_Form;
typedef struct DW_Attrib
typedef struct DW_Attrib DW_Attrib;
struct DW_Attrib
{
U64 info_off;
U64 abbrev_off;
U64 abbrev_id;
DW_AttribKind attrib_kind;
DW_FormKind form_kind;
DW_Form form;
} DW_Attrib;
U64 info_off;
U64 abbrev_off;
U64 abbrev_id;
DW_AttribKind attrib_kind;
DW_FormKind form_kind;
DW_Form form;
};
typedef struct DW_AttribNode
typedef struct DW_AttribNode DW_AttribNode;
struct DW_AttribNode
{
struct DW_AttribNode *next;
DW_Attrib v;
} DW_AttribNode;
DW_AttribNode *next;
DW_Attrib v;
};
typedef struct DW_AttribList
typedef struct DW_AttribList DW_AttribList;
struct DW_AttribList
{
DW_AttribNode *first;
DW_AttribNode *last;
U64 count;
} DW_AttribList;
U64 count;
};
typedef struct DW_Tag
typedef struct DW_Tag DW_Tag;
struct DW_Tag
{
B32 has_children;
U64 abbrev_id;
DW_TagKind kind;
DW_AttribList attribs;
U64 info_off;
U8 v[1];
} DW_Tag;
B32 has_children;
U64 abbrev_id;
DW_TagKind kind;
DW_AttribList attribs;
U64 info_off;
U8 v[1];
};
typedef struct DW_TagNode
typedef struct DW_TagNode DW_TagNode;
struct DW_TagNode
{
DW_Tag tag;
struct DW_TagNode *sibling;
struct DW_TagNode *first_child;
struct DW_TagNode *last_child;
} DW_TagNode;
DW_Tag tag;
DW_TagNode *sibling;
DW_TagNode *first_child;
DW_TagNode *last_child;
};
typedef struct DW_Loc
typedef struct DW_Loc DW_Loc;
struct DW_Loc
{
Rng1U64 range;
String8 expr;
} DW_Loc;
};
typedef struct DW_LocNode
typedef struct DW_LocNode DW_LocNode;
struct DW_LocNode
{
DW_Loc v;
struct DW_LocNode *next;
} DW_LocNode;
DW_LocNode *next;
DW_Loc v;
};
typedef struct DW_LocList
typedef struct DW_LocList DW_LocList;
struct DW_LocList
{
U64 count;
DW_LocNode *first;
DW_LocNode *last;
} DW_LocList;
U64 count;
};
typedef struct DW_CompUnit
typedef struct DW_CompUnit DW_CompUnit;
struct DW_CompUnit
{
B32 relaxed;
DW_Ext ext;
DW_CompUnitKind kind;
DW_Version version;
@@ -183,7 +199,7 @@ typedef struct DW_CompUnit
U64 dwo_id;
DW_Tag tag;
HashTable *tag_ht;
} DW_CompUnit;
};
typedef struct DW_TagTree
{
@@ -328,12 +344,12 @@ typedef union DW_ExprOperand
U16 u16;
U32 u32;
U64 u64;
S8 s8;
S16 s16;
S32 s32;
S64 s64;
String8 block;
} DW_ExprOperand;
@@ -431,10 +447,6 @@ typedef struct DW_CFA_InstList
#define DW_DECODE_PTR(name) U64 name(String8 data, void *ud, U64 *ptr_out)
typedef DW_DECODE_PTR(DW_DecodePtr);
// hasher
internal U64 dw_hash_from_string(String8 string);
// deserial helpers
internal U64 str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out);
+170 -159
View File
@@ -1596,25 +1596,26 @@ d2r_push_scope(Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D
////////////////////////////////
//~ Tag Iterator
internal D2R_TagIterator *
d2r_tag_iterator_init(Arena *arena, DW_TagNode *root)
internal D2R_TagIter *
d2r_tag_iter_init(Arena *arena, DW_TagNode *root)
{
D2R_TagIterator *iter = push_array(arena, D2R_TagIterator, 1);
iter->free_list = 0;
iter->stack = push_array(arena, D2R_TagFrame, 1);
iter->stack->node = push_array(arena, DW_TagNode, 1);
D2R_TagIter *iter = push_array(arena, D2R_TagIter, 1);
iter->free_list = 0;
iter->stack = push_array(arena, D2R_TagFrame, 1);
iter->stack->node = push_array(arena, DW_TagNode, 1);
if(root != 0)
{
*iter->stack->node = *root;
*iter->stack->node = *root;
}
iter->stack->node->sibling = 0;
iter->visit_children = 1;
iter->tag_node = root;
iter->visit_children = 1;
iter->tag_node = root;
iter->root = root;
return iter;
}
internal void
d2r_tag_iterator_next(Arena *arena, D2R_TagIterator *iter)
d2r_tag_iter_next(Arena *arena, D2R_TagIter *iter)
{
// descend to first child
if (iter->visit_children) {
@@ -1643,24 +1644,30 @@ d2r_tag_iterator_next(Arena *arena, D2R_TagIterator *iter)
// update iterator
iter->visit_children = 1;
iter->tag_node = iter->stack ? iter->stack->node : 0;
// rjf: exit on root
if(iter->tag_node == iter->root)
{
iter->tag_node = 0;
}
}
internal void
d2r_tag_iterator_skip_children(D2R_TagIterator *iter)
d2r_tag_iter_skip_children(D2R_TagIter *iter)
{
iter->visit_children = 0;
}
internal DW_TagNode *
d2r_tag_iterator_parent_tag_node(D2R_TagIterator *iter)
d2r_tag_iter_parent_tag_node(D2R_TagIter *iter)
{
return iter->stack->next->node;
}
internal DW_Tag
d2r_tag_iterator_parent_tag(D2R_TagIterator *iter)
d2r_tag_iter_parent_tag(D2R_TagIter *iter)
{
DW_TagNode *tag_node = d2r_tag_iterator_parent_tag_node(iter);
DW_TagNode *tag_node = d2r_tag_iter_parent_tag_node(iter);
return tag_node->tag;
}
@@ -1723,18 +1730,12 @@ d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *inpu
}
internal void
d2r_convert_types(Arena *arena,
D2R_TypeTable *type_table,
DW_Input *input,
DW_CompUnit *cu,
DW_Language cu_lang,
U64 arch_addr_size,
DW_TagNode *root)
d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root)
{
Temp scratch = scratch_begin(&arena, 1);
for(D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root);
for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root);
it->tag_node != 0;
d2r_tag_iterator_next(scratch.arena, it))
d2r_tag_iter_next(scratch.arena, it))
{
DW_TagNode *tag_node = it->tag_node;
DW_Tag tag = tag_node->tag;
@@ -1742,7 +1743,7 @@ d2r_convert_types(Arena *arena,
// skip converted tags
if(d2r_is_tag_converted(tag_node))
{
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
continue;
}
@@ -1759,7 +1760,7 @@ d2r_convert_types(Arena *arena,
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->kind = RDI_TypeKind_IncompleteClass;
type->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}
else
{
@@ -1780,7 +1781,7 @@ d2r_convert_types(Arena *arena,
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
type->kind = RDI_TypeKind_IncompleteStruct;
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}
else
{
@@ -1799,7 +1800,7 @@ d2r_convert_types(Arena *arena,
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
type->kind = RDI_TypeKind_IncompleteUnion;
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}
else
{
@@ -1818,7 +1819,7 @@ d2r_convert_types(Arena *arena,
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
type->kind = RDI_TypeKind_IncompleteEnum;
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}
else
{
@@ -1857,7 +1858,7 @@ d2r_convert_types(Arena *arena,
type->count = param_list.count;
type->param_types = rdim_array_from_type_list(arena, param_list);
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}break;
case DW_TagKind_Typedef:
@@ -1877,107 +1878,92 @@ d2r_convert_types(Arena *arena,
case DW_TagKind_BaseType:
{
DW_ATE encoding = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Encoding);
U64 byte_size = dw_byte_size_from_tag(input, cu, tag);
DW_ATE encoding = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Encoding);
U64 byte_size = dw_byte_size_from_tag(input, cu, tag);
// convert base type encoding to RDI version
// rjf: attribute type encoding -> RDI type kind
RDI_TypeKind kind = RDI_TypeKind_NULL;
switch (encoding) {
case DW_ATE_Null: kind = RDI_TypeKind_NULL; break;
case DW_ATE_Address: kind = RDI_TypeKind_Void; break;
case DW_ATE_Boolean: kind = RDI_TypeKind_Bool; break;
case DW_ATE_ComplexFloat: {
switch (byte_size) {
case 4: kind = RDI_TypeKind_ComplexF32; break;
case 8: kind = RDI_TypeKind_ComplexF64; break;
case 10: kind = RDI_TypeKind_ComplexF80; break;
case 16: kind = RDI_TypeKind_ComplexF128; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_Float: {
switch (byte_size) {
case 2: kind = RDI_TypeKind_F16; break;
case 4: kind = RDI_TypeKind_F32; break;
case 6: kind = RDI_TypeKind_F48; break;
case 8: kind = RDI_TypeKind_F64; break;
case 16: kind = RDI_TypeKind_F128; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_Signed: {
switch (byte_size) {
case 1: kind = RDI_TypeKind_S8; break;
case 2: kind = RDI_TypeKind_S16; break;
case 4: kind = RDI_TypeKind_S32; break;
case 8: kind = RDI_TypeKind_S64; break;
case 16: kind = RDI_TypeKind_S128; break;
case 32: kind = RDI_TypeKind_S256; break;
case 64: kind = RDI_TypeKind_S512; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_SignedChar: {
switch (byte_size) {
case 1: kind = RDI_TypeKind_Char8; break;
case 2: kind = RDI_TypeKind_Char16; break;
case 4: kind = RDI_TypeKind_Char32; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_Unsigned: {
switch (byte_size) {
case 1: kind = RDI_TypeKind_U8; break;
case 2: kind = RDI_TypeKind_U16; break;
case 4: kind = RDI_TypeKind_U32; break;
case 8: kind = RDI_TypeKind_U64; break;
case 16: kind = RDI_TypeKind_U128; break;
case 32: kind = RDI_TypeKind_U256; break;
case 64: kind = RDI_TypeKind_U512; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_UnsignedChar: {
switch (byte_size) {
case 1: kind = RDI_TypeKind_UChar8; break;
case 2: kind = RDI_TypeKind_UChar16; break;
case 4: kind = RDI_TypeKind_UChar32; break;
default: AssertAlways(!"unexpected size"); break; // TODO: error handling
}
} break;
case DW_ATE_ImaginaryFloat: {
NotImplemented;
} break;
case DW_ATE_PackedDecimal: {
NotImplemented;
} break;
case DW_ATE_NumericString: {
NotImplemented;
} break;
case DW_ATE_Edited: {
NotImplemented;
} break;
case DW_ATE_SignedFixed: {
NotImplemented;
} break;
case DW_ATE_UnsignedFixed: {
NotImplemented;
} break;
case DW_ATE_DecimalFloat: {
NotImplemented;
} break;
case DW_ATE_Utf: {
NotImplemented;
} break;
case DW_ATE_Ucs: {
NotImplemented;
} break;
case DW_ATE_Ascii: {
NotImplemented;
} break;
default: AssertAlways(!"unexpected base type encoding"); break; // TODO: error handling
switch(encoding)
{
default:{}break;
case DW_ATE_Null: {kind = RDI_TypeKind_NULL;}break;
case DW_ATE_Boolean: {kind = RDI_TypeKind_Bool;}break;
case DW_ATE_ComplexFloat:
switch(byte_size)
{
case 4: {kind = RDI_TypeKind_ComplexF32;}break;
case 8: {kind = RDI_TypeKind_ComplexF64;}break;
case 10: {kind = RDI_TypeKind_ComplexF80;}break;
case 16: {kind = RDI_TypeKind_ComplexF128;}break;
default: {log_infof("Unsupported complex float size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_Float:
switch(byte_size)
{
case 2: {kind = RDI_TypeKind_F16; }break;
case 4: {kind = RDI_TypeKind_F32; }break;
case 6: {kind = RDI_TypeKind_F48; }break;
case 8: {kind = RDI_TypeKind_F64; }break;
case 16: {kind = RDI_TypeKind_F128;}break;
default: {log_infof("Unsupported float size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_Signed:
switch(byte_size)
{
case 1: {kind = RDI_TypeKind_S8; }break;
case 2: {kind = RDI_TypeKind_S16; }break;
case 4: {kind = RDI_TypeKind_S32; }break;
case 8: {kind = RDI_TypeKind_S64; }break;
case 16: {kind = RDI_TypeKind_S128;}break;
case 32: {kind = RDI_TypeKind_S256;}break;
case 64: {kind = RDI_TypeKind_S512;}break;
default: {log_infof("Unsupported signed integer size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_SignedChar:
switch(byte_size)
{
case 1: {kind = RDI_TypeKind_Char8; }break;
case 2: {kind = RDI_TypeKind_Char16;}break;
case 4: {kind = RDI_TypeKind_Char32;}break;
default:{log_infof("Unsupported signed character size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_Address:
case DW_ATE_Unsigned:
switch(byte_size)
{
case 1: {kind = RDI_TypeKind_U8; }break;
case 2: {kind = RDI_TypeKind_U16; }break;
case 4: {kind = RDI_TypeKind_U32; }break;
case 8: {kind = RDI_TypeKind_U64; }break;
case 16: {kind = RDI_TypeKind_U128;}break;
case 32: {kind = RDI_TypeKind_U256;}break;
case 64: {kind = RDI_TypeKind_U512;}break;
default:{log_infof("Unsupported unsigned integer size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_UnsignedChar:
switch(byte_size)
{
case 1: {kind = RDI_TypeKind_UChar8; }break;
case 2: {kind = RDI_TypeKind_UChar16;}break;
case 4: {kind = RDI_TypeKind_UChar32;}break;
default:{log_infof("Unsupported unsigned character size (%I64u) at 0x%I64x.\n", byte_size, tag.info_off);}break;
}break;
case DW_ATE_ImaginaryFloat:
case DW_ATE_PackedDecimal:
case DW_ATE_NumericString:
case DW_ATE_Edited:
case DW_ATE_SignedFixed:
case DW_ATE_UnsignedFixed:
case DW_ATE_DecimalFloat:
case DW_ATE_Utf:
case DW_ATE_Ucs:
case DW_ATE_Ascii:
{
// TODO(rjf): not implemented
}break;
}
// rjf: build
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->kind = RDI_TypeKind_Alias;
type->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
@@ -1998,9 +1984,7 @@ d2r_convert_types(Arena *arena,
Assert(!dw_tag_has_attrib(input, cu, tag, DW_AttribKind_AddressClass));
U64 byte_size = arch_addr_size;
if (cu->version == DW_Version_5 || cu->relaxed) {
dw_try_byte_size_from_tag(input, cu, tag, &byte_size);
}
dw_try_byte_size_from_tag(input, cu, tag, &byte_size);
RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off);
type->kind = RDI_TypeKind_Ptr;
@@ -2126,7 +2110,7 @@ d2r_convert_types(Arena *arena,
direct_type = t;
}
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}break;
case DW_TagKind_SubrangeType:
@@ -2137,7 +2121,7 @@ d2r_convert_types(Arena *arena,
case DW_TagKind_Inheritance:
{
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if (parent_tag.kind != DW_TagKind_StructureType && parent_tag.kind != DW_TagKind_ClassType) {
// TODO: error handling
AssertAlways(!"unexpected parent tag");
@@ -2169,14 +2153,17 @@ d2r_convert_udts(Arena *arena,
DW_TagNode *root)
{
Temp scratch = scratch_begin(&arena, 1);
for (D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root); it->tag_node != 0; d2r_tag_iterator_next(scratch.arena, it)) {
for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root);
it->tag_node != 0;
d2r_tag_iter_next(scratch.arena, it))
{
DW_TagNode *tag_node = it->tag_node;
DW_Tag tag = tag_node->tag;
switch (tag.kind) {
case DW_TagKind_ClassType: {
B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration);
if (is_decl) {
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
} else {
RDIM_Type *type = d2r_type_from_offset(type_table, tag.info_off);
RDIM_UDT *udt = rdim_udt_chunk_list_push(arena, &udts, UDT_CHUNK_CAP);
@@ -2187,7 +2174,7 @@ d2r_convert_udts(Arena *arena,
case DW_TagKind_StructureType: {
B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration);
if (is_decl) {
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
} else {
RDIM_Type *type = d2r_type_from_offset(type_table, tag.info_off);
RDIM_UDT *udt = rdim_udt_chunk_list_push(arena, &udts, UDT_CHUNK_CAP);
@@ -2198,7 +2185,7 @@ d2r_convert_udts(Arena *arena,
case DW_TagKind_UnionType: {
B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration);
if (is_decl) {
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
} else {
RDIM_Type *type = d2r_type_from_offset(type_table, tag.info_off);
RDIM_UDT *udt = rdim_udt_chunk_list_push(arena, &udts, UDT_CHUNK_CAP);
@@ -2209,7 +2196,7 @@ d2r_convert_udts(Arena *arena,
case DW_TagKind_EnumerationType: {
B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration);
if (is_decl) {
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
} else {
RDIM_Type *type = d2r_type_from_offset(type_table, tag.info_off);
RDIM_UDT *udt = rdim_udt_chunk_list_push(arena, &udts, UDT_CHUNK_CAP);
@@ -2218,7 +2205,7 @@ d2r_convert_udts(Arena *arena,
}
} break;
case DW_TagKind_Member: {
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
B32 is_parent_udt = parent_tag.kind == DW_TagKind_StructureType ||
parent_tag.kind == DW_TagKind_ClassType ||
parent_tag.kind == DW_TagKind_UnionType;
@@ -2241,7 +2228,7 @@ d2r_convert_udts(Arena *arena,
}
} break;
case DW_TagKind_Enumerator: {
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if (parent_tag.kind == DW_TagKind_EnumerationType) {
RDIM_Type *parent_type = d2r_type_from_offset(type_table, parent_tag.info_off);
RDIM_UDTEnumVal *udt_member = rdim_udt_push_enum_val(arena, &udts, parent_type->udt);
@@ -2258,12 +2245,12 @@ d2r_convert_udts(Arena *arena,
}
internal void
d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_scope, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root)
d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root)
{
Temp scratch = scratch_begin(&arena, 1);
for(D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root);
for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root);
it->tag_node != 0;
d2r_tag_iterator_next(scratch.arena, it))
d2r_tag_iter_next(scratch.arena, it))
{
DW_TagNode *tag_node = it->tag_node;
DW_Tag tag = tag_node->tag;
@@ -2292,7 +2279,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
case DW_TagKind_Enumerator:
case DW_TagKind_Member:
{
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}break;
case DW_TagKind_SubProgram:
@@ -2345,7 +2332,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
proc->location_cases = d2r_locset_from_attrib(arena, &scopes, root_scope, &locations, input, cu, image_base, arch, tag, DW_AttribKind_FrameBase);
// sub program with user-defined parent tag is a method
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if (parent_tag.kind == DW_TagKind_ClassType || parent_tag.kind == DW_TagKind_StructureType) {
RDI_MemberKind member_kind = RDI_MemberKind_NULL;
DW_VirtualityKind virtuality = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Virtuality);
@@ -2371,7 +2358,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
case DW_Inl_DeclaredInlined:
case DW_Inl_Inlined:
{
d2r_tag_iterator_skip_children(it);
d2r_tag_iter_skip_children(it);
}break;
default:{}break;
}
@@ -2417,7 +2404,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
String8 name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
RDIM_Type *type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type);
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if (parent_tag.kind == DW_TagKind_SubProgram ||
parent_tag.kind == DW_TagKind_InlinedSubroutine ||
parent_tag.kind == DW_TagKind_LexicalBlock) {
@@ -2477,7 +2464,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
case DW_TagKind_FormalParameter:
{
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if (parent_tag.kind == DW_TagKind_SubProgram || parent_tag.kind == DW_TagKind_InlinedSubroutine) {
RDIM_Scope *scope = it->stack->next->scope;
RDIM_Local *param = rdim_scope_push_local(arena, &scopes, scope);
@@ -2494,7 +2481,7 @@ d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_
case DW_TagKind_LexicalBlock:
{
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
DW_Tag parent_tag = d2r_tag_iter_parent_tag(it);
if(parent_tag.kind == DW_TagKind_SubProgram ||
parent_tag.kind == DW_TagKind_InlinedSubroutine ||
parent_tag.kind == DW_TagKind_LexicalBlock)
@@ -2564,9 +2551,9 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
case ExecutableImageKind_CoffPe:
{
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, params->exe_data);
String8 raw_sections = str8_substr(params->exe_data, pe.section_table_range);
String8 raw_sections = str8_substr(params->exe_data, pe.section_table_range);
COFF_SectionHeader *section_table = str8_deserial_get_raw_ptr(raw_sections, 0, sizeof(COFF_SectionHeader) * pe.section_count);
String8 string_table = str8_substr(params->exe_data, pe.string_table_range);
String8 string_table = str8_substr(params->exe_data, pe.string_table_range);
arch = pe.arch;
image_base = pe.image_base;
binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, params->exe_data, string_table, pe.section_count, section_table);
@@ -2608,12 +2595,38 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
////////////////////////////
//- rjf: unpack input image info
//
top_level_info = rdim_make_top_level_info(params->exe_name, arch, exe_hash, binary_sections);
////////////////////////////
//- rjf: build global scope
//
RDIM_Scope *global_scope = rdim_scope_chunk_list_push(arena, &scopes, SCOPE_CHUNK_CAP);
{
// rjf: base arch -> rdi
RDI_Arch arch_rdi = RDI_Arch_NULL;
switch(arch)
{
case Arch_Null:
case Arch_arm64:
case Arch_arm32:
case Arch_COUNT:
{}break;
case Arch_x64:{arch_rdi = RDI_Arch_X64;}break;
case Arch_x86:{arch_rdi = RDI_Arch_X86;}break;
}
// rjf: binary sections -> voff max
U64 exe_voff_max = 0;
for EachNode(sect_n, RDIM_BinarySectionNode, binary_sections.first)
{
exe_voff_max = Max(exe_voff_max, sect_n->v.voff_opl);
}
// rjf: fill
top_level_info.arch = arch_rdi;
top_level_info.exe_name = params->exe_name;
top_level_info.exe_hash = exe_hash;
top_level_info.voff_max = exe_voff_max;
if(!params->deterministic)
{
// TODO(rjf): top_level_info.guid = ...;
top_level_info.producer_name = str8_lit(BUILD_TITLE_STRING_LITERAL);
}
}
////////////////////////////
//- rjf: parse unit contribution map
@@ -2892,8 +2905,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
RDIM_LineSequence *line_seq = rdim_line_table_push_sequence(arena, &line_tables, cu_line_tables_rdi[cu_idx], src_file, file_voffs, file_line_nums, file_col_nums, file_line_count);
rdim_src_file_push_line_sequence(arena, &src_files, src_file, line_seq);
}
//Assert(line_idx == line_seq->count);
}
}
}
@@ -2912,7 +2923,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
type->byte_size = rdi_size_from_basic_type_kind(type_kind);
builtin_types[type_kind] = type;
}
builtin_types[RDI_TypeKind_Void]->byte_size = arch_addr_size;
builtin_types[RDI_TypeKind_Handle]->byte_size = arch_addr_size;
builtin_types[RDI_TypeKind_Variadic] = rdim_type_chunk_list_push(arena, &types, TYPE_CHUNK_CAP);
builtin_types[RDI_TypeKind_Variadic]->kind = RDI_TypeKind_Variadic;
@@ -2962,7 +2972,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
// convert debug info
d2r_convert_types(arena, type_table, &input, cu, cu_lang, arch_addr_size, tag_tree.root);
d2r_convert_udts(arena, type_table, &input, cu, cu_lang, arch_addr_size, tag_tree.root);
d2r_convert_symbols(arena, type_table, global_scope, &input, cu, cu_lang, arch_addr_size, image_base, arch, tag_tree.root);
d2r_convert_symbols(arena, type_table, &input, cu, cu_lang, arch_addr_size, image_base, arch, tag_tree.root);
RDIM_Rng1U64ChunkList cu_voff_ranges = {0};
if(cu_idx < cu_contrib_map.count)
@@ -2996,6 +3006,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
temp_end(comp_temp);
}
}
}
lane_sync();
RDIM_BakeParams bake_params = {0};
+26 -21
View File
@@ -22,35 +22,40 @@ struct D2R_ConvertParams
////////////////////////////////
//~ rjf: Conversion Helper Types
typedef struct D2R_TypeTable
typedef struct D2R_TypeTable D2R_TypeTable;
struct D2R_TypeTable
{
HashTable *ht;
HashTable *ht;
RDIM_TypeChunkList *types;
U64 type_chunk_cap;
RDIM_Type **builtin_types;
} D2R_TypeTable;
U64 type_chunk_cap;
RDIM_Type **builtin_types;
};
typedef struct D2R_TagFrame
typedef struct D2R_TagFrame D2R_TagFrame;
struct D2R_TagFrame
{
DW_TagNode *node;
RDIM_Scope *scope;
struct D2R_TagFrame *next;
} D2R_TagFrame;
};
typedef struct D2R_TagIterator
typedef struct D2R_TagIter D2R_TagIter;
struct D2R_TagIter
{
D2R_TagFrame *free_list;
D2R_TagFrame *stack;
DW_TagNode *tag_node;
B32 visit_children;
} D2R_TagIterator;
DW_TagNode *tag_node;
DW_TagNode *root;
B32 visit_children;
};
typedef struct D2R_CompUnitContribMap
typedef struct D2R_CompUnitContribMap D2R_CompUnitContribMap;
struct D2R_CompUnitContribMap
{
U64 count;
U64 *info_off_arr;
U64 count;
U64 *info_off_arr;
RDIM_Rng1U64ChunkList *voff_range_arr;
} D2R_CompUnitContribMap;
};
#define D2R_ValueType_IsSigned(x) ((x) == D2R_ValueType_S8 || (x) == D2R_ValueType_S16 || (x) == D2R_ValueType_S32 || (x) == D2R_ValueType_S64 || (x) == D2R_ValueType_S128 || (x) == D2R_ValueType_S256 || (x) == D2R_ValueType_S512)
#define D2R_ValueType_IsUnsigned(x) ((x) == D2R_ValueType_U8 || (x) == D2R_ValueType_U16 || (x) == D2R_ValueType_U32 || (x) == D2R_ValueType_U64 || (x) == D2R_ValueType_U128 || (x) == D2R_ValueType_U256 || (x) == D2R_ValueType_U512)
@@ -150,11 +155,11 @@ internal RDIM_Scope *d2r_push_scope(Arena *arena, RDIM_ScopeChunkList *scopes, U
////////////////////////////////
//~ Tag Iterator
internal D2R_TagIterator * d2r_tag_iterator_init(Arena *arena, DW_TagNode *root);
internal void d2r_tag_iterator_next(Arena *arena, D2R_TagIterator *iter);
internal void d2r_tag_iterator_skip_children(D2R_TagIterator *iter);
internal DW_TagNode * d2r_tag_iterator_parent_tag_node(D2R_TagIterator *iter);
internal DW_Tag d2r_tag_iterator_parent_tag(D2R_TagIterator *iter);
internal D2R_TagIter *d2r_tag_iter_init(Arena *arena, DW_TagNode *root);
internal void d2r_tag_iter_next(Arena *arena, D2R_TagIter *iter);
internal void d2r_tag_iter_skip_children(D2R_TagIter *iter);
internal DW_TagNode * d2r_tag_iter_parent_tag_node(D2R_TagIter *iter);
internal DW_Tag d2r_tag_iter_parent_tag(D2R_TagIter *iter);
////////////////////////////////
//~ Type/UDT/Symbol Conversion
@@ -166,7 +171,7 @@ internal RDIM_Type *d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_t
internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root);
internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_scope, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root);
////////////////////////////////
//~ rjf: Main Conversion Entry Point
-29
View File
@@ -17,35 +17,6 @@ rdim_data_model_from_os_arch(OperatingSystem os, RDI_Arch arch)
return data_model;
}
internal RDIM_TopLevelInfo
rdim_make_top_level_info(String8 image_name, Arch arch, U64 exe_hash, RDIM_BinarySectionList sections)
{
// convert arch
RDI_Arch arch_rdi = RDI_Arch_NULL;
switch(arch)
{
default:{}break;
case Arch_x64:{arch_rdi = RDI_Arch_X64;}break;
case Arch_x86:{arch_rdi = RDI_Arch_X86;}break;
}
// find max VOFF
U64 exe_voff_max = 0;
for EachNode(sect_n, RDIM_BinarySectionNode, sections.first)
{
exe_voff_max = Max(exe_voff_max, sect_n->v.voff_opl);
}
// fill out top level info
RDIM_TopLevelInfo top_level_info = {0};
top_level_info.arch = arch_rdi;
top_level_info.exe_hash = exe_hash;
top_level_info.voff_max = exe_voff_max;
top_level_info.producer_name = str8_lit(BUILD_TITLE_STRING_LITERAL);
return top_level_info;
}
internal RDIM_BakeResults
rdim_bake(Arena *arena, RDIM_BakeParams *params)
{
-1
View File
@@ -161,7 +161,6 @@ struct RDIM_Shared
global RDIM_Shared *rdim_shared = 0;
internal RDIM_DataModel rdim_data_model_from_os_arch(OperatingSystem os, RDI_Arch arch);
internal RDIM_TopLevelInfo rdim_make_top_level_info(String8 image_name, Arch arch, U64 exe_hash, RDIM_BinarySectionList sections);
internal RDIM_BakeResults rdim_bake(Arena *arena, RDIM_BakeParams *params);
internal RDIM_SerializedSectionBundle rdim_compress(Arena *arena, RDIM_SerializedSectionBundle *in);