mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-29 18:50:03 +00:00
git normalize all files
This commit is contained in:
+106
-106
@@ -1,106 +1,106 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
@table(name num_children op_string)
|
||||
// num_children - # of children packed after this node kind
|
||||
// op_string - string for quick display of the operator
|
||||
EVAL_ExprKindTable:
|
||||
{
|
||||
{ Nil 0 "" }
|
||||
|
||||
{ ArrayIndex 2 "[]" }
|
||||
{ MemberAccess 2 "." }
|
||||
{ Deref 1 "*" }
|
||||
{ Address 1 "&" }
|
||||
|
||||
{ Cast 2 "cast" }
|
||||
{ Sizeof 1 "sizeof" }
|
||||
|
||||
{ Neg 1 "-" }
|
||||
{ LogNot 1 "!" }
|
||||
{ BitNot 1 "~" }
|
||||
{ Mul 2 "*" }
|
||||
{ Div 2 "/" }
|
||||
{ Mod 2 "%" }
|
||||
{ Add 2 "+" }
|
||||
{ Sub 2 "-" }
|
||||
{ LShift 2 "<<" }
|
||||
{ RShift 2 ">>" }
|
||||
{ Less 2 "<" }
|
||||
{ LsEq 2 "<=" }
|
||||
{ Grtr 2 ">" }
|
||||
{ GrEq 2 ">=" }
|
||||
{ EqEq 2 "==" }
|
||||
{ NtEq 2 "!=" }
|
||||
|
||||
{ BitAnd 2 "&" }
|
||||
{ BitXor 2 "^" }
|
||||
{ BitOr 2 "|" }
|
||||
{ LogAnd 2 "&&" }
|
||||
{ LogOr 2 "||" }
|
||||
|
||||
{ Ternary 3 "? " }
|
||||
|
||||
{ LeafBytecode 0 "bytecode" }
|
||||
{ LeafMember 0 "member" }
|
||||
{ LeafU64 0 "U64" }
|
||||
{ LeafF64 0 "F64" }
|
||||
{ LeafF32 0 "F32" }
|
||||
|
||||
{ TypeIdent 0 "type_ident" }
|
||||
{ Ptr 1 "ptr" }
|
||||
{ Array 2 "array" }
|
||||
{ Func 1 "function" }
|
||||
|
||||
{ Define 2 "=" }
|
||||
{ LeafIdent 0 "leaf_ident" }
|
||||
}
|
||||
|
||||
@table(name display_string)
|
||||
EVAL_ResultCodeTable:
|
||||
{
|
||||
{ Good "" }
|
||||
{ DivideByZero "Cannot divide by zero." }
|
||||
{ BadOp "Invalid operation." }
|
||||
{ BadOpTypes "Invalid operation types." }
|
||||
{ BadMemRead "Failed memory read." }
|
||||
{ BadRegRead "Failed register read." }
|
||||
{ BadFrameBase "Invalid frame base address." }
|
||||
{ BadModuleBase "Invalid module base address." }
|
||||
{ BadTLSBase "Invalid thread-local storage base address." }
|
||||
{ InsufficientStackSpace "Insufficient evaluation machine stack space." }
|
||||
{ MalformedBytecode "Malformed bytecode." }
|
||||
}
|
||||
|
||||
@enum(U32) EVAL_ExprKind:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@enum EVAL_ResultCode:
|
||||
{
|
||||
@expand(EVAL_ResultCodeTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@data(U8) eval_expr_kind_child_counts:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `$(a.num_children)`
|
||||
}
|
||||
|
||||
@data(String8)
|
||||
eval_expr_kind_strings:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@data(String8) eval_result_code_display_strings:
|
||||
{
|
||||
@expand(EVAL_ResultCodeTable a) `str8_lit_comp("$(a.display_string)")`
|
||||
}
|
||||
|
||||
@data(String8) eval_expr_op_strings:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.op_string)")`
|
||||
}
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
@table(name num_children op_string)
|
||||
// num_children - # of children packed after this node kind
|
||||
// op_string - string for quick display of the operator
|
||||
EVAL_ExprKindTable:
|
||||
{
|
||||
{ Nil 0 "" }
|
||||
|
||||
{ ArrayIndex 2 "[]" }
|
||||
{ MemberAccess 2 "." }
|
||||
{ Deref 1 "*" }
|
||||
{ Address 1 "&" }
|
||||
|
||||
{ Cast 2 "cast" }
|
||||
{ Sizeof 1 "sizeof" }
|
||||
|
||||
{ Neg 1 "-" }
|
||||
{ LogNot 1 "!" }
|
||||
{ BitNot 1 "~" }
|
||||
{ Mul 2 "*" }
|
||||
{ Div 2 "/" }
|
||||
{ Mod 2 "%" }
|
||||
{ Add 2 "+" }
|
||||
{ Sub 2 "-" }
|
||||
{ LShift 2 "<<" }
|
||||
{ RShift 2 ">>" }
|
||||
{ Less 2 "<" }
|
||||
{ LsEq 2 "<=" }
|
||||
{ Grtr 2 ">" }
|
||||
{ GrEq 2 ">=" }
|
||||
{ EqEq 2 "==" }
|
||||
{ NtEq 2 "!=" }
|
||||
|
||||
{ BitAnd 2 "&" }
|
||||
{ BitXor 2 "^" }
|
||||
{ BitOr 2 "|" }
|
||||
{ LogAnd 2 "&&" }
|
||||
{ LogOr 2 "||" }
|
||||
|
||||
{ Ternary 3 "? " }
|
||||
|
||||
{ LeafBytecode 0 "bytecode" }
|
||||
{ LeafMember 0 "member" }
|
||||
{ LeafU64 0 "U64" }
|
||||
{ LeafF64 0 "F64" }
|
||||
{ LeafF32 0 "F32" }
|
||||
|
||||
{ TypeIdent 0 "type_ident" }
|
||||
{ Ptr 1 "ptr" }
|
||||
{ Array 2 "array" }
|
||||
{ Func 1 "function" }
|
||||
|
||||
{ Define 2 "=" }
|
||||
{ LeafIdent 0 "leaf_ident" }
|
||||
}
|
||||
|
||||
@table(name display_string)
|
||||
EVAL_ResultCodeTable:
|
||||
{
|
||||
{ Good "" }
|
||||
{ DivideByZero "Cannot divide by zero." }
|
||||
{ BadOp "Invalid operation." }
|
||||
{ BadOpTypes "Invalid operation types." }
|
||||
{ BadMemRead "Failed memory read." }
|
||||
{ BadRegRead "Failed register read." }
|
||||
{ BadFrameBase "Invalid frame base address." }
|
||||
{ BadModuleBase "Invalid module base address." }
|
||||
{ BadTLSBase "Invalid thread-local storage base address." }
|
||||
{ InsufficientStackSpace "Insufficient evaluation machine stack space." }
|
||||
{ MalformedBytecode "Malformed bytecode." }
|
||||
}
|
||||
|
||||
@enum(U32) EVAL_ExprKind:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@enum EVAL_ResultCode:
|
||||
{
|
||||
@expand(EVAL_ResultCodeTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@data(U8) eval_expr_kind_child_counts:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `$(a.num_children)`
|
||||
}
|
||||
|
||||
@data(String8)
|
||||
eval_expr_kind_strings:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@data(String8) eval_result_code_display_strings:
|
||||
{
|
||||
@expand(EVAL_ResultCodeTable a) `str8_lit_comp("$(a.display_string)")`
|
||||
}
|
||||
|
||||
@data(String8) eval_expr_op_strings:
|
||||
{
|
||||
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.op_string)")`
|
||||
}
|
||||
|
||||
+1641
-1641
File diff suppressed because it is too large
Load Diff
+82
-82
@@ -1,82 +1,82 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_COMPILER_H
|
||||
#define EVAL_COMPILER_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Bytecode Helpers
|
||||
|
||||
internal String8 eval_bytecode_from_oplist(Arena *arena, EVAL_OpList *list);
|
||||
|
||||
internal void eval_oplist_push_op(Arena *arena, EVAL_OpList *list, RDI_EvalOp op, U64 p);
|
||||
internal void eval_oplist_push_uconst(Arena *arena, EVAL_OpList *list, U64 x);
|
||||
internal void eval_oplist_push_sconst(Arena *arena, EVAL_OpList *list, S64 x);
|
||||
|
||||
internal void eval_oplist_push_bytecode(Arena *arena, EVAL_OpList *list, String8 bytecode);
|
||||
|
||||
internal void eval_oplist_concat_in_place(EVAL_OpList *left_dst, EVAL_OpList *right_destroyed);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Expression Info Functions
|
||||
|
||||
internal RDI_EvalOp eval_opcode_from_expr_kind(EVAL_ExprKind kind);
|
||||
internal B32 eval_expr_kind_is_comparison(EVAL_ExprKind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Expression Constructors
|
||||
|
||||
internal EVAL_Expr* eval_expr(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *c0, EVAL_Expr *c1, EVAL_Expr *c2);
|
||||
internal EVAL_Expr* eval_expr_u64(Arena *arena, void *location, U64 u64);
|
||||
internal EVAL_Expr* eval_expr_f64(Arena *arena, void *location, F64 f64);
|
||||
internal EVAL_Expr* eval_expr_f32(Arena *arena, void *location, F32 f32);
|
||||
internal EVAL_Expr* eval_expr_child_and_u64(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *child, U64 u64);
|
||||
internal EVAL_Expr* eval_expr_leaf_member(Arena *arena, void *location, String8 name);
|
||||
internal EVAL_Expr* eval_expr_leaf_ident(Arena *arena, void *location, String8 name);
|
||||
internal EVAL_Expr* eval_expr_leaf_bytecode(Arena *arena, void *location, TG_Key type_key, String8 bytecode, EVAL_EvalMode mode);
|
||||
internal EVAL_Expr* eval_expr_leaf_op_list(Arena *arena, void *location, TG_Key type_key, EVAL_OpList *ops, EVAL_EvalMode mode);
|
||||
internal EVAL_Expr* eval_expr_leaf_type(Arena *arena, void *location, TG_Key type_key);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Type Information Transformers
|
||||
|
||||
internal RDI_EvalTypeGroup eval_type_group_from_kind(TG_Kind kind);
|
||||
|
||||
internal TG_Key eval_type_unwrap_enum(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key eval_type_promote(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key eval_type_coerce(TG_Graph *graph, RDI_Parsed *rdi, TG_Key l, TG_Key r);
|
||||
|
||||
internal B32 eval_type_match(TG_Graph *graph, RDI_Parsed *rdi, TG_Key l, TG_Key r);
|
||||
|
||||
internal B32 eval_kind_is_integer(TG_Kind kind);
|
||||
internal B32 eval_kind_is_signed(TG_Kind kind);
|
||||
internal B32 eval_kind_is_basic_or_enum(TG_Kind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL IR-Tree Constructors
|
||||
|
||||
internal EVAL_IRTree* eval_irtree_const_u(Arena *arena, U64 v);
|
||||
internal EVAL_IRTree* eval_irtree_unary_op(Arena *arena, RDI_EvalOp op, RDI_EvalTypeGroup group, EVAL_IRTree *c);
|
||||
internal EVAL_IRTree* eval_irtree_binary_op(Arena *arena, RDI_EvalOp op, RDI_EvalTypeGroup group, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_binary_op_u(Arena *arena, RDI_EvalOp op, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_conditional(Arena *arena, EVAL_IRTree *c, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_bytecode_no_copy(Arena *arena, String8 bytecode);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL IR-Tree High Level Helpers
|
||||
|
||||
internal EVAL_IRTree* eval_irtree_mem_read_type(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key type_key);
|
||||
internal EVAL_IRTree* eval_irtree_convert_lo(Arena *arena, EVAL_IRTree *c, RDI_EvalTypeGroup out, RDI_EvalTypeGroup in);
|
||||
internal EVAL_IRTree* eval_irtree_trunc(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key type_key);
|
||||
internal EVAL_IRTree* eval_irtree_convert_hi(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key out, TG_Key in);
|
||||
internal EVAL_IRTree* eval_irtree_resolve_to_value(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_EvalMode from_mode, EVAL_IRTree *tree, TG_Key type_key);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Compiler Phases
|
||||
|
||||
internal void eval_push_leaf_ident_exprs_from_expr__in_place(Arena *arena, EVAL_String2ExprMap *map, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal TG_Key eval_type_from_type_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal EVAL_IRTreeAndType eval_irtree_and_type_from_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_String2ExprMap *leaf_ident_expr_map, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal void eval_oplist_from_irtree(Arena *arena, EVAL_IRTree *tree, EVAL_OpList *out);
|
||||
|
||||
#endif //EVAL_COMPILER_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_COMPILER_H
|
||||
#define EVAL_COMPILER_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Bytecode Helpers
|
||||
|
||||
internal String8 eval_bytecode_from_oplist(Arena *arena, EVAL_OpList *list);
|
||||
|
||||
internal void eval_oplist_push_op(Arena *arena, EVAL_OpList *list, RDI_EvalOp op, U64 p);
|
||||
internal void eval_oplist_push_uconst(Arena *arena, EVAL_OpList *list, U64 x);
|
||||
internal void eval_oplist_push_sconst(Arena *arena, EVAL_OpList *list, S64 x);
|
||||
|
||||
internal void eval_oplist_push_bytecode(Arena *arena, EVAL_OpList *list, String8 bytecode);
|
||||
|
||||
internal void eval_oplist_concat_in_place(EVAL_OpList *left_dst, EVAL_OpList *right_destroyed);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Expression Info Functions
|
||||
|
||||
internal RDI_EvalOp eval_opcode_from_expr_kind(EVAL_ExprKind kind);
|
||||
internal B32 eval_expr_kind_is_comparison(EVAL_ExprKind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Expression Constructors
|
||||
|
||||
internal EVAL_Expr* eval_expr(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *c0, EVAL_Expr *c1, EVAL_Expr *c2);
|
||||
internal EVAL_Expr* eval_expr_u64(Arena *arena, void *location, U64 u64);
|
||||
internal EVAL_Expr* eval_expr_f64(Arena *arena, void *location, F64 f64);
|
||||
internal EVAL_Expr* eval_expr_f32(Arena *arena, void *location, F32 f32);
|
||||
internal EVAL_Expr* eval_expr_child_and_u64(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *child, U64 u64);
|
||||
internal EVAL_Expr* eval_expr_leaf_member(Arena *arena, void *location, String8 name);
|
||||
internal EVAL_Expr* eval_expr_leaf_ident(Arena *arena, void *location, String8 name);
|
||||
internal EVAL_Expr* eval_expr_leaf_bytecode(Arena *arena, void *location, TG_Key type_key, String8 bytecode, EVAL_EvalMode mode);
|
||||
internal EVAL_Expr* eval_expr_leaf_op_list(Arena *arena, void *location, TG_Key type_key, EVAL_OpList *ops, EVAL_EvalMode mode);
|
||||
internal EVAL_Expr* eval_expr_leaf_type(Arena *arena, void *location, TG_Key type_key);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Type Information Transformers
|
||||
|
||||
internal RDI_EvalTypeGroup eval_type_group_from_kind(TG_Kind kind);
|
||||
|
||||
internal TG_Key eval_type_unwrap_enum(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key eval_type_promote(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key eval_type_coerce(TG_Graph *graph, RDI_Parsed *rdi, TG_Key l, TG_Key r);
|
||||
|
||||
internal B32 eval_type_match(TG_Graph *graph, RDI_Parsed *rdi, TG_Key l, TG_Key r);
|
||||
|
||||
internal B32 eval_kind_is_integer(TG_Kind kind);
|
||||
internal B32 eval_kind_is_signed(TG_Kind kind);
|
||||
internal B32 eval_kind_is_basic_or_enum(TG_Kind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL IR-Tree Constructors
|
||||
|
||||
internal EVAL_IRTree* eval_irtree_const_u(Arena *arena, U64 v);
|
||||
internal EVAL_IRTree* eval_irtree_unary_op(Arena *arena, RDI_EvalOp op, RDI_EvalTypeGroup group, EVAL_IRTree *c);
|
||||
internal EVAL_IRTree* eval_irtree_binary_op(Arena *arena, RDI_EvalOp op, RDI_EvalTypeGroup group, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_binary_op_u(Arena *arena, RDI_EvalOp op, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_conditional(Arena *arena, EVAL_IRTree *c, EVAL_IRTree *l, EVAL_IRTree *r);
|
||||
internal EVAL_IRTree* eval_irtree_bytecode_no_copy(Arena *arena, String8 bytecode);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL IR-Tree High Level Helpers
|
||||
|
||||
internal EVAL_IRTree* eval_irtree_mem_read_type(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key type_key);
|
||||
internal EVAL_IRTree* eval_irtree_convert_lo(Arena *arena, EVAL_IRTree *c, RDI_EvalTypeGroup out, RDI_EvalTypeGroup in);
|
||||
internal EVAL_IRTree* eval_irtree_trunc(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key type_key);
|
||||
internal EVAL_IRTree* eval_irtree_convert_hi(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_IRTree *c, TG_Key out, TG_Key in);
|
||||
internal EVAL_IRTree* eval_irtree_resolve_to_value(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_EvalMode from_mode, EVAL_IRTree *tree, TG_Key type_key);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: EVAL Compiler Phases
|
||||
|
||||
internal void eval_push_leaf_ident_exprs_from_expr__in_place(Arena *arena, EVAL_String2ExprMap *map, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal TG_Key eval_type_from_type_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal EVAL_IRTreeAndType eval_irtree_and_type_from_expr(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, EVAL_String2ExprMap *leaf_ident_expr_map, EVAL_Expr *expr, EVAL_ErrorList *eout);
|
||||
internal void eval_oplist_from_irtree(Arena *arena, EVAL_IRTree *tree, EVAL_OpList *out);
|
||||
|
||||
#endif //EVAL_COMPILER_H
|
||||
|
||||
+254
-254
@@ -1,254 +1,254 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/eval.meta.c"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Functions
|
||||
|
||||
internal U64
|
||||
eval_hash_from_string(String8 string)
|
||||
{
|
||||
U64 result = 5381;
|
||||
for(U64 i = 0; i < string.size; i += 1)
|
||||
{
|
||||
result = ((result << 5) + result) + string.str[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Error List Building Functions
|
||||
|
||||
internal void
|
||||
eval_error(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, String8 text){
|
||||
EVAL_Error *error = push_array_no_zero(arena, EVAL_Error, 1);
|
||||
SLLQueuePush(list->first, list->last, error);
|
||||
list->count += 1;
|
||||
list->max_kind = Max(kind, list->max_kind);
|
||||
error->kind = kind;
|
||||
error->location = location;
|
||||
error->text = text;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_errorf(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, char *fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 text = push_str8fv(arena, fmt, args);
|
||||
va_end(args);
|
||||
eval_error(arena, list, kind, location, text);
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_error_list_concat_in_place(EVAL_ErrorList *dst, EVAL_ErrorList *to_push){
|
||||
if (dst->last != 0){
|
||||
if (to_push->last != 0){
|
||||
dst->last->next = to_push->first;
|
||||
dst->last = to_push->last;
|
||||
dst->count += to_push->count;
|
||||
}
|
||||
}
|
||||
else{
|
||||
*dst = *to_push;
|
||||
}
|
||||
MemoryZeroStruct(to_push);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Functions
|
||||
|
||||
//- rjf: string -> num
|
||||
|
||||
internal EVAL_String2NumMap
|
||||
eval_string2num_map_make(Arena *arena, U64 slot_count)
|
||||
{
|
||||
EVAL_String2NumMap map = {0};
|
||||
map.slots_count = slot_count;
|
||||
map.slots = push_array(arena, EVAL_String2NumMapSlot, map.slots_count);
|
||||
return map;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2num_map_insert(Arena *arena, EVAL_String2NumMap *map, String8 string, U64 num)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2NumMapNode *existing_node = 0;
|
||||
for(EVAL_String2NumMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->num == num)
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node == 0)
|
||||
{
|
||||
EVAL_String2NumMapNode *node = push_array(arena, EVAL_String2NumMapNode, 1);
|
||||
SLLQueuePush_N(map->slots[slot_idx].first, map->slots[slot_idx].last, node, hash_next);
|
||||
SLLQueuePush_N(map->first, map->last, node, order_next);
|
||||
node->string = push_str8_copy(arena, string);
|
||||
node->num = num;
|
||||
map->node_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
internal U64
|
||||
eval_num_from_string(EVAL_String2NumMap *map, String8 string)
|
||||
{
|
||||
U64 num = 0;
|
||||
if(map->slots_count != 0)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2NumMapNode *existing_node = 0;
|
||||
for(EVAL_String2NumMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node != 0)
|
||||
{
|
||||
num = existing_node->num;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
internal EVAL_String2NumMapNodeArray
|
||||
eval_string2num_map_node_array_from_map(Arena *arena, EVAL_String2NumMap *map)
|
||||
{
|
||||
EVAL_String2NumMapNodeArray result = {0};
|
||||
result.count = map->node_count;
|
||||
result.v = push_array(arena, EVAL_String2NumMapNode *, result.count);
|
||||
U64 idx = 0;
|
||||
for(EVAL_String2NumMapNode *n = map->first; n != 0; n = n->order_next, idx += 1)
|
||||
{
|
||||
result.v[idx] = n;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal int
|
||||
eval_string2num_map_node_qsort_compare__num_ascending(EVAL_String2NumMapNode **a, EVAL_String2NumMapNode **b)
|
||||
{
|
||||
int result = 0;
|
||||
if(a[0]->num < b[0]->num)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else if(a[0]->num > b[0]->num)
|
||||
{
|
||||
result = +1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2num_map_node_array_sort__in_place(EVAL_String2NumMapNodeArray *array)
|
||||
{
|
||||
quick_sort(array->v, array->count, sizeof(array->v[0]), eval_string2num_map_node_qsort_compare__num_ascending);
|
||||
}
|
||||
|
||||
//- rjf: string -> expr
|
||||
|
||||
internal EVAL_String2ExprMap
|
||||
eval_string2expr_map_make(Arena *arena, U64 slot_count)
|
||||
{
|
||||
EVAL_String2ExprMap map = {0};
|
||||
map.slots_count = slot_count;
|
||||
map.slots = push_array(arena, EVAL_String2ExprMapSlot, map.slots_count);
|
||||
return map;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_insert(Arena *arena, EVAL_String2ExprMap *map, String8 string, EVAL_Expr *expr)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2ExprMapNode *existing_node = 0;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node == 0)
|
||||
{
|
||||
EVAL_String2ExprMapNode *node = push_array(arena, EVAL_String2ExprMapNode, 1);
|
||||
SLLQueuePush_N(map->slots[slot_idx].first, map->slots[slot_idx].last, node, hash_next);
|
||||
node->string = push_str8_copy(arena, string);
|
||||
existing_node = node;
|
||||
}
|
||||
existing_node->expr = expr;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_inc_poison(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
node->poison_count += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_dec_poison(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->poison_count > 0)
|
||||
{
|
||||
node->poison_count -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal EVAL_Expr *
|
||||
eval_expr_from_string(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
EVAL_Expr *expr = &eval_expr_nil;
|
||||
if(map->slots_count != 0)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2ExprMapNode *existing_node = 0;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->poison_count == 0)
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node != 0)
|
||||
{
|
||||
expr = existing_node->expr;
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/eval.meta.c"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Functions
|
||||
|
||||
internal U64
|
||||
eval_hash_from_string(String8 string)
|
||||
{
|
||||
U64 result = 5381;
|
||||
for(U64 i = 0; i < string.size; i += 1)
|
||||
{
|
||||
result = ((result << 5) + result) + string.str[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Error List Building Functions
|
||||
|
||||
internal void
|
||||
eval_error(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, String8 text){
|
||||
EVAL_Error *error = push_array_no_zero(arena, EVAL_Error, 1);
|
||||
SLLQueuePush(list->first, list->last, error);
|
||||
list->count += 1;
|
||||
list->max_kind = Max(kind, list->max_kind);
|
||||
error->kind = kind;
|
||||
error->location = location;
|
||||
error->text = text;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_errorf(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, char *fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 text = push_str8fv(arena, fmt, args);
|
||||
va_end(args);
|
||||
eval_error(arena, list, kind, location, text);
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_error_list_concat_in_place(EVAL_ErrorList *dst, EVAL_ErrorList *to_push){
|
||||
if (dst->last != 0){
|
||||
if (to_push->last != 0){
|
||||
dst->last->next = to_push->first;
|
||||
dst->last = to_push->last;
|
||||
dst->count += to_push->count;
|
||||
}
|
||||
}
|
||||
else{
|
||||
*dst = *to_push;
|
||||
}
|
||||
MemoryZeroStruct(to_push);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Functions
|
||||
|
||||
//- rjf: string -> num
|
||||
|
||||
internal EVAL_String2NumMap
|
||||
eval_string2num_map_make(Arena *arena, U64 slot_count)
|
||||
{
|
||||
EVAL_String2NumMap map = {0};
|
||||
map.slots_count = slot_count;
|
||||
map.slots = push_array(arena, EVAL_String2NumMapSlot, map.slots_count);
|
||||
return map;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2num_map_insert(Arena *arena, EVAL_String2NumMap *map, String8 string, U64 num)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2NumMapNode *existing_node = 0;
|
||||
for(EVAL_String2NumMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->num == num)
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node == 0)
|
||||
{
|
||||
EVAL_String2NumMapNode *node = push_array(arena, EVAL_String2NumMapNode, 1);
|
||||
SLLQueuePush_N(map->slots[slot_idx].first, map->slots[slot_idx].last, node, hash_next);
|
||||
SLLQueuePush_N(map->first, map->last, node, order_next);
|
||||
node->string = push_str8_copy(arena, string);
|
||||
node->num = num;
|
||||
map->node_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
internal U64
|
||||
eval_num_from_string(EVAL_String2NumMap *map, String8 string)
|
||||
{
|
||||
U64 num = 0;
|
||||
if(map->slots_count != 0)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2NumMapNode *existing_node = 0;
|
||||
for(EVAL_String2NumMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node != 0)
|
||||
{
|
||||
num = existing_node->num;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
internal EVAL_String2NumMapNodeArray
|
||||
eval_string2num_map_node_array_from_map(Arena *arena, EVAL_String2NumMap *map)
|
||||
{
|
||||
EVAL_String2NumMapNodeArray result = {0};
|
||||
result.count = map->node_count;
|
||||
result.v = push_array(arena, EVAL_String2NumMapNode *, result.count);
|
||||
U64 idx = 0;
|
||||
for(EVAL_String2NumMapNode *n = map->first; n != 0; n = n->order_next, idx += 1)
|
||||
{
|
||||
result.v[idx] = n;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal int
|
||||
eval_string2num_map_node_qsort_compare__num_ascending(EVAL_String2NumMapNode **a, EVAL_String2NumMapNode **b)
|
||||
{
|
||||
int result = 0;
|
||||
if(a[0]->num < b[0]->num)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else if(a[0]->num > b[0]->num)
|
||||
{
|
||||
result = +1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2num_map_node_array_sort__in_place(EVAL_String2NumMapNodeArray *array)
|
||||
{
|
||||
quick_sort(array->v, array->count, sizeof(array->v[0]), eval_string2num_map_node_qsort_compare__num_ascending);
|
||||
}
|
||||
|
||||
//- rjf: string -> expr
|
||||
|
||||
internal EVAL_String2ExprMap
|
||||
eval_string2expr_map_make(Arena *arena, U64 slot_count)
|
||||
{
|
||||
EVAL_String2ExprMap map = {0};
|
||||
map.slots_count = slot_count;
|
||||
map.slots = push_array(arena, EVAL_String2ExprMapSlot, map.slots_count);
|
||||
return map;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_insert(Arena *arena, EVAL_String2ExprMap *map, String8 string, EVAL_Expr *expr)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2ExprMapNode *existing_node = 0;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node == 0)
|
||||
{
|
||||
EVAL_String2ExprMapNode *node = push_array(arena, EVAL_String2ExprMapNode, 1);
|
||||
SLLQueuePush_N(map->slots[slot_idx].first, map->slots[slot_idx].last, node, hash_next);
|
||||
node->string = push_str8_copy(arena, string);
|
||||
existing_node = node;
|
||||
}
|
||||
existing_node->expr = expr;
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_inc_poison(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0))
|
||||
{
|
||||
node->poison_count += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
eval_string2expr_map_dec_poison(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first;
|
||||
node != 0;
|
||||
node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->poison_count > 0)
|
||||
{
|
||||
node->poison_count -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal EVAL_Expr *
|
||||
eval_expr_from_string(EVAL_String2ExprMap *map, String8 string)
|
||||
{
|
||||
EVAL_Expr *expr = &eval_expr_nil;
|
||||
if(map->slots_count != 0)
|
||||
{
|
||||
U64 hash = eval_hash_from_string(string);
|
||||
U64 slot_idx = hash%map->slots_count;
|
||||
EVAL_String2ExprMapNode *existing_node = 0;
|
||||
for(EVAL_String2ExprMapNode *node = map->slots[slot_idx].first; node != 0; node = node->hash_next)
|
||||
{
|
||||
if(str8_match(node->string, string, 0) && node->poison_count == 0)
|
||||
{
|
||||
existing_node = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(existing_node != 0)
|
||||
{
|
||||
expr = existing_node->expr;
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
+232
-232
@@ -1,232 +1,232 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_CORE_H
|
||||
#define EVAL_CORE_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Errors
|
||||
|
||||
typedef enum EVAL_ErrorKind
|
||||
{
|
||||
EVAL_ErrorKind_Null,
|
||||
EVAL_ErrorKind_MalformedInput,
|
||||
EVAL_ErrorKind_MissingInfo,
|
||||
EVAL_ErrorKind_ResolutionFailure,
|
||||
EVAL_ErrorKind_InterpretationError,
|
||||
EVAL_ErrorKind_COUNT
|
||||
}
|
||||
EVAL_ErrorKind;
|
||||
|
||||
typedef struct EVAL_Error EVAL_Error;
|
||||
struct EVAL_Error
|
||||
{
|
||||
EVAL_Error *next;
|
||||
EVAL_ErrorKind kind;
|
||||
void *location;
|
||||
String8 text;
|
||||
};
|
||||
|
||||
typedef struct EVAL_ErrorList EVAL_ErrorList;
|
||||
struct EVAL_ErrorList
|
||||
{
|
||||
EVAL_Error *first;
|
||||
EVAL_Error *last;
|
||||
EVAL_ErrorKind max_kind;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Operation Types
|
||||
|
||||
enum
|
||||
{
|
||||
EVAL_IRExtKind_Bytecode = RDI_EvalOp_COUNT,
|
||||
EVAL_IRExtKind_COUNT
|
||||
};
|
||||
|
||||
typedef struct EVAL_Op EVAL_Op;
|
||||
struct EVAL_Op
|
||||
{
|
||||
EVAL_Op *next;
|
||||
RDI_EvalOp opcode;
|
||||
union
|
||||
{
|
||||
U64 p;
|
||||
String8 bytecode;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct EVAL_OpList EVAL_OpList;
|
||||
struct EVAL_OpList
|
||||
{
|
||||
EVAL_Op *first_op;
|
||||
EVAL_Op *last_op;
|
||||
U32 op_count;
|
||||
U32 encoded_size;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "eval/generated/eval.meta.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Expression Tree Types
|
||||
|
||||
typedef enum EVAL_EvalMode
|
||||
{
|
||||
EVAL_EvalMode_NULL,
|
||||
EVAL_EvalMode_Value,
|
||||
EVAL_EvalMode_Addr,
|
||||
EVAL_EvalMode_Reg
|
||||
}
|
||||
EVAL_EvalMode;
|
||||
|
||||
typedef struct EVAL_Expr EVAL_Expr;
|
||||
struct EVAL_Expr
|
||||
{
|
||||
EVAL_ExprKind kind;
|
||||
void *location;
|
||||
union
|
||||
{
|
||||
EVAL_Expr *children[3];
|
||||
U32 u32;
|
||||
U64 u64;
|
||||
F32 f32;
|
||||
F64 f64;
|
||||
struct
|
||||
{
|
||||
EVAL_Expr *child;
|
||||
U64 u64;
|
||||
} child_and_constant;
|
||||
String8 name;
|
||||
struct
|
||||
{
|
||||
TG_Key type_key;
|
||||
String8 bytecode;
|
||||
EVAL_EvalMode mode;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: IR Tree Types
|
||||
|
||||
typedef struct EVAL_IRTree EVAL_IRTree;
|
||||
struct EVAL_IRTree{
|
||||
RDI_EvalOp op;
|
||||
EVAL_IRTree *children[3];
|
||||
union{
|
||||
U64 p;
|
||||
String8 bytecode;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct EVAL_IRTreeAndType EVAL_IRTreeAndType;
|
||||
struct EVAL_IRTreeAndType{
|
||||
EVAL_IRTree *tree;
|
||||
TG_Key type_key;
|
||||
EVAL_EvalMode mode;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Types
|
||||
|
||||
//- rjf: string -> num
|
||||
|
||||
typedef struct EVAL_String2NumMapNode EVAL_String2NumMapNode;
|
||||
struct EVAL_String2NumMapNode
|
||||
{
|
||||
EVAL_String2NumMapNode *order_next;
|
||||
EVAL_String2NumMapNode *hash_next;
|
||||
String8 string;
|
||||
U64 num;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMapNodeArray EVAL_String2NumMapNodeArray;
|
||||
struct EVAL_String2NumMapNodeArray
|
||||
{
|
||||
EVAL_String2NumMapNode **v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMapSlot EVAL_String2NumMapSlot;
|
||||
struct EVAL_String2NumMapSlot
|
||||
{
|
||||
EVAL_String2NumMapNode *first;
|
||||
EVAL_String2NumMapNode *last;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMap EVAL_String2NumMap;
|
||||
struct EVAL_String2NumMap
|
||||
{
|
||||
U64 slots_count;
|
||||
U64 node_count;
|
||||
EVAL_String2NumMapSlot *slots;
|
||||
EVAL_String2NumMapNode *first;
|
||||
EVAL_String2NumMapNode *last;
|
||||
};
|
||||
|
||||
//- rjf: string -> expr
|
||||
|
||||
typedef struct EVAL_String2ExprMapNode EVAL_String2ExprMapNode;
|
||||
struct EVAL_String2ExprMapNode
|
||||
{
|
||||
EVAL_String2ExprMapNode *hash_next;
|
||||
String8 string;
|
||||
EVAL_Expr *expr;
|
||||
U64 poison_count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2ExprMapSlot EVAL_String2ExprMapSlot;
|
||||
struct EVAL_String2ExprMapSlot
|
||||
{
|
||||
EVAL_String2ExprMapNode *first;
|
||||
EVAL_String2ExprMapNode *last;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2ExprMap EVAL_String2ExprMap;
|
||||
struct EVAL_String2ExprMap
|
||||
{
|
||||
U64 slots_count;
|
||||
EVAL_String2ExprMapSlot *slots;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
global read_only EVAL_Expr eval_expr_nil = {0};
|
||||
global read_only EVAL_IRTree eval_irtree_nil = {0};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Functions
|
||||
|
||||
internal U64 eval_hash_from_string(String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Error List Building Functions
|
||||
|
||||
internal void eval_error(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, String8 text);
|
||||
internal void eval_errorf(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, char *fmt, ...);
|
||||
internal void eval_error_list_concat_in_place(EVAL_ErrorList *dst, EVAL_ErrorList *to_push);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Functions
|
||||
|
||||
//- rjf: string -> num
|
||||
internal EVAL_String2NumMap eval_string2num_map_make(Arena *arena, U64 slot_count);
|
||||
internal void eval_string2num_map_insert(Arena *arena, EVAL_String2NumMap *map, String8 string, U64 num);
|
||||
internal U64 eval_num_from_string(EVAL_String2NumMap *map, String8 string);
|
||||
internal EVAL_String2NumMapNodeArray eval_string2num_map_node_array_from_map(Arena *arena, EVAL_String2NumMap *map);
|
||||
internal int eval_string2num_map_node_qsort_compare__num_ascending(EVAL_String2NumMapNode **a, EVAL_String2NumMapNode **b);
|
||||
internal void eval_string2num_map_node_array_sort__in_place(EVAL_String2NumMapNodeArray *array);
|
||||
|
||||
//- rjf: string -> expr
|
||||
internal EVAL_String2ExprMap eval_string2expr_map_make(Arena *arena, U64 slot_count);
|
||||
internal void eval_string2expr_map_insert(Arena *arena, EVAL_String2ExprMap *map, String8 string, EVAL_Expr *expr);
|
||||
internal void eval_string2expr_map_inc_poison(EVAL_String2ExprMap *map, String8 string);
|
||||
internal void eval_string2expr_map_dec_poison(EVAL_String2ExprMap *map, String8 string);
|
||||
internal EVAL_Expr *eval_expr_from_string(EVAL_String2ExprMap *map, String8 string);
|
||||
|
||||
#endif // EVAL_CORE_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_CORE_H
|
||||
#define EVAL_CORE_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Errors
|
||||
|
||||
typedef enum EVAL_ErrorKind
|
||||
{
|
||||
EVAL_ErrorKind_Null,
|
||||
EVAL_ErrorKind_MalformedInput,
|
||||
EVAL_ErrorKind_MissingInfo,
|
||||
EVAL_ErrorKind_ResolutionFailure,
|
||||
EVAL_ErrorKind_InterpretationError,
|
||||
EVAL_ErrorKind_COUNT
|
||||
}
|
||||
EVAL_ErrorKind;
|
||||
|
||||
typedef struct EVAL_Error EVAL_Error;
|
||||
struct EVAL_Error
|
||||
{
|
||||
EVAL_Error *next;
|
||||
EVAL_ErrorKind kind;
|
||||
void *location;
|
||||
String8 text;
|
||||
};
|
||||
|
||||
typedef struct EVAL_ErrorList EVAL_ErrorList;
|
||||
struct EVAL_ErrorList
|
||||
{
|
||||
EVAL_Error *first;
|
||||
EVAL_Error *last;
|
||||
EVAL_ErrorKind max_kind;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Operation Types
|
||||
|
||||
enum
|
||||
{
|
||||
EVAL_IRExtKind_Bytecode = RDI_EvalOp_COUNT,
|
||||
EVAL_IRExtKind_COUNT
|
||||
};
|
||||
|
||||
typedef struct EVAL_Op EVAL_Op;
|
||||
struct EVAL_Op
|
||||
{
|
||||
EVAL_Op *next;
|
||||
RDI_EvalOp opcode;
|
||||
union
|
||||
{
|
||||
U64 p;
|
||||
String8 bytecode;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct EVAL_OpList EVAL_OpList;
|
||||
struct EVAL_OpList
|
||||
{
|
||||
EVAL_Op *first_op;
|
||||
EVAL_Op *last_op;
|
||||
U32 op_count;
|
||||
U32 encoded_size;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "eval/generated/eval.meta.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Expression Tree Types
|
||||
|
||||
typedef enum EVAL_EvalMode
|
||||
{
|
||||
EVAL_EvalMode_NULL,
|
||||
EVAL_EvalMode_Value,
|
||||
EVAL_EvalMode_Addr,
|
||||
EVAL_EvalMode_Reg
|
||||
}
|
||||
EVAL_EvalMode;
|
||||
|
||||
typedef struct EVAL_Expr EVAL_Expr;
|
||||
struct EVAL_Expr
|
||||
{
|
||||
EVAL_ExprKind kind;
|
||||
void *location;
|
||||
union
|
||||
{
|
||||
EVAL_Expr *children[3];
|
||||
U32 u32;
|
||||
U64 u64;
|
||||
F32 f32;
|
||||
F64 f64;
|
||||
struct
|
||||
{
|
||||
EVAL_Expr *child;
|
||||
U64 u64;
|
||||
} child_and_constant;
|
||||
String8 name;
|
||||
struct
|
||||
{
|
||||
TG_Key type_key;
|
||||
String8 bytecode;
|
||||
EVAL_EvalMode mode;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: IR Tree Types
|
||||
|
||||
typedef struct EVAL_IRTree EVAL_IRTree;
|
||||
struct EVAL_IRTree{
|
||||
RDI_EvalOp op;
|
||||
EVAL_IRTree *children[3];
|
||||
union{
|
||||
U64 p;
|
||||
String8 bytecode;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct EVAL_IRTreeAndType EVAL_IRTreeAndType;
|
||||
struct EVAL_IRTreeAndType{
|
||||
EVAL_IRTree *tree;
|
||||
TG_Key type_key;
|
||||
EVAL_EvalMode mode;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Types
|
||||
|
||||
//- rjf: string -> num
|
||||
|
||||
typedef struct EVAL_String2NumMapNode EVAL_String2NumMapNode;
|
||||
struct EVAL_String2NumMapNode
|
||||
{
|
||||
EVAL_String2NumMapNode *order_next;
|
||||
EVAL_String2NumMapNode *hash_next;
|
||||
String8 string;
|
||||
U64 num;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMapNodeArray EVAL_String2NumMapNodeArray;
|
||||
struct EVAL_String2NumMapNodeArray
|
||||
{
|
||||
EVAL_String2NumMapNode **v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMapSlot EVAL_String2NumMapSlot;
|
||||
struct EVAL_String2NumMapSlot
|
||||
{
|
||||
EVAL_String2NumMapNode *first;
|
||||
EVAL_String2NumMapNode *last;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2NumMap EVAL_String2NumMap;
|
||||
struct EVAL_String2NumMap
|
||||
{
|
||||
U64 slots_count;
|
||||
U64 node_count;
|
||||
EVAL_String2NumMapSlot *slots;
|
||||
EVAL_String2NumMapNode *first;
|
||||
EVAL_String2NumMapNode *last;
|
||||
};
|
||||
|
||||
//- rjf: string -> expr
|
||||
|
||||
typedef struct EVAL_String2ExprMapNode EVAL_String2ExprMapNode;
|
||||
struct EVAL_String2ExprMapNode
|
||||
{
|
||||
EVAL_String2ExprMapNode *hash_next;
|
||||
String8 string;
|
||||
EVAL_Expr *expr;
|
||||
U64 poison_count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2ExprMapSlot EVAL_String2ExprMapSlot;
|
||||
struct EVAL_String2ExprMapSlot
|
||||
{
|
||||
EVAL_String2ExprMapNode *first;
|
||||
EVAL_String2ExprMapNode *last;
|
||||
};
|
||||
|
||||
typedef struct EVAL_String2ExprMap EVAL_String2ExprMap;
|
||||
struct EVAL_String2ExprMap
|
||||
{
|
||||
U64 slots_count;
|
||||
EVAL_String2ExprMapSlot *slots;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
global read_only EVAL_Expr eval_expr_nil = {0};
|
||||
global read_only EVAL_IRTree eval_irtree_nil = {0};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Functions
|
||||
|
||||
internal U64 eval_hash_from_string(String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Error List Building Functions
|
||||
|
||||
internal void eval_error(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, String8 text);
|
||||
internal void eval_errorf(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, char *fmt, ...);
|
||||
internal void eval_error_list_concat_in_place(EVAL_ErrorList *dst, EVAL_ErrorList *to_push);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Map Functions
|
||||
|
||||
//- rjf: string -> num
|
||||
internal EVAL_String2NumMap eval_string2num_map_make(Arena *arena, U64 slot_count);
|
||||
internal void eval_string2num_map_insert(Arena *arena, EVAL_String2NumMap *map, String8 string, U64 num);
|
||||
internal U64 eval_num_from_string(EVAL_String2NumMap *map, String8 string);
|
||||
internal EVAL_String2NumMapNodeArray eval_string2num_map_node_array_from_map(Arena *arena, EVAL_String2NumMap *map);
|
||||
internal int eval_string2num_map_node_qsort_compare__num_ascending(EVAL_String2NumMapNode **a, EVAL_String2NumMapNode **b);
|
||||
internal void eval_string2num_map_node_array_sort__in_place(EVAL_String2NumMapNodeArray *array);
|
||||
|
||||
//- rjf: string -> expr
|
||||
internal EVAL_String2ExprMap eval_string2expr_map_make(Arena *arena, U64 slot_count);
|
||||
internal void eval_string2expr_map_insert(Arena *arena, EVAL_String2ExprMap *map, String8 string, EVAL_Expr *expr);
|
||||
internal void eval_string2expr_map_inc_poison(EVAL_String2ExprMap *map, String8 string);
|
||||
internal void eval_string2expr_map_dec_poison(EVAL_String2ExprMap *map, String8 string);
|
||||
internal EVAL_Expr *eval_expr_from_string(EVAL_String2ExprMap *map, String8 string);
|
||||
|
||||
#endif // EVAL_CORE_H
|
||||
|
||||
+50
-50
@@ -1,50 +1,50 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Eval Decode Function
|
||||
|
||||
internal void
|
||||
eval_print_decode_from_bytecode(FILE *out, String8 bytecode){
|
||||
U8 *ptr = bytecode.str;
|
||||
U8 *opl = bytecode.str + bytecode.size;
|
||||
|
||||
for (;ptr < opl;){
|
||||
// consume opcode
|
||||
SYMS_EvalOp op = (SYMS_EvalOp)*ptr;
|
||||
if (op >= SYMS_EvalOp_COUNT){
|
||||
fprintf(out, "decode error: undefined op code\n");
|
||||
goto done;
|
||||
}
|
||||
U8 ctrlbits = syms_eval_opcode_ctrlbits[op];
|
||||
ptr += 1;
|
||||
|
||||
// decode
|
||||
U64 imm = 0;
|
||||
U32 decode_size = (ctrlbits >> SYMS_EvalOpCtrlBits_DecodeShft)&SYMS_EvalOpCtrlBits_DecodeMask;
|
||||
{
|
||||
U8 *next_ptr = ptr + decode_size;
|
||||
if (next_ptr > opl){
|
||||
fprintf(out, "decode error: expected constant goes past the end of bytecode\n");
|
||||
goto done;
|
||||
}
|
||||
// TODO(allen): to improve this:
|
||||
// gaurantee 8 bytes padding after the end of serialized bytecode
|
||||
// read 8 bytes and mask
|
||||
switch (decode_size){
|
||||
case 1: imm = *ptr; break;
|
||||
case 2: imm = *(U16*)ptr; break;
|
||||
case 4: imm = *(U32*)ptr; break;
|
||||
case 8: imm = *(U64*)ptr; break;
|
||||
}
|
||||
ptr = next_ptr;
|
||||
}
|
||||
|
||||
// op string & control bits
|
||||
SYMS_String8 op_string = syms_eval_opcode_strings[op];
|
||||
|
||||
// print
|
||||
fprintf(out, "%.*s 0x%llx\n", str8_varg(op_string), imm);
|
||||
}
|
||||
done:;
|
||||
}
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Eval Decode Function
|
||||
|
||||
internal void
|
||||
eval_print_decode_from_bytecode(FILE *out, String8 bytecode){
|
||||
U8 *ptr = bytecode.str;
|
||||
U8 *opl = bytecode.str + bytecode.size;
|
||||
|
||||
for (;ptr < opl;){
|
||||
// consume opcode
|
||||
SYMS_EvalOp op = (SYMS_EvalOp)*ptr;
|
||||
if (op >= SYMS_EvalOp_COUNT){
|
||||
fprintf(out, "decode error: undefined op code\n");
|
||||
goto done;
|
||||
}
|
||||
U8 ctrlbits = syms_eval_opcode_ctrlbits[op];
|
||||
ptr += 1;
|
||||
|
||||
// decode
|
||||
U64 imm = 0;
|
||||
U32 decode_size = (ctrlbits >> SYMS_EvalOpCtrlBits_DecodeShft)&SYMS_EvalOpCtrlBits_DecodeMask;
|
||||
{
|
||||
U8 *next_ptr = ptr + decode_size;
|
||||
if (next_ptr > opl){
|
||||
fprintf(out, "decode error: expected constant goes past the end of bytecode\n");
|
||||
goto done;
|
||||
}
|
||||
// TODO(allen): to improve this:
|
||||
// gaurantee 8 bytes padding after the end of serialized bytecode
|
||||
// read 8 bytes and mask
|
||||
switch (decode_size){
|
||||
case 1: imm = *ptr; break;
|
||||
case 2: imm = *(U16*)ptr; break;
|
||||
case 4: imm = *(U32*)ptr; break;
|
||||
case 8: imm = *(U64*)ptr; break;
|
||||
}
|
||||
ptr = next_ptr;
|
||||
}
|
||||
|
||||
// op string & control bits
|
||||
SYMS_String8 op_string = syms_eval_opcode_strings[op];
|
||||
|
||||
// print
|
||||
fprintf(out, "%.*s 0x%llx\n", str8_varg(op_string), imm);
|
||||
}
|
||||
done:;
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_DECODE_H
|
||||
#define EVAL_DECODE_H
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Eval Decode Function
|
||||
|
||||
internal void eval_print_decode_from_bytecode(FILE *out, String8 bytecode);
|
||||
|
||||
#endif //EVAL_DECODE_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_DECODE_H
|
||||
#define EVAL_DECODE_H
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Eval Decode Function
|
||||
|
||||
internal void eval_print_decode_from_bytecode(FILE *out, String8 bytecode);
|
||||
|
||||
#endif //EVAL_DECODE_H
|
||||
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#include "eval/eval_core.c"
|
||||
#include "eval/eval_compiler.c"
|
||||
#include "eval/eval_machine.c"
|
||||
#include "eval/eval_parser.c"
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#include "eval/eval_core.c"
|
||||
#include "eval/eval_compiler.c"
|
||||
#include "eval/eval_machine.c"
|
||||
#include "eval/eval_parser.c"
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_INC_H
|
||||
#define EVAL_INC_H
|
||||
|
||||
#include "eval/eval_core.h"
|
||||
#include "eval/eval_compiler.h"
|
||||
#include "eval/eval_machine.h"
|
||||
#include "eval/eval_parser.h"
|
||||
|
||||
#endif // EVAL_INC_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_INC_H
|
||||
#define EVAL_INC_H
|
||||
|
||||
#include "eval/eval_core.h"
|
||||
#include "eval/eval_compiler.h"
|
||||
#include "eval/eval_machine.h"
|
||||
#include "eval/eval_parser.h"
|
||||
|
||||
#endif // EVAL_INC_H
|
||||
|
||||
+647
-647
File diff suppressed because it is too large
Load Diff
+48
-48
@@ -1,48 +1,48 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL2_MACHINE_H
|
||||
#define EVAL2_MACHINE_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Eval Machine Types
|
||||
|
||||
typedef B32 EVAL_MemoryRead(void *u, void *out, U64 addr, U64 size);
|
||||
|
||||
typedef struct EVAL_Machine EVAL_Machine;
|
||||
struct EVAL_Machine
|
||||
{
|
||||
void *u;
|
||||
Architecture arch;
|
||||
EVAL_MemoryRead *memory_read;
|
||||
void *reg_data;
|
||||
U64 reg_size;
|
||||
U64 *module_base;
|
||||
U64 *frame_base;
|
||||
U64 *tls_base;
|
||||
};
|
||||
|
||||
typedef union EVAL_Slot EVAL_Slot;
|
||||
union EVAL_Slot
|
||||
{
|
||||
U64 u256[4];
|
||||
U64 u128[2];
|
||||
U64 u64;
|
||||
S64 s64;
|
||||
F64 f64;
|
||||
F32 f32;
|
||||
};
|
||||
|
||||
typedef struct EVAL_Result EVAL_Result;
|
||||
struct EVAL_Result
|
||||
{
|
||||
EVAL_Slot value;
|
||||
EVAL_ResultCode code;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Eval Machine Functions
|
||||
|
||||
internal EVAL_Result eval_interpret(EVAL_Machine *machine, String8 bytecode);
|
||||
|
||||
#endif //EVAL2_MACHINE_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL2_MACHINE_H
|
||||
#define EVAL2_MACHINE_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Eval Machine Types
|
||||
|
||||
typedef B32 EVAL_MemoryRead(void *u, void *out, U64 addr, U64 size);
|
||||
|
||||
typedef struct EVAL_Machine EVAL_Machine;
|
||||
struct EVAL_Machine
|
||||
{
|
||||
void *u;
|
||||
Architecture arch;
|
||||
EVAL_MemoryRead *memory_read;
|
||||
void *reg_data;
|
||||
U64 reg_size;
|
||||
U64 *module_base;
|
||||
U64 *frame_base;
|
||||
U64 *tls_base;
|
||||
};
|
||||
|
||||
typedef union EVAL_Slot EVAL_Slot;
|
||||
union EVAL_Slot
|
||||
{
|
||||
U64 u256[4];
|
||||
U64 u128[2];
|
||||
U64 u64;
|
||||
S64 s64;
|
||||
F64 f64;
|
||||
F32 f32;
|
||||
};
|
||||
|
||||
typedef struct EVAL_Result EVAL_Result;
|
||||
struct EVAL_Result
|
||||
{
|
||||
EVAL_Slot value;
|
||||
EVAL_ResultCode code;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Eval Machine Functions
|
||||
|
||||
internal EVAL_Result eval_interpret(EVAL_Machine *machine, String8 bytecode);
|
||||
|
||||
#endif //EVAL2_MACHINE_H
|
||||
|
||||
+1444
-1444
File diff suppressed because it is too large
Load Diff
+109
-109
@@ -1,109 +1,109 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_PARSER_H
|
||||
#define EVAL_PARSER_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Token Types
|
||||
|
||||
typedef enum EVAL_TokenKind
|
||||
{
|
||||
EVAL_TokenKind_Null,
|
||||
EVAL_TokenKind_Identifier,
|
||||
EVAL_TokenKind_Numeric,
|
||||
EVAL_TokenKind_StringLiteral,
|
||||
EVAL_TokenKind_CharLiteral,
|
||||
EVAL_TokenKind_Symbol,
|
||||
EVAL_TokenKind_COUNT
|
||||
}
|
||||
EVAL_TokenKind;
|
||||
|
||||
typedef struct EVAL_Token EVAL_Token;
|
||||
struct EVAL_Token
|
||||
{
|
||||
EVAL_TokenKind kind;
|
||||
Rng1U64 range;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenChunkNode EVAL_TokenChunkNode;
|
||||
struct EVAL_TokenChunkNode
|
||||
{
|
||||
EVAL_TokenChunkNode *next;
|
||||
EVAL_Token *v;
|
||||
U64 count;
|
||||
U64 cap;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenChunkList EVAL_TokenChunkList;
|
||||
struct EVAL_TokenChunkList
|
||||
{
|
||||
EVAL_TokenChunkNode *first;
|
||||
EVAL_TokenChunkNode *last;
|
||||
U64 node_count;
|
||||
U64 total_count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenArray EVAL_TokenArray;
|
||||
struct EVAL_TokenArray
|
||||
{
|
||||
EVAL_Token *v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parser Types
|
||||
|
||||
typedef struct EVAL_ParseResult EVAL_ParseResult;
|
||||
struct EVAL_ParseResult
|
||||
{
|
||||
EVAL_Token *last_token;
|
||||
EVAL_Expr *expr;
|
||||
EVAL_ErrorList errors;
|
||||
};
|
||||
|
||||
typedef struct EVAL_ParseCtx EVAL_ParseCtx;
|
||||
struct EVAL_ParseCtx
|
||||
{
|
||||
Architecture arch;
|
||||
U64 ip_voff;
|
||||
RDI_Parsed *rdi;
|
||||
TG_Graph *type_graph;
|
||||
EVAL_String2NumMap *regs_map;
|
||||
EVAL_String2NumMap *reg_alias_map;
|
||||
EVAL_String2NumMap *locals_map;
|
||||
EVAL_String2NumMap *member_map;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
read_only global EVAL_String2NumMap eval_string2num_map_nil = {0};
|
||||
read_only global EVAL_String2ExprMap eval_string2expr_map_nil = {0};
|
||||
global read_only EVAL_ParseResult eval_parse_result_nil = {0, &eval_expr_nil};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Debug-Info-Driven Map Building Fast Paths
|
||||
|
||||
internal EVAL_String2NumMap *eval_push_locals_map_from_rdi_voff(Arena *arena, RDI_Parsed *rdi, U64 voff);
|
||||
internal EVAL_String2NumMap *eval_push_member_map_from_rdi_voff(Arena *arena, RDI_Parsed *rdi, U64 voff);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Tokenization Functions
|
||||
|
||||
#define eval_token_at_it(it, arr) (((it) < (arr)->v+(arr)->count) ? (*(it)) : eval_token_zero())
|
||||
internal EVAL_Token eval_token_zero(void);
|
||||
internal void eval_token_chunk_list_push(Arena *arena, EVAL_TokenChunkList *list, U64 chunk_size, EVAL_Token *token);
|
||||
internal EVAL_TokenArray eval_token_array_from_chunk_list(Arena *arena, EVAL_TokenChunkList *list);
|
||||
internal EVAL_TokenArray eval_token_array_from_text(Arena *arena, String8 text);
|
||||
internal EVAL_TokenArray eval_token_array_make_first_opl(EVAL_Token *first, EVAL_Token *opl);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parser Functions
|
||||
|
||||
internal TG_Key eval_leaf_type_from_name(RDI_Parsed *rdi, String8 name);
|
||||
internal EVAL_ParseResult eval_parse_type_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
|
||||
internal EVAL_ParseResult eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens, S64 max_precedence);
|
||||
internal EVAL_ParseResult eval_parse_expr_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
|
||||
|
||||
#endif // EVAL_PARSER_H
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef EVAL_PARSER_H
|
||||
#define EVAL_PARSER_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Token Types
|
||||
|
||||
typedef enum EVAL_TokenKind
|
||||
{
|
||||
EVAL_TokenKind_Null,
|
||||
EVAL_TokenKind_Identifier,
|
||||
EVAL_TokenKind_Numeric,
|
||||
EVAL_TokenKind_StringLiteral,
|
||||
EVAL_TokenKind_CharLiteral,
|
||||
EVAL_TokenKind_Symbol,
|
||||
EVAL_TokenKind_COUNT
|
||||
}
|
||||
EVAL_TokenKind;
|
||||
|
||||
typedef struct EVAL_Token EVAL_Token;
|
||||
struct EVAL_Token
|
||||
{
|
||||
EVAL_TokenKind kind;
|
||||
Rng1U64 range;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenChunkNode EVAL_TokenChunkNode;
|
||||
struct EVAL_TokenChunkNode
|
||||
{
|
||||
EVAL_TokenChunkNode *next;
|
||||
EVAL_Token *v;
|
||||
U64 count;
|
||||
U64 cap;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenChunkList EVAL_TokenChunkList;
|
||||
struct EVAL_TokenChunkList
|
||||
{
|
||||
EVAL_TokenChunkNode *first;
|
||||
EVAL_TokenChunkNode *last;
|
||||
U64 node_count;
|
||||
U64 total_count;
|
||||
};
|
||||
|
||||
typedef struct EVAL_TokenArray EVAL_TokenArray;
|
||||
struct EVAL_TokenArray
|
||||
{
|
||||
EVAL_Token *v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parser Types
|
||||
|
||||
typedef struct EVAL_ParseResult EVAL_ParseResult;
|
||||
struct EVAL_ParseResult
|
||||
{
|
||||
EVAL_Token *last_token;
|
||||
EVAL_Expr *expr;
|
||||
EVAL_ErrorList errors;
|
||||
};
|
||||
|
||||
typedef struct EVAL_ParseCtx EVAL_ParseCtx;
|
||||
struct EVAL_ParseCtx
|
||||
{
|
||||
Architecture arch;
|
||||
U64 ip_voff;
|
||||
RDI_Parsed *rdi;
|
||||
TG_Graph *type_graph;
|
||||
EVAL_String2NumMap *regs_map;
|
||||
EVAL_String2NumMap *reg_alias_map;
|
||||
EVAL_String2NumMap *locals_map;
|
||||
EVAL_String2NumMap *member_map;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
read_only global EVAL_String2NumMap eval_string2num_map_nil = {0};
|
||||
read_only global EVAL_String2ExprMap eval_string2expr_map_nil = {0};
|
||||
global read_only EVAL_ParseResult eval_parse_result_nil = {0, &eval_expr_nil};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Debug-Info-Driven Map Building Fast Paths
|
||||
|
||||
internal EVAL_String2NumMap *eval_push_locals_map_from_rdi_voff(Arena *arena, RDI_Parsed *rdi, U64 voff);
|
||||
internal EVAL_String2NumMap *eval_push_member_map_from_rdi_voff(Arena *arena, RDI_Parsed *rdi, U64 voff);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Tokenization Functions
|
||||
|
||||
#define eval_token_at_it(it, arr) (((it) < (arr)->v+(arr)->count) ? (*(it)) : eval_token_zero())
|
||||
internal EVAL_Token eval_token_zero(void);
|
||||
internal void eval_token_chunk_list_push(Arena *arena, EVAL_TokenChunkList *list, U64 chunk_size, EVAL_Token *token);
|
||||
internal EVAL_TokenArray eval_token_array_from_chunk_list(Arena *arena, EVAL_TokenChunkList *list);
|
||||
internal EVAL_TokenArray eval_token_array_from_text(Arena *arena, String8 text);
|
||||
internal EVAL_TokenArray eval_token_array_make_first_opl(EVAL_Token *first, EVAL_Token *opl);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parser Functions
|
||||
|
||||
internal TG_Key eval_leaf_type_from_name(RDI_Parsed *rdi, String8 name);
|
||||
internal EVAL_ParseResult eval_parse_type_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
|
||||
internal EVAL_ParseResult eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens, S64 max_precedence);
|
||||
internal EVAL_ParseResult eval_parse_expr_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
|
||||
|
||||
#endif // EVAL_PARSER_H
|
||||
|
||||
Reference in New Issue
Block a user