blob: d4863b1662124f18ebe2676edc004300d24ada24 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_INTERPRETER_BYTECODES_H_
6#define V8_INTERPRETER_BYTECODES_H_
7
8#include <iosfwd>
9
10// Clients of this interface shouldn't depend on lots of interpreter internals.
11// Do not include anything from src/interpreter here!
12#include "src/utils.h"
13
14namespace v8 {
15namespace internal {
16namespace interpreter {
17
Ben Murdoch097c5b22016-05-18 11:27:45 +010018#define INVALID_OPERAND_TYPE_LIST(V) \
19 V(None, OperandSize::kNone)
20
21#define REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
22 /* Byte operands. */ \
23 V(MaybeReg8, OperandSize::kByte) \
24 V(Reg8, OperandSize::kByte) \
25 V(RegPair8, OperandSize::kByte) \
26 /* Short operands. */ \
27 V(MaybeReg16, OperandSize::kShort) \
28 V(Reg16, OperandSize::kShort) \
29 V(RegPair16, OperandSize::kShort)
30
31#define REGISTER_OUTPUT_OPERAND_TYPE_LIST(V) \
32 /* Byte operands. */ \
33 V(RegOut8, OperandSize::kByte) \
34 V(RegOutPair8, OperandSize::kByte) \
35 V(RegOutTriple8, OperandSize::kByte) \
36 /* Short operands. */ \
37 V(RegOut16, OperandSize::kShort) \
38 V(RegOutPair16, OperandSize::kShort) \
39 V(RegOutTriple16, OperandSize::kShort)
40
41#define SCALAR_OPERAND_TYPE_LIST(V) \
42 /* Byte operands. */ \
43 V(Idx8, OperandSize::kByte) \
44 V(Imm8, OperandSize::kByte) \
45 V(RegCount8, OperandSize::kByte) \
46 /* Short operands. */ \
47 V(Idx16, OperandSize::kShort) \
48 V(RegCount16, OperandSize::kShort)
49
50#define REGISTER_OPERAND_TYPE_LIST(V) \
51 REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
52 REGISTER_OUTPUT_OPERAND_TYPE_LIST(V)
53
54#define NON_REGISTER_OPERAND_TYPE_LIST(V) \
55 INVALID_OPERAND_TYPE_LIST(V) \
56 SCALAR_OPERAND_TYPE_LIST(V)
57
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058// The list of operand types used by bytecodes.
Ben Murdoch097c5b22016-05-18 11:27:45 +010059#define OPERAND_TYPE_LIST(V) \
60 NON_REGISTER_OPERAND_TYPE_LIST(V) \
61 REGISTER_OPERAND_TYPE_LIST(V)
62
63// Define one debug break bytecode for each operands size.
64#define DEBUG_BREAK_BYTECODE_LIST(V) \
65 V(DebugBreak0, OperandType::kNone) \
66 V(DebugBreak1, OperandType::kReg8) \
67 V(DebugBreak2, OperandType::kReg16) \
68 V(DebugBreak3, OperandType::kReg16, OperandType::kReg8) \
69 V(DebugBreak4, OperandType::kReg16, OperandType::kReg16) \
70 V(DebugBreak5, OperandType::kReg16, OperandType::kReg16, OperandType::kReg8) \
71 V(DebugBreak6, OperandType::kReg16, OperandType::kReg16, \
72 OperandType::kReg16) \
73 V(DebugBreak7, OperandType::kReg16, OperandType::kReg16, \
74 OperandType::kReg16, OperandType::kReg8) \
75 V(DebugBreak8, OperandType::kReg16, OperandType::kReg16, \
76 OperandType::kReg16, OperandType::kReg16)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077
78// The list of bytecodes which are interpreted by the interpreter.
79#define BYTECODE_LIST(V) \
80 \
81 /* Loading the accumulator */ \
82 V(LdaZero, OperandType::kNone) \
83 V(LdaSmi8, OperandType::kImm8) \
84 V(LdaUndefined, OperandType::kNone) \
85 V(LdaNull, OperandType::kNone) \
86 V(LdaTheHole, OperandType::kNone) \
87 V(LdaTrue, OperandType::kNone) \
88 V(LdaFalse, OperandType::kNone) \
89 V(LdaConstant, OperandType::kIdx8) \
90 V(LdaConstantWide, OperandType::kIdx16) \
91 \
92 /* Globals */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +010093 V(LdaGlobal, OperandType::kIdx8, OperandType::kIdx8) \
94 V(LdaGlobalInsideTypeof, OperandType::kIdx8, OperandType::kIdx8) \
95 V(LdaGlobalWide, OperandType::kIdx16, OperandType::kIdx16) \
96 V(LdaGlobalInsideTypeofWide, OperandType::kIdx16, OperandType::kIdx16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097 V(StaGlobalSloppy, OperandType::kIdx8, OperandType::kIdx8) \
98 V(StaGlobalStrict, OperandType::kIdx8, OperandType::kIdx8) \
99 V(StaGlobalSloppyWide, OperandType::kIdx16, OperandType::kIdx16) \
100 V(StaGlobalStrictWide, OperandType::kIdx16, OperandType::kIdx16) \
101 \
102 /* Context operations */ \
103 V(PushContext, OperandType::kReg8) \
104 V(PopContext, OperandType::kReg8) \
105 V(LdaContextSlot, OperandType::kReg8, OperandType::kIdx8) \
106 V(StaContextSlot, OperandType::kReg8, OperandType::kIdx8) \
107 V(LdaContextSlotWide, OperandType::kReg8, OperandType::kIdx16) \
108 V(StaContextSlotWide, OperandType::kReg8, OperandType::kIdx16) \
109 \
110 /* Load-Store lookup slots */ \
111 V(LdaLookupSlot, OperandType::kIdx8) \
112 V(LdaLookupSlotInsideTypeof, OperandType::kIdx8) \
113 V(LdaLookupSlotWide, OperandType::kIdx16) \
114 V(LdaLookupSlotInsideTypeofWide, OperandType::kIdx16) \
115 V(StaLookupSlotSloppy, OperandType::kIdx8) \
116 V(StaLookupSlotStrict, OperandType::kIdx8) \
117 V(StaLookupSlotSloppyWide, OperandType::kIdx16) \
118 V(StaLookupSlotStrictWide, OperandType::kIdx16) \
119 \
120 /* Register-accumulator transfers */ \
121 V(Ldar, OperandType::kReg8) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100122 V(Star, OperandType::kRegOut8) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123 \
124 /* Register-register transfers */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100125 V(Mov, OperandType::kReg8, OperandType::kRegOut8) \
126 V(MovWide, OperandType::kReg16, OperandType::kRegOut16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 \
128 /* LoadIC operations */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100129 V(LoadIC, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \
130 V(KeyedLoadIC, OperandType::kReg8, OperandType::kIdx8) \
131 V(LoadICWide, OperandType::kReg8, OperandType::kIdx16, OperandType::kIdx16) \
132 V(KeyedLoadICWide, OperandType::kReg8, OperandType::kIdx16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 \
134 /* StoreIC operations */ \
135 V(StoreICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \
136 V(StoreICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \
137 V(KeyedStoreICSloppy, OperandType::kReg8, OperandType::kReg8, \
138 OperandType::kIdx8) \
139 V(KeyedStoreICStrict, OperandType::kReg8, OperandType::kReg8, \
140 OperandType::kIdx8) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 V(StoreICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \
142 OperandType::kIdx16) \
143 V(StoreICStrictWide, OperandType::kReg8, OperandType::kIdx16, \
144 OperandType::kIdx16) \
145 V(KeyedStoreICSloppyWide, OperandType::kReg8, OperandType::kReg8, \
146 OperandType::kIdx16) \
147 V(KeyedStoreICStrictWide, OperandType::kReg8, OperandType::kReg8, \
148 OperandType::kIdx16) \
149 \
150 /* Binary Operators */ \
151 V(Add, OperandType::kReg8) \
152 V(Sub, OperandType::kReg8) \
153 V(Mul, OperandType::kReg8) \
154 V(Div, OperandType::kReg8) \
155 V(Mod, OperandType::kReg8) \
156 V(BitwiseOr, OperandType::kReg8) \
157 V(BitwiseXor, OperandType::kReg8) \
158 V(BitwiseAnd, OperandType::kReg8) \
159 V(ShiftLeft, OperandType::kReg8) \
160 V(ShiftRight, OperandType::kReg8) \
161 V(ShiftRightLogical, OperandType::kReg8) \
162 \
163 /* Unary Operators */ \
164 V(Inc, OperandType::kNone) \
165 V(Dec, OperandType::kNone) \
166 V(LogicalNot, OperandType::kNone) \
167 V(TypeOf, OperandType::kNone) \
168 V(DeletePropertyStrict, OperandType::kReg8) \
169 V(DeletePropertySloppy, OperandType::kReg8) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170 \
171 /* Call operations */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100172 V(Call, OperandType::kReg8, OperandType::kReg8, OperandType::kRegCount8, \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173 OperandType::kIdx8) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100174 V(CallWide, OperandType::kReg16, OperandType::kReg16, \
175 OperandType::kRegCount16, OperandType::kIdx16) \
176 V(TailCall, OperandType::kReg8, OperandType::kReg8, OperandType::kRegCount8, \
177 OperandType::kIdx8) \
178 V(TailCallWide, OperandType::kReg16, OperandType::kReg16, \
179 OperandType::kRegCount16, OperandType::kIdx16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000180 V(CallRuntime, OperandType::kIdx16, OperandType::kMaybeReg8, \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100181 OperandType::kRegCount8) \
182 V(CallRuntimeWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
183 OperandType::kRegCount8) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000184 V(CallRuntimeForPair, OperandType::kIdx16, OperandType::kMaybeReg8, \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100185 OperandType::kRegCount8, OperandType::kRegOutPair8) \
186 V(CallRuntimeForPairWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
187 OperandType::kRegCount8, OperandType::kRegOutPair16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000188 V(CallJSRuntime, OperandType::kIdx16, OperandType::kReg8, \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100189 OperandType::kRegCount8) \
190 V(CallJSRuntimeWide, OperandType::kIdx16, OperandType::kReg16, \
191 OperandType::kRegCount16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000192 \
193 /* New operator */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100194 V(New, OperandType::kReg8, OperandType::kMaybeReg8, OperandType::kRegCount8) \
195 V(NewWide, OperandType::kReg16, OperandType::kMaybeReg16, \
196 OperandType::kRegCount16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197 \
198 /* Test Operators */ \
199 V(TestEqual, OperandType::kReg8) \
200 V(TestNotEqual, OperandType::kReg8) \
201 V(TestEqualStrict, OperandType::kReg8) \
202 V(TestNotEqualStrict, OperandType::kReg8) \
203 V(TestLessThan, OperandType::kReg8) \
204 V(TestGreaterThan, OperandType::kReg8) \
205 V(TestLessThanOrEqual, OperandType::kReg8) \
206 V(TestGreaterThanOrEqual, OperandType::kReg8) \
207 V(TestInstanceOf, OperandType::kReg8) \
208 V(TestIn, OperandType::kReg8) \
209 \
210 /* Cast operators */ \
211 V(ToName, OperandType::kNone) \
212 V(ToNumber, OperandType::kNone) \
213 V(ToObject, OperandType::kNone) \
214 \
215 /* Literals */ \
216 V(CreateRegExpLiteral, OperandType::kIdx8, OperandType::kIdx8, \
217 OperandType::kImm8) \
218 V(CreateArrayLiteral, OperandType::kIdx8, OperandType::kIdx8, \
219 OperandType::kImm8) \
220 V(CreateObjectLiteral, OperandType::kIdx8, OperandType::kIdx8, \
221 OperandType::kImm8) \
222 V(CreateRegExpLiteralWide, OperandType::kIdx16, OperandType::kIdx16, \
223 OperandType::kImm8) \
224 V(CreateArrayLiteralWide, OperandType::kIdx16, OperandType::kIdx16, \
225 OperandType::kImm8) \
226 V(CreateObjectLiteralWide, OperandType::kIdx16, OperandType::kIdx16, \
227 OperandType::kImm8) \
228 \
229 /* Closure allocation */ \
230 V(CreateClosure, OperandType::kIdx8, OperandType::kImm8) \
231 V(CreateClosureWide, OperandType::kIdx16, OperandType::kImm8) \
232 \
233 /* Arguments allocation */ \
234 V(CreateMappedArguments, OperandType::kNone) \
235 V(CreateUnmappedArguments, OperandType::kNone) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100236 V(CreateRestParameter, OperandType::kNone) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 \
238 /* Control Flow */ \
239 V(Jump, OperandType::kImm8) \
240 V(JumpConstant, OperandType::kIdx8) \
241 V(JumpConstantWide, OperandType::kIdx16) \
242 V(JumpIfTrue, OperandType::kImm8) \
243 V(JumpIfTrueConstant, OperandType::kIdx8) \
244 V(JumpIfTrueConstantWide, OperandType::kIdx16) \
245 V(JumpIfFalse, OperandType::kImm8) \
246 V(JumpIfFalseConstant, OperandType::kIdx8) \
247 V(JumpIfFalseConstantWide, OperandType::kIdx16) \
248 V(JumpIfToBooleanTrue, OperandType::kImm8) \
249 V(JumpIfToBooleanTrueConstant, OperandType::kIdx8) \
250 V(JumpIfToBooleanTrueConstantWide, OperandType::kIdx16) \
251 V(JumpIfToBooleanFalse, OperandType::kImm8) \
252 V(JumpIfToBooleanFalseConstant, OperandType::kIdx8) \
253 V(JumpIfToBooleanFalseConstantWide, OperandType::kIdx16) \
254 V(JumpIfNull, OperandType::kImm8) \
255 V(JumpIfNullConstant, OperandType::kIdx8) \
256 V(JumpIfNullConstantWide, OperandType::kIdx16) \
257 V(JumpIfUndefined, OperandType::kImm8) \
258 V(JumpIfUndefinedConstant, OperandType::kIdx8) \
259 V(JumpIfUndefinedConstantWide, OperandType::kIdx16) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100260 V(JumpIfNotHole, OperandType::kImm8) \
261 V(JumpIfNotHoleConstant, OperandType::kIdx8) \
262 V(JumpIfNotHoleConstantWide, OperandType::kIdx16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000263 \
264 /* Complex flow control For..in */ \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100265 V(ForInPrepare, OperandType::kRegOutTriple8) \
266 V(ForInPrepareWide, OperandType::kRegOutTriple16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000267 V(ForInDone, OperandType::kReg8, OperandType::kReg8) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100268 V(ForInNext, OperandType::kReg8, OperandType::kReg8, OperandType::kRegPair8) \
269 V(ForInNextWide, OperandType::kReg16, OperandType::kReg16, \
270 OperandType::kRegPair16) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271 V(ForInStep, OperandType::kReg8) \
272 \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100273 /* Perform a stack guard check */ \
274 V(StackCheck, OperandType::kNone) \
275 \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276 /* Non-local flow control */ \
277 V(Throw, OperandType::kNone) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100278 V(ReThrow, OperandType::kNone) \
279 V(Return, OperandType::kNone) \
280 \
281 /* Debugger */ \
282 V(Debugger, OperandType::kNone) \
283 DEBUG_BREAK_BYTECODE_LIST(V)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000284
285// Enumeration of the size classes of operand types used by bytecodes.
286enum class OperandSize : uint8_t {
287 kNone = 0,
288 kByte = 1,
289 kShort = 2,
290};
291
292
293// Enumeration of operand types used by bytecodes.
294enum class OperandType : uint8_t {
295#define DECLARE_OPERAND_TYPE(Name, _) k##Name,
296 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE)
297#undef DECLARE_OPERAND_TYPE
298#define COUNT_OPERAND_TYPES(x, _) +1
299 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will
300 // evaluate to the same value as the last operand.
301 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES)
302#undef COUNT_OPERAND_TYPES
303};
304
305
306// Enumeration of interpreter bytecodes.
307enum class Bytecode : uint8_t {
308#define DECLARE_BYTECODE(Name, ...) k##Name,
309 BYTECODE_LIST(DECLARE_BYTECODE)
310#undef DECLARE_BYTECODE
311#define COUNT_BYTECODE(x, ...) +1
312 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will
313 // evaluate to the same value as the last real bytecode.
314 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE)
315#undef COUNT_BYTECODE
316};
317
318
319// An interpreter Register which is located in the function's Register file
320// in its stack-frame. Register hold parameters, this, and expression values.
321class Register {
322 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100323 explicit Register(int index = kInvalidIndex) : index_(index) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324
Ben Murdoch097c5b22016-05-18 11:27:45 +0100325 int index() const { return index_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326 bool is_parameter() const { return index() < 0; }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100327 bool is_valid() const { return index_ != kInvalidIndex; }
328 bool is_byte_operand() const;
329 bool is_short_operand() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000330
331 static Register FromParameterIndex(int index, int parameter_count);
332 int ToParameterIndex(int parameter_count) const;
333 static int MaxParameterIndex();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100334 static int MaxRegisterIndex();
335 static int MaxRegisterIndexForByteOperand();
336
337 // Returns an invalid register.
338 static Register invalid_value() { return Register(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339
340 // Returns the register for the function's closure object.
341 static Register function_closure();
342 bool is_function_closure() const;
343
Ben Murdoch097c5b22016-05-18 11:27:45 +0100344 // Returns the register which holds the current context object.
345 static Register current_context();
346 bool is_current_context() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000347
348 // Returns the register for the incoming new target value.
349 static Register new_target();
350 bool is_new_target() const;
351
352 static Register FromOperand(uint8_t operand);
353 uint8_t ToOperand() const;
354
355 static Register FromWideOperand(uint16_t operand);
356 uint16_t ToWideOperand() const;
357
Ben Murdoch097c5b22016-05-18 11:27:45 +0100358 static Register FromRawOperand(uint32_t raw_operand);
359 uint32_t ToRawOperand() const;
360
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000361 static bool AreContiguous(Register reg1, Register reg2,
362 Register reg3 = Register(),
363 Register reg4 = Register(),
364 Register reg5 = Register());
365
Ben Murdoch097c5b22016-05-18 11:27:45 +0100366 std::string ToString(int parameter_count);
367
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000368 bool operator==(const Register& other) const {
369 return index() == other.index();
370 }
371 bool operator!=(const Register& other) const {
372 return index() != other.index();
373 }
374 bool operator<(const Register& other) const {
375 return index() < other.index();
376 }
377 bool operator<=(const Register& other) const {
378 return index() <= other.index();
379 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100380 bool operator>(const Register& other) const {
381 return index() > other.index();
382 }
383 bool operator>=(const Register& other) const {
384 return index() >= other.index();
385 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000386
387 private:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100388 static const int kInvalidIndex = kMaxInt;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000389
390 void* operator new(size_t size);
391 void operator delete(void* p);
392
393 int index_;
394};
395
396
397class Bytecodes {
398 public:
399 // Returns string representation of |bytecode|.
400 static const char* ToString(Bytecode bytecode);
401
402 // Returns string representation of |operand_type|.
403 static const char* OperandTypeToString(OperandType operand_type);
404
405 // Returns string representation of |operand_size|.
406 static const char* OperandSizeToString(OperandSize operand_size);
407
408 // Returns byte value of bytecode.
409 static uint8_t ToByte(Bytecode bytecode);
410
411 // Returns bytecode for |value|.
412 static Bytecode FromByte(uint8_t value);
413
414 // Returns the number of operands expected by |bytecode|.
415 static int NumberOfOperands(Bytecode bytecode);
416
Ben Murdoch097c5b22016-05-18 11:27:45 +0100417 // Returns the number of register operands expected by |bytecode|.
418 static int NumberOfRegisterOperands(Bytecode bytecode);
419
420 // Returns the i-th operand of |bytecode|.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000421 static OperandType GetOperandType(Bytecode bytecode, int i);
422
Ben Murdoch097c5b22016-05-18 11:27:45 +0100423 // Returns the size of the i-th operand of |bytecode|.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424 static OperandSize GetOperandSize(Bytecode bytecode, int i);
425
426 // Returns the offset of the i-th operand of |bytecode| relative to the start
427 // of the bytecode.
428 static int GetOperandOffset(Bytecode bytecode, int i);
429
Ben Murdoch097c5b22016-05-18 11:27:45 +0100430 // Returns a zero-based bitmap of the register operand positions of
431 // |bytecode|.
432 static int GetRegisterOperandBitmap(Bytecode bytecode);
433
434 // Returns a debug break bytecode with a matching operand size.
435 static Bytecode GetDebugBreak(Bytecode bytecode);
436
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 // Returns the size of the bytecode including its operands.
438 static int Size(Bytecode bytecode);
439
440 // Returns the size of |operand|.
441 static OperandSize SizeOfOperand(OperandType operand);
442
Ben Murdoch097c5b22016-05-18 11:27:45 +0100443 // Returns true if the bytecode is a conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000444 // an immediate byte operand (OperandType::kImm8).
445 static bool IsConditionalJumpImmediate(Bytecode bytecode);
446
Ben Murdoch097c5b22016-05-18 11:27:45 +0100447 // Returns true if the bytecode is a conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 // a constant pool entry (OperandType::kIdx8).
449 static bool IsConditionalJumpConstant(Bytecode bytecode);
450
Ben Murdoch097c5b22016-05-18 11:27:45 +0100451 // Returns true if the bytecode is a conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000452 // a constant pool entry (OperandType::kIdx16).
453 static bool IsConditionalJumpConstantWide(Bytecode bytecode);
454
Ben Murdoch097c5b22016-05-18 11:27:45 +0100455 // Returns true if the bytecode is a conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000456 // any kind of operand.
457 static bool IsConditionalJump(Bytecode bytecode);
458
Ben Murdoch097c5b22016-05-18 11:27:45 +0100459 // Returns true if the bytecode is a jump or a conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000460 // an immediate byte operand (OperandType::kImm8).
461 static bool IsJumpImmediate(Bytecode bytecode);
462
Ben Murdoch097c5b22016-05-18 11:27:45 +0100463 // Returns true if the bytecode is a jump or conditional jump taking a
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000464 // constant pool entry (OperandType::kIdx8).
465 static bool IsJumpConstant(Bytecode bytecode);
466
Ben Murdoch097c5b22016-05-18 11:27:45 +0100467 // Returns true if the bytecode is a jump or conditional jump taking a
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000468 // constant pool entry (OperandType::kIdx16).
469 static bool IsJumpConstantWide(Bytecode bytecode);
470
Ben Murdoch097c5b22016-05-18 11:27:45 +0100471 // Returns true if the bytecode is a jump or conditional jump taking
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000472 // any kind of operand.
473 static bool IsJump(Bytecode bytecode);
474
Ben Murdoch097c5b22016-05-18 11:27:45 +0100475 // Returns true if the bytecode is a conditional jump, a jump, or a return.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000476 static bool IsJumpOrReturn(Bytecode bytecode);
477
Ben Murdoch097c5b22016-05-18 11:27:45 +0100478 // Returns true if the bytecode is a call or a constructor call.
479 static bool IsCallOrNew(Bytecode bytecode);
480
481 // Returns true if the bytecode is a debug break.
482 static bool IsDebugBreak(Bytecode bytecode);
483
484 // Returns true if |operand_type| is a register index operand (kIdx8/kIdx16).
485 static bool IsIndexOperandType(OperandType operand_type);
486
487 // Returns true if |operand_type| represents an immediate.
488 static bool IsImmediateOperandType(OperandType operand_type);
489
490 // Returns true if |operand_type| is a register count operand
491 // (kRegCount8/kRegCount16).
492 static bool IsRegisterCountOperandType(OperandType operand_type);
493
494 // Returns true if |operand_type| is any type of register operand.
495 static bool IsRegisterOperandType(OperandType operand_type);
496
497 // Returns true if |operand_type| represents a register used as an input.
498 static bool IsRegisterInputOperandType(OperandType operand_type);
499
500 // Returns true if |operand_type| represents a register used as an output.
501 static bool IsRegisterOutputOperandType(OperandType operand_type);
502
503 // Returns true if |operand_type| is a maybe register operand
504 // (kMaybeReg8/kMaybeReg16).
505 static bool IsMaybeRegisterOperandType(OperandType operand_type);
506
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000507 // Decode a single bytecode and operands to |os|.
508 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start,
509 int number_of_parameters);
510
511 private:
512 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes);
513};
514
515std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode);
516std::ostream& operator<<(std::ostream& os, const OperandType& operand_type);
517std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type);
518
519} // namespace interpreter
520} // namespace internal
521} // namespace v8
522
523#endif // V8_INTERPRETER_BYTECODES_H_