bswap view rule

This commit is contained in:
Ryan Fleury
2024-08-27 11:37:27 -07:00
parent cf7b664ab2
commit 90273e7a2e
8 changed files with 18 additions and 30 deletions
+1 -1
View File
@@ -528,7 +528,7 @@ DF_CoreViewRuleTable:
{Array array "array" - - x - - "Array" x "x:{expr}" "Specifies that a pointer points to N elements, rather than only 1." }
{Slice slice "slice" - - x - - "Slice" x "" "Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer." }
{List list "list" - - - - x "List" x "x:{member}" "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 integral evaluations should be byte-swapped, such that their endianness is reversed." }
{ByteSwap bswap "bswap" x - x - - "Byte Swap" x "" "Specifies that all integral evaluations 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." }
{BaseBin base_bin "bin" x - - - - "Binary Base (Base 2)" x "" "Specifies that all integral evaluations should appear in base-2 form." }
{BaseOct base_oct "oct" x - - - - "Octal Base (Base 8)" x "" "Specifies that all integral evaluations should appear in base-8 form." }
+1 -1
View File
@@ -487,7 +487,7 @@ DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[19] =
{str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("x:{expr}"), 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_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , 0, 0, },
{str8_lit_comp("slice"), str8_lit_comp("Slice"), str8_lit_comp(""), str8_lit_comp("Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, 0, },
{str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("x:{member}"), 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_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(list) , },
{str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(bswap) , 0, },
{str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, 0, },
{str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, 0, },
{str8_lit_comp("bin"), str8_lit_comp("Binary Base (Base 2)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-2 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, 0, },
{str8_lit_comp("oct"), str8_lit_comp("Octal Base (Base 8)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-8 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, 0, },
+1 -1
View File
@@ -432,7 +432,7 @@ U64 inline_depth;
DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(array);
DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(slice);
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(bswap);
DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(bswap);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(default);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(list);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(only);
+3 -25
View File
@@ -275,32 +275,10 @@ DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_DEF(list){}
////////////////////////////////
//~ rjf: "bswap"
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(bswap)
DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(bswap)
{
Temp scratch = scratch_begin(&arena, 1);
E_TypeKey type_key = eval.type_key;
E_TypeKind type_kind = e_type_kind_from_key(type_key);
U64 type_size_bytes = e_type_byte_size_from_key(type_key);
if(E_TypeKind_Char8 <= type_kind && type_kind <= E_TypeKind_S256 &&
(type_size_bytes == 2 ||
type_size_bytes == 4 ||
type_size_bytes == 8))
{
E_Eval value_eval = e_value_eval_from_eval(eval);
if(value_eval.mode == E_Mode_Value)
{
switch(type_size_bytes)
{
default:{}break;
case 2:{U16 v = (U16)value_eval.value.u64; v = bswap_u16(v); value_eval.value.u64 = (U64)v;}break;
case 4:{U32 v = (U32)value_eval.value.u64; v = bswap_u32(v); value_eval.value.u64 = (U64)v;}break;
case 8:{U64 v = value_eval.value.u64; v = bswap_u64(v); value_eval.value.u64 = v;}break;
}
}
eval = value_eval;
}
scratch_end(scratch);
return eval;
expr = e_expr_ref_bswap(arena, expr);
return expr;
}
////////////////////////////////
+1 -1
View File
@@ -86,7 +86,7 @@ E_ExprKindTable:
{ Cast Null 1 "cast" "(" ")" "" }
{ Sizeof UnaryPrefix 1 "sizeof" "sizeof" "" "" }
{ ByteSwap UnaryPrefix 1 "bswap" "bswap" "(" ")"}
{ ByteSwap UnaryPrefix 1 "bswap" "bswap" ."(" ")"}
{ Neg UnaryPrefix 2 "-" "-" "" "" }
{ LogNot UnaryPrefix 2 "!" "!" "" "" }
+9
View File
@@ -716,6 +716,15 @@ e_expr_ref_cast(Arena *arena, E_TypeKey type_key, E_Expr *rhs)
return root;
}
internal E_Expr *
e_expr_ref_bswap(Arena *arena, E_Expr *rhs)
{
E_Expr *root = e_push_expr(arena, E_ExprKind_ByteSwap, 0);
E_Expr *rhs_ref = e_expr_ref(arena, rhs);
e_expr_push_child(root, rhs_ref);
return root;
}
////////////////////////////////
//~ rjf: Expression Tree -> String Conversions
+1
View File
@@ -222,6 +222,7 @@ internal E_Expr *e_expr_ref_member_access(Arena *arena, E_Expr *lhs, String8 mem
internal E_Expr *e_expr_ref_array_index(Arena *arena, E_Expr *lhs, U64 index);
internal E_Expr *e_expr_ref_deref(Arena *arena, E_Expr *rhs);
internal E_Expr *e_expr_ref_cast(Arena *arena, E_TypeKey type_key, E_Expr *rhs);
internal E_Expr *e_expr_ref_bswap(Arena *arena, E_Expr *rhs);
////////////////////////////////
//~ rjf: Expression Tree -> String Conversions
+1 -1
View File
@@ -88,7 +88,7 @@ E_OpInfo e_expr_kind_op_info_table[45] =
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("Address") },
{ E_OpKind_Null, 1, str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp("Cast") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("sizeof"), str8_lit_comp(""), str8_lit_comp("Sizeof") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("bswap"), str8_lit_comp("("), str8_lit_comp("ByteSwap") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("bswap"), str8_lit_comp("."), str8_lit_comp("ByteSwap") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("Neg") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("LogNot") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("BitNot") },