]> git.bts.cx Git - sun.git/blob - runtime/src/sun/vm/instruction.h
Initial commit
[sun.git] / runtime / src / sun / vm / instruction.h
1 #ifndef SUN_VM_INSTRUCTION_H
2 #define SUN_VM_INSTRUCTION_H
3
4 #include <stddef.h>
5 #include <stdint.h>
6
7 #include <sun/vm/fixed.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 enum SVMOpcode {
14 SVMOpcodeInvalid,
15
16 SVMOpcodeMOV,
17 SVMOpcodeSET,
18
19 SVMOpcodeINV,
20 SVMOpcodeBNOT,
21 SVMOpcodeNOT,
22 SVMOpcodeADD,
23 SVMOpcodeSUB,
24 SVMOpcodeMUL,
25 SVMOpcodeDIV,
26 SVMOpcodeMOD,
27 SVMOpcodeBAND,
28 SVMOpcodeBOR,
29 SVMOpcodeBXOR,
30 SVMOpcodeAND,
31 SVMOpcodeOR,
32 SVMOpcodeEQ,
33 SVMOpcodeNEQ,
34 SVMOpcodeLT,
35 SVMOpcodeLTEQ,
36 SVMOpcodeGT,
37 SVMOpcodeGTEQ,
38
39 SVMOpcodeSTK,
40
41 SVMOpcodeSLEEP,
42 SVMOpcodePOPJUMP,
43 SVMOpcodeJUMP,
44 SVMOpcodePUSHJUMP,
45 SVMOpcodeCALL,
46
47 SVMOpcodeJT,
48 };
49 typedef enum SVMOpcode SVMOpcode;
50
51 extern const char *svmOpcodeToString(SVMOpcode opcode);
52
53 typedef int32_t SVMStackOffset;
54 typedef Fixed/*float*/ SVMFloat;
55 typedef Fixed/*int32_t*/ SVMInteger;
56 typedef uint32_t SVMPointer;
57
58 union SVMOperand {
59 SVMStackOffset stackOffset;
60 SVMFloat floatLiteral;
61 SVMInteger integerLiteral;
62 SVMPointer pointerLiteral; // Strings, function pointer
63 int32_t __raw;
64 };
65 typedef union SVMOperand SVMOperand;
66
67 struct SVMInstruction {
68 SVMOpcode opcode;
69 union __attribute__((__packed__)) {
70 struct __attribute__((__packed__)) {
71 SVMOperand dst;
72 SVMOperand p1;
73 SVMOperand p2;
74 };
75
76 SVMOperand operands[3];
77 };
78 };
79 typedef struct SVMInstruction SVMInstruction;
80
81 #ifdef __cplusplus
82 }
83 #endif
84
85 #endif