-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopcodes.h
More file actions
69 lines (55 loc) · 1.34 KB
/
Copy pathopcodes.h
File metadata and controls
69 lines (55 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdint.h>
#ifndef KUMA_OPCODES_H
#define KUMA_OPCODES_H
/*
Opcode: 8 bits
'A': 8 bits
'B': 8 bits
'C': 8 bits
'Bx': 16 bits ('B' and 'C')
*/
typedef uint32_t kuma_instruction;
#define SIZE_OP 8
#define SIZE_A 8
#define SIZE_B 8
#define SIZE_C 8
#define SIZE_Bx (SIZE_B + SIZE_C)
#define POS_OP 0
#define POS_A (POS_OP + SIZE_OP)
#define POS_B (POS_A + SIZE_A)
#define POS_C (POS_B + SIZE_B)
#define POS_Bx POS_B
#define GET_OPCODE(i) ((kuma_opcode)(i>>POS_OP)) & (~(0xFFFFFF<<SIZE_OP))
#define GET_ARG_A(i) ((uint32_t)(i>>POS_A)) & (~(0xFFFFFF<<SIZE_A))
#define GET_ARG_B(i) ((uint32_t)(i>>POS_B)) & (~(0xFFFFFF<<SIZE_B))
#define GET_ARG_C(i) ((uint32_t)(i>>POS_C)) & (~(0xFFFFFF<<SIZE_C))
#define GET_ARG_Bx(i) ((uint32_t)(i>>POS_Bx)) & (~(0xFFFFFF<<SIZE_Bx))
#define CREATE_ABC(o,a,b,c) ((((kuma_opcode)o)<<POS_OP) \
| (((uint8_t)a)<<POS_A) \
| (((uint8_t)b)<<POS_B) \
| (((uint8_t)c)<<POS_C))
#define CREATE_ABx(o,a,bx) ((((kuma_opcode)o)<<POS_OP) \
| (((uint8_t)a)<<POS_A) \
| (((uint16_t)bx)<<POS_Bx))
typedef enum
{
OP_LOADCONSTANT = 0,
OP_LOADBOOL,
OP_MOVE,
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_JMP,
OP_EQ,
OP_LT,
OP_LEQ,
OP_GT,
OP_GEQ,
OP_CALL,
OP_NOP,
OP_HALT,
OP_EOF,
} kuma_opcode;
int kuma_opcodes_dump(kuma_instruction *ops);
#endif