Skip to content

Commit 5dce5ed

Browse files
committed
sketch out more locals baking stuff, + notes for unit-arrangement pass
1 parent 148b3db commit 5dce5ed

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

src/lib_rdi/rdi.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,10 @@ RDI_MemberKind_NestedType = 0x0300,
387387
typedef RDI_U8 RDI_ContainerKind;
388388
typedef enum RDI_ContainerKindEnum
389389
{
390-
RDI_ContainerKind_Type = 0x0,
391-
RDI_ContainerKind_Scope = 0x1,
392-
RDI_ContainerKind_Namespace = 0x2,
390+
RDI_ContainerKind_Unit = 0x0,
391+
RDI_ContainerKind_Type = 0x1,
392+
RDI_ContainerKind_Scope = 0x2,
393+
RDI_ContainerKind_Namespace = 0x3,
393394
} RDI_ContainerKindEnum;
394395

395396
typedef RDI_U8 RDI_ContainerFlags;

src/raddbg/raddbg_main.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
//~ rjf: post-0.9.20 TODO notes
66
//
77
//- namespace/locations/variables RDI pass
8-
// [ ] RDI_Local, RDI_GlobalVariable, RDI_ThreadVariable -> RDI_Variable
9-
// [ ] RDI_Variable gets RDI_ContainerFlags, and a container_idx
10-
// [ ] RDI_Namespace can be a container, same as types/procedures
11-
// [ ] If procedure-contained, then index goes to scope now, not procedure
12-
// [ ] Location sections -> split by location kind, fixed tables for simple locations, one catch-all table for bytecode.
13-
// [ ] Location kind -> can be thread-local offset, or module virtual offset, to enclose globals/tlocals cases
14-
// [ ] Referring to one location -> kind * index
15-
// [ ] Referring to many locations, based on scope offsets -> kind = BlockList; BlockList encodes a first/opl pair into Block table, each Block has scope_off_first/opl, location_kind, location_idx - but a block's location kind CANNOT BE BlockList
16-
// [ ] RDI_Variable has location_kind, location_idx
8+
// [x] RDI_Local, RDI_GlobalVariable, RDI_ThreadVariable -> RDI_Variable
9+
// [x] RDI_Variable gets RDI_ContainerFlags, and a container_idx
10+
// [x] RDI_Namespace can be a container, same as types/procedures
11+
// [x] If procedure-contained, then index goes to scope now, not procedure
12+
// [x] Location sections -> split by location kind, fixed tables for simple locations, one catch-all table for bytecode.
13+
// [x] Location kind -> can be thread-local offset, or module virtual offset, to enclose globals/tlocals cases
14+
// [x] Referring to one location -> kind * index
15+
// [x] Referring to many locations, based on scope offsets -> kind = BlockList; BlockList encodes a first/opl pair into Block table, each Block has scope_off_first/opl, location_kind, location_idx - but a block's location kind CANNOT BE BlockList
16+
// [x] RDI_Variable has location_kind, location_idx
17+
//
18+
// [ ] we keep flat tables of symbols, *but*, "sort" by containing unit. unit -> [f, opl) of procedures, globals, threadvars, constants, etc.
19+
// [ ] container can also be a unit, so you can also go from procedure/global/tvar -> unit
20+
//
1721
// [ ] symbols only store their *partly-qualified name*, e.g. `x` for A::B::C::x
1822
// [ ] default name maps look up *partly-qualified names*
1923
// [ ] to match a *fully qualified name*, there needs to be a second kind of different lookup - instead of string-matching, we need to match against the *fully qualified names*. the maps must be built by hashing the *fully qualified name*, but redirecting to the symbol with the *partially qualified name*. this is to allow fully-qualified lookups, but avoid storing fully-qualified names.

src/rdi/rdi.mdesk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,10 @@ RDI_EnumMemberTable:
992992
@table(name value)
993993
RDI_ContainerKindTable:
994994
{
995-
{Type 0x0}
996-
{Scope 0x1}
997-
{Namespace 0x2}
995+
{Unit 0x0}
996+
{Type 0x1}
997+
{Scope 0x2}
998+
{Namespace 0x3}
998999
}
9991000

10001001
@table(name value)

src/rdi_from_dwarf/rdi_from_dwarf.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ d2r_locset_from_attrib(Arena *arena,
13591359
for EachNode(loc_n, DW_LocNode, loclist.first) {
13601360
RDIM_Location location = d2r_transpile_expression(arena, input, image_base, arch, cu->addr_lu, cu, loc_n->v.expr);
13611361
RDIM_Rng1U64 voff_range = { .min = loc_n->v.range.min - image_base, .max = loc_n->v.range.max - image_base };
1362-
rdim_push_location_case(arena, scopes, &locset, &location, voff_range);
1362+
rdim_location_case_list_push(arena, &locset, location, voff_range);
13631363
}
13641364

13651365
scratch_end(scratch);
@@ -1370,7 +1370,7 @@ d2r_locset_from_attrib(Arena *arena,
13701370
// convert expression and inherit life-time ranges from enclosed scope
13711371
RDIM_Location location = d2r_transpile_expression(arena, input, image_base, arch, cu->addr_lu, cu, expr);
13721372
for EachNode(range_n, RDIM_Rng1U64Node, curr_scope->voff_ranges.first) {
1373-
rdim_push_location_case(arena, scopes, &locset, &location, range_n->v);
1373+
rdim_location_case_list_push(arena, &locset, location, range_n->v);
13741374
}
13751375
} else if (attrib_class != DW_AttribClass_Null) {
13761376
log_user_errorf("unexpected attrib class @ .debug_info+%llx", tag.info_off);
@@ -1414,7 +1414,7 @@ d2r_var_locset_from_tag(Arena *arena,
14141414

14151415
// push location cases
14161416
for EachNode(range_n, RDIM_Rng1U64Node, curr_scope->voff_ranges.first) {
1417-
rdim_push_location_case(arena, scopes, &locset, &loc, range_n->v);
1417+
rdim_location_case_list_push(arena, &locset, loc, range_n->v);
14181418
}
14191419
} else if (has_location) {
14201420
locset = d2r_locset_from_attrib(arena, scopes, curr_scope, input, cu, image_base, arch, tag, DW_AttribKind_Location);
@@ -2468,10 +2468,9 @@ d2r_convert_symbols(Arena *arena,
24682468
parent_tag.kind == DW_TagKind_InlinedSubroutine ||
24692469
parent_tag.kind == DW_TagKind_LexicalBlock) {
24702470
RDIM_Scope *scope = it->stack->next->scope;
2471-
RDIM_Local *local = rdim_scope_push_local(arena, &g_d2r_shared.scopes, scope);
2472-
local->kind = RDI_LocalKind_Variable;
2473-
local->name = name;
2474-
local->type = type;
2471+
RDIM_Symbol *local = rdim_symbol_chunk_list_push(arena, &scope->locals, 8);
2472+
local->name = name;
2473+
local->type = type;
24752474
local->location_cases = d2r_var_locset_from_tag(arena, &g_d2r_shared.scopes, scope, input, cu, image_base, arch, tag);
24762475
} else {
24772476

@@ -2531,10 +2530,10 @@ d2r_convert_symbols(Arena *arena,
25312530
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
25322531
if (parent_tag.kind == DW_TagKind_SubProgram || parent_tag.kind == DW_TagKind_InlinedSubroutine) {
25332532
RDIM_Scope *scope = it->stack->next->scope;
2534-
RDIM_Local *param = rdim_scope_push_local(arena, &g_d2r_shared.scopes, scope);
2535-
param->kind = RDI_LocalKind_Parameter;
2536-
param->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
2537-
param->type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type);
2533+
RDIM_Symbol *param = rdim_symbol_chunk_list_push(arena, &scope->locals, 4);
2534+
param->is_param = 1;
2535+
param->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
2536+
param->type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type);
25382537
param->location_cases = d2r_var_locset_from_tag(arena, &g_d2r_shared.scopes, scope, input, cu, image_base, arch, tag);
25392538
} else {
25402539
Assert(!"this is a local variable");

src/rdi_make/rdi_make_local.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
29822982
lane_sync();
29832983

29842984
//////////////////////////////////////////////////////////////
2985-
//- rjf: @rdim_bake_stage bake scopes
2985+
//- rjf: @rdim_bake_stage bake scopes, gather locals
29862986
//
29872987
typedef struct BakedScopes BakedScopes;
29882988
struct BakedScopes
@@ -2991,8 +2991,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
29912991
RDI_U64 scopes_count;
29922992
RDI_U64 *scope_voffs;
29932993
RDI_U64 scope_voffs_count;
2994-
RDI_Symbol *locals;
2995-
RDI_U64 locals_count;
2994+
RDIM_SymbolChunkList arranged_locals;
29962995
};
29972996
BakedScopes *baked_scopes = 0;
29982997
ProfScope("bake scopes")
@@ -3013,11 +3012,6 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
30133012
baked_scopes->scope_voffs_count = params->scopes.scope_voff_count+1;
30143013
baked_scopes->scope_voffs = push_array(arena, RDI_U64, baked_scopes->scope_voffs_count);
30153014
}
3016-
if(lane_idx() == lane_from_task_idx(2))
3017-
{
3018-
baked_scopes->locals_count = params->scopes.local_count+1;
3019-
baked_scopes->locals = push_array(arena, RDI_Symbol, baked_scopes->locals_count);
3020-
}
30213015
lane_sync();
30223016

30233017
//- rjf: wide fill
@@ -3052,8 +3046,8 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
30523046
for EachIndex(src_local_idx, src_local_n->count)
30533047
{
30543048
RDIM_Symbol *src_local = &src_local_n->v[src_local_idx];
3055-
RDI_Symbol *dst_local = &baked_scopes->locals[chunk_local_off];
30563049
#if 0
3050+
RDI_Symbol *dst_local = &baked_scopes->locals[chunk_local_off];
30573051
dst_local->kind = src_local->kind;
30583052
dst_local->name_string_idx = rdim_bake_idx_from_string(bake_strings, src_local->name);
30593053
dst_local->type_idx = (RDI_U32)rdim_idx_from_type(src_local->type); // TODO(rjf): @u64_to_u32
@@ -3483,6 +3477,8 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
34833477
U64 baked_procedures_count = 0;
34843478
RDI_Symbol *baked_constants = 0;
34853479
U64 baked_constants_count = 0;
3480+
RDI_Symbol *baked_locals = 0;
3481+
U64 baked_locals_count = 0;
34863482
struct
34873483
{
34883484
RDIM_SymbolChunkList *symbols;
@@ -3491,10 +3487,11 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
34913487
}
34923488
symbol_table_lists[] =
34933489
{
3494-
{&params->global_variables, &baked_global_variables, &baked_global_variables_count},
3495-
{&params->thread_variables, &baked_thread_variables, &baked_thread_variables_count},
3496-
{&params->procedures, &baked_procedures, &baked_procedures_count},
3497-
{&params->constants, &baked_constants, &baked_constants_count},
3490+
{&params->global_variables, &baked_global_variables, &baked_global_variables_count},
3491+
{&params->thread_variables, &baked_thread_variables, &baked_thread_variables_count},
3492+
{&params->procedures, &baked_procedures, &baked_procedures_count},
3493+
{&params->constants, &baked_constants, &baked_constants_count},
3494+
{&baked_scopes->arranged_locals, &baked_locals, &baked_locals_count},
34983495
};
34993496

35003497
//////////////////////////////////////////////////////////////
@@ -3910,7 +3907,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
39103907
Map(ThreadVariableSymbols, baked_thread_variables, baked_thread_variables_count);
39113908
Map(ConstantSymbols, baked_constants, baked_constants_count);
39123909
Map(ProcedureSymbols, baked_procedures, baked_procedures_count);
3913-
// Map(LocalVariableSymbols, );
3910+
Map(LocalVariableSymbols, baked_locals, baked_locals_count);
39143911
Map(LocationsBytecodeData, baked_location_bytecode_data, baked_location_bytecode_data_size);
39153912
Map(LocationsConstantData, baked_location_constant_data, baked_location_constant_data_size);
39163913
Map(LocationsSetElements, baked_location_set_elements, baked_location_set_elements_count);

0 commit comments

Comments
 (0)