subset flag for constants conversion; fix empty-tpi-hash case

This commit is contained in:
Ryan Fleury
2025-09-24 12:42:04 -07:00
parent 7f2a066e8f
commit fa0b2440ec
3 changed files with 175 additions and 171 deletions
+1
View File
@@ -318,6 +318,7 @@ X(Units, units)\
X(Procedures, procedures)\ X(Procedures, procedures)\
X(GlobalVariables, global_variables)\ X(GlobalVariables, global_variables)\
X(ThreadVariables, thread_variables)\ X(ThreadVariables, thread_variables)\
X(Constants, constants)\
X(Scopes, scopes)\ X(Scopes, scopes)\
X(Locals, locals)\ X(Locals, locals)\
X(Types, types)\ X(Types, types)\
+156 -154
View File
@@ -823,207 +823,209 @@ pdb_leaf_data_from_tpi(PDB_TpiParsed *tpi){
} }
internal CV_TypeIdArray internal CV_TypeIdArray
pdb_tpi_itypes_from_name(Arena *arena, PDB_TpiHashParsed *tpi_hash, CV_LeafParsed *leaf, pdb_tpi_itypes_from_name(Arena *arena, PDB_TpiHashParsed *tpi_hash, CV_LeafParsed *leaf, String8 name, B32 compare_unique_name, U32 output_cap)
String8 name, B32 compare_unique_name, U32 output_cap){ {
U32 hash = pdb_hash_v1(name); CV_TypeIdArray result = {0};
U32 bucket_idx = ((tpi_hash->bucket_mask != 0) ? if(tpi_hash->bucket_count != 0)
hash&tpi_hash->bucket_mask : {
hash%tpi_hash->bucket_count); U32 hash = pdb_hash_v1(name);
U32 bucket_idx = ((tpi_hash->bucket_mask != 0) ?
hash&tpi_hash->bucket_mask :
hash%tpi_hash->bucket_count);
CV_TypeId itype_first = leaf->itype_first; CV_TypeId itype_first = leaf->itype_first;
CV_TypeId itype_opl = leaf->itype_opl; CV_TypeId itype_opl = leaf->itype_opl;
String8 data = leaf->data; String8 data = leaf->data;
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
struct Chain{ struct Chain
struct Chain *next; {
CV_TypeId itype; struct Chain *next;
}; CV_TypeId itype;
struct Chain *first = 0; };
struct Chain *last = 0; struct Chain *first = 0;
U32 count = 0; struct Chain *last = 0;
U32 count = 0;
for (PDB_TpiHashBlock *block = tpi_hash->buckets[bucket_idx]; for (PDB_TpiHashBlock *block = tpi_hash->buckets[bucket_idx];
block != 0; block != 0;
block = block->next){ block = block->next){
U32 local_count = block->local_count; U32 local_count = block->local_count;
CV_TypeId *itype_ptr = block->itypes; CV_TypeId *itype_ptr = block->itypes;
for (U32 i = 0; i < local_count; i += 1, itype_ptr += 1){ for (U32 i = 0; i < local_count; i += 1, itype_ptr += 1){
String8 extracted_name = {0}; String8 extracted_name = {0};
CV_TypeId itype = *itype_ptr; CV_TypeId itype = *itype_ptr;
if (itype_first <= itype && itype < itype_opl){ if (itype_first <= itype && itype < itype_opl){
CV_RecRange *range = &leaf->leaf_ranges.ranges[itype - leaf->itype_first]; CV_RecRange *range = &leaf->leaf_ranges.ranges[itype - leaf->itype_first];
if (range->off + range->hdr.size <= data.size){ if (range->off + range->hdr.size <= data.size){
U8 *first = data.str + range->off + 2; U8 *first = data.str + range->off + 2;
U64 cap = range->hdr.size - 2; U64 cap = range->hdr.size - 2;
switch (range->hdr.kind){ switch (range->hdr.kind){
default:break; default:break;
case CV_LeafKind_CLASS: case CV_LeafKind_CLASS:
case CV_LeafKind_STRUCTURE: case CV_LeafKind_STRUCTURE:
{ {
if (sizeof(CV_LeafStruct) <= cap){ if (sizeof(CV_LeafStruct) <= cap){
CV_LeafStruct *lf_struct = (CV_LeafStruct*)first; CV_LeafStruct *lf_struct = (CV_LeafStruct*)first;
if (!(lf_struct->props & CV_TypeProp_FwdRef)){ if (!(lf_struct->props & CV_TypeProp_FwdRef)){
// size // size
U8 *numeric_ptr = (U8*)(lf_struct + 1); U8 *numeric_ptr = (U8*)(lf_struct + 1);
CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap); CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap);
// name // name
U8 *name_ptr = numeric_ptr + size.encoded_size; U8 *name_ptr = numeric_ptr + size.encoded_size;
String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap)); String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap));
// unique name // unique name
if (compare_unique_name){ if (compare_unique_name){
if (lf_struct->props & CV_TypeProp_HasUniqueName) { if (lf_struct->props & CV_TypeProp_HasUniqueName) {
U8 *unique_name_ptr = name_ptr + name.size + 1; U8 *unique_name_ptr = name_ptr + name.size + 1;
String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap)); String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap));
extracted_name = unique_name; extracted_name = unique_name;
}
}
else{
extracted_name = name;
} }
} }
else{
extracted_name = name;
}
} }
} }break;
}break;
case CV_LeafKind_CLASS2: case CV_LeafKind_CLASS2:
case CV_LeafKind_STRUCT2: case CV_LeafKind_STRUCT2:
{ {
if (sizeof(CV_LeafStruct2) <= cap){ if (sizeof(CV_LeafStruct2) <= cap){
CV_LeafStruct2 *lf_struct = (CV_LeafStruct2*)first; CV_LeafStruct2 *lf_struct = (CV_LeafStruct2*)first;
if (!(lf_struct->props & CV_TypeProp_FwdRef)){ if (!(lf_struct->props & CV_TypeProp_FwdRef)){
// size // size
U8 *numeric_ptr = (U8*)(lf_struct + 1); U8 *numeric_ptr = (U8*)(lf_struct + 1);
CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap); CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap);
// name // name
U8 *name_ptr = numeric_ptr + size.encoded_size; U8 *name_ptr = numeric_ptr + size.encoded_size;
String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap)); String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap));
// unique name // unique name
if (compare_unique_name){ if (compare_unique_name){
if (lf_struct->props & CV_TypeProp_HasUniqueName) { if (lf_struct->props & CV_TypeProp_HasUniqueName) {
U8 *unique_name_ptr = name_ptr + name.size + 1; U8 *unique_name_ptr = name_ptr + name.size + 1;
String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap)); String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap));
extracted_name = unique_name; extracted_name = unique_name;
}
}
else{
extracted_name = name;
} }
} }
else{
extracted_name = name;
}
} }
} }break;
}break;
case CV_LeafKind_UNION: case CV_LeafKind_UNION:
{ {
if (sizeof(CV_LeafUnion) <= cap){ if (sizeof(CV_LeafUnion) <= cap){
CV_LeafUnion *lf_union = (CV_LeafUnion*)first; CV_LeafUnion *lf_union = (CV_LeafUnion*)first;
if (!(lf_union->props & CV_TypeProp_FwdRef)){ if (!(lf_union->props & CV_TypeProp_FwdRef)){
// size // size
U8 *numeric_ptr = (U8*)(lf_union + 1); U8 *numeric_ptr = (U8*)(lf_union + 1);
CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap); CV_NumericParsed size = cv_numeric_from_data_range(numeric_ptr, first + cap);
// name // name
U8 *name_ptr = numeric_ptr + size.encoded_size; U8 *name_ptr = numeric_ptr + size.encoded_size;
String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap)); String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap));
// unique name // unique name
if (compare_unique_name){ if (compare_unique_name){
if (lf_union->props & CV_TypeProp_HasUniqueName) { if (lf_union->props & CV_TypeProp_HasUniqueName) {
U8 *unique_name_ptr = name_ptr + name.size + 1; U8 *unique_name_ptr = name_ptr + name.size + 1;
String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap)); String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap));
extracted_name = unique_name; extracted_name = unique_name;
}
}
else{
extracted_name = name;
} }
} }
else{
extracted_name = name;
}
} }
} }break;
}break;
case CV_LeafKind_ENUM: case CV_LeafKind_ENUM:
{ {
if (sizeof(CV_LeafEnum) <= cap){ if (sizeof(CV_LeafEnum) <= cap){
CV_LeafEnum *lf_enum = (CV_LeafEnum*)first; CV_LeafEnum *lf_enum = (CV_LeafEnum*)first;
if (!(lf_enum->props & CV_TypeProp_FwdRef)){ if (!(lf_enum->props & CV_TypeProp_FwdRef)){
// name // name
U8 *name_ptr = (U8*)(lf_enum + 1); U8 *name_ptr = (U8*)(lf_enum + 1);
String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap)); String8 name = str8_cstring_capped((char*)name_ptr, (char *)(first + cap));
// unique name // unique name
if (compare_unique_name){ if (compare_unique_name){
if (lf_enum->props & CV_TypeProp_HasUniqueName) { if (lf_enum->props & CV_TypeProp_HasUniqueName) {
U8 *unique_name_ptr = name_ptr + name.size + 1; U8 *unique_name_ptr = name_ptr + name.size + 1;
String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap)); String8 unique_name = str8_cstring_capped((char*)unique_name_ptr, (char *)(first + cap));
extracted_name = unique_name; extracted_name = unique_name;
}
}
else{
extracted_name = name;
} }
} }
else{
extracted_name = name;
}
} }
} }break;
}break; }
}
}
if (str8_match(extracted_name, name, 0)){
struct Chain *chain = push_array(scratch.arena, struct Chain, 1);
SLLQueuePush(first, last, chain);
count += 1;
chain->itype = itype;
if (count == output_cap){
goto dblbreak;
} }
} }
} }
}
if (str8_match(extracted_name, name, 0)){ dblbreak:;
struct Chain *chain = push_array(scratch.arena, struct Chain, 1);
SLLQueuePush(first, last, chain);
count += 1; // assemble result
chain->itype = itype; CV_TypeId *itypes = push_array_aligned(arena, CV_TypeId, count, 8);
if (count == output_cap){ {
goto dblbreak; CV_TypeId *itype_ptr = itypes;
} for (struct Chain *node = first;
node != 0;
node = node->next, itype_ptr += 1){
*itype_ptr = node->itype;
} }
} }
result.itypes = itypes;
result.count = count;
scratch_end(scratch);
} }
return result;
dblbreak:;
// assemble result
CV_TypeId *itypes = push_array_aligned(arena, CV_TypeId, count, 8);
{
CV_TypeId *itype_ptr = itypes;
for (struct Chain *node = first;
node != 0;
node = node->next, itype_ptr += 1){
*itype_ptr = node->itype;
}
}
CV_TypeIdArray result = {0};
result.itypes = itypes;
result.count = count;
scratch_end(scratch);
return(result);
} }
internal CV_TypeId internal CV_TypeId
pdb_tpi_first_itype_from_name(PDB_TpiHashParsed *tpi_hash, CV_LeafParsed *tpi_leaf, pdb_tpi_first_itype_from_name(PDB_TpiHashParsed *tpi_hash, CV_LeafParsed *tpi_leaf, String8 name, B32 compare_unique_name)
String8 name, B32 compare_unique_name){ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CV_TypeIdArray array = pdb_tpi_itypes_from_name(scratch.arena, tpi_hash, tpi_leaf, CV_TypeIdArray array = pdb_tpi_itypes_from_name(scratch.arena, tpi_hash, tpi_leaf, name, compare_unique_name, 1);
name, compare_unique_name, 1);
CV_TypeId result = 0; CV_TypeId result = 0;
if (array.count > 0){ if(array.count > 0)
{
result = array.itypes[0]; result = array.itypes[0];
} }
scratch_end(scratch); scratch_end(scratch);
return(result); return(result);
} }
+1
View File
@@ -4118,6 +4118,7 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params)
//- rjf: CONSTANT //- rjf: CONSTANT
case CV_SymKind_CONSTANT: case CV_SymKind_CONSTANT:
if(params->subset_flags & RDIM_SubsetFlag_Constants)
{ {
// rjf: unpack // rjf: unpack
CV_SymConstant *sym = (CV_SymConstant *)sym_header_struct_base; CV_SymConstant *sym = (CV_SymConstant *)sym_header_struct_base;