Skip to content

Commit 523d1e6

Browse files
committed
jit/ir: Add opcode interface
Signed-off-by: Ronald Caesar <github43132@proton.me>
1 parent fa1f91d commit 523d1e6

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

src/jit/ir/opcode.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
#include "opcode.h"
2-
#include "type.h"
32
#include <stddef.h>
43

54
#define LOG_MODULE "jit"
65
#include "common/logging.h"
76

87
namespace pound::jit::ir {
9-
#define OPCODE_ARGS_TYPES_SIZE 4
10-
#define OPCODE_ARRAY_SIZE 386
118

12-
typedef struct
13-
{
14-
const char *name;
15-
type_t type;
16-
type_t arg_types[OPCODE_ARGS_TYPES_SIZE];
17-
} decoded_opcode_t;
18-
19-
decoded_opcode_t opcodes[OPCODE_ARRAY_SIZE] = {
9+
decoded_opcode_t g_opcodes[NUM_OPCODE] = {
2010
#define OPCODE(name, type, ...) \
2111
decoded_opcode_t { #name, type, { __VA_ARGS__ } },
2212
#define A32OPC(name, type, ...) \
@@ -31,9 +21,9 @@ decoded_opcode_t opcodes[OPCODE_ARRAY_SIZE] = {
3121
void
3222
opcode_init (void)
3323
{
34-
for (size_t i = 0; i < OPCODE_ARRAY_SIZE; ++i)
24+
for (size_t i = 0; i < NUM_OPCODE; ++i)
3525
{
36-
LOG_TRACE("Opcode Registered: %s", opcodes[i].name);
26+
LOG_TRACE("Opcode Registered: %s", g_opcodes[i].name);
3727
}
3828
}
3929
} // namespace pound::jit::ir

src/jit/ir/opcode.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
/**
2+
* @file opcode.h
3+
*
4+
* @brief Defines JIT IR opcodes and their metadata.
5+
*
6+
* The actual definitions of opcodes and their metadata are generated
7+
* by including "opcode.inc", which is processed using X-macros.
8+
*/
9+
10+
#include "type.h"
11+
112
namespace pound::jit::ir {
13+
// The maximum number of argument types an IR opcode can have.
14+
#define OPCODE_ARGS_TYPES_SIZE 4
15+
16+
/*!
17+
* @brief Enumeration of all microinstructions (opcodes) in the JIT IR.
18+
*
19+
* Each enum value corresponds to a specific operation that can be
20+
* performed by the JIT, such as arithmetic operations, memory accesses,
21+
* or system register manipulations.
22+
*
23+
* The enum values are generated by including "opcode.inc" and using
24+
* the OPCODE and A32OPC macros. A64OPC is currently disabled.
25+
*/
26+
typedef enum
27+
{
28+
#define OPCODE(name, type, ...) OPCODE_##name,
29+
#define A32OPC(name, type, ...) OPCODE_A32##name,
30+
// #define A64OPC(name, type, ...) OPCODE_A64##name,
31+
#include "./opcode.inc"
32+
#undef OPCODE
33+
#undef A32OPC
34+
#undef A64OPC
35+
NUM_OPCODE
36+
} opcode_t;
37+
38+
/*!
39+
* @brief Structure holding static metadata for an IR opcode.
40+
*/
41+
typedef struct
42+
{
43+
const char *name;
44+
type_t type;
45+
type_t arg_types[OPCODE_ARGS_TYPES_SIZE];
46+
} decoded_opcode_t;
47+
48+
/*!
49+
* @brief Global array of `decoded_opcode_t` structures for all opcodes.
50+
*
51+
* This array is indexed by the `opcode_t` enum values, providing a direct
52+
* lookup for opcode metadata. For example, `g_opcodes[OPCODE_Add32].name`
53+
* would yield "Add32".
54+
*/
55+
extern decoded_opcode_t g_opcodes[NUM_OPCODE];
56+
257
void opcode_init(void);
358
}

0 commit comments

Comments
 (0)