diff --git a/src/lib_rdi_make/rdi_make.c b/src/lib_rdi_make/rdi_make.c index 4d2d2f1d..e19ad8bb 100644 --- a/src/lib_rdi_make/rdi_make.c +++ b/src/lib_rdi_make/rdi_make.c @@ -983,16 +983,94 @@ rdim_inline_site_chunk_list_concat_in_place(RDIM_InlineSiteChunkList *dst, RDIM_ //////////////////////////////// //~ rjf: [Building] Location Info Building -RDI_PROC RDIM_Location * -rdim_location_chunk_list_push_new(RDIM_Arena *arena, RDIM_LocationChunkList *list, RDI_U64 cap, RDIM_Location *loc) +RDI_PROC RDI_U64 +rdim_encoded_size_from_location_info(RDIM_LocationInfo *info) { - + RDI_U64 result = 0; + switch((RDI_LocationKindEnum)info->kind) + { + case RDI_LocationKind_NULL:{}break; + + case RDI_LocationKind_AddrBytecodeStream: + case RDI_LocationKind_ValBytecodeStream: + { + result = sizeof(RDI_LocationBytecodeStream) + info->bytecode.encoded_size + 1; + }break; + + case RDI_LocationKind_AddrRegPlusU16: + case RDI_LocationKind_AddrAddrRegPlusU16: + { + result = sizeof(RDI_LocationRegPlusU16); + }break; + + case RDI_LocationKind_ValReg: + { + result = sizeof(RDI_LocationReg); + }break; + } + return result; +} + +RDI_PROC RDIM_Location2 * +rdim_location_chunk_list_push_new(RDIM_Arena *arena, RDIM_LocationChunkList *list, RDI_U64 cap, RDIM_LocationInfo *info) +{ + RDIM_IdxedChunkListPush(arena, list, RDIM_LocationChunkNode, RDIM_Location2, cap, result); + { + RDI_U64 encoded_size = rdim_encoded_size_from_location_info(info); + rdim_memcpy_struct(&result->info, info); + result->relative_encoding_off = list->last->encoded_size; + list->last->encoded_size += encoded_size; + list->total_encoded_size += encoded_size; + } + return result; +} + +RDI_PROC RDI_U64 +rdim_idx_from_location(RDIM_Location2 *location) +{ + RDIM_IdxedChunkListElementGetIdx(location, idx); + return idx; +} + +RDI_PROC RDI_U64 +rdim_off_from_location(RDIM_Location2 *location) +{ + RDI_U64 off = 0; + if(location != 0 && location->chunk != 0) + { + off = location->chunk->base_encoding_off + location->relative_encoding_off + 1; + } + return off; } RDI_PROC void rdim_location_chunk_list_concat_in_place(RDIM_LocationChunkList *dst, RDIM_LocationChunkList *to_push) { - + for(RDIM_LocationChunkNode *n = to_push->first; n != 0; n = n->next) + { + n->base_encoding_off += dst->total_encoded_size; + } + RDIM_IdxedChunkListConcatInPlace(RDIM_LocationChunkNode, dst, to_push, dst->total_encoded_size += to_push->total_encoded_size); +} + +RDI_PROC RDIM_LocationCase2 * +rdim_location_case_chunk_list_push(RDIM_Arena *arena, RDIM_LocationCaseChunkList *list, RDI_U64 cap) +{ + RDIM_IdxedChunkListPush(arena, list, RDIM_LocationCaseChunkNode, RDIM_LocationCase2, cap, result); + return result; +} + +RDI_PROC RDI_U64 +rdim_idx_from_location_case(RDIM_LocationCase2 *location_case) +{ + RDIM_IdxedChunkListElementGetIdx(location_case, idx); + return idx; +} + +RDI_PROC void +rdim_location_case_chunk_list_concat_in_place(RDIM_LocationCaseChunkList *dst, RDIM_LocationCaseChunkList *to_push) +{ + RDIM_IdxedChunkListConcatInPlace(RDIM_LocationCaseChunkNode, dst, to_push); } //////////////////////////////// diff --git a/src/lib_rdi_make/rdi_make.h b/src/lib_rdi_make/rdi_make.h index 2c48b916..105060fd 100644 --- a/src/lib_rdi_make/rdi_make.h +++ b/src/lib_rdi_make/rdi_make.h @@ -844,8 +844,8 @@ struct RDIM_EvalBytecode //- rjf: location types -typedef struct RDIM_Location RDIM_Location; -struct RDIM_Location +typedef struct RDIM_LocationInfo RDIM_LocationInfo; +struct RDIM_LocationInfo { RDI_LocationKind kind; RDI_U8 reg_code; @@ -853,15 +853,24 @@ struct RDIM_Location RDIM_EvalBytecode bytecode; }; +typedef struct RDIM_Location2 RDIM_Location2; +struct RDIM_Location2 +{ + struct RDIM_LocationChunkNode *chunk; + RDIM_LocationInfo info; + RDI_U64 relative_encoding_off; +}; + typedef struct RDIM_LocationChunkNode RDIM_LocationChunkNode; struct RDIM_LocationChunkNode { RDIM_LocationChunkNode *next; - RDIM_Location *v; + RDIM_Location2 *v; RDI_U64 count; RDI_U64 cap; RDI_U64 base_idx; RDI_U64 base_encoding_off; + RDI_U64 encoded_size; }; typedef struct RDIM_LocationChunkList RDIM_LocationChunkList; @@ -874,7 +883,47 @@ struct RDIM_LocationChunkList RDI_U64 total_encoded_size; }; -//- rjf: location case types (location * voff range) +//- rjf: location cases + +typedef struct RDIM_LocationCase2 RDIM_LocationCase2; +struct RDIM_LocationCase2 +{ + struct RDIM_LocationCaseChunkNode *chunk; + RDIM_Location2 *location; + RDIM_Rng1U64 voff_range; +}; + +typedef struct RDIM_LocationCaseChunkNode RDIM_LocationCaseChunkNode; +struct RDIM_LocationCaseChunkNode +{ + RDIM_LocationCaseChunkNode *next; + RDIM_LocationCase2 *v; + RDI_U64 count; + RDI_U64 cap; + RDI_U64 base_idx; +}; + +typedef struct RDIM_LocationCaseChunkList RDIM_LocationCaseChunkList; +struct RDIM_LocationCaseChunkList +{ + RDIM_LocationCaseChunkNode *first; + RDIM_LocationCaseChunkNode *last; + RDI_U64 chunk_count; + RDI_U64 total_count; +}; + +//- rjf: locations (OLD) + +typedef struct RDIM_Location RDIM_Location; +struct RDIM_Location +{ + RDI_LocationKind kind; + RDI_U8 reg_code; + RDI_U16 offset; + RDIM_EvalBytecode bytecode; +}; + +//- rjf: location case types (location * voff range) (OLD) typedef struct RDIM_LocationCase RDIM_LocationCase; struct RDIM_LocationCase @@ -974,6 +1023,8 @@ struct RDIM_Local RDIM_String8 name; RDIM_Type *type; RDIM_LocationSet locset; + RDIM_LocationCase2 *first_location_case; + RDI_U64 location_case_count; }; typedef struct RDIM_Scope RDIM_Scope; @@ -1031,6 +1082,8 @@ struct RDIM_BakeParams RDIM_UDTEnumValChunkList enum_vals; RDIM_SrcFileChunkList src_files; RDIM_LineTableChunkList line_tables; + RDIM_LocationChunkList locations; + RDIM_LocationCaseChunkList location_cases; RDIM_SymbolChunkList global_variables; RDIM_SymbolChunkList thread_variables; RDIM_SymbolChunkList constants; @@ -1407,6 +1460,13 @@ struct RDIM_UDTBakeResult RDI_U64 enum_members_count; }; +typedef struct RDIM_LocationBakeResult RDIM_LocationBakeResult; +struct RDIM_LocationBakeResult +{ + RDI_U8 *location_data; + RDI_U64 location_data_size; +}; + typedef struct RDIM_GlobalVariableBakeResult RDIM_GlobalVariableBakeResult; struct RDIM_GlobalVariableBakeResult { @@ -1695,9 +1755,16 @@ RDI_PROC void rdim_inline_site_chunk_list_concat_in_place(RDIM_InlineSiteChunkLi //////////////////////////////// //~ rjf: [Building] Location Info Building -RDI_PROC RDIM_Location *rdim_location_chunk_list_push_new(RDIM_Arena *arena, RDIM_LocationChunkList *list, RDI_U64 cap, RDIM_Location *loc); +RDI_PROC RDI_U64 rdim_encoded_size_from_location_info(RDIM_LocationInfo *info); +RDI_PROC RDIM_Location2 *rdim_location_chunk_list_push_new(RDIM_Arena *arena, RDIM_LocationChunkList *list, RDI_U64 cap, RDIM_LocationInfo *info); +RDI_PROC RDI_U64 rdim_idx_from_location(RDIM_Location2 *location); +RDI_PROC RDI_U64 rdim_off_from_location(RDIM_Location2 *location); RDI_PROC void rdim_location_chunk_list_concat_in_place(RDIM_LocationChunkList *dst, RDIM_LocationChunkList *to_push); +RDI_PROC RDIM_LocationCase2 *rdim_location_case_chunk_list_push(RDIM_Arena *arena, RDIM_LocationCaseChunkList *list, RDI_U64 cap); +RDI_PROC RDI_U64 rdim_idx_from_location_case(RDIM_LocationCase2 *location_case); +RDI_PROC void rdim_location_case_chunk_list_concat_in_place(RDIM_LocationCaseChunkList *dst, RDIM_LocationCaseChunkList *to_push); + //////////////////////////////// //~ rjf: [Building] Scope Info Building diff --git a/src/rdi_from_pdb/rdi_from_pdb_2.c b/src/rdi_from_pdb/rdi_from_pdb_2.c index e5130135..063b4bdb 100644 --- a/src/rdi_from_pdb/rdi_from_pdb_2.c +++ b/src/rdi_from_pdb/rdi_from_pdb_2.c @@ -1,6 +1,49 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +internal RDIM_LocationInfo +p2r2_location_info_from_addr_reg_off(Arena *arena, RDI_Arch arch, RDI_RegCode reg_code, U32 reg_byte_size, U32 reg_byte_pos, S64 offset, B32 extra_indirection) +{ + RDIM_LocationInfo result = {0}; + if(0 <= offset && offset <= (S64)max_U16) + { + if(extra_indirection) + { + result.kind = RDI_LocationKind_AddrAddrRegPlusU16; + result.reg_code = reg_code; + result.offset = offset; + } + else + { + result.kind = RDI_LocationKind_AddrRegPlusU16; + result.reg_code = reg_code; + result.offset = offset; + } + } + else + { + RDIM_EvalBytecode bytecode = {0}; + U32 regread_param = RDI_EncodeRegReadParam(reg_code, reg_byte_size, reg_byte_pos); + rdim_bytecode_push_op(arena, &bytecode, RDI_EvalOp_RegRead, regread_param); + rdim_bytecode_push_sconst(arena, &bytecode, offset); + rdim_bytecode_push_op(arena, &bytecode, RDI_EvalOp_Add, 0); + if(extra_indirection) + { + U64 addr_size = rdi_addr_size_from_arch(arch); + rdim_bytecode_push_op(arena, &bytecode, RDI_EvalOp_MemRead, addr_size); + } + result.kind = RDI_LocationKind_AddrBytecodeStream; + result.bytecode = bytecode; + } + return result; +} + +internal void +p2r2_location_over_lvar_addr_range(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_LocationSet *locset, RDIM_Location *location, CV_LvarAddrRange *range, COFF_SectionHeader *section, CV_LvarAddrGap *gaps, U64 gap_count) +{ + +} + internal RDIM_BakeParams p2r2_convert(Arena *arena, P2R_ConvertParams *params) { @@ -2990,6 +3033,8 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) // if(lane_idx() == 0) { + p2r2_shared->lanes_locations = push_array(arena, RDIM_LocationChunkList, lane_count()); + p2r2_shared->lanes_location_cases = push_array(arena, RDIM_LocationCaseChunkList, lane_count()); p2r2_shared->lanes_procedures = push_array(arena, RDIM_SymbolChunkList, lane_count()); p2r2_shared->lanes_global_variables = push_array(arena, RDIM_SymbolChunkList, lane_count()); p2r2_shared->lanes_thread_variables = push_array(arena, RDIM_SymbolChunkList, lane_count()); @@ -3003,12 +3048,16 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) //////////////////////////// //- rjf: set up outputs for this sym stream // + U64 sym_locations_chunk_cap = 16384; + U64 sym_location_cases_chunk_cap = 16384; U64 sym_procedures_chunk_cap = 16384; U64 sym_global_variables_chunk_cap = 16384; U64 sym_thread_variables_chunk_cap = 16384; U64 sym_constants_chunk_cap = 16384; U64 sym_scopes_chunk_cap = 16384; U64 sym_inline_sites_chunk_cap = 16384; + RDIM_LocationChunkList sym_locations = {0}; + RDIM_LocationCaseChunkList sym_location_cases = {0}; RDIM_SymbolChunkList sym_procedures = {0}; RDIM_SymbolChunkList sym_global_variables = {0}; RDIM_SymbolChunkList sym_thread_variables = {0}; @@ -3444,6 +3493,18 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) U32 byte_size = 8; U32 byte_pos = 0; + // rjf: build location + RDIM_LocationInfo loc_info = p2r2_location_info_from_addr_reg_off(arena, arch, reg_code, byte_size, byte_pos, (S64)(S32)var_off, extra_indirection_to_value); + RDIM_Location2 *loc2 = rdim_location_chunk_list_push_new(arena, &sym_locations, sym_locations_chunk_cap, &loc_info); + RDIM_LocationCase2 *loc_case = rdim_location_case_chunk_list_push(arena, &sym_location_cases, sym_locations_chunk_cap); + loc_case->location = loc2; + loc_case->voff_range.min = 0; + loc_case->voff_range.max = max_U64; + + // rjf: equip location case to local + local->first_location_case = loc_case; + local->location_case_count = 1; + // rjf: set location case RDIM_Location *loc = p2r_location_from_addr_reg_off(arena, arch, reg_code, byte_size, byte_pos, (S64)(S32)var_off, extra_indirection_to_value); RDIM_Rng1U64 voff_range = {0, max_U64}; @@ -3542,7 +3603,7 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) } }break; - //- rjf: DEFRANGE_REGISTESR + //- rjf: DEFRANGE_REGISTER case CV_SymKind_DEFRANGE_REGISTER: { // rjf: no defrange target? -> somehow we got to a defrange symbol without first seeing @@ -3608,10 +3669,11 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) U32 byte_size = rdi_addr_size_from_arch(arch); U32 byte_pos = 0; S64 var_off = (S64)defrange_fprel->off; - RDIM_Location *location = p2r_location_from_addr_reg_off(arena, arch, fp_register_code, byte_size, byte_pos, var_off, extra_indirection); + RDIM_LocationInfo location_info = p2r2_location_info_from_addr_reg_off(arena, arch, fp_register_code, byte_size, byte_pos, var_off, extra_indirection); + RDIM_Location2 *location = rdim_location_chunk_list_push_new(arena, &sym_locations, sym_locations_chunk_cap, &location_info); // rjf: emit locations over ranges - p2r_location_over_lvar_addr_range(arena, &sym_scopes, defrange_target, location, range, range_section, gaps, gap_count); + // TODO(rjf): p2r_location_over_lvar_addr_range(arena, &sym_scopes, defrange_target, location, range, range_section, gaps, gap_count); }break; //- rjf: DEFRANGE_SUBFIELD_REGISTER @@ -3903,6 +3965,8 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) //////////////////////////// //- rjf: output this lane's symbols // + p2r2_shared->lanes_locations[lane_idx()] = sym_locations; + p2r2_shared->lanes_location_cases[lane_idx()] = sym_location_cases; p2r2_shared->lanes_procedures[lane_idx()] = sym_procedures; p2r2_shared->lanes_global_variables[lane_idx()] = sym_global_variables; p2r2_shared->lanes_thread_variables[lane_idx()] = sym_thread_variables; @@ -3919,49 +3983,63 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) //- rjf: join all lane symbols // { - if(lane_idx() == lane_from_task_idx(0)) ProfScope("join procedures") + if(lane_idx() == lane_from_task_idx(0)) ProfScope("join locations") + { + for EachIndex(idx, lane_count()) + { + rdim_location_chunk_list_concat_in_place(&p2r2_shared->all_locations, &p2r2_shared->lanes_locations[idx]); + } + } + if(lane_idx() == lane_from_task_idx(1)) ProfScope("join location cases") + { + for EachIndex(idx, lane_count()) + { + rdim_location_case_chunk_list_concat_in_place(&p2r2_shared->all_location_cases, &p2r2_shared->lanes_location_cases[idx]); + } + } + if(lane_idx() == lane_from_task_idx(2)) ProfScope("join procedures") { for EachIndex(idx, lane_count()) { rdim_symbol_chunk_list_concat_in_place(&p2r2_shared->all_procedures, &p2r2_shared->lanes_procedures[idx]); } } - if(lane_idx() == lane_from_task_idx(1)) ProfScope("join global variables") + if(lane_idx() == lane_from_task_idx(3)) ProfScope("join global variables") { for EachIndex(idx, lane_count()) { rdim_symbol_chunk_list_concat_in_place(&p2r2_shared->all_global_variables, &p2r2_shared->lanes_global_variables[idx]); } } - if(lane_idx() == lane_from_task_idx(2)) ProfScope("join thread variables") + if(lane_idx() == lane_from_task_idx(4)) ProfScope("join thread variables") { for EachIndex(idx, lane_count()) { rdim_symbol_chunk_list_concat_in_place(&p2r2_shared->all_thread_variables, &p2r2_shared->lanes_thread_variables[idx]); } } - if(lane_idx() == lane_from_task_idx(3)) ProfScope("join constants") + if(lane_idx() == lane_from_task_idx(5)) ProfScope("join constants") { for EachIndex(idx, lane_count()) { rdim_symbol_chunk_list_concat_in_place(&p2r2_shared->all_constants, &p2r2_shared->lanes_constants[idx]); } } - if(lane_idx() == lane_from_task_idx(4)) ProfScope("join scopes") + if(lane_idx() == lane_from_task_idx(6)) ProfScope("join scopes") { for EachIndex(idx, lane_count()) { rdim_scope_chunk_list_concat_in_place(&p2r2_shared->all_scopes, &p2r2_shared->lanes_scopes[idx]); } } - if(lane_idx() == lane_from_task_idx(5)) ProfScope("join inline sites") + if(lane_idx() == lane_from_task_idx(7)) ProfScope("join inline sites") { for EachIndex(idx, lane_count()) { rdim_inline_site_chunk_list_concat_in_place(&p2r2_shared->all_inline_sites, &p2r2_shared->lanes_inline_sites[idx]); } } - if(lane_idx() == lane_from_task_idx(6)) ProfScope("join typedefs") + if(lane_idx() == lane_from_task_idx(8)) ProfScope("join typedefs") { for EachIndex(idx, lane_count()) { @@ -3971,6 +4049,8 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) } } lane_sync(); + RDIM_LocationChunkList all_locations = p2r2_shared->all_locations; + RDIM_LocationCaseChunkList all_location_cases = p2r2_shared->all_location_cases; RDIM_SymbolChunkList all_procedures = p2r2_shared->all_procedures; RDIM_SymbolChunkList all_global_variables = p2r2_shared->all_global_variables; RDIM_SymbolChunkList all_thread_variables = p2r2_shared->all_thread_variables; @@ -3991,7 +4071,7 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) top_level_info.exe_name = str8_skip_last_slash(params->input_exe_name); top_level_info.exe_hash = exe_hash; top_level_info.voff_max = exe_voff_max; - if(params->deterministic) + if(!params->deterministic) { top_level_info.producer_name = str8_lit(BUILD_TITLE_STRING_LITERAL); } @@ -4027,6 +4107,8 @@ p2r2_convert(Arena *arena, P2R_ConvertParams *params) result.enum_vals = all_enum_vals; result.src_files = all_src_files; result.line_tables = all_line_tables; + result.locations = all_locations; + result.location_cases = all_location_cases; result.global_variables = all_global_variables; result.thread_variables = all_thread_variables; result.constants = all_constants; diff --git a/src/rdi_from_pdb/rdi_from_pdb_2.h b/src/rdi_from_pdb/rdi_from_pdb_2.h index 709fa5b2..02e6495c 100644 --- a/src/rdi_from_pdb/rdi_from_pdb_2.h +++ b/src/rdi_from_pdb/rdi_from_pdb_2.h @@ -118,6 +118,8 @@ struct P2R2_Shared RDIM_UDTMemberChunkList all_members; RDIM_UDTEnumValChunkList all_enum_vals; + RDIM_LocationChunkList *lanes_locations; + RDIM_LocationCaseChunkList *lanes_location_cases; RDIM_SymbolChunkList *lanes_procedures; RDIM_SymbolChunkList *lanes_global_variables; RDIM_SymbolChunkList *lanes_thread_variables; @@ -126,6 +128,8 @@ struct P2R2_Shared RDIM_InlineSiteChunkList *lanes_inline_sites; RDIM_TypeChunkList *lanes_typedefs; + RDIM_LocationChunkList all_locations; + RDIM_LocationCaseChunkList all_location_cases; RDIM_SymbolChunkList all_procedures; RDIM_SymbolChunkList all_global_variables; RDIM_SymbolChunkList all_thread_variables; @@ -137,6 +141,9 @@ struct P2R2_Shared global P2R2_Shared *p2r2_shared = 0; +internal RDIM_LocationInfo p2r2_location_info_from_addr_reg_off(Arena *arena, RDI_Arch arch, RDI_RegCode reg_code, U32 reg_byte_size, U32 reg_byte_pos, S64 offset, B32 extra_indirection); +internal void p2r2_location_over_lvar_addr_range(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_LocationSet *locset, RDIM_Location *location, CV_LvarAddrRange *range, COFF_SectionHeader *section, CV_LvarAddrGap *gaps, U64 gap_count); + internal RDIM_BakeParams p2r2_convert(Arena *arena, P2R_ConvertParams *params); #endif // RDI_FROM_PDB_2_H diff --git a/src/rdi_make/rdi_make_local_2.c b/src/rdi_make/rdi_make_local_2.c index 2bd4c0b0..efbb8569 100644 --- a/src/rdi_make/rdi_make_local_2.c +++ b/src/rdi_make/rdi_make_local_2.c @@ -815,36 +815,41 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) rdim2_shared->baked_udts.enum_members = push_array(arena, RDI_EnumMember, rdim2_shared->baked_udts.enum_members_count); } if(lane_idx() == lane_from_task_idx(7)) + { + rdim2_shared->baked_locations.location_data_size = params->locations.total_encoded_size+1; + rdim2_shared->baked_locations.location_data = push_array(arena, RDI_U8, rdim2_shared->baked_locations.location_data_size); + } + if(lane_idx() == lane_from_task_idx(8)) { rdim2_shared->baked_global_variables.global_variables_count = params->global_variables.total_count+1; rdim2_shared->baked_global_variables.global_variables = push_array(arena, RDI_GlobalVariable, rdim2_shared->baked_global_variables.global_variables_count); } - if(lane_idx() == lane_from_task_idx(8)) + if(lane_idx() == lane_from_task_idx(9)) { rdim2_shared->baked_thread_variables.thread_variables_count = params->thread_variables.total_count+1; rdim2_shared->baked_thread_variables.thread_variables = push_array(arena, RDI_ThreadVariable, rdim2_shared->baked_thread_variables.thread_variables_count); } - if(lane_idx() == lane_from_task_idx(9)) + if(lane_idx() == lane_from_task_idx(10)) { rdim2_shared->baked_constants.constants_count = params->constants.total_count+1; rdim2_shared->baked_constants.constants = push_array(arena, RDI_Constant, rdim2_shared->baked_constants.constants_count); } - if(lane_idx() == lane_from_task_idx(10)) + if(lane_idx() == lane_from_task_idx(11)) { rdim2_shared->baked_constants.constant_values_count = params->constants.total_count+1; rdim2_shared->baked_constants.constant_values = push_array(arena, RDI_U32, rdim2_shared->baked_constants.constant_values_count); } - if(lane_idx() == lane_from_task_idx(11)) + if(lane_idx() == lane_from_task_idx(12)) { rdim2_shared->baked_constants.constant_value_data_size = params->constants.total_value_data_size; rdim2_shared->baked_constants.constant_value_data = push_array(arena, RDI_U8, rdim2_shared->baked_constants.constant_value_data_size); } - if(lane_idx() == lane_from_task_idx(12)) + if(lane_idx() == lane_from_task_idx(13)) { rdim2_shared->baked_procedures.procedures_count = params->procedures.total_count+1; rdim2_shared->baked_procedures.procedures = push_array(arena, RDI_Procedure, rdim2_shared->baked_procedures.procedures_count); } - if(lane_idx() == lane_from_task_idx(13)) + if(lane_idx() == lane_from_task_idx(14)) { rdim2_shared->baked_inline_sites.inline_sites_count = params->inline_sites.total_count+1; rdim2_shared->baked_inline_sites.inline_sites = push_array(arena, RDI_InlineSite, rdim2_shared->baked_inline_sites.inline_sites_count); @@ -1016,6 +1021,49 @@ rdim2_bake(Arena *arena, RDIM_BakeParams *params) } } + //- rjf: bake locations + ProfScope("bake locations") + { + for EachNode(n, RDIM_LocationChunkNode, params->locations.first) + { + Rng1U64 range = lane_range(n->count); + for EachInRange(n_idx, range) + { + RDIM_Location2 *loc = &n->v[n_idx]; + RDI_U8 *dst = &rdim2_shared->baked_locations.location_data[n->base_encoding_off + loc->relative_encoding_off + 1]; + switch((RDI_LocationKindEnum)loc->info.kind) + { + case RDI_LocationKind_NULL:{}break; + case RDI_LocationKind_AddrBytecodeStream: + case RDI_LocationKind_ValBytecodeStream: + { + MemoryCopy(dst+0, &loc->info.kind, sizeof(loc->info.kind)); + RDI_U64 write_off = sizeof(loc->info.kind); + for EachNode(op_node, RDIM_EvalBytecodeOp, loc->info.bytecode.first_op) + { + MemoryCopy(dst + write_off, &op_node->op, 1); + write_off += 1; + MemoryCopy(dst + write_off, &op_node->p, op_node->p_size); + write_off += op_node->p_size; + } + dst[write_off] = 0; + }break; + case RDI_LocationKind_AddrRegPlusU16: + case RDI_LocationKind_AddrAddrRegPlusU16: + { + RDI_LocationRegPlusU16 baked = {loc->info.kind, loc->info.reg_code, loc->info.offset}; + MemoryCopy(dst, &baked, sizeof(baked)); + }break; + case RDI_LocationKind_ValReg: + { + RDI_LocationReg baked = {loc->info.kind, loc->info.reg_code}; + MemoryCopy(dst, &baked, sizeof(baked)); + }break; + } + } + } + } + //- rjf: bake global variables ProfScope("bake global variables") { diff --git a/src/rdi_make/rdi_make_local_2.h b/src/rdi_make/rdi_make_local_2.h index d4d16932..9e679f6a 100644 --- a/src/rdi_make/rdi_make_local_2.h +++ b/src/rdi_make/rdi_make_local_2.h @@ -53,6 +53,7 @@ struct RDIM2_Shared RDIM_SrcFileBakeResult baked_src_files; RDIM_TypeNodeBakeResult baked_type_nodes; RDIM_UDTBakeResult baked_udts; + RDIM_LocationBakeResult baked_locations; RDIM_GlobalVariableBakeResult baked_global_variables; RDIM_ThreadVariableBakeResult baked_thread_variables; RDIM_ConstantsBakeResult baked_constants;