quake3_qvm/bytecode.rs
1//! Types for the compiled format of a QVM.
2
3/// Size of procedure stack adjustment.
4pub type FrameSize = u32;
5
6/// Size of memory block to copy.
7pub type BlockSize = u32;
8
9/// Offset within stack frame.
10pub type FrameOffset = u32;
11
12/// Offset within the argument marshalling space.
13pub type ArgOffset = u8;
14
15/// Absolute instruction offset within code segment.
16pub type Address = u32;
17
18/// Literal value.
19pub type Literal = u32;
20
21// These should match their opcodes
22#[allow(non_camel_case_types)]
23/// A QVM instruction.
24#[derive(Debug,PartialEq, Copy, Clone)]
25pub enum Instruction {
26 /// Undefined instruction.
27 ///
28 /// Used for padding the code segment. Should not occur at runtime.
29 UNDEF,
30
31 /// No-operation (NOP).
32 IGNORE,
33
34 /// Software breakpoint.
35 BREAK,
36
37 /// Enter a procedure, adjusting stack.
38 ENTER(FrameSize),
39 /// Leave a procedure, adjusting stack.
40 LEAVE(FrameSize),
41 /// Call a procedure.
42 CALL,
43 /// Push stack.
44 PUSH,
45 /// Pop stack.
46 POP,
47
48 /// Push constant onto stack.
49 CONST(Literal),
50 /// Get address of frame local variable or argument.
51 LOCAL(FrameOffset),
52
53 /// Jump to top of stack.
54 JUMP,
55
56 /// Check (signed integer) equality, jump to `Address` if true.
57 EQ(Address),
58 /// Check (signed integer) inequality, jump to `Address` if true.
59 NE(Address),
60
61 /// Check (signed integer) less-than, jump to `Address` if true.
62 LTI(Address),
63 /// Check (signed integer) less-than or equal-to, jump to `Address` if true.
64 LEI(Address),
65 /// Check (signed integer) greater-than, jump to `Address` if true.
66 GTI(Address),
67 /// Check (signed integer) greater-than or equal-to, jump to `Address` if true.
68 GEI(Address),
69
70 /// Check (unsigned integer) less-than, jump to `Address` if true.
71 LTU(Address),
72 /// Check (unsigned integer) less-than or equal-to, jump to `Address` if true.
73 LEU(Address),
74 /// Check (unsigned integer) greater-than, jump to `Address` if true.
75 GTU(Address),
76 /// Check (unsigned integer) greater-than or equal-to, jump to `Address` if true.
77 GEU(Address),
78
79 /// Check (float) equality, jump to `Address` if true.
80 EQF(Address),
81 /// Check (float) inequality, jump to `Address` if true.
82 NEF(Address),
83
84 /// Check (float) less-than, jump to `Address` if true.
85 LTF(Address),
86 /// Check (float) less-than or equal-to, jump to `Address` if true.
87 LEF(Address),
88 /// Check (float) greater-than, jump to `Address` if true.
89 GTF(Address),
90 /// Check (float) greater-than or equal-to, jump to `Address` if true.
91 GEF(Address),
92
93 /// Load 1-octet value.
94 LOAD1,
95 /// Load 2-octet value.
96 LOAD2,
97 /// Load 4-octet value.
98 LOAD4,
99 /// Store 1-octet value.
100 STORE1,
101 /// Store 2-octet value.
102 STORE2,
103 /// Store 4-octet value.
104 STORE4,
105 /// Store value into marshalling space.
106 ARG(ArgOffset),
107
108 /// Copy a block of memory.
109 BLOCK_COPY(BlockSize),
110
111 /// Sign-extend 8-bit.
112 SEX8,
113 /// Sign-extend 16-bit.
114 SEX16,
115
116 /// Negate (signed integer).
117 NEGI,
118 /// Add.
119 ADD,
120 /// Subtract.
121 SUB,
122 /// Divide (signed integer).
123 DIVI,
124 /// Divide (unsigned integer).
125 DIVU,
126 /// Modulo (signed integer).
127 MODI,
128 /// Modulo (unsigned integer).
129 MODU,
130 /// Multiply (signed integer).
131 MULI,
132 /// Multiply (unsigned integer).
133 MULU,
134
135 /// Bitwise AND.
136 BAND,
137 /// Bitwise OR.
138 BOR,
139 /// Bitwise XOR.
140 BXOR,
141 /// Bitwise complement.
142 BCOM,
143
144 /// Bitwise left-shift.
145 LSH,
146 /// Algebraic (signed) right-shift.
147 RSHI,
148 /// Bitwise (unsigned) right-shift.
149 RSHU,
150
151 /// Negate (float).
152 NEGF,
153 /// Add (float).
154 ADDF,
155 /// Subtract (float).
156 SUBF,
157 /// Divide (float).
158 DIVF,
159 /// Multiply (float).
160 MULF,
161
162 /// Convert signed integer to float.
163 CVIF,
164 /// Convert float to signed integer.
165 CVFI,
166}