OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_INTERPRETER_BYTECODES_H_ | 5 #ifndef V8_INTERPRETER_BYTECODES_H_ |
6 #define V8_INTERPRETER_BYTECODES_H_ | 6 #define V8_INTERPRETER_BYTECODES_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 // Clients of this interface shouldn't depend on lots of interpreter internals. | 10 // Clients of this interface shouldn't depend on lots of interpreter internals. |
(...skipping 86 matching lines...) Loading... |
97 \ | 97 \ |
98 /* Register-register transfers */ \ | 98 /* Register-register transfers */ \ |
99 V(Mov, OperandType::kReg8, OperandType::kReg8) \ | 99 V(Mov, OperandType::kReg8, OperandType::kReg8) \ |
100 V(MovWide, OperandType::kReg16, OperandType::kReg16) \ | 100 V(MovWide, OperandType::kReg16, OperandType::kReg16) \ |
101 \ | 101 \ |
102 /* LoadIC operations */ \ | 102 /* LoadIC operations */ \ |
103 V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 103 V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
104 V(LoadICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 104 V(LoadICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
105 V(KeyedLoadICSloppy, OperandType::kReg8, OperandType::kIdx8) \ | 105 V(KeyedLoadICSloppy, OperandType::kReg8, OperandType::kIdx8) \ |
106 V(KeyedLoadICStrict, OperandType::kReg8, OperandType::kIdx8) \ | 106 V(KeyedLoadICStrict, OperandType::kReg8, OperandType::kIdx8) \ |
107 /* TODO(rmcilroy): Wide register operands too? */ \ | |
108 V(LoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ | 107 V(LoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ |
109 OperandType::kIdx16) \ | 108 OperandType::kIdx16) \ |
110 V(LoadICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ | 109 V(LoadICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ |
111 OperandType::kIdx16) \ | 110 OperandType::kIdx16) \ |
112 V(KeyedLoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16) \ | 111 V(KeyedLoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16) \ |
113 V(KeyedLoadICStrictWide, OperandType::kReg8, OperandType::kIdx16) \ | 112 V(KeyedLoadICStrictWide, OperandType::kReg8, OperandType::kIdx16) \ |
114 \ | 113 \ |
115 /* StoreIC operations */ \ | 114 /* StoreIC operations */ \ |
116 V(StoreICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 115 V(StoreICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
117 V(StoreICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 116 V(StoreICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
118 V(KeyedStoreICSloppy, OperandType::kReg8, OperandType::kReg8, \ | 117 V(KeyedStoreICSloppy, OperandType::kReg8, OperandType::kReg8, \ |
119 OperandType::kIdx8) \ | 118 OperandType::kIdx8) \ |
120 V(KeyedStoreICStrict, OperandType::kReg8, OperandType::kReg8, \ | 119 V(KeyedStoreICStrict, OperandType::kReg8, OperandType::kReg8, \ |
121 OperandType::kIdx8) \ | 120 OperandType::kIdx8) \ |
122 /* TODO(rmcilroy): Wide register operands too? */ \ | |
123 V(StoreICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ | 121 V(StoreICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ |
124 OperandType::kIdx16) \ | 122 OperandType::kIdx16) \ |
125 V(StoreICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ | 123 V(StoreICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ |
126 OperandType::kIdx16) \ | 124 OperandType::kIdx16) \ |
127 V(KeyedStoreICSloppyWide, OperandType::kReg8, OperandType::kReg8, \ | 125 V(KeyedStoreICSloppyWide, OperandType::kReg8, OperandType::kReg8, \ |
128 OperandType::kIdx16) \ | 126 OperandType::kIdx16) \ |
129 V(KeyedStoreICStrictWide, OperandType::kReg8, OperandType::kReg8, \ | 127 V(KeyedStoreICStrictWide, OperandType::kReg8, OperandType::kReg8, \ |
130 OperandType::kIdx16) \ | 128 OperandType::kIdx16) \ |
131 \ | 129 \ |
132 /* Binary Operators */ \ | 130 /* Binary Operators */ \ |
(...skipping 149 matching lines...) Loading... |
282 // evaluate to the same value as the last real bytecode. | 280 // evaluate to the same value as the last real bytecode. |
283 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) | 281 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) |
284 #undef COUNT_BYTECODE | 282 #undef COUNT_BYTECODE |
285 }; | 283 }; |
286 | 284 |
287 | 285 |
288 // An interpreter Register which is located in the function's Register file | 286 // An interpreter Register which is located in the function's Register file |
289 // in its stack-frame. Register hold parameters, this, and expression values. | 287 // in its stack-frame. Register hold parameters, this, and expression values. |
290 class Register { | 288 class Register { |
291 public: | 289 public: |
292 Register() : index_(kIllegalIndex) {} | 290 explicit Register(int index = kInvalidIndex) : index_(index) {} |
293 | |
294 explicit Register(int index) : index_(index) {} | |
295 | 291 |
296 int index() const { | 292 int index() const { |
297 DCHECK(index_ != kIllegalIndex); | 293 DCHECK(index_ != kInvalidIndex); |
298 return index_; | 294 return index_; |
299 } | 295 } |
300 bool is_parameter() const { return index() < 0; } | 296 bool is_parameter() const { return index() < 0; } |
301 bool is_valid() const { return index_ != kIllegalIndex; } | 297 bool is_valid() const { return index_ != kInvalidIndex; } |
| 298 bool is_byte_operand() const; |
| 299 bool is_short_operand() const; |
302 | 300 |
303 static Register FromParameterIndex(int index, int parameter_count); | 301 static Register FromParameterIndex(int index, int parameter_count); |
304 int ToParameterIndex(int parameter_count) const; | 302 int ToParameterIndex(int parameter_count) const; |
305 static int MaxParameterIndex(); | 303 static int MaxParameterIndex(); |
| 304 static int MaxRegisterIndex(); |
| 305 static int MaxRegisterIndexForByteOperand(); |
306 | 306 |
307 // Returns the register for the function's closure object. | 307 // Returns the register for the function's closure object. |
308 static Register function_closure(); | 308 static Register function_closure(); |
309 bool is_function_closure() const; | 309 bool is_function_closure() const; |
310 | 310 |
311 // Returns the register which holds the current context object. | 311 // Returns the register which holds the current context object. |
312 static Register current_context(); | 312 static Register current_context(); |
313 bool is_current_context() const; | 313 bool is_current_context() const; |
314 | 314 |
315 // Returns the register for the incoming new target value. | 315 // Returns the register for the incoming new target value. |
(...skipping 27 matching lines...) Loading... |
343 return index() <= other.index(); | 343 return index() <= other.index(); |
344 } | 344 } |
345 bool operator>(const Register& other) const { | 345 bool operator>(const Register& other) const { |
346 return index() > other.index(); | 346 return index() > other.index(); |
347 } | 347 } |
348 bool operator>=(const Register& other) const { | 348 bool operator>=(const Register& other) const { |
349 return index() >= other.index(); | 349 return index() >= other.index(); |
350 } | 350 } |
351 | 351 |
352 private: | 352 private: |
353 static const int kIllegalIndex = kMaxInt; | 353 static const int kInvalidIndex = kMaxInt; |
354 | 354 |
355 void* operator new(size_t size); | 355 void* operator new(size_t size); |
356 void operator delete(void* p); | 356 void operator delete(void* p); |
357 | 357 |
358 int index_; | 358 int index_; |
359 }; | 359 }; |
360 | 360 |
361 | 361 |
362 class Bytecodes { | 362 class Bytecodes { |
363 public: | 363 public: |
364 // Returns string representation of |bytecode|. | 364 // Returns string representation of |bytecode|. |
365 static const char* ToString(Bytecode bytecode); | 365 static const char* ToString(Bytecode bytecode); |
366 | 366 |
367 // Returns string representation of |operand_type|. | 367 // Returns string representation of |operand_type|. |
368 static const char* OperandTypeToString(OperandType operand_type); | 368 static const char* OperandTypeToString(OperandType operand_type); |
369 | 369 |
370 // Returns string representation of |operand_size|. | 370 // Returns string representation of |operand_size|. |
371 static const char* OperandSizeToString(OperandSize operand_size); | 371 static const char* OperandSizeToString(OperandSize operand_size); |
372 | 372 |
373 // Returns byte value of bytecode. | 373 // Returns byte value of bytecode. |
374 static uint8_t ToByte(Bytecode bytecode); | 374 static uint8_t ToByte(Bytecode bytecode); |
375 | 375 |
376 // Returns bytecode for |value|. | 376 // Returns bytecode for |value|. |
377 static Bytecode FromByte(uint8_t value); | 377 static Bytecode FromByte(uint8_t value); |
378 | 378 |
379 // Returns the number of operands expected by |bytecode|. | 379 // Returns the number of operands expected by |bytecode|. |
380 static int NumberOfOperands(Bytecode bytecode); | 380 static int NumberOfOperands(Bytecode bytecode); |
381 | 381 |
| 382 // Returns the number of register operands expected by |bytecode|. |
| 383 static int NumberOfRegisterOperands(Bytecode bytecode); |
| 384 |
382 // Return the i-th operand of |bytecode|. | 385 // Return the i-th operand of |bytecode|. |
383 static OperandType GetOperandType(Bytecode bytecode, int i); | 386 static OperandType GetOperandType(Bytecode bytecode, int i); |
384 | 387 |
385 // Return the size of the i-th operand of |bytecode|. | 388 // Return the size of the i-th operand of |bytecode|. |
386 static OperandSize GetOperandSize(Bytecode bytecode, int i); | 389 static OperandSize GetOperandSize(Bytecode bytecode, int i); |
387 | 390 |
388 // Returns the offset of the i-th operand of |bytecode| relative to the start | 391 // Returns the offset of the i-th operand of |bytecode| relative to the start |
389 // of the bytecode. | 392 // of the bytecode. |
390 static int GetOperandOffset(Bytecode bytecode, int i); | 393 static int GetOperandOffset(Bytecode bytecode, int i); |
391 | 394 |
| 395 // Returns a zero-based bitmap of the register operand positions of |
| 396 // |bytecode|. |
| 397 static int GetRegisterOperandBitmap(Bytecode bytecode); |
| 398 |
392 // Returns the size of the bytecode including its operands. | 399 // Returns the size of the bytecode including its operands. |
393 static int Size(Bytecode bytecode); | 400 static int Size(Bytecode bytecode); |
394 | 401 |
395 // Returns the size of |operand|. | 402 // Returns the size of |operand|. |
396 static OperandSize SizeOfOperand(OperandType operand); | 403 static OperandSize SizeOfOperand(OperandType operand); |
397 | 404 |
398 // Return true if the bytecode is a conditional jump taking | 405 // Returns true if the bytecode is a conditional jump taking |
399 // an immediate byte operand (OperandType::kImm8). | 406 // an immediate byte operand (OperandType::kImm8). |
400 static bool IsConditionalJumpImmediate(Bytecode bytecode); | 407 static bool IsConditionalJumpImmediate(Bytecode bytecode); |
401 | 408 |
402 // Return true if the bytecode is a conditional jump taking | 409 // Returns true if the bytecode is a conditional jump taking |
403 // a constant pool entry (OperandType::kIdx8). | 410 // a constant pool entry (OperandType::kIdx8). |
404 static bool IsConditionalJumpConstant(Bytecode bytecode); | 411 static bool IsConditionalJumpConstant(Bytecode bytecode); |
405 | 412 |
406 // Return true if the bytecode is a conditional jump taking | 413 // Returns true if the bytecode is a conditional jump taking |
407 // a constant pool entry (OperandType::kIdx16). | 414 // a constant pool entry (OperandType::kIdx16). |
408 static bool IsConditionalJumpConstantWide(Bytecode bytecode); | 415 static bool IsConditionalJumpConstantWide(Bytecode bytecode); |
409 | 416 |
410 // Return true if the bytecode is a conditional jump taking | 417 // Returns true if the bytecode is a conditional jump taking |
411 // any kind of operand. | 418 // any kind of operand. |
412 static bool IsConditionalJump(Bytecode bytecode); | 419 static bool IsConditionalJump(Bytecode bytecode); |
413 | 420 |
414 // Return true if the bytecode is a jump or a conditional jump taking | 421 // Returns true if the bytecode is a jump or a conditional jump taking |
415 // an immediate byte operand (OperandType::kImm8). | 422 // an immediate byte operand (OperandType::kImm8). |
416 static bool IsJumpImmediate(Bytecode bytecode); | 423 static bool IsJumpImmediate(Bytecode bytecode); |
417 | 424 |
418 // Return true if the bytecode is a jump or conditional jump taking a | 425 // Returns true if the bytecode is a jump or conditional jump taking a |
419 // constant pool entry (OperandType::kIdx8). | 426 // constant pool entry (OperandType::kIdx8). |
420 static bool IsJumpConstant(Bytecode bytecode); | 427 static bool IsJumpConstant(Bytecode bytecode); |
421 | 428 |
422 // Return true if the bytecode is a jump or conditional jump taking a | 429 // Returns true if the bytecode is a jump or conditional jump taking a |
423 // constant pool entry (OperandType::kIdx16). | 430 // constant pool entry (OperandType::kIdx16). |
424 static bool IsJumpConstantWide(Bytecode bytecode); | 431 static bool IsJumpConstantWide(Bytecode bytecode); |
425 | 432 |
426 // Return true if the bytecode is a jump or conditional jump taking | 433 // Return true if the bytecode is a jump or conditional jump taking |
427 // any kind of operand. | 434 // any kind of operand. |
428 static bool IsJump(Bytecode bytecode); | 435 static bool IsJump(Bytecode bytecode); |
429 | 436 |
430 // Return true if the bytecode is a conditional jump, a jump, or a return. | 437 // Return true if the bytecode is a conditional jump, a jump, or a return. |
431 static bool IsJumpOrReturn(Bytecode bytecode); | 438 static bool IsJumpOrReturn(Bytecode bytecode); |
432 | 439 |
433 // Decode a single bytecode and operands to |os|. | 440 // Decode a single bytecode and operands to |os|. |
434 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, | 441 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, |
435 int number_of_parameters); | 442 int number_of_parameters); |
436 | 443 |
437 private: | 444 private: |
438 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); | 445 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); |
439 }; | 446 }; |
440 | 447 |
441 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 448 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
442 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); | 449 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); |
443 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type); | 450 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type); |
444 | 451 |
445 } // namespace interpreter | 452 } // namespace interpreter |
446 } // namespace internal | 453 } // namespace internal |
447 } // namespace v8 | 454 } // namespace v8 |
448 | 455 |
449 #endif // V8_INTERPRETER_BYTECODES_H_ | 456 #endif // V8_INTERPRETER_BYTECODES_H_ |
OLD | NEW |