Add view rule slice

This commit is contained in:
gingerBill
2024-02-12 14:16:23 +00:00
parent 57a35c6b28
commit 156615a3ba
4 changed files with 71 additions and 0 deletions
+1
View File
@@ -487,6 +487,7 @@ DF_CoreViewRuleTable:
{
{Null null "" - - - - "" - "" }
{Array array "array" - - x - "Array" x "Specifies that a pointer points to N elements, rather than only 1." }
{Slice slice "slice" - - x - "Slice" x "Specifies that a struct to be rendered as a slice." }
{List list "list" - - - x "List" x "Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list." }
{ByteSwap bswap "bswap" x - x - "Byte Swap" x "Specifies that all integer primitives should be byte-swapped, such that their endianness is reversed." }
{BaseDec base_dec "dec" x - - - "Decimal Base (Base 10)" x "Specifies that all integral evaluations should appear in base-10 form." }
+1
View File
@@ -217,6 +217,7 @@ DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[] =
{
{str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("Specifies that a pointer points to N elements, rather than only 1."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(array) , 0, },
{str8_lit_comp("slice"), str8_lit_comp("Slice"), str8_lit_comp("Specifies that a struct to be rendered as a slice."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(slice) , 0, },
{str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(list) , },
{str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp("Specifies that all integer primitives should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(bswap) , 0, },
{str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
+2
View File
@@ -344,6 +344,7 @@ typedef enum DF_CoreViewRuleKind
{
DF_CoreViewRuleKind_Null,
DF_CoreViewRuleKind_Array,
DF_CoreViewRuleKind_Slice,
DF_CoreViewRuleKind_List,
DF_CoreViewRuleKind_ByteSwap,
DF_CoreViewRuleKind_BaseDec,
@@ -410,6 +411,7 @@ B32 force_confirm;
};
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(array);
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(slice);
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(bswap);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(list);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(only);
+67
View File
@@ -352,6 +352,73 @@ DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(array)
return eval;
}
void dbg_printf(char const *fmt, ...) {
va_list argp;
va_start(argp, fmt);
char buf[4096] = {};
vsnprintf_s(buf, 4095, fmt, argp);
va_end(argp);
OutputDebugStringA(buf);
}
////////////////////////////////
//~ bill: "slice"
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(slice)
{
TG_Key type_key = eval.type_key;
TG_Kind type_kind = tg_kind_from_key(type_key);
if (type_kind == TG_Kind_Struct) {
Temp scratch = scratch_begin(&arena, 1);
DF_CfgNode *struct_node = val->last;
if (struct_node != &df_g_nil_cfg_node) {
TG_MemberArray data_members = tg_data_members_from_graph_raddbg_key(arena, parse_ctx->type_graph, parse_ctx->rdbg, type_key);
TG_Member *member_ptr = NULL;
TG_Member *member_len = NULL;
for (U64 i = 0; i < data_members.count; i++) {
TG_Member *member = &data_members.v[i];
if (str8_match(member->name, str8_lit("data"), StringMatchFlag_CaseInsensitive) ||
str8_match(member->name, str8_lit("ptr"), StringMatchFlag_CaseInsensitive)) {
member_ptr = member;
} else if (str8_match(member->name, str8_lit("len"), StringMatchFlag_CaseInsensitive) ||
str8_match(member->name, str8_lit("size"), StringMatchFlag_CaseInsensitive)) {
member_len = member;
}
}
if (member_ptr && member_len) {
U64 slice_len = 0;
DF_Eval len_eval = zero_struct;
len_eval.mode = EVAL_EvalMode_Addr;
len_eval.offset = eval.offset + member_len->off;
len_eval.type_key = member_len->type_key;
len_eval = df_value_mode_eval_from_eval(parse_ctx->type_graph, parse_ctx->rdbg, ctrl_ctx, len_eval);
if (len_eval.mode == EVAL_EvalMode_Value) {
slice_len = len_eval.imm_u64;
}
TG_Key pointee = tg_ptee_from_graph_raddbg_key(parse_ctx->type_graph, parse_ctx->rdbg, member_ptr->type_key);
TG_Key array_type = tg_cons_type_make(parse_ctx->type_graph, TG_Kind_Array, pointee, slice_len);
// TODO(bill): How do you make this render with the original name, if possible?
DF_Eval new_eval = zero_struct;
new_eval.mode = EVAL_EvalMode_Addr;
new_eval.offset = eval.offset + member_ptr->off;
new_eval.type_key = tg_cons_type_make(parse_ctx->type_graph, TG_Kind_Ptr, array_type, 0);
eval = new_eval;
}
}
scratch_end(scratch);
}
return eval;
}
////////////////////////////////
//~ rjf: "list"