-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpz_instructions.h
133 lines (118 loc) · 2.65 KB
/
pz_instructions.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Plasma bytecode instructions
* vim: ts=4 sw=4 et
*
* Copyright (C) Plasma Team
* Distributed under the terms of the MIT license, see ../LICENSE.code
*/
#ifndef PZ_INSTRUCTIONS_H
#define PZ_INSTRUCTIONS_H
/*
* Instructions are made from an opcode (byte), then depending on the opcode
* zero or more bytes describing the width of the operands, and zero or one
* intermediate values.
*
* For example, PZI_CALL is followed by zero operand width bytes and one
* intermediate value, the reference to the callee. Likewise, PZI_ADD is
* followed by one operand width byte describing the width of the data used
* in the addition (both inputs and the output).
*/
typedef enum {
/*
* These instructions may appear in bytecode.
* XXX: Need a way to load immedate data with a fast opcode width but
* whose static data may be some other size.
*/
PZI_LOAD_IMMEDIATE_NUM = 0,
PZI_ZE,
PZI_SE,
PZI_TRUNC,
PZI_ADD,
PZI_SUB,
PZI_MUL,
/*
* TODO: Check how signedness affects division/modulo.
*/
PZI_DIV,
PZI_MOD,
PZI_LSHIFT,
/*
* TODO: Right shift is unsigned, need to add a signed version.
*/
PZI_RSHIFT,
PZI_AND,
PZI_OR,
PZI_XOR,
PZI_LT_U,
PZI_LT_S,
PZI_GT_U,
PZI_GT_S,
PZI_EQ,
PZI_NOT,
PZI_DROP,
/*
* rotate N-1 items to the left, the leftmost item becomes the rightmost
* item.
*/
PZI_ROLL,
PZI_PICK,
PZI_CALL,
PZI_CALL_IMPORT,
PZI_CALL_IND,
PZI_CALL_PROC,
PZI_TCALL,
PZI_TCALL_IMPORT,
PZI_TCALL_IND,
PZI_TCALL_PROC,
PZI_RET,
PZI_CJMP,
PZI_JMP,
PZI_ALLOC,
PZI_MAKE_CLOSURE,
PZI_LOAD,
PZI_STORE,
PZI_GET_ENV,
/*
* These instructions do not appear in bytecode, they are implied by
* other instructions during bytecode loading and inserted into the
* instruction stream then.
*/
PZI_END,
PZI_CCALL,
PZI_CCALL_ALLOC,
PZI_CCALL_SPECIAL,
} PZ_Opcode;
#define PZ_NUM_OPCODES (PZI_CCALL_SPECIAL + 1)
#ifdef __cplusplus
namespace pz {
union ImmediateValue {
uint8_t uint8;
uint16_t uint16;
uint32_t uint32;
uint64_t uint64;
uintptr_t word;
};
enum ImmediateType {
IMT_NONE,
IMT_8,
IMT_16,
IMT_32,
IMT_64,
IMT_CLOSURE_REF,
IMT_PROC_REF,
IMT_IMPORT_CLOSURE_REF,
IMT_STRUCT_REF,
IMT_STRUCT_REF_FIELD,
IMT_LABEL_REF
};
struct InstructionInfo {
unsigned ii_num_width_bytes;
ImmediateType ii_immediate_type;
};
/*
* Instruction info is indexed by opcode
*/
extern InstructionInfo instruction_info[];
} // namespace pz
#endif
#endif /* ! PZ_INSTRUCTIONS_H */