From 523d1e6656d11607126f24cd5afe415b7f49fe6c Mon Sep 17 00:00:00 2001 From: Ronald Caesar Date: Sun, 9 Nov 2025 12:47:45 -0400 Subject: [PATCH] jit/ir: Add opcode interface Signed-off-by: Ronald Caesar --- src/jit/ir/opcode.cpp | 16 +++---------- src/jit/ir/opcode.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/jit/ir/opcode.cpp b/src/jit/ir/opcode.cpp index 672c058..80c204d 100644 --- a/src/jit/ir/opcode.cpp +++ b/src/jit/ir/opcode.cpp @@ -1,22 +1,12 @@ #include "opcode.h" -#include "type.h" #include #define LOG_MODULE "jit" #include "common/logging.h" namespace pound::jit::ir { -#define OPCODE_ARGS_TYPES_SIZE 4 -#define OPCODE_ARRAY_SIZE 386 -typedef struct -{ - const char *name; - type_t type; - type_t arg_types[OPCODE_ARGS_TYPES_SIZE]; -} decoded_opcode_t; - -decoded_opcode_t opcodes[OPCODE_ARRAY_SIZE] = { +decoded_opcode_t g_opcodes[NUM_OPCODE] = { #define OPCODE(name, type, ...) \ decoded_opcode_t { #name, type, { __VA_ARGS__ } }, #define A32OPC(name, type, ...) \ @@ -31,9 +21,9 @@ decoded_opcode_t opcodes[OPCODE_ARRAY_SIZE] = { void opcode_init (void) { - for (size_t i = 0; i < OPCODE_ARRAY_SIZE; ++i) + for (size_t i = 0; i < NUM_OPCODE; ++i) { - LOG_TRACE("Opcode Registered: %s", opcodes[i].name); + LOG_TRACE("Opcode Registered: %s", g_opcodes[i].name); } } } // namespace pound::jit::ir diff --git a/src/jit/ir/opcode.h b/src/jit/ir/opcode.h index 6b02176..832ec40 100644 --- a/src/jit/ir/opcode.h +++ b/src/jit/ir/opcode.h @@ -1,3 +1,58 @@ +/** + * @file opcode.h + * + * @brief Defines JIT IR opcodes and their metadata. + * + * The actual definitions of opcodes and their metadata are generated + * by including "opcode.inc", which is processed using X-macros. + */ + +#include "type.h" + namespace pound::jit::ir { +// The maximum number of argument types an IR opcode can have. +#define OPCODE_ARGS_TYPES_SIZE 4 + +/*! + * @brief Enumeration of all microinstructions (opcodes) in the JIT IR. + * + * Each enum value corresponds to a specific operation that can be + * performed by the JIT, such as arithmetic operations, memory accesses, + * or system register manipulations. + * + * The enum values are generated by including "opcode.inc" and using + * the OPCODE and A32OPC macros. A64OPC is currently disabled. + */ +typedef enum +{ +#define OPCODE(name, type, ...) OPCODE_##name, +#define A32OPC(name, type, ...) OPCODE_A32##name, +// #define A64OPC(name, type, ...) OPCODE_A64##name, +#include "./opcode.inc" +#undef OPCODE +#undef A32OPC +#undef A64OPC + NUM_OPCODE +} opcode_t; + +/*! + * @brief Structure holding static metadata for an IR opcode. + */ +typedef struct +{ + const char *name; + type_t type; + type_t arg_types[OPCODE_ARGS_TYPES_SIZE]; +} decoded_opcode_t; + +/*! + * @brief Global array of `decoded_opcode_t` structures for all opcodes. + * + * This array is indexed by the `opcode_t` enum values, providing a direct + * lookup for opcode metadata. For example, `g_opcodes[OPCODE_Add32].name` + * would yield "Add32". + */ +extern decoded_opcode_t g_opcodes[NUM_OPCODE]; + void opcode_init(void); }