metagen: simplify metacode structs

This commit is contained in:
Ryan Fleury
2024-02-13 11:00:58 -08:00
parent ea840a71e8
commit 742d2387e2
6 changed files with 34 additions and 46 deletions
+3 -8
View File
@@ -1733,15 +1733,10 @@ DF_DevToggleTable:
COUNT,
}
@table_gen
@struct DF_CmdParams:
{
`typedef struct DF_CmdParams DF_CmdParams;`;
`struct DF_CmdParams`;
`{`;
`U64 slot_props[(DF_CmdParamSlot_COUNT + 63) / 64];`;
@expand(DF_CmdParamSlotTable a)
`$(a.c_type) $(a.name_lower);`;
`};`;
`U64 slot_props[(DF_CmdParamSlot_COUNT + 63) / 64]`;
@expand(DF_CmdParamSlotTable a) `$(a.c_type) $(a.name_lower)`;
}
@table_gen_data(type:Rng1U64, fallback:0)
+1
View File
@@ -409,6 +409,7 @@ B32 prefer_dasm;
B32 force_confirm;
};
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(array);
DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_DEF(bswap);
DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(list);
+3 -8
View File
@@ -70,15 +70,10 @@ EVAL_ResultCodeTable:
{ MalformedBytecode "Malformed bytecode." }
}
@table_gen
@enum(U32) EVAL_ExprKind:
{
`typedef U32 EVAL_ExprKind;`;
`enum`;
`{`;
@expand(EVAL_ExprKindTable a) `EVAL_ExprKind_$(a.name),`;
`EVAL_ExprKind_COUNT`;
`};`;
``;
@expand(EVAL_ExprKindTable a) `$(a.name)`,
COUNT,
}
@enum EVAL_ResultCode:
+19 -19
View File
@@ -6,24 +6,8 @@
#ifndef EVAL_META_H
#define EVAL_META_H
typedef enum EVAL_ResultCode
{
EVAL_ResultCode_Good,
EVAL_ResultCode_DivideByZero,
EVAL_ResultCode_BadOp,
EVAL_ResultCode_BadOpTypes,
EVAL_ResultCode_BadMemRead,
EVAL_ResultCode_BadRegRead,
EVAL_ResultCode_BadFrameBase,
EVAL_ResultCode_BadModuleBase,
EVAL_ResultCode_BadTLSBase,
EVAL_ResultCode_InsufficientStackSpace,
EVAL_ResultCode_MalformedBytecode,
EVAL_ResultCode_COUNT,
} EVAL_ResultCode;
typedef U32 EVAL_ExprKind;
enum
typedef enum EVAL_ExprKindEnum
{
EVAL_ExprKind_ArrayIndex,
EVAL_ExprKind_MemberAccess,
@@ -64,8 +48,24 @@ EVAL_ExprKind_Array,
EVAL_ExprKind_Func,
EVAL_ExprKind_Define,
EVAL_ExprKind_LeafIdent,
EVAL_ExprKind_COUNT
};
EVAL_ExprKind_COUNT,
} EVAL_ExprKindEnum;
typedef enum EVAL_ResultCode
{
EVAL_ResultCode_Good,
EVAL_ResultCode_DivideByZero,
EVAL_ResultCode_BadOp,
EVAL_ResultCode_BadOpTypes,
EVAL_ResultCode_BadMemRead,
EVAL_ResultCode_BadRegRead,
EVAL_ResultCode_BadFrameBase,
EVAL_ResultCode_BadModuleBase,
EVAL_ResultCode_BadTLSBase,
EVAL_ResultCode_InsufficientStackSpace,
EVAL_ResultCode_MalformedBytecode,
EVAL_ResultCode_COUNT,
} EVAL_ResultCode;
U8 eval_expr_kind_child_counts[] =
{
+4 -5
View File
@@ -142,7 +142,7 @@ int main(int argument_count, char **arguments)
}
//////////////////////////////
//- rjf: generate table enums
//- rjf: generate enums
//
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
{
@@ -183,14 +183,14 @@ int main(int argument_count, char **arguments)
}
//////////////////////////////
//- rjf: generate table structs
//- rjf: generate structs
//
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
{
MD_Node *file = n->v.root;
for(MD_EachNode(node, file->first))
{
if(md_node_has_tag(node, str8_lit("table_gen_struct"), 0))
if(md_node_has_tag(node, str8_lit("struct"), 0))
{
String8 layer_key = mg_layer_key_from_path(file->string);
MG_Layer *layer = mg_layer_from_key(layer_key);
@@ -200,8 +200,7 @@ int main(int argument_count, char **arguments)
for(String8Node *n = gen_strings.first; n != 0; n = n->next)
{
String8 escaped = mg_escaped_from_str8(mg_arena, n->string);
str8_list_push(mg_arena, &layer->structs, escaped);
str8_list_push(mg_arena, &layer->structs, str8_lit("\n"));
str8_list_pushf(mg_arena, &layer->structs, "%S;\n", escaped);
}
str8_list_pushf(mg_arena, &layer->structs, "};\n\n");
}
+4 -6
View File
@@ -313,10 +313,9 @@ REGS_ArchTable:
COUNT,
}
@table_gen_struct
REGS_RegBlockX64:
@struct REGS_RegBlockX64:
{
@expand(REGS_RegTableX64 a) `REGS_Reg$(a.size) $(a.name);`;
@expand(REGS_RegTableX64 a) `REGS_Reg$(a.size) $(a.name)`,
}
@table_gen_data(type:REGS_UsageKind, fallback:`REGS_UsageKind_Normal`)
@@ -378,10 +377,9 @@ regs_g_alias_code_x64_slice_table:
COUNT,
}
@table_gen_struct
REGS_RegBlockX86:
@struct REGS_RegBlockX86:
{
@expand(REGS_RegTableX86 a) `REGS_Reg$(a.size) $(a.name);`;
@expand(REGS_RegTableX86 a) `REGS_Reg$(a.size) $(a.name)`,
}
@table_gen_data(type:REGS_UsageKind, fallback:`REGS_UsageKind_Normal`)