Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: src/interpreter/bytecodes.cc

Issue 1257543003: [Interpreter] Add more bytecode definitions and add operand types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/interpreter/interpreter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/interpreter/bytecodes.h" 5 #include "src/interpreter/bytecodes.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace interpreter { 9 namespace interpreter {
10 10
11 // Maximum number of operands a bytecode may have.
12 static const int kMaxOperands = 3;
13
14 // kBytecodeTable relies on kNone being the same as zero to detect length.
15 STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0);
16
17 static const OperandType kBytecodeTable[][kMaxOperands] = {
18 #define DECLARE_OPERAND(_, ...) \
19 { __VA_ARGS__ } \
20 ,
21 BYTECODE_LIST(DECLARE_OPERAND)
22 #undef DECLARE_OPERAND
23 };
24
25
11 // static 26 // static
12 const char* Bytecodes::ToString(Bytecode bytecode) { 27 const char* Bytecodes::ToString(Bytecode bytecode) {
13 switch (bytecode) { 28 switch (bytecode) {
14 #define CASE(Name, _) \ 29 #define CASE(Name, ...) \
15 case Bytecode::k##Name: \ 30 case Bytecode::k##Name: \
16 return #Name; 31 return #Name;
17 BYTECODE_LIST(CASE) 32 BYTECODE_LIST(CASE)
18 #undef CASE 33 #undef CASE
19 } 34 }
20 UNREACHABLE(); 35 UNREACHABLE();
21 return ""; 36 return "";
22 } 37 }
23 38
24 39
25 // static 40 // static
26 const int Bytecodes::NumberOfArguments(Bytecode bytecode) { 41 uint8_t Bytecodes::ToByte(Bytecode bytecode) {
27 switch (bytecode) { 42 return static_cast<uint8_t>(bytecode);
28 #define CASE(Name, arg_count) \ 43 }
29 case Bytecode::k##Name: \ 44
30 return arg_count; 45
31 BYTECODE_LIST(CASE) 46 // static
32 #undef CASE 47 Bytecode Bytecodes::FromByte(uint8_t value) {
48 Bytecode bytecode = static_cast<Bytecode>(value);
49 DCHECK(bytecode <= Bytecode::kLast);
50 return bytecode;
51 }
52
53
54 // static
55 const int Bytecodes::NumberOfOperands(Bytecode bytecode) {
56 DCHECK(bytecode <= Bytecode::kLast);
57 int count;
58 uint8_t row = ToByte(bytecode);
59 for (count = 0; count < kMaxOperands; count++) {
60 if (kBytecodeTable[row][count] == OperandType::kNone) {
61 break;
62 }
33 } 63 }
34 UNREACHABLE(); 64 return count;
35 return 0; 65 }
66
67
68 // static
69 const OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) {
70 DCHECK(bytecode <= Bytecode::kLast && i < NumberOfOperands(bytecode));
71 return kBytecodeTable[ToByte(bytecode)][i];
36 } 72 }
37 73
38 74
39 // static 75 // static
40 const int Bytecodes::Size(Bytecode bytecode) { 76 const int Bytecodes::Size(Bytecode bytecode) {
41 return NumberOfArguments(bytecode) + 1; 77 return 1 + NumberOfOperands(bytecode);
42 } 78 }
43 79
44 80
45 #define CHECK_SIZE(Name, arg_count) \ 81 // static
46 STATIC_ASSERT(arg_count <= Bytecodes::kMaximumNumberOfArguments); 82 const int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; }
47 BYTECODE_LIST(CHECK_SIZE) 83
48 #undef CHECK_SIZE 84
85 // static
86 const int Bytecodes::MaximumSize() { return 1 + kMaxOperands; }
49 87
50 88
51 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { 89 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) {
52 return os << Bytecodes::ToString(bytecode); 90 return os << Bytecodes::ToString(bytecode);
53 } 91 }
54 92
55 } // namespace interpreter 93 } // namespace interpreter
56 } // namespace internal 94 } // namespace internal
57 } // namespace v8 95 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/interpreter/interpreter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698