bitfield support in address mode -> value mode evaluation path

This commit is contained in:
Ryan Fleury
2024-03-29 09:51:38 -07:00
parent 60e1f105e4
commit 60030b298b
2 changed files with 22 additions and 8 deletions
+15 -1
View File
@@ -4219,7 +4219,7 @@ df_value_mode_eval_from_eval(TG_Graph *graph, RDI_Parsed *rdi, DF_CtrlCtx *ctrl_
TG_Key type_key = eval.type_key;
TG_Kind type_kind = tg_kind_from_key(type_key);
U64 type_byte_size = tg_byte_size_from_graph_rdi_key(graph, rdi, type_key);
if(!tg_key_match(type_key, tg_key_zero()) && type_byte_size <= 8)
if(!tg_key_match(type_key, tg_key_zero()) && type_byte_size <= sizeof(U64)*2)
{
Temp scratch = scratch_begin(0, 0);
Rng1U64 vaddr_range = r1u64(eval.offset, eval.offset + type_byte_size);
@@ -4231,6 +4231,20 @@ df_value_mode_eval_from_eval(TG_Graph *graph, RDI_Parsed *rdi, DF_CtrlCtx *ctrl_
MemoryCopy(eval.imm_u128, data.str, Min(data.size, sizeof(U64)*2));
eval.mode = EVAL_EvalMode_Value;
// rjf: mask&shift, for bitfields
if(type_kind == TG_Kind_Bitfield && type_byte_size <= sizeof(U64))
{
TG_Type *type = tg_type_from_graph_rdi_key(scratch.arena, graph, rdi, type_key);
U64 valid_bits_mask = 0;
for(U64 idx = 0; idx < type->count; idx += 1)
{
valid_bits_mask |= (1<<idx);
}
eval.imm_u64 = eval.imm_u64 >> type->off;
eval.imm_u64 = eval.imm_u64 & valid_bits_mask;
eval.type_key = type->direct_type_key;
}
// rjf: manually sign-extend
switch(type_kind)
{
+7 -7
View File
@@ -1151,8 +1151,11 @@ tg_lhs_string_from_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key ke
case TG_Kind_Bitfield:
{
TG_Key direct = tg_direct_from_graph_rdi_key(graph, rdi, key);
tg_lhs_string_from_key(arena, graph, rdi, direct, out, prec, skip_return);
Temp scratch = scratch_begin(&arena, 1);
TG_Type *type = tg_type_from_graph_rdi_key(scratch.arena, graph, rdi, key);
tg_lhs_string_from_key(arena, graph, rdi, type->direct_type_key, out, prec, skip_return);
str8_list_pushf(arena, out, ": %I64u", type->count);
scratch_end(scratch);
}break;
case TG_Kind_Modifier:
@@ -1280,11 +1283,8 @@ tg_rhs_string_from_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key ke
case TG_Kind_Bitfield:
{
Temp scratch = scratch_begin(&arena, 1);
TG_Type *type = tg_type_from_graph_rdi_key(scratch.arena, graph, rdi, key);
tg_rhs_string_from_key(arena, graph, rdi, type->direct_type_key, out, prec);
str8_list_pushf(arena, out, ": %I64u", type->count);
scratch_end(scratch);
TG_Key direct = tg_direct_from_graph_rdi_key(graph, rdi, key);
tg_rhs_string_from_key(arena, graph, rdi, direct, out, prec);
}break;
case TG_Kind_Modifier: