mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-17 17:42:22 -07:00
eliminate old eval/type-graph layers
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/eval2.meta.c"
|
||||
#include "generated/eval.meta.c"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Lexing/Parsing Data Tables
|
||||
@@ -7,7 +7,7 @@
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/eval2.meta.h"
|
||||
#include "generated/eval.meta.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Messages
|
||||
+186
-106
@@ -1,106 +1,186 @@
|
||||
// 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 basic_string basic_byte_size)
|
||||
// NOTE(rjf): basic_byte_size == 0xFF? => address sized
|
||||
E_TypeKindTable:
|
||||
{
|
||||
{Null "" 0 }
|
||||
{Void "void" 0 }
|
||||
{Handle "HANDLE" 0xFF }
|
||||
{Char8 "char8" 1 }
|
||||
{Char16 "char16" 2 }
|
||||
{Char32 "char32" 4 }
|
||||
{UChar8 "uchar8" 1 }
|
||||
{UChar16 "uchar16" 2 }
|
||||
{UChar32 "uchar32" 4 }
|
||||
{U8 "U8" 1 }
|
||||
{U16 "U16" 2 }
|
||||
{U32 "U32" 4 }
|
||||
{U64 "U64" 8 }
|
||||
{U128 "U128" 16 }
|
||||
{U256 "U256" 32 }
|
||||
{U512 "U512" 64 }
|
||||
{S8 "S8" 1 }
|
||||
{S16 "S16" 2 }
|
||||
{S32 "S32" 4 }
|
||||
{S64 "S64" 8 }
|
||||
{S128 "S128" 16 }
|
||||
{S256 "S256" 32 }
|
||||
{S512 "S512" 64 }
|
||||
{Bool "bool" 1 }
|
||||
{F16 "F16" 2 }
|
||||
{F32 "F32" 4 }
|
||||
{F32PP "F32PP" 4 }
|
||||
{F48 "F48" 6 }
|
||||
{F64 "F64" 8 }
|
||||
{F80 "F80" 10 }
|
||||
{F128 "F128" 16 }
|
||||
{ComplexF32 "ComplexF32" 8 }
|
||||
{ComplexF64 "ComplexF64" 16 }
|
||||
{ComplexF80 "ComplexF80" 20 }
|
||||
{ComplexF128 "ComplexF128" 32 }
|
||||
{Modifier "" 0 }
|
||||
{Ptr "" 0 }
|
||||
{LRef "" 0 }
|
||||
{RRef "" 0 }
|
||||
{Array "" 0 }
|
||||
{Function "" 0 }
|
||||
{Method "" 0 }
|
||||
{MemberPtr "" 0 }
|
||||
{Struct "struct" 0 }
|
||||
{Class "class" 0 }
|
||||
{Union "union" 0 }
|
||||
{Enum "enum" 0 }
|
||||
{Alias "typedef" 0 }
|
||||
{IncompleteStruct "struct" 0 }
|
||||
{IncompleteUnion "union" 0 }
|
||||
{IncompleteClass "class" 0 }
|
||||
{IncompleteEnum "enum" 0 }
|
||||
{Bitfield "" 0 }
|
||||
{Variadic "" 0 }
|
||||
}
|
||||
|
||||
@table(name op_string)
|
||||
E_ExprKindTable:
|
||||
{
|
||||
{ Nil "" }
|
||||
|
||||
{ ArrayIndex "[]" }
|
||||
{ MemberAccess "." }
|
||||
{ Deref "*" }
|
||||
{ Address "&" }
|
||||
|
||||
{ Cast "cast" }
|
||||
{ Sizeof "sizeof" }
|
||||
|
||||
{ Neg "-" }
|
||||
{ LogNot "!" }
|
||||
{ BitNot "~" }
|
||||
{ Mul "*" }
|
||||
{ Div "/" }
|
||||
{ Mod "%" }
|
||||
{ Add "+" }
|
||||
{ Sub "-" }
|
||||
{ LShift "<<" }
|
||||
{ RShift ">>" }
|
||||
{ Less "<" }
|
||||
{ LsEq "<=" }
|
||||
{ Grtr ">" }
|
||||
{ GrEq ">=" }
|
||||
{ EqEq "==" }
|
||||
{ NtEq "!=" }
|
||||
|
||||
{ BitAnd "&" }
|
||||
{ BitXor "^" }
|
||||
{ BitOr "|" }
|
||||
{ LogAnd "&&" }
|
||||
{ LogOr "||" }
|
||||
|
||||
{ Ternary "? " }
|
||||
|
||||
{ LeafBytecode "bytecode" }
|
||||
{ LeafMember "member" }
|
||||
{ LeafStringLiteral "string_literal" }
|
||||
{ LeafU64 "U64" }
|
||||
{ LeafF64 "F64" }
|
||||
{ LeafF32 "F32" }
|
||||
|
||||
{ TypeIdent "type_ident" }
|
||||
{ Ptr "ptr" }
|
||||
{ Array "array" }
|
||||
{ Func "function" }
|
||||
|
||||
{ Define "=" }
|
||||
{ LeafIdent "leaf_ident" }
|
||||
}
|
||||
|
||||
@table(name display_string)
|
||||
E_InterpretationCodeTable:
|
||||
{
|
||||
{ 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 E_TypeKind:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
`FirstBasic = E_TypeKind_Void`,
|
||||
`LastBasic = E_TypeKind_ComplexF128`,
|
||||
`FirstInteger = E_TypeKind_Char8`,
|
||||
`LastInteger = E_TypeKind_S512`,
|
||||
`FirstSigned1 = E_TypeKind_Char8`,
|
||||
`LastSigned1 = E_TypeKind_Char32`,
|
||||
`FirstSigned2 = E_TypeKind_S8`,
|
||||
`LastSigned2 = E_TypeKind_S512`,
|
||||
`FirstIncomplete = E_TypeKind_IncompleteStruct`,
|
||||
`LastIncomplete = E_TypeKind_IncompleteEnum`,
|
||||
}
|
||||
|
||||
@enum(U32) E_ExprKind:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@enum E_InterpretationCode:
|
||||
{
|
||||
@expand(E_InterpretationCodeTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@data(String8)
|
||||
e_expr_kind_strings:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@data(String8) e_interpretation_code_display_strings:
|
||||
{
|
||||
@expand(E_InterpretationCodeTable a) `str8_lit_comp("$(a.display_string)")`
|
||||
}
|
||||
|
||||
@data(String8) e_expr_op_strings:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `str8_lit_comp("$(a.op_string)")`
|
||||
}
|
||||
|
||||
@data(U8) e_kind_basic_byte_size_table:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `$(a.basic_byte_size)`;
|
||||
}
|
||||
|
||||
@data(String8) e_kind_basic_string_table:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `str8_lit_comp("$(a.basic_string)")`;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
||||
// 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
|
||||
@@ -1,254 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
// 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
|
||||
@@ -1,50 +0,0 @@
|
||||
// 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:;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// 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
|
||||
@@ -1,7 +0,0 @@
|
||||
// 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"
|
||||
@@ -1,12 +0,0 @@
|
||||
// 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
|
||||
@@ -1,648 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Eval Machine Functions
|
||||
|
||||
internal EVAL_Result
|
||||
eval_interpret(EVAL_Machine *machine, String8 bytecode)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
EVAL_Result result = {0};
|
||||
|
||||
// TODO(allen): We could scan the bytecode and figure out the
|
||||
// maximum depth of the stack
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U64 stack_cap = 128;
|
||||
EVAL_Slot *stack = push_array_no_zero(scratch.arena, EVAL_Slot, stack_cap);
|
||||
|
||||
U64 stack_count = 0;
|
||||
U8 *ptr = bytecode.str;
|
||||
U8 *opl = bytecode.str + bytecode.size;
|
||||
|
||||
for (;ptr < opl;){
|
||||
// consume opcode
|
||||
RDI_EvalOp op = (RDI_EvalOp)*ptr;
|
||||
if (op >= RDI_EvalOp_COUNT){
|
||||
result.code = EVAL_ResultCode_BadOp;
|
||||
goto done;
|
||||
}
|
||||
U8 ctrlbits = rdi_eval_op_ctrlbits_table[op];
|
||||
ptr += 1;
|
||||
|
||||
// decode
|
||||
U64 imm = 0;
|
||||
{
|
||||
U32 decode_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
|
||||
U8 *next_ptr = ptr + decode_size;
|
||||
if (next_ptr > opl){
|
||||
result.code = EVAL_ResultCode_BadOp;
|
||||
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;
|
||||
}
|
||||
|
||||
// pop
|
||||
EVAL_Slot *svals = 0;
|
||||
{
|
||||
U32 pop_count = RDI_POPN_FROM_CTRLBITS(ctrlbits);
|
||||
if (pop_count > stack_count){
|
||||
result.code = EVAL_ResultCode_BadOp;
|
||||
goto done;
|
||||
}
|
||||
if (pop_count <= stack_count){
|
||||
stack_count -= pop_count;
|
||||
svals = stack + stack_count;
|
||||
}
|
||||
}
|
||||
|
||||
// interpret
|
||||
EVAL_Slot nval = {0};
|
||||
switch (op){
|
||||
case RDI_EvalOp_Stop:
|
||||
{
|
||||
goto done;
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Noop:
|
||||
{
|
||||
// do nothing
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Cond:
|
||||
{
|
||||
if (svals[0].u64){
|
||||
ptr += imm;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Skip:
|
||||
{
|
||||
ptr += imm;
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_MemRead:
|
||||
{
|
||||
U64 addr = svals[0].u64;
|
||||
U64 size = imm;
|
||||
B32 good_read = 0;
|
||||
if (machine->memory_read != 0 &&
|
||||
machine->memory_read(machine->u, &nval, addr, size)){
|
||||
good_read = 1;
|
||||
}
|
||||
if (!good_read){
|
||||
result.code = EVAL_ResultCode_BadMemRead;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_RegRead:
|
||||
{
|
||||
U8 rdi_reg_code = (imm&0x0000FF)>>0;
|
||||
U8 byte_size = (imm&0x00FF00)>>8;
|
||||
U8 byte_off = (imm&0xFF0000)>>16;
|
||||
REGS_RegCode base_reg_code = regs_reg_code_from_arch_rdi_code(machine->arch, rdi_reg_code);
|
||||
REGS_Rng rng = regs_reg_code_rng_table_from_architecture(machine->arch)[base_reg_code];
|
||||
U64 off = (U64)rng.byte_off + byte_off;
|
||||
U64 size = (U64)byte_size;
|
||||
if (off + size <= machine->reg_size){
|
||||
MemoryCopy(&nval, (U8*)machine->reg_data + off, size);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadRegRead;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_RegReadDyn:
|
||||
{
|
||||
U64 off = svals[0].u64;
|
||||
U64 size = bit_size_from_arch(machine->arch)/8;
|
||||
if (off + size <= machine->reg_size){
|
||||
MemoryCopy(&nval, (U8*)machine->reg_data + off, size);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadRegRead;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_FrameOff:
|
||||
{
|
||||
if (machine->frame_base != 0){
|
||||
nval.u64 = *machine->frame_base + imm;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadFrameBase;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_ModuleOff:
|
||||
{
|
||||
if (machine->module_base != 0){
|
||||
nval.u64 = *machine->module_base + imm;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadModuleBase;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_TLSOff:
|
||||
{
|
||||
if (machine->tls_base != 0){
|
||||
nval.u64 = *machine->tls_base + imm;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadTLSBase;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_ConstU8:
|
||||
case RDI_EvalOp_ConstU16:
|
||||
case RDI_EvalOp_ConstU32:
|
||||
case RDI_EvalOp_ConstU64:
|
||||
{
|
||||
nval.u64 = imm;
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Abs:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.f32 = svals[0].f32;
|
||||
if (svals[0].f32 < 0){
|
||||
nval.f32 = -svals[0].f32;
|
||||
}
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.f64 = svals[0].f64;
|
||||
if (svals[0].f64 < 0){
|
||||
nval.f64 = -svals[0].f64;
|
||||
}
|
||||
}
|
||||
else{
|
||||
nval.s64 = svals[0].s64;
|
||||
if (svals[0].s64 < 0){
|
||||
nval.s64 = -svals[0].s64;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Neg:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.f32 = -svals[0].f32;
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.f64 = -svals[0].f64;
|
||||
}
|
||||
else{
|
||||
nval.u64 = (~svals[0].u64) + 1;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Add:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.f32 = svals[0].f32 + svals[1].f32;
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.f64 = svals[0].f64 + svals[1].f64;
|
||||
}
|
||||
else{
|
||||
nval.u64 = svals[0].u64 + svals[1].u64;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Sub:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.f32 = svals[0].f32 - svals[1].f32;
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.f64 = svals[0].f64 - svals[1].f64;
|
||||
}
|
||||
else{
|
||||
nval.u64 = svals[0].u64 - svals[1].u64;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Mul:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.f32 = svals[0].f32*svals[1].f32;
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.f64 = svals[0].f64*svals[1].f64;
|
||||
}
|
||||
else{
|
||||
nval.u64 = svals[0].u64*svals[1].u64;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Div:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
if (svals[1].f32 != 0.f){
|
||||
nval.f32 = svals[0].f32/svals[1].f32;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.code = EVAL_ResultCode_DivideByZero;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
if (svals[1].f64 != 0.){
|
||||
nval.f64 = svals[0].f64/svals[1].f64;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.code = EVAL_ResultCode_DivideByZero;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
if (svals[1].u64 != 0){
|
||||
nval.u64 = svals[0].u64/svals[1].u64;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.code = EVAL_ResultCode_DivideByZero;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Mod:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
if (svals[1].u64 != 0){
|
||||
nval.u64 = svals[0].u64%svals[1].u64;
|
||||
}
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_LShift:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = svals[0].u64 << svals[1].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_RShift:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U){
|
||||
nval.u64 = svals[0].u64 >> svals[1].u64;
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = svals[0].s64 >> svals[1].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_BitAnd:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = svals[0].u64&svals[1].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_BitOr:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = svals[0].u64|svals[1].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_BitXor:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = svals[0].u64^svals[1].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_BitNot:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = ~svals[0].u64;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_LogAnd:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].u64 && svals[1].u64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_LogOr:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].u64 || svals[1].u64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_LogNot:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_U ||
|
||||
imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (!svals[0].u64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_EqEq:
|
||||
{
|
||||
nval.u64 = (svals[0].u64 == svals[1].u64);
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_NtEq:
|
||||
{
|
||||
nval.u64 = (svals[0].u64 != svals[1].u64);
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_LsEq:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.u64 = (svals[0].f32 <= svals[1].f32);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.u64 = (svals[0].f64 <= svals[1].f64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_U){
|
||||
nval.u64 = (svals[0].u64 <= svals[1].u64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].s64 <= svals[1].s64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_GrEq:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.u64 = (svals[0].f32 >= svals[1].f32);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.u64 = (svals[0].f64 >= svals[1].f64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_U){
|
||||
nval.u64 = (svals[0].u64 >= svals[1].u64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].s64 >= svals[1].s64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Less:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.u64 = (svals[0].f32 < svals[1].f32);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.u64 = (svals[0].f64 < svals[1].f64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_U){
|
||||
nval.u64 = (svals[0].u64 < svals[1].u64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].s64 < svals[1].s64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Grtr:
|
||||
{
|
||||
if (imm == RDI_EvalTypeGroup_F32){
|
||||
nval.u64 = (svals[0].f32 > svals[1].f32);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_F64){
|
||||
nval.u64 = (svals[0].f64 > svals[1].f64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_U){
|
||||
nval.u64 = (svals[0].u64 > svals[1].u64);
|
||||
}
|
||||
else if (imm == RDI_EvalTypeGroup_S){
|
||||
nval.u64 = (svals[0].s64 > svals[1].s64);
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOpTypes;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Trunc:
|
||||
{
|
||||
if (0 < imm){
|
||||
U64 mask = 0;
|
||||
if (imm < 64){
|
||||
mask = max_U64 >> (64 - imm);
|
||||
}
|
||||
nval.u64 = svals[0].u64&mask;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_TruncSigned:
|
||||
{
|
||||
if (0 < imm){
|
||||
U64 mask = 0;
|
||||
if (imm < 64){
|
||||
mask = max_U64 >> (64 - imm);
|
||||
}
|
||||
U64 high = 0;
|
||||
if (svals[0].u64 & (1 << (imm - 1))){
|
||||
high = ~mask;
|
||||
}
|
||||
nval.u64 = high|(svals[0].u64&mask);
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Convert:
|
||||
{
|
||||
U32 in = imm&0xFF;
|
||||
U32 out = (imm >> 8)&0xFF;
|
||||
if (in != out){
|
||||
switch (in + out*RDI_EvalTypeGroup_COUNT){
|
||||
case RDI_EvalTypeGroup_F32 + RDI_EvalTypeGroup_U*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.u64 = (U64)svals[0].f32;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_F64 + RDI_EvalTypeGroup_U*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.u64 = (U64)svals[0].f64;
|
||||
}break;
|
||||
|
||||
case RDI_EvalTypeGroup_F32 + RDI_EvalTypeGroup_S*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.s64 = (S64)svals[0].f32;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_F64 + RDI_EvalTypeGroup_S*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.s64 = (S64)svals[0].f64;
|
||||
}break;
|
||||
|
||||
case RDI_EvalTypeGroup_U + RDI_EvalTypeGroup_F32*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f32 = (F32)svals[0].u64;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_S + RDI_EvalTypeGroup_F32*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f32 = (F32)svals[0].s64;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_F64 + RDI_EvalTypeGroup_F32*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f32 = (F32)svals[0].f64;
|
||||
}break;
|
||||
|
||||
case RDI_EvalTypeGroup_U + RDI_EvalTypeGroup_F64*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f64 = (F64)svals[0].u64;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_S + RDI_EvalTypeGroup_F64*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f64 = (F64)svals[0].s64;
|
||||
}break;
|
||||
case RDI_EvalTypeGroup_F32 + RDI_EvalTypeGroup_F64*RDI_EvalTypeGroup_COUNT:
|
||||
{
|
||||
nval.f64 = (F64)svals[0].f32;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Pick:
|
||||
{
|
||||
if (stack_count > imm){
|
||||
nval = stack[stack_count - imm - 1];
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOp;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Pop:
|
||||
{
|
||||
// do nothing - the pop is handled by the control bits
|
||||
}break;
|
||||
|
||||
case RDI_EvalOp_Insert:
|
||||
{
|
||||
if (stack_count > imm){
|
||||
if (imm > 0){
|
||||
EVAL_Slot tval = stack[stack_count - 1];
|
||||
EVAL_Slot *dst = stack + stack_count - 1 - imm;
|
||||
EVAL_Slot *shift = dst + 1;
|
||||
MemoryCopy(shift, dst, imm*sizeof(EVAL_Slot));
|
||||
*dst = tval;
|
||||
}
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_BadOp;
|
||||
goto done;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
||||
// push
|
||||
{
|
||||
U64 push_count = RDI_PUSHN_FROM_CTRLBITS(ctrlbits);
|
||||
if (push_count == 1){
|
||||
if (stack_count < stack_cap){
|
||||
stack[stack_count] = nval;
|
||||
stack_count += 1;
|
||||
}
|
||||
else{
|
||||
result.code = EVAL_ResultCode_InsufficientStackSpace;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
done:;
|
||||
|
||||
if (stack_count == 1){
|
||||
result.value = stack[0];
|
||||
}
|
||||
else if(result.code == EVAL_ResultCode_Good){
|
||||
result.code = EVAL_ResultCode_MalformedBytecode;
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
return(result);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// 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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,109 +0,0 @@
|
||||
// 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
|
||||
+121
-47
@@ -4,51 +4,7 @@
|
||||
//- GENERATED CODE
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
U8 eval_expr_kind_child_counts[40] =
|
||||
{
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
};
|
||||
|
||||
String8 eval_expr_kind_strings[40] =
|
||||
String8 e_expr_kind_strings[41] =
|
||||
{
|
||||
str8_lit_comp("Nil"),
|
||||
str8_lit_comp("ArrayIndex"),
|
||||
@@ -81,6 +37,7 @@ str8_lit_comp("LogOr"),
|
||||
str8_lit_comp("Ternary"),
|
||||
str8_lit_comp("LeafBytecode"),
|
||||
str8_lit_comp("LeafMember"),
|
||||
str8_lit_comp("LeafStringLiteral"),
|
||||
str8_lit_comp("LeafU64"),
|
||||
str8_lit_comp("LeafF64"),
|
||||
str8_lit_comp("LeafF32"),
|
||||
@@ -92,7 +49,7 @@ str8_lit_comp("Define"),
|
||||
str8_lit_comp("LeafIdent"),
|
||||
};
|
||||
|
||||
String8 eval_result_code_display_strings[11] =
|
||||
String8 e_interpretation_code_display_strings[11] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("Cannot divide by zero."),
|
||||
@@ -107,7 +64,7 @@ str8_lit_comp("Insufficient evaluation machine stack space."),
|
||||
str8_lit_comp("Malformed bytecode."),
|
||||
};
|
||||
|
||||
String8 eval_expr_op_strings[40] =
|
||||
String8 e_expr_op_strings[41] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("[]"),
|
||||
@@ -140,6 +97,7 @@ str8_lit_comp("||"),
|
||||
str8_lit_comp("? "),
|
||||
str8_lit_comp("bytecode"),
|
||||
str8_lit_comp("member"),
|
||||
str8_lit_comp("string_literal"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F32"),
|
||||
@@ -151,5 +109,121 @@ str8_lit_comp("="),
|
||||
str8_lit_comp("leaf_ident"),
|
||||
};
|
||||
|
||||
U8 e_kind_basic_byte_size_table[54] =
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0xFF,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
10,
|
||||
16,
|
||||
8,
|
||||
16,
|
||||
20,
|
||||
32,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
String8 e_kind_basic_string_table[54] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("void"),
|
||||
str8_lit_comp("HANDLE"),
|
||||
str8_lit_comp("char8"),
|
||||
str8_lit_comp("char16"),
|
||||
str8_lit_comp("char32"),
|
||||
str8_lit_comp("uchar8"),
|
||||
str8_lit_comp("uchar16"),
|
||||
str8_lit_comp("uchar32"),
|
||||
str8_lit_comp("U8"),
|
||||
str8_lit_comp("U16"),
|
||||
str8_lit_comp("U32"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("U128"),
|
||||
str8_lit_comp("U256"),
|
||||
str8_lit_comp("U512"),
|
||||
str8_lit_comp("S8"),
|
||||
str8_lit_comp("S16"),
|
||||
str8_lit_comp("S32"),
|
||||
str8_lit_comp("S64"),
|
||||
str8_lit_comp("S128"),
|
||||
str8_lit_comp("S256"),
|
||||
str8_lit_comp("S512"),
|
||||
str8_lit_comp("bool"),
|
||||
str8_lit_comp("F16"),
|
||||
str8_lit_comp("F32"),
|
||||
str8_lit_comp("F32PP"),
|
||||
str8_lit_comp("F48"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F80"),
|
||||
str8_lit_comp("F128"),
|
||||
str8_lit_comp("ComplexF32"),
|
||||
str8_lit_comp("ComplexF64"),
|
||||
str8_lit_comp("ComplexF80"),
|
||||
str8_lit_comp("ComplexF128"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp("typedef"),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
};
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
|
||||
+133
-62
@@ -6,73 +6,144 @@
|
||||
#ifndef EVAL_META_H
|
||||
#define EVAL_META_H
|
||||
|
||||
typedef U32 EVAL_ExprKind;
|
||||
typedef enum EVAL_ExprKindEnum
|
||||
typedef enum E_TypeKind
|
||||
{
|
||||
EVAL_ExprKind_Nil,
|
||||
EVAL_ExprKind_ArrayIndex,
|
||||
EVAL_ExprKind_MemberAccess,
|
||||
EVAL_ExprKind_Deref,
|
||||
EVAL_ExprKind_Address,
|
||||
EVAL_ExprKind_Cast,
|
||||
EVAL_ExprKind_Sizeof,
|
||||
EVAL_ExprKind_Neg,
|
||||
EVAL_ExprKind_LogNot,
|
||||
EVAL_ExprKind_BitNot,
|
||||
EVAL_ExprKind_Mul,
|
||||
EVAL_ExprKind_Div,
|
||||
EVAL_ExprKind_Mod,
|
||||
EVAL_ExprKind_Add,
|
||||
EVAL_ExprKind_Sub,
|
||||
EVAL_ExprKind_LShift,
|
||||
EVAL_ExprKind_RShift,
|
||||
EVAL_ExprKind_Less,
|
||||
EVAL_ExprKind_LsEq,
|
||||
EVAL_ExprKind_Grtr,
|
||||
EVAL_ExprKind_GrEq,
|
||||
EVAL_ExprKind_EqEq,
|
||||
EVAL_ExprKind_NtEq,
|
||||
EVAL_ExprKind_BitAnd,
|
||||
EVAL_ExprKind_BitXor,
|
||||
EVAL_ExprKind_BitOr,
|
||||
EVAL_ExprKind_LogAnd,
|
||||
EVAL_ExprKind_LogOr,
|
||||
EVAL_ExprKind_Ternary,
|
||||
EVAL_ExprKind_LeafBytecode,
|
||||
EVAL_ExprKind_LeafMember,
|
||||
EVAL_ExprKind_LeafU64,
|
||||
EVAL_ExprKind_LeafF64,
|
||||
EVAL_ExprKind_LeafF32,
|
||||
EVAL_ExprKind_TypeIdent,
|
||||
EVAL_ExprKind_Ptr,
|
||||
EVAL_ExprKind_Array,
|
||||
EVAL_ExprKind_Func,
|
||||
EVAL_ExprKind_Define,
|
||||
EVAL_ExprKind_LeafIdent,
|
||||
EVAL_ExprKind_COUNT,
|
||||
} EVAL_ExprKindEnum;
|
||||
E_TypeKind_Null,
|
||||
E_TypeKind_Void,
|
||||
E_TypeKind_Handle,
|
||||
E_TypeKind_Char8,
|
||||
E_TypeKind_Char16,
|
||||
E_TypeKind_Char32,
|
||||
E_TypeKind_UChar8,
|
||||
E_TypeKind_UChar16,
|
||||
E_TypeKind_UChar32,
|
||||
E_TypeKind_U8,
|
||||
E_TypeKind_U16,
|
||||
E_TypeKind_U32,
|
||||
E_TypeKind_U64,
|
||||
E_TypeKind_U128,
|
||||
E_TypeKind_U256,
|
||||
E_TypeKind_U512,
|
||||
E_TypeKind_S8,
|
||||
E_TypeKind_S16,
|
||||
E_TypeKind_S32,
|
||||
E_TypeKind_S64,
|
||||
E_TypeKind_S128,
|
||||
E_TypeKind_S256,
|
||||
E_TypeKind_S512,
|
||||
E_TypeKind_Bool,
|
||||
E_TypeKind_F16,
|
||||
E_TypeKind_F32,
|
||||
E_TypeKind_F32PP,
|
||||
E_TypeKind_F48,
|
||||
E_TypeKind_F64,
|
||||
E_TypeKind_F80,
|
||||
E_TypeKind_F128,
|
||||
E_TypeKind_ComplexF32,
|
||||
E_TypeKind_ComplexF64,
|
||||
E_TypeKind_ComplexF80,
|
||||
E_TypeKind_ComplexF128,
|
||||
E_TypeKind_Modifier,
|
||||
E_TypeKind_Ptr,
|
||||
E_TypeKind_LRef,
|
||||
E_TypeKind_RRef,
|
||||
E_TypeKind_Array,
|
||||
E_TypeKind_Function,
|
||||
E_TypeKind_Method,
|
||||
E_TypeKind_MemberPtr,
|
||||
E_TypeKind_Struct,
|
||||
E_TypeKind_Class,
|
||||
E_TypeKind_Union,
|
||||
E_TypeKind_Enum,
|
||||
E_TypeKind_Alias,
|
||||
E_TypeKind_IncompleteStruct,
|
||||
E_TypeKind_IncompleteUnion,
|
||||
E_TypeKind_IncompleteClass,
|
||||
E_TypeKind_IncompleteEnum,
|
||||
E_TypeKind_Bitfield,
|
||||
E_TypeKind_Variadic,
|
||||
E_TypeKind_COUNT,
|
||||
E_TypeKind_FirstBasic = E_TypeKind_Void,
|
||||
E_TypeKind_LastBasic = E_TypeKind_ComplexF128,
|
||||
E_TypeKind_FirstInteger = E_TypeKind_Char8,
|
||||
E_TypeKind_LastInteger = E_TypeKind_S512,
|
||||
E_TypeKind_FirstSigned1 = E_TypeKind_Char8,
|
||||
E_TypeKind_LastSigned1 = E_TypeKind_Char32,
|
||||
E_TypeKind_FirstSigned2 = E_TypeKind_S8,
|
||||
E_TypeKind_LastSigned2 = E_TypeKind_S512,
|
||||
E_TypeKind_FirstIncomplete = E_TypeKind_IncompleteStruct,
|
||||
E_TypeKind_LastIncomplete = E_TypeKind_IncompleteEnum,
|
||||
} E_TypeKind;
|
||||
|
||||
typedef enum EVAL_ResultCode
|
||||
typedef U32 E_ExprKind;
|
||||
typedef enum E_ExprKindEnum
|
||||
{
|
||||
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;
|
||||
E_ExprKind_Nil,
|
||||
E_ExprKind_ArrayIndex,
|
||||
E_ExprKind_MemberAccess,
|
||||
E_ExprKind_Deref,
|
||||
E_ExprKind_Address,
|
||||
E_ExprKind_Cast,
|
||||
E_ExprKind_Sizeof,
|
||||
E_ExprKind_Neg,
|
||||
E_ExprKind_LogNot,
|
||||
E_ExprKind_BitNot,
|
||||
E_ExprKind_Mul,
|
||||
E_ExprKind_Div,
|
||||
E_ExprKind_Mod,
|
||||
E_ExprKind_Add,
|
||||
E_ExprKind_Sub,
|
||||
E_ExprKind_LShift,
|
||||
E_ExprKind_RShift,
|
||||
E_ExprKind_Less,
|
||||
E_ExprKind_LsEq,
|
||||
E_ExprKind_Grtr,
|
||||
E_ExprKind_GrEq,
|
||||
E_ExprKind_EqEq,
|
||||
E_ExprKind_NtEq,
|
||||
E_ExprKind_BitAnd,
|
||||
E_ExprKind_BitXor,
|
||||
E_ExprKind_BitOr,
|
||||
E_ExprKind_LogAnd,
|
||||
E_ExprKind_LogOr,
|
||||
E_ExprKind_Ternary,
|
||||
E_ExprKind_LeafBytecode,
|
||||
E_ExprKind_LeafMember,
|
||||
E_ExprKind_LeafStringLiteral,
|
||||
E_ExprKind_LeafU64,
|
||||
E_ExprKind_LeafF64,
|
||||
E_ExprKind_LeafF32,
|
||||
E_ExprKind_TypeIdent,
|
||||
E_ExprKind_Ptr,
|
||||
E_ExprKind_Array,
|
||||
E_ExprKind_Func,
|
||||
E_ExprKind_Define,
|
||||
E_ExprKind_LeafIdent,
|
||||
E_ExprKind_COUNT,
|
||||
} E_ExprKindEnum;
|
||||
|
||||
typedef enum E_InterpretationCode
|
||||
{
|
||||
E_InterpretationCode_Good,
|
||||
E_InterpretationCode_DivideByZero,
|
||||
E_InterpretationCode_BadOp,
|
||||
E_InterpretationCode_BadOpTypes,
|
||||
E_InterpretationCode_BadMemRead,
|
||||
E_InterpretationCode_BadRegRead,
|
||||
E_InterpretationCode_BadFrameBase,
|
||||
E_InterpretationCode_BadModuleBase,
|
||||
E_InterpretationCode_BadTLSBase,
|
||||
E_InterpretationCode_InsufficientStackSpace,
|
||||
E_InterpretationCode_MalformedBytecode,
|
||||
E_InterpretationCode_COUNT,
|
||||
} E_InterpretationCode;
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern U8 eval_expr_kind_child_counts[40];
|
||||
extern String8 eval_expr_kind_strings[40];
|
||||
extern String8 eval_result_code_display_strings[11];
|
||||
extern String8 eval_expr_op_strings[40];
|
||||
extern String8 e_expr_kind_strings[41];
|
||||
extern String8 e_interpretation_code_display_strings[11];
|
||||
extern String8 e_expr_op_strings[41];
|
||||
extern U8 e_kind_basic_byte_size_table[54];
|
||||
extern String8 e_kind_basic_string_table[54];
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
@table(name basic_string basic_byte_size)
|
||||
// NOTE(rjf): basic_byte_size == 0xFF? => address sized
|
||||
E_TypeKindTable:
|
||||
{
|
||||
{Null "" 0 }
|
||||
{Void "void" 0 }
|
||||
{Handle "HANDLE" 0xFF }
|
||||
{Char8 "char8" 1 }
|
||||
{Char16 "char16" 2 }
|
||||
{Char32 "char32" 4 }
|
||||
{UChar8 "uchar8" 1 }
|
||||
{UChar16 "uchar16" 2 }
|
||||
{UChar32 "uchar32" 4 }
|
||||
{U8 "U8" 1 }
|
||||
{U16 "U16" 2 }
|
||||
{U32 "U32" 4 }
|
||||
{U64 "U64" 8 }
|
||||
{U128 "U128" 16 }
|
||||
{U256 "U256" 32 }
|
||||
{U512 "U512" 64 }
|
||||
{S8 "S8" 1 }
|
||||
{S16 "S16" 2 }
|
||||
{S32 "S32" 4 }
|
||||
{S64 "S64" 8 }
|
||||
{S128 "S128" 16 }
|
||||
{S256 "S256" 32 }
|
||||
{S512 "S512" 64 }
|
||||
{Bool "bool" 1 }
|
||||
{F16 "F16" 2 }
|
||||
{F32 "F32" 4 }
|
||||
{F32PP "F32PP" 4 }
|
||||
{F48 "F48" 6 }
|
||||
{F64 "F64" 8 }
|
||||
{F80 "F80" 10 }
|
||||
{F128 "F128" 16 }
|
||||
{ComplexF32 "ComplexF32" 8 }
|
||||
{ComplexF64 "ComplexF64" 16 }
|
||||
{ComplexF80 "ComplexF80" 20 }
|
||||
{ComplexF128 "ComplexF128" 32 }
|
||||
{Modifier "" 0 }
|
||||
{Ptr "" 0 }
|
||||
{LRef "" 0 }
|
||||
{RRef "" 0 }
|
||||
{Array "" 0 }
|
||||
{Function "" 0 }
|
||||
{Method "" 0 }
|
||||
{MemberPtr "" 0 }
|
||||
{Struct "struct" 0 }
|
||||
{Class "class" 0 }
|
||||
{Union "union" 0 }
|
||||
{Enum "enum" 0 }
|
||||
{Alias "typedef" 0 }
|
||||
{IncompleteStruct "struct" 0 }
|
||||
{IncompleteUnion "union" 0 }
|
||||
{IncompleteClass "class" 0 }
|
||||
{IncompleteEnum "enum" 0 }
|
||||
{Bitfield "" 0 }
|
||||
{Variadic "" 0 }
|
||||
}
|
||||
|
||||
@table(name op_string)
|
||||
E_ExprKindTable:
|
||||
{
|
||||
{ Nil "" }
|
||||
|
||||
{ ArrayIndex "[]" }
|
||||
{ MemberAccess "." }
|
||||
{ Deref "*" }
|
||||
{ Address "&" }
|
||||
|
||||
{ Cast "cast" }
|
||||
{ Sizeof "sizeof" }
|
||||
|
||||
{ Neg "-" }
|
||||
{ LogNot "!" }
|
||||
{ BitNot "~" }
|
||||
{ Mul "*" }
|
||||
{ Div "/" }
|
||||
{ Mod "%" }
|
||||
{ Add "+" }
|
||||
{ Sub "-" }
|
||||
{ LShift "<<" }
|
||||
{ RShift ">>" }
|
||||
{ Less "<" }
|
||||
{ LsEq "<=" }
|
||||
{ Grtr ">" }
|
||||
{ GrEq ">=" }
|
||||
{ EqEq "==" }
|
||||
{ NtEq "!=" }
|
||||
|
||||
{ BitAnd "&" }
|
||||
{ BitXor "^" }
|
||||
{ BitOr "|" }
|
||||
{ LogAnd "&&" }
|
||||
{ LogOr "||" }
|
||||
|
||||
{ Ternary "? " }
|
||||
|
||||
{ LeafBytecode "bytecode" }
|
||||
{ LeafMember "member" }
|
||||
{ LeafStringLiteral "string_literal" }
|
||||
{ LeafU64 "U64" }
|
||||
{ LeafF64 "F64" }
|
||||
{ LeafF32 "F32" }
|
||||
|
||||
{ TypeIdent "type_ident" }
|
||||
{ Ptr "ptr" }
|
||||
{ Array "array" }
|
||||
{ Func "function" }
|
||||
|
||||
{ Define "=" }
|
||||
{ LeafIdent "leaf_ident" }
|
||||
}
|
||||
|
||||
@table(name display_string)
|
||||
E_InterpretationCodeTable:
|
||||
{
|
||||
{ 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 E_TypeKind:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
`FirstBasic = E_TypeKind_Void`,
|
||||
`LastBasic = E_TypeKind_ComplexF128`,
|
||||
`FirstInteger = E_TypeKind_Char8`,
|
||||
`LastInteger = E_TypeKind_S512`,
|
||||
`FirstSigned1 = E_TypeKind_Char8`,
|
||||
`LastSigned1 = E_TypeKind_Char32`,
|
||||
`FirstSigned2 = E_TypeKind_S8`,
|
||||
`LastSigned2 = E_TypeKind_S512`,
|
||||
`FirstIncomplete = E_TypeKind_IncompleteStruct`,
|
||||
`LastIncomplete = E_TypeKind_IncompleteEnum`,
|
||||
}
|
||||
|
||||
@enum(U32) E_ExprKind:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@enum E_InterpretationCode:
|
||||
{
|
||||
@expand(E_InterpretationCodeTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
}
|
||||
|
||||
@data(String8)
|
||||
e_expr_kind_strings:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@data(String8) e_interpretation_code_display_strings:
|
||||
{
|
||||
@expand(E_InterpretationCodeTable a) `str8_lit_comp("$(a.display_string)")`
|
||||
}
|
||||
|
||||
@data(String8) e_expr_op_strings:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `str8_lit_comp("$(a.op_string)")`
|
||||
}
|
||||
|
||||
@data(U8) e_kind_basic_byte_size_table:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `$(a.basic_byte_size)`;
|
||||
}
|
||||
|
||||
@data(String8) e_kind_basic_string_table:
|
||||
{
|
||||
@expand(E_TypeKindTable a) `str8_lit_comp("$(a.basic_string)")`;
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
//- GENERATED CODE
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
String8 e_expr_kind_strings[41] =
|
||||
{
|
||||
str8_lit_comp("Nil"),
|
||||
str8_lit_comp("ArrayIndex"),
|
||||
str8_lit_comp("MemberAccess"),
|
||||
str8_lit_comp("Deref"),
|
||||
str8_lit_comp("Address"),
|
||||
str8_lit_comp("Cast"),
|
||||
str8_lit_comp("Sizeof"),
|
||||
str8_lit_comp("Neg"),
|
||||
str8_lit_comp("LogNot"),
|
||||
str8_lit_comp("BitNot"),
|
||||
str8_lit_comp("Mul"),
|
||||
str8_lit_comp("Div"),
|
||||
str8_lit_comp("Mod"),
|
||||
str8_lit_comp("Add"),
|
||||
str8_lit_comp("Sub"),
|
||||
str8_lit_comp("LShift"),
|
||||
str8_lit_comp("RShift"),
|
||||
str8_lit_comp("Less"),
|
||||
str8_lit_comp("LsEq"),
|
||||
str8_lit_comp("Grtr"),
|
||||
str8_lit_comp("GrEq"),
|
||||
str8_lit_comp("EqEq"),
|
||||
str8_lit_comp("NtEq"),
|
||||
str8_lit_comp("BitAnd"),
|
||||
str8_lit_comp("BitXor"),
|
||||
str8_lit_comp("BitOr"),
|
||||
str8_lit_comp("LogAnd"),
|
||||
str8_lit_comp("LogOr"),
|
||||
str8_lit_comp("Ternary"),
|
||||
str8_lit_comp("LeafBytecode"),
|
||||
str8_lit_comp("LeafMember"),
|
||||
str8_lit_comp("LeafStringLiteral"),
|
||||
str8_lit_comp("LeafU64"),
|
||||
str8_lit_comp("LeafF64"),
|
||||
str8_lit_comp("LeafF32"),
|
||||
str8_lit_comp("TypeIdent"),
|
||||
str8_lit_comp("Ptr"),
|
||||
str8_lit_comp("Array"),
|
||||
str8_lit_comp("Func"),
|
||||
str8_lit_comp("Define"),
|
||||
str8_lit_comp("LeafIdent"),
|
||||
};
|
||||
|
||||
String8 e_interpretation_code_display_strings[11] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("Cannot divide by zero."),
|
||||
str8_lit_comp("Invalid operation."),
|
||||
str8_lit_comp("Invalid operation types."),
|
||||
str8_lit_comp("Failed memory read."),
|
||||
str8_lit_comp("Failed register read."),
|
||||
str8_lit_comp("Invalid frame base address."),
|
||||
str8_lit_comp("Invalid module base address."),
|
||||
str8_lit_comp("Invalid thread-local storage base address."),
|
||||
str8_lit_comp("Insufficient evaluation machine stack space."),
|
||||
str8_lit_comp("Malformed bytecode."),
|
||||
};
|
||||
|
||||
String8 e_expr_op_strings[41] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("[]"),
|
||||
str8_lit_comp("."),
|
||||
str8_lit_comp("*"),
|
||||
str8_lit_comp("&"),
|
||||
str8_lit_comp("cast"),
|
||||
str8_lit_comp("sizeof"),
|
||||
str8_lit_comp("-"),
|
||||
str8_lit_comp("!"),
|
||||
str8_lit_comp("~"),
|
||||
str8_lit_comp("*"),
|
||||
str8_lit_comp("/"),
|
||||
str8_lit_comp("%"),
|
||||
str8_lit_comp("+"),
|
||||
str8_lit_comp("-"),
|
||||
str8_lit_comp("<<"),
|
||||
str8_lit_comp(">>"),
|
||||
str8_lit_comp("<"),
|
||||
str8_lit_comp("<="),
|
||||
str8_lit_comp(">"),
|
||||
str8_lit_comp(">="),
|
||||
str8_lit_comp("=="),
|
||||
str8_lit_comp("!="),
|
||||
str8_lit_comp("&"),
|
||||
str8_lit_comp("^"),
|
||||
str8_lit_comp("|"),
|
||||
str8_lit_comp("&&"),
|
||||
str8_lit_comp("||"),
|
||||
str8_lit_comp("? "),
|
||||
str8_lit_comp("bytecode"),
|
||||
str8_lit_comp("member"),
|
||||
str8_lit_comp("string_literal"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F32"),
|
||||
str8_lit_comp("type_ident"),
|
||||
str8_lit_comp("ptr"),
|
||||
str8_lit_comp("array"),
|
||||
str8_lit_comp("function"),
|
||||
str8_lit_comp("="),
|
||||
str8_lit_comp("leaf_ident"),
|
||||
};
|
||||
|
||||
U8 e_kind_basic_byte_size_table[54] =
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0xFF,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
10,
|
||||
16,
|
||||
8,
|
||||
16,
|
||||
20,
|
||||
32,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
String8 e_kind_basic_string_table[54] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("void"),
|
||||
str8_lit_comp("HANDLE"),
|
||||
str8_lit_comp("char8"),
|
||||
str8_lit_comp("char16"),
|
||||
str8_lit_comp("char32"),
|
||||
str8_lit_comp("uchar8"),
|
||||
str8_lit_comp("uchar16"),
|
||||
str8_lit_comp("uchar32"),
|
||||
str8_lit_comp("U8"),
|
||||
str8_lit_comp("U16"),
|
||||
str8_lit_comp("U32"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("U128"),
|
||||
str8_lit_comp("U256"),
|
||||
str8_lit_comp("U512"),
|
||||
str8_lit_comp("S8"),
|
||||
str8_lit_comp("S16"),
|
||||
str8_lit_comp("S32"),
|
||||
str8_lit_comp("S64"),
|
||||
str8_lit_comp("S128"),
|
||||
str8_lit_comp("S256"),
|
||||
str8_lit_comp("S512"),
|
||||
str8_lit_comp("bool"),
|
||||
str8_lit_comp("F16"),
|
||||
str8_lit_comp("F32"),
|
||||
str8_lit_comp("F32PP"),
|
||||
str8_lit_comp("F48"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F80"),
|
||||
str8_lit_comp("F128"),
|
||||
str8_lit_comp("ComplexF32"),
|
||||
str8_lit_comp("ComplexF64"),
|
||||
str8_lit_comp("ComplexF80"),
|
||||
str8_lit_comp("ComplexF128"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp("typedef"),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
};
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
//- GENERATED CODE
|
||||
|
||||
#ifndef EVAL2_META_H
|
||||
#define EVAL2_META_H
|
||||
|
||||
typedef enum E_TypeKind
|
||||
{
|
||||
E_TypeKind_Null,
|
||||
E_TypeKind_Void,
|
||||
E_TypeKind_Handle,
|
||||
E_TypeKind_Char8,
|
||||
E_TypeKind_Char16,
|
||||
E_TypeKind_Char32,
|
||||
E_TypeKind_UChar8,
|
||||
E_TypeKind_UChar16,
|
||||
E_TypeKind_UChar32,
|
||||
E_TypeKind_U8,
|
||||
E_TypeKind_U16,
|
||||
E_TypeKind_U32,
|
||||
E_TypeKind_U64,
|
||||
E_TypeKind_U128,
|
||||
E_TypeKind_U256,
|
||||
E_TypeKind_U512,
|
||||
E_TypeKind_S8,
|
||||
E_TypeKind_S16,
|
||||
E_TypeKind_S32,
|
||||
E_TypeKind_S64,
|
||||
E_TypeKind_S128,
|
||||
E_TypeKind_S256,
|
||||
E_TypeKind_S512,
|
||||
E_TypeKind_Bool,
|
||||
E_TypeKind_F16,
|
||||
E_TypeKind_F32,
|
||||
E_TypeKind_F32PP,
|
||||
E_TypeKind_F48,
|
||||
E_TypeKind_F64,
|
||||
E_TypeKind_F80,
|
||||
E_TypeKind_F128,
|
||||
E_TypeKind_ComplexF32,
|
||||
E_TypeKind_ComplexF64,
|
||||
E_TypeKind_ComplexF80,
|
||||
E_TypeKind_ComplexF128,
|
||||
E_TypeKind_Modifier,
|
||||
E_TypeKind_Ptr,
|
||||
E_TypeKind_LRef,
|
||||
E_TypeKind_RRef,
|
||||
E_TypeKind_Array,
|
||||
E_TypeKind_Function,
|
||||
E_TypeKind_Method,
|
||||
E_TypeKind_MemberPtr,
|
||||
E_TypeKind_Struct,
|
||||
E_TypeKind_Class,
|
||||
E_TypeKind_Union,
|
||||
E_TypeKind_Enum,
|
||||
E_TypeKind_Alias,
|
||||
E_TypeKind_IncompleteStruct,
|
||||
E_TypeKind_IncompleteUnion,
|
||||
E_TypeKind_IncompleteClass,
|
||||
E_TypeKind_IncompleteEnum,
|
||||
E_TypeKind_Bitfield,
|
||||
E_TypeKind_Variadic,
|
||||
E_TypeKind_COUNT,
|
||||
E_TypeKind_FirstBasic = E_TypeKind_Void,
|
||||
E_TypeKind_LastBasic = E_TypeKind_ComplexF128,
|
||||
E_TypeKind_FirstInteger = E_TypeKind_Char8,
|
||||
E_TypeKind_LastInteger = E_TypeKind_S512,
|
||||
E_TypeKind_FirstSigned1 = E_TypeKind_Char8,
|
||||
E_TypeKind_LastSigned1 = E_TypeKind_Char32,
|
||||
E_TypeKind_FirstSigned2 = E_TypeKind_S8,
|
||||
E_TypeKind_LastSigned2 = E_TypeKind_S512,
|
||||
E_TypeKind_FirstIncomplete = E_TypeKind_IncompleteStruct,
|
||||
E_TypeKind_LastIncomplete = E_TypeKind_IncompleteEnum,
|
||||
} E_TypeKind;
|
||||
|
||||
typedef U32 E_ExprKind;
|
||||
typedef enum E_ExprKindEnum
|
||||
{
|
||||
E_ExprKind_Nil,
|
||||
E_ExprKind_ArrayIndex,
|
||||
E_ExprKind_MemberAccess,
|
||||
E_ExprKind_Deref,
|
||||
E_ExprKind_Address,
|
||||
E_ExprKind_Cast,
|
||||
E_ExprKind_Sizeof,
|
||||
E_ExprKind_Neg,
|
||||
E_ExprKind_LogNot,
|
||||
E_ExprKind_BitNot,
|
||||
E_ExprKind_Mul,
|
||||
E_ExprKind_Div,
|
||||
E_ExprKind_Mod,
|
||||
E_ExprKind_Add,
|
||||
E_ExprKind_Sub,
|
||||
E_ExprKind_LShift,
|
||||
E_ExprKind_RShift,
|
||||
E_ExprKind_Less,
|
||||
E_ExprKind_LsEq,
|
||||
E_ExprKind_Grtr,
|
||||
E_ExprKind_GrEq,
|
||||
E_ExprKind_EqEq,
|
||||
E_ExprKind_NtEq,
|
||||
E_ExprKind_BitAnd,
|
||||
E_ExprKind_BitXor,
|
||||
E_ExprKind_BitOr,
|
||||
E_ExprKind_LogAnd,
|
||||
E_ExprKind_LogOr,
|
||||
E_ExprKind_Ternary,
|
||||
E_ExprKind_LeafBytecode,
|
||||
E_ExprKind_LeafMember,
|
||||
E_ExprKind_LeafStringLiteral,
|
||||
E_ExprKind_LeafU64,
|
||||
E_ExprKind_LeafF64,
|
||||
E_ExprKind_LeafF32,
|
||||
E_ExprKind_TypeIdent,
|
||||
E_ExprKind_Ptr,
|
||||
E_ExprKind_Array,
|
||||
E_ExprKind_Func,
|
||||
E_ExprKind_Define,
|
||||
E_ExprKind_LeafIdent,
|
||||
E_ExprKind_COUNT,
|
||||
} E_ExprKindEnum;
|
||||
|
||||
typedef enum E_InterpretationCode
|
||||
{
|
||||
E_InterpretationCode_Good,
|
||||
E_InterpretationCode_DivideByZero,
|
||||
E_InterpretationCode_BadOp,
|
||||
E_InterpretationCode_BadOpTypes,
|
||||
E_InterpretationCode_BadMemRead,
|
||||
E_InterpretationCode_BadRegRead,
|
||||
E_InterpretationCode_BadFrameBase,
|
||||
E_InterpretationCode_BadModuleBase,
|
||||
E_InterpretationCode_BadTLSBase,
|
||||
E_InterpretationCode_InsufficientStackSpace,
|
||||
E_InterpretationCode_MalformedBytecode,
|
||||
E_InterpretationCode_COUNT,
|
||||
} E_InterpretationCode;
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern String8 e_expr_kind_strings[41];
|
||||
extern String8 e_interpretation_code_display_strings[11];
|
||||
extern String8 e_expr_op_strings[41];
|
||||
extern U8 e_kind_basic_byte_size_table[54];
|
||||
extern String8 e_kind_basic_string_table[54];
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
#endif // EVAL2_META_H
|
||||
@@ -50,13 +50,11 @@
|
||||
#include "rdi_from_pdb/rdi_from_pdb.h"
|
||||
#include "regs/regs.h"
|
||||
#include "regs/rdi/regs_rdi.h"
|
||||
//#include "type_graph/type_graph.h"
|
||||
#include "dbgi/dbgi.h"
|
||||
#include "dasm_cache/dasm_cache.h"
|
||||
#include "fuzzy_search/fuzzy_search.h"
|
||||
#include "demon/demon_inc.h"
|
||||
//#include "eval/eval_inc.h"
|
||||
#include "eval2/eval2.h"
|
||||
#include "eval/eval.h"
|
||||
#include "ctrl/ctrl_inc.h"
|
||||
#include "font_provider/font_provider_inc.h"
|
||||
#include "render/render_inc.h"
|
||||
@@ -91,13 +89,11 @@
|
||||
#include "rdi_from_pdb/rdi_from_pdb.c"
|
||||
#include "regs/regs.c"
|
||||
#include "regs/rdi/regs_rdi.c"
|
||||
//#include "type_graph/type_graph.c"
|
||||
#include "dbgi/dbgi.c"
|
||||
#include "dasm_cache/dasm_cache.c"
|
||||
#include "fuzzy_search/fuzzy_search.c"
|
||||
#include "demon/demon_inc.c"
|
||||
//#include "eval/eval_inc.c"
|
||||
#include "eval2/eval2.c"
|
||||
#include "eval/eval.c"
|
||||
#include "ctrl/ctrl_inc.c"
|
||||
#include "font_provider/font_provider_inc.c"
|
||||
#include "render/render_inc.c"
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
//- GENERATED CODE
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
U8 tg_kind_basic_byte_size_table[54] =
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0xFF,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
4,
|
||||
6,
|
||||
8,
|
||||
10,
|
||||
16,
|
||||
8,
|
||||
16,
|
||||
20,
|
||||
32,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
String8 tg_kind_basic_string_table[54] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("void"),
|
||||
str8_lit_comp("HANDLE"),
|
||||
str8_lit_comp("char8"),
|
||||
str8_lit_comp("char16"),
|
||||
str8_lit_comp("char32"),
|
||||
str8_lit_comp("uchar8"),
|
||||
str8_lit_comp("uchar16"),
|
||||
str8_lit_comp("uchar32"),
|
||||
str8_lit_comp("U8"),
|
||||
str8_lit_comp("U16"),
|
||||
str8_lit_comp("U32"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("U128"),
|
||||
str8_lit_comp("U256"),
|
||||
str8_lit_comp("U512"),
|
||||
str8_lit_comp("S8"),
|
||||
str8_lit_comp("S16"),
|
||||
str8_lit_comp("S32"),
|
||||
str8_lit_comp("S64"),
|
||||
str8_lit_comp("S128"),
|
||||
str8_lit_comp("S256"),
|
||||
str8_lit_comp("S512"),
|
||||
str8_lit_comp("bool"),
|
||||
str8_lit_comp("F16"),
|
||||
str8_lit_comp("F32"),
|
||||
str8_lit_comp("F32PP"),
|
||||
str8_lit_comp("F48"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F80"),
|
||||
str8_lit_comp("F128"),
|
||||
str8_lit_comp("ComplexF32"),
|
||||
str8_lit_comp("ComplexF64"),
|
||||
str8_lit_comp("ComplexF80"),
|
||||
str8_lit_comp("ComplexF128"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp("typedef"),
|
||||
str8_lit_comp("struct"),
|
||||
str8_lit_comp("union"),
|
||||
str8_lit_comp("class"),
|
||||
str8_lit_comp("enum"),
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp(""),
|
||||
};
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
//- GENERATED CODE
|
||||
|
||||
#ifndef TYPE_GRAPH_META_H
|
||||
#define TYPE_GRAPH_META_H
|
||||
|
||||
typedef enum TG_Kind
|
||||
{
|
||||
TG_Kind_Null,
|
||||
TG_Kind_Void,
|
||||
TG_Kind_Handle,
|
||||
TG_Kind_Char8,
|
||||
TG_Kind_Char16,
|
||||
TG_Kind_Char32,
|
||||
TG_Kind_UChar8,
|
||||
TG_Kind_UChar16,
|
||||
TG_Kind_UChar32,
|
||||
TG_Kind_U8,
|
||||
TG_Kind_U16,
|
||||
TG_Kind_U32,
|
||||
TG_Kind_U64,
|
||||
TG_Kind_U128,
|
||||
TG_Kind_U256,
|
||||
TG_Kind_U512,
|
||||
TG_Kind_S8,
|
||||
TG_Kind_S16,
|
||||
TG_Kind_S32,
|
||||
TG_Kind_S64,
|
||||
TG_Kind_S128,
|
||||
TG_Kind_S256,
|
||||
TG_Kind_S512,
|
||||
TG_Kind_Bool,
|
||||
TG_Kind_F16,
|
||||
TG_Kind_F32,
|
||||
TG_Kind_F32PP,
|
||||
TG_Kind_F48,
|
||||
TG_Kind_F64,
|
||||
TG_Kind_F80,
|
||||
TG_Kind_F128,
|
||||
TG_Kind_ComplexF32,
|
||||
TG_Kind_ComplexF64,
|
||||
TG_Kind_ComplexF80,
|
||||
TG_Kind_ComplexF128,
|
||||
TG_Kind_Modifier,
|
||||
TG_Kind_Ptr,
|
||||
TG_Kind_LRef,
|
||||
TG_Kind_RRef,
|
||||
TG_Kind_Array,
|
||||
TG_Kind_Function,
|
||||
TG_Kind_Method,
|
||||
TG_Kind_MemberPtr,
|
||||
TG_Kind_Struct,
|
||||
TG_Kind_Class,
|
||||
TG_Kind_Union,
|
||||
TG_Kind_Enum,
|
||||
TG_Kind_Alias,
|
||||
TG_Kind_IncompleteStruct,
|
||||
TG_Kind_IncompleteUnion,
|
||||
TG_Kind_IncompleteClass,
|
||||
TG_Kind_IncompleteEnum,
|
||||
TG_Kind_Bitfield,
|
||||
TG_Kind_Variadic,
|
||||
TG_Kind_COUNT,
|
||||
TG_Kind_FirstBasic = TG_Kind_Void,
|
||||
TG_Kind_LastBasic = TG_Kind_ComplexF128,
|
||||
TG_Kind_FirstInteger = TG_Kind_Char8,
|
||||
TG_Kind_LastInteger = TG_Kind_S512,
|
||||
TG_Kind_FirstSigned1 = TG_Kind_Char8,
|
||||
TG_Kind_LastSigned1 = TG_Kind_Char32,
|
||||
TG_Kind_FirstSigned2 = TG_Kind_S8,
|
||||
TG_Kind_LastSigned2 = TG_Kind_S512,
|
||||
TG_Kind_FirstIncomplete = TG_Kind_IncompleteStruct,
|
||||
TG_Kind_LastIncomplete = TG_Kind_IncompleteEnum,
|
||||
} TG_Kind;
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern U8 tg_kind_basic_byte_size_table[54];
|
||||
extern String8 tg_kind_basic_string_table[54];
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
#endif // TYPE_GRAPH_META_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,243 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef TYPE_GRAPH_H
|
||||
#define TYPE_GRAPH_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/type_graph.meta.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Key Types
|
||||
|
||||
typedef enum TG_KeyKind
|
||||
{
|
||||
TG_KeyKind_Null,
|
||||
TG_KeyKind_Basic,
|
||||
TG_KeyKind_Ext,
|
||||
TG_KeyKind_Cons,
|
||||
TG_KeyKind_Reg,
|
||||
TG_KeyKind_RegAlias,
|
||||
}
|
||||
TG_KeyKind;
|
||||
|
||||
typedef struct TG_Key TG_Key;
|
||||
struct TG_Key
|
||||
{
|
||||
TG_KeyKind kind;
|
||||
U32 u32[1]; // basic -> type_kind; cons -> type_kind; ext -> type_kind; reg -> arch
|
||||
U64 u64[1]; // ext -> unique id; cons -> idx; reg -> code
|
||||
};
|
||||
|
||||
typedef struct TG_KeyNode TG_KeyNode;
|
||||
struct TG_KeyNode
|
||||
{
|
||||
TG_KeyNode *next;
|
||||
TG_Key v;
|
||||
};
|
||||
|
||||
typedef struct TG_KeyList TG_KeyList;
|
||||
struct TG_KeyList
|
||||
{
|
||||
TG_KeyNode *first;
|
||||
TG_KeyNode *last;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Graph Types
|
||||
|
||||
typedef struct TG_ConsType TG_ConsType;
|
||||
struct TG_ConsType
|
||||
{
|
||||
TG_Kind kind;
|
||||
TG_Key direct_type_key;
|
||||
U64 u64;
|
||||
};
|
||||
|
||||
typedef struct TG_Node TG_Node;
|
||||
struct TG_Node
|
||||
{
|
||||
TG_Node *key_hash_next;
|
||||
TG_Node *content_hash_next;
|
||||
TG_Key key;
|
||||
TG_ConsType cons_type;
|
||||
};
|
||||
|
||||
typedef struct TG_Slot TG_Slot;
|
||||
struct TG_Slot
|
||||
{
|
||||
TG_Node *first;
|
||||
TG_Node *last;
|
||||
};
|
||||
|
||||
typedef struct TG_Graph TG_Graph;
|
||||
struct TG_Graph
|
||||
{
|
||||
U64 address_size;
|
||||
U64 cons_id_gen;
|
||||
U64 content_hash_slots_count;
|
||||
TG_Slot *content_hash_slots;
|
||||
U64 key_hash_slots_count;
|
||||
TG_Slot *key_hash_slots;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Extracted Info Types
|
||||
|
||||
typedef enum TG_MemberKind
|
||||
{
|
||||
TG_MemberKind_Null,
|
||||
TG_MemberKind_DataField,
|
||||
TG_MemberKind_StaticData,
|
||||
TG_MemberKind_Method,
|
||||
TG_MemberKind_StaticMethod,
|
||||
TG_MemberKind_VirtualMethod,
|
||||
TG_MemberKind_VTablePtr,
|
||||
TG_MemberKind_Base,
|
||||
TG_MemberKind_VirtualBase,
|
||||
TG_MemberKind_NestedType,
|
||||
TG_MemberKind_Padding,
|
||||
TG_MemberKind_COUNT
|
||||
}
|
||||
TG_MemberKind;
|
||||
|
||||
typedef U32 TG_Flags;
|
||||
enum
|
||||
{
|
||||
TG_Flag_Const = (1<<0),
|
||||
TG_Flag_Volatile = (1<<1),
|
||||
};
|
||||
|
||||
typedef struct TG_Member TG_Member;
|
||||
struct TG_Member
|
||||
{
|
||||
TG_MemberKind kind;
|
||||
TG_Key type_key;
|
||||
String8 name;
|
||||
U64 off;
|
||||
TG_KeyList inheritance_key_chain;
|
||||
};
|
||||
|
||||
typedef struct TG_MemberNode TG_MemberNode;
|
||||
struct TG_MemberNode
|
||||
{
|
||||
TG_MemberNode *next;
|
||||
TG_Member v;
|
||||
};
|
||||
|
||||
typedef struct TG_MemberList TG_MemberList;
|
||||
struct TG_MemberList
|
||||
{
|
||||
TG_MemberNode *first;
|
||||
TG_MemberNode *last;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
typedef struct TG_MemberArray TG_MemberArray;
|
||||
struct TG_MemberArray
|
||||
{
|
||||
TG_Member *v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
typedef struct TG_EnumVal TG_EnumVal;
|
||||
struct TG_EnumVal
|
||||
{
|
||||
String8 name;
|
||||
U64 val;
|
||||
};
|
||||
|
||||
typedef struct TG_EnumValArray TG_EnumValArray;
|
||||
struct TG_EnumValArray
|
||||
{
|
||||
TG_EnumVal *v;
|
||||
U64 count;
|
||||
};
|
||||
|
||||
typedef struct TG_Type TG_Type;
|
||||
struct TG_Type
|
||||
{
|
||||
TG_Kind kind;
|
||||
TG_Flags flags;
|
||||
String8 name;
|
||||
U64 byte_size;
|
||||
U64 count;
|
||||
U32 off;
|
||||
TG_Key direct_type_key;
|
||||
TG_Key owner_type_key;
|
||||
TG_Key *param_type_keys;
|
||||
TG_Member *members;
|
||||
TG_EnumVal *enum_vals;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
global read_only TG_Type tg_type_nil =
|
||||
{
|
||||
/* kind */ TG_Kind_Null,
|
||||
/* flags */ 0,
|
||||
/* name */ {(U8*)"???",3},
|
||||
};
|
||||
|
||||
global read_only TG_Type tg_type_variadic =
|
||||
{
|
||||
/* kind */ TG_Kind_Variadic,
|
||||
/* flags */ 0,
|
||||
/* name */ {(U8*)"...",3},
|
||||
};
|
||||
|
||||
thread_static Arena *tg_build_arena = 0;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Helpers
|
||||
|
||||
internal U64 tg_hash_from_string(U64 seed, String8 string);
|
||||
internal int tg_qsort_compare_members_offset(TG_Member *a, TG_Member *b);
|
||||
internal void tg_key_list_push(Arena *arena, TG_KeyList *list, TG_Key key);
|
||||
internal TG_KeyList tg_key_list_copy(Arena *arena, TG_KeyList *src);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: RADDBG <-> TG Enum Conversions
|
||||
|
||||
internal TG_Kind tg_kind_from_rdi_type_kind(RDI_TypeKind kind);
|
||||
internal TG_MemberKind tg_member_kind_from_rdi_member_kind(RDI_MemberKind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Key Type Functions
|
||||
|
||||
internal TG_Key tg_key_zero(void);
|
||||
internal TG_Key tg_key_basic(TG_Kind kind);
|
||||
internal TG_Key tg_key_ext(TG_Kind kind, U64 id);
|
||||
internal TG_Key tg_key_reg(Architecture arch, REGS_RegCode code);
|
||||
internal TG_Key tg_key_reg_alias(Architecture arch, REGS_AliasCode code);
|
||||
internal B32 tg_key_match(TG_Key a, TG_Key b);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Graph Construction API
|
||||
|
||||
internal TG_Graph *tg_graph_begin(U64 address_size, U64 slot_count);
|
||||
internal TG_Key tg_cons_type_make(TG_Graph *graph, TG_Kind kind, TG_Key direct_type_key, U64 u64);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Graph Introspection API
|
||||
|
||||
internal TG_Type *tg_type_from_graph_rdi_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key tg_direct_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key tg_unwrapped_direct_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key tg_owner_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key tg_ptee_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Key tg_unwrapped_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal U64 tg_byte_size_from_graph_rdi_key(TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_Kind tg_kind_from_key(TG_Key key);
|
||||
internal TG_Member *tg_member_copy(Arena *arena, TG_Member *src);
|
||||
internal TG_MemberArray tg_members_from_graph_rdi_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal TG_MemberArray tg_data_members_from_graph_rdi_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
internal void tg_lhs_string_from_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key, String8List *out, U32 prec, B32 skip_return);
|
||||
internal void tg_rhs_string_from_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key, String8List *out, U32 prec);
|
||||
internal String8 tg_string_from_key(Arena *arena, TG_Graph *graph, RDI_Parsed *rdi, TG_Key key);
|
||||
|
||||
#endif // TYPE_GRAPH_H
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Tables
|
||||
|
||||
@table(name basic_string basic_byte_size)
|
||||
// NOTE(rjf): basic_byte_size == 0xFF? => address sized
|
||||
TG_KindTable:
|
||||
{
|
||||
{Null "" 0 }
|
||||
{Void "void" 0 }
|
||||
{Handle "HANDLE" 0xFF }
|
||||
{Char8 "char8" 1 }
|
||||
{Char16 "char16" 2 }
|
||||
{Char32 "char32" 4 }
|
||||
{UChar8 "uchar8" 1 }
|
||||
{UChar16 "uchar16" 2 }
|
||||
{UChar32 "uchar32" 4 }
|
||||
{U8 "U8" 1 }
|
||||
{U16 "U16" 2 }
|
||||
{U32 "U32" 4 }
|
||||
{U64 "U64" 8 }
|
||||
{U128 "U128" 16 }
|
||||
{U256 "U256" 32 }
|
||||
{U512 "U512" 64 }
|
||||
{S8 "S8" 1 }
|
||||
{S16 "S16" 2 }
|
||||
{S32 "S32" 4 }
|
||||
{S64 "S64" 8 }
|
||||
{S128 "S128" 16 }
|
||||
{S256 "S256" 32 }
|
||||
{S512 "S512" 64 }
|
||||
{Bool "bool" 1 }
|
||||
{F16 "F16" 2 }
|
||||
{F32 "F32" 4 }
|
||||
{F32PP "F32PP" 4 }
|
||||
{F48 "F48" 6 }
|
||||
{F64 "F64" 8 }
|
||||
{F80 "F80" 10 }
|
||||
{F128 "F128" 16 }
|
||||
{ComplexF32 "ComplexF32" 8 }
|
||||
{ComplexF64 "ComplexF64" 16 }
|
||||
{ComplexF80 "ComplexF80" 20 }
|
||||
{ComplexF128 "ComplexF128" 32 }
|
||||
{Modifier "" 0 }
|
||||
{Ptr "" 0 }
|
||||
{LRef "" 0 }
|
||||
{RRef "" 0 }
|
||||
{Array "" 0 }
|
||||
{Function "" 0 }
|
||||
{Method "" 0 }
|
||||
{MemberPtr "" 0 }
|
||||
{Struct "struct" 0 }
|
||||
{Class "class" 0 }
|
||||
{Union "union" 0 }
|
||||
{Enum "enum" 0 }
|
||||
{Alias "typedef" 0 }
|
||||
{IncompleteStruct "struct" 0 }
|
||||
{IncompleteUnion "union" 0 }
|
||||
{IncompleteClass "class" 0 }
|
||||
{IncompleteEnum "enum" 0 }
|
||||
{Bitfield "" 0 }
|
||||
{Variadic "" 0 }
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generators
|
||||
|
||||
@enum TG_Kind:
|
||||
{
|
||||
@expand(TG_KindTable a) `$(a.name)`,
|
||||
COUNT,
|
||||
`FirstBasic = TG_Kind_Void`,
|
||||
`LastBasic = TG_Kind_ComplexF128`,
|
||||
`FirstInteger = TG_Kind_Char8`,
|
||||
`LastInteger = TG_Kind_S512`,
|
||||
`FirstSigned1 = TG_Kind_Char8`,
|
||||
`LastSigned1 = TG_Kind_Char32`,
|
||||
`FirstSigned2 = TG_Kind_S8`,
|
||||
`LastSigned2 = TG_Kind_S512`,
|
||||
`FirstIncomplete = TG_Kind_IncompleteStruct`,
|
||||
`LastIncomplete = TG_Kind_IncompleteEnum`,
|
||||
}
|
||||
|
||||
@data(U8) tg_kind_basic_byte_size_table:
|
||||
{
|
||||
@expand(TG_KindTable a) `$(a.basic_byte_size)`;
|
||||
}
|
||||
|
||||
@data(String8) tg_kind_basic_string_table:
|
||||
{
|
||||
@expand(TG_KindTable a) `str8_lit_comp("$(a.basic_string)")`;
|
||||
}
|
||||
Reference in New Issue
Block a user