jit/ir: Add opcode interface

Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
Ronald Caesar 2025-11-09 12:47:45 -04:00
parent fa1f91dc94
commit 523d1e6656
No known key found for this signature in database
GPG key ID: 04307C401999C596
2 changed files with 58 additions and 13 deletions

View file

@ -1,22 +1,12 @@
#include "opcode.h"
#include "type.h"
#include <stddef.h>
#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

View file

@ -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);
}