|
| 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 | + |
1 | 12 | 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 | + |
2 | 57 | void opcode_init(void); |
3 | 58 | } |
0 commit comments