first pass at rdi format constant value support

This commit is contained in:
Ryan Fleury
2025-05-29 16:37:36 -07:00
parent a53ccee46d
commit 3513d6cfb9
11 changed files with 216 additions and 67 deletions
+51 -6
View File
@@ -294,7 +294,7 @@ rdim_sort_key_array(RDIM_Arena *arena, RDIM_SortKey *keys, RDI_U64 count)
// generate an ordered range node
RDIM_OrderedRange *new_range = rdim_push_array(rdim_temp_arena(scratch), RDIM_OrderedRange, 1);
SLLQueuePush(ranges_first, ranges_last, new_range);
RDIM_SLLQueuePush(ranges_first, ranges_last, new_range);
range_count += 1;
new_range->first = first;
new_range->opl = opl;
@@ -330,7 +330,7 @@ rdim_sort_key_array(RDIM_Arena *arena, RDIM_SortKey *keys, RDI_U64 count)
// get first range
RDIM_OrderedRange *range1 = src_ranges;
SLLStackPop(src_ranges);
RDIM_SLLStackPop(src_ranges);
// if this range is the whole array, we are done
if(range1->first == 0 && range1->opl == count)
@@ -344,15 +344,16 @@ rdim_sort_key_array(RDIM_Arena *arena, RDIM_SortKey *keys, RDI_U64 count)
{
RDI_U64 first = range1->first;
rdim_memcpy(dst + first, src + first, sizeof(*src)*(range1->opl - first));
SLLQueuePush(dst_ranges, dst_ranges_last, range1);
RDIM_SLLQueuePush(dst_ranges, dst_ranges_last, range1);
break;
}
// get second range
RDIM_OrderedRange *range2 = src_ranges;
SLLStackPop(src_ranges);
RDIM_SLLStackPop(src_ranges);
#if 0
rdim_assert(range1->opl == range2->first);
#endif
// merge these ranges
RDI_U64 jd = range1->first;
@@ -419,7 +420,7 @@ rdim_sort_key_array(RDIM_Arena *arena, RDIM_SortKey *keys, RDI_U64 count)
}
#endif
scratch_end(scratch);
rdim_scratch_end(scratch);
return result;
}
@@ -994,6 +995,7 @@ rdim_symbol_chunk_list_concat_in_place(RDIM_SymbolChunkList *dst, RDIM_SymbolChu
dst->last = to_push->last;
dst->chunk_count += to_push->chunk_count;
dst->total_count += to_push->total_count;
dst->total_value_data_size += to_push->total_value_data_size;
}
else if(dst->first == 0)
{
@@ -1002,6 +1004,13 @@ rdim_symbol_chunk_list_concat_in_place(RDIM_SymbolChunkList *dst, RDIM_SymbolChu
rdim_memzero_struct(to_push);
}
internal void
rdim_symbol_push_value_data(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDIM_Symbol *symbol, RDIM_String8 data)
{
symbol->value_data = rdim_str8_copy(arena, data);
list->total_value_data_size += data.size;
}
////////////////////////////////
//~ rjf: [Building] Inline Site Info Building
@@ -3497,6 +3506,39 @@ rdim_bake_thread_variables(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings,
return result;
}
RDI_PROC RDIM_ConstantsBakeResult
rdim_bake_constants(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_SymbolChunkList *src)
{
RDI_Constant *constants = push_array(arena, RDI_Constant, src->total_count+1);
RDI_U32 *constant_values = push_array(arena, RDI_U32, src->total_count+1);
RDI_U8 *constant_value_data = push_array(arena, RDI_U8, src->total_value_data_size+1);
RDI_U32 dst_idx = 1;
RDI_U64 dst_constant_value_data_off = 1;
for(RDIM_SymbolChunkNode *n = src->first; n != 0; n = n->next)
{
for(RDI_U64 chunk_idx = 0; chunk_idx < n->count; chunk_idx += 1, dst_idx += 1)
{
RDIM_Symbol *src = &n->v[chunk_idx];
RDI_Constant *dst = &constants[dst_idx];
RDI_U32 *dst_value_idx = &constant_values[dst_idx];
dst->name_string_idx = rdim_bake_idx_from_string(strings, src->name);
dst->type_idx = (RDI_U32)rdim_idx_from_type(src->type); // TODO(rjf): @u64_to_u32
dst->constant_value_idx = dst_idx;
dst_value_idx[0] = dst_constant_value_data_off;
rdim_memcpy(constant_value_data + dst_constant_value_data_off, src->value_data.str, src->value_data.size);
dst_constant_value_data_off += src->value_data.size;
}
}
RDIM_ConstantsBakeResult result = {0};
result.constants = constants;
result.constants_count = src->total_count+1;
result.constant_values = constant_values;
result.constant_values_count = src->total_count+1;
result.constant_value_data = constant_value_data;
result.constant_value_data_size = dst_constant_value_data_off;
return result;
}
RDI_PROC U64
rdim_bake_location(RDIM_Arena *arena, RDIM_String8List *location_data_blobs, RDIM_Location *src_location)
{
@@ -3970,6 +4012,7 @@ rdim_serialized_section_bundle_from_bake_results(RDIM_BakeResults *results)
bundle.sections[RDI_SectionKind_GlobalVariables] = rdim_serialized_section_make_unpacked_array(results->global_variables.global_variables, results->global_variables.global_variables_count);
bundle.sections[RDI_SectionKind_GlobalVMap] = rdim_serialized_section_make_unpacked_array(results->global_vmap.vmap.vmap, results->global_vmap.vmap.count+1);
bundle.sections[RDI_SectionKind_ThreadVariables] = rdim_serialized_section_make_unpacked_array(results->thread_variables.thread_variables, results->thread_variables.thread_variables_count);
bundle.sections[RDI_SectionKind_Constants] = rdim_serialized_section_make_unpacked_array(results->constants.constants, results->constants.constants_count);
bundle.sections[RDI_SectionKind_Procedures] = rdim_serialized_section_make_unpacked_array(results->procedures.procedures, results->procedures.procedures_count);
bundle.sections[RDI_SectionKind_Scopes] = rdim_serialized_section_make_unpacked_array(results->scopes.scopes, results->scopes.scopes_count);
bundle.sections[RDI_SectionKind_ScopeVOffData] = rdim_serialized_section_make_unpacked_array(results->scopes.scope_voffs, results->scopes.scope_voffs_count);
@@ -3978,6 +4021,8 @@ rdim_serialized_section_bundle_from_bake_results(RDIM_BakeResults *results)
bundle.sections[RDI_SectionKind_Locals] = rdim_serialized_section_make_unpacked_array(results->scopes.locals, results->scopes.locals_count);
bundle.sections[RDI_SectionKind_LocationBlocks] = rdim_serialized_section_make_unpacked_array(results->location_blocks.str, results->location_blocks.size);
bundle.sections[RDI_SectionKind_LocationData] = rdim_serialized_section_make_unpacked_array(results->location_data.str, results->location_data.size);
bundle.sections[RDI_SectionKind_ConstantValueData] = rdim_serialized_section_make_unpacked_array(results->constants.constant_value_data, results->constants.constant_value_data_size);
bundle.sections[RDI_SectionKind_ConstantValueTable] = rdim_serialized_section_make_unpacked_array(results->constants.constant_values, results->constants.constant_values_count);
bundle.sections[RDI_SectionKind_NameMaps] = rdim_serialized_section_make_unpacked_array(results->top_level_name_maps.name_maps, results->top_level_name_maps.name_maps_count);
bundle.sections[RDI_SectionKind_NameMapBuckets] = rdim_serialized_section_make_unpacked_array(results->name_maps.buckets, results->name_maps.buckets_count);
bundle.sections[RDI_SectionKind_NameMapNodes] = rdim_serialized_section_make_unpacked_array(results->name_maps.nodes, results->name_maps.nodes_count);
+17 -10
View File
@@ -763,16 +763,6 @@ struct RDIM_LocationSet
////////////////////////////////
//~ rjf: Symbol Info Types
typedef enum RDIM_SymbolKind
{
RDIM_SymbolKind_NULL,
RDIM_SymbolKind_GlobalVariable,
RDIM_SymbolKind_ThreadVariable,
RDIM_SymbolKind_Procedure,
RDIM_SymbolKind_COUNT
}
RDIM_SymbolKind;
typedef struct RDIM_Symbol RDIM_Symbol;
struct RDIM_Symbol
{
@@ -786,6 +776,7 @@ struct RDIM_Symbol
RDIM_Type *container_type;
struct RDIM_Scope *root_scope;
RDIM_LocationSet frame_base;
RDIM_String8 value_data;
};
typedef struct RDIM_SymbolChunkNode RDIM_SymbolChunkNode;
@@ -805,6 +796,7 @@ struct RDIM_SymbolChunkList
RDIM_SymbolChunkNode *last;
RDI_U64 chunk_count;
RDI_U64 total_count;
RDI_U64 total_value_data_size;
};
////////////////////////////////
@@ -907,6 +899,7 @@ struct RDIM_BakeParams
RDIM_LineTableChunkList line_tables;
RDIM_SymbolChunkList global_variables;
RDIM_SymbolChunkList thread_variables;
RDIM_SymbolChunkList constants;
RDIM_SymbolChunkList procedures;
RDIM_ScopeChunkList scopes;
RDIM_InlineSiteChunkList inline_sites;
@@ -1192,6 +1185,17 @@ struct RDIM_ThreadVariableBakeResult
RDI_U64 thread_variables_count;
};
typedef struct RDIM_ConstantsBakeResult RDIM_ConstantsBakeResult;
struct RDIM_ConstantsBakeResult
{
RDI_Constant *constants;
RDI_U64 constants_count;
RDI_U32 *constant_values;
RDI_U64 constant_values_count;
RDI_U8 *constant_value_data;
RDI_U64 constant_value_data_size;
};
typedef struct RDIM_ProcedureBakeResult RDIM_ProcedureBakeResult;
struct RDIM_ProcedureBakeResult
{
@@ -1276,6 +1280,7 @@ struct RDIM_BakeResults
RDIM_GlobalVariableBakeResult global_variables;
RDIM_GlobalVMapBakeResult global_vmap;
RDIM_ThreadVariableBakeResult thread_variables;
RDIM_ConstantsBakeResult constants;
RDIM_ProcedureBakeResult procedures;
RDIM_ScopeBakeResult scopes;
RDIM_InlineSiteBakeResult inline_sites;
@@ -1419,6 +1424,7 @@ RDI_PROC RDIM_UDTEnumVal *rdim_udt_push_enum_val(RDIM_Arena *arena, RDIM_UDTChun
RDI_PROC RDIM_Symbol *rdim_symbol_chunk_list_push(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDI_U64 cap);
RDI_PROC RDI_U64 rdim_idx_from_symbol(RDIM_Symbol *symbol);
RDI_PROC void rdim_symbol_chunk_list_concat_in_place(RDIM_SymbolChunkList *dst, RDIM_SymbolChunkList *to_push);
internal void rdim_symbol_push_value_data(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDIM_Symbol *symbol, RDIM_String8 data);
////////////////////////////////
//~ rjf: [Building] Inline Site Info Building
@@ -1562,6 +1568,7 @@ RDI_PROC RDIM_UDTBakeResult rdim_bake_udts(RDIM_Arena *arena, RDIM_B
RDI_PROC RDIM_GlobalVariableBakeResult rdim_bake_global_variables(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_SymbolChunkList *src);
RDI_PROC RDIM_GlobalVMapBakeResult rdim_bake_global_vmap(RDIM_Arena *arena, RDIM_SymbolChunkList *src);
RDI_PROC RDIM_ThreadVariableBakeResult rdim_bake_thread_variables(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_SymbolChunkList *src);
RDI_PROC RDIM_ConstantsBakeResult rdim_bake_constants(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_SymbolChunkList *src);
RDI_PROC RDIM_ProcedureBakeResult rdim_bake_procedures(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_String8List *location_blocks, RDIM_String8List *location_data_blobs, RDIM_SymbolChunkList *src);
RDI_PROC RDIM_ScopeBakeResult rdim_bake_scopes(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_String8List *location_blocks, RDIM_String8List *location_data_blobs, RDIM_ScopeChunkList *src);
RDI_PROC RDIM_ScopeVMapBakeResult rdim_bake_scope_vmap(RDIM_Arena *arena, RDIM_ScopeChunkList *src);