clean up & merge inline binary annotation decoders

This commit is contained in:
Ryan Fleury
2024-05-28 07:37:18 -07:00
parent f14686c6fb
commit 86a9934016
2 changed files with 49 additions and 41 deletions
+42 -35
View File
@@ -171,44 +171,51 @@ cv_f64_from_numeric(CV_NumericParsed *num){
internal U64 internal U64
cv_decode_inline_annot_u32(String8 data, U64 offset, U32 *out_value) cv_decode_inline_annot_u32(String8 data, U64 offset, U32 *out_value)
{ {
U32 value;
U64 cursor = offset; U64 cursor = offset;
// rjf: read header
U8 header = 0; U8 header = 0;
cursor += str8_deserial_read_struct(data, cursor, &header); cursor += str8_deserial_read_struct(data, cursor, &header);
// 1 byte // rjf: decode value
if((header & 0x80) == 0) U32 value = 0;
{ {
value = header; // 1 byte
if((header & 0x80) == 0)
{
value = header;
}
// 2 bytes
else if((header & 0xC0) == 0x80 && cursor+2 <= data.size)
{
U8 second_byte;
cursor += str8_deserial_read_struct(data, cursor, &second_byte);
value = ((header & 0x3F) << 8) | second_byte;
}
// 4 bytes
else if((header & 0xE0) == 0xC0 && cursor+3 <= data.size)
{
U8 second_byte, third_byte, fourth_byte;
cursor += str8_deserial_read_struct(data, cursor, &second_byte);
cursor += str8_deserial_read_struct(data, cursor, &third_byte);
cursor += str8_deserial_read_struct(data, cursor, &fourth_byte);
value = (((U32)header & 0x1F) << 24) | ((U32)second_byte << 16) | ((U32)third_byte << 8) | (U32)fourth_byte;
}
// bad encode
else if((header & 0xE0) == 0xE0)
{
value = max_U32;
}
} }
// 2 bytes
else if((header & 0xC0) == 0x80) // rjf: output results
if(out_value)
{ {
Assert(cursor + sizeof(U8) * 2 <= data.size); *out_value = value;
U8 second_byte;
cursor += str8_deserial_read_struct(data, cursor, &second_byte);
value = ((header & 0x3F) << 8) | second_byte;
} }
// 4 bytes
else if((header & 0xE0) == 0xC0)
{
Assert(cursor + sizeof(U8) * 3 <= data.size);
U8 second_byte, third_byte, fourth_byte;
cursor += str8_deserial_read_struct(data, cursor, &second_byte);
cursor += str8_deserial_read_struct(data, cursor, &third_byte);
cursor += str8_deserial_read_struct(data, cursor, &fourth_byte);
value = (((U32)header & 0x1F) << 24) | ((U32)second_byte << 16) | ((U32)third_byte << 8) | (U32)fourth_byte;
}
// bad encode
else if((header & 0xE0) == 0xE0)
{
value = max_U32;
}
*out_value = value;
U64 read_size = cursor - offset; U64 read_size = cursor - offset;
return read_size; return read_size;
} }
@@ -217,9 +224,9 @@ internal U64
cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value) cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value)
{ {
U32 value; U32 value;
U64 read_size = cv_decode_inline_annot_u32(data, offset, &value); U64 read_size = cv_decode_inline_annot_u32(data, offset, &value);
if(value & 1) if(value & 1)
{ {
value = -(value >> 1); value = -(value >> 1);
@@ -228,9 +235,9 @@ cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value)
{ {
value = value >> 1; value = value >> 1;
} }
*out_value = (S32)value; *out_value = (S32)value;
return read_size; return read_size;
} }
+7 -6
View File
@@ -1761,8 +1761,8 @@ struct CV_SymBuildInfo
//- (SymKind: INLINESITE) //- (SymKind: INLINESITE)
typedef U32 CV_InlineBinaryAnnotaiton; typedef U32 CV_InlineBinaryAnnotation;
typedef enum CV_InlineBinaryAnnotationenum typedef enum CV_InlineBinaryAnnotationEnum
{ {
CV_InlineBinaryAnnotation_Null, CV_InlineBinaryAnnotation_Null,
CV_InlineBinaryAnnotation_CodeOffset, CV_InlineBinaryAnnotation_CodeOffset,
@@ -1778,14 +1778,16 @@ typedef enum CV_InlineBinaryAnnotationenum
CV_InlineBinaryAnnotation_ChangeCodeOffsetAndLineOffset, CV_InlineBinaryAnnotation_ChangeCodeOffsetAndLineOffset,
CV_InlineBinaryAnnotation_ChangeCodeLengthAndCodeOffset, CV_InlineBinaryAnnotation_ChangeCodeLengthAndCodeOffset,
CV_InlineBinaryAnnotaiton_ChangeColumnEnd CV_InlineBinaryAnnotaiton_ChangeColumnEnd
}; }
CV_InlineBinaryAnnotationEnum;
typedef U32 CV_InlineRangeKind; typedef U32 CV_InlineRangeKind;
typedef enum CV_InlnineRangeKindEnum typedef enum CV_InlineRangeKindEnum
{ {
CV_InlineRangeKind_Expr, CV_InlineRangeKind_Expr,
CV_InlineRangeKind_Stmt CV_InlineRangeKind_Stmt
}; }
CV_InlineRangeKindEnum;
typedef struct CV_SymInlineSite CV_SymInlineSite; typedef struct CV_SymInlineSite CV_SymInlineSite;
struct CV_SymInlineSite struct CV_SymInlineSite
@@ -2917,7 +2919,6 @@ struct CV_TypeIdArray
U64 count; U64 count;
}; };
//////////////////////////////// ////////////////////////////////
//~ CodeView Common Functions //~ CodeView Common Functions