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

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

Issue 1257543003: [Interpreter] Add more bytecode definitions and add operand types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Preprocessor robust method of describing bytecode operands. 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
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 #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.
11 // Do not include anything from src/interpreter here! 11 // Do not include anything from src/interpreter here!
12 #include "src/utils.h" 12 #include "src/utils.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace interpreter { 16 namespace interpreter {
17 17
18 // The list of operands used by bytecodes.
19 #define OPERAND_LIST(V) \
rmcilroy 2015/07/27 14:56:58 nit - OPERAND_TYPE_LIST
oth 2015/07/27 16:59:00 Done.
20 V(None) \
21 V(Imm8) \
22 V(Reg)
23
24 enum class Operand : uint8_t {
rmcilroy 2015/07/27 14:56:57 nit - OperandType
oth 2015/07/27 16:59:00 Done.
25 #define DECLARE_OPERAND(Name) k##Name,
26 OPERAND_LIST(DECLARE_OPERAND)
27 #undef DECLARE_OPERAND
28 #define COUNT_OPERAND(x) +1
29 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will
30 // evaluate to the same value as the last operand.
31 kLast = -1 OPERAND_LIST(COUNT_OPERAND)
32 #undef COUNT_OPERAND
33 };
34
18 // The list of bytecodes which are interpreted by the interpreter. 35 // The list of bytecodes which are interpreted by the interpreter.
19 #define BYTECODE_LIST(V) \ 36 #define BYTECODE_LIST(V) \
20 V(LoadLiteral0, 1) \ 37 V(LoadSmi0, Operand::kReg) \
21 V(Return, 0) 38 V(LoadSmi8, Operand::kReg, Operand::kImm8) \
39 V(Return, Operand::kNone)
rmcilroy 2015/07/27 14:56:58 nit - can we move this up just below OPERAND_LIST
oth 2015/07/27 16:59:00 Done.
40
22 41
23 enum class Bytecode : uint8_t { 42 enum class Bytecode : uint8_t {
24 #define DECLARE_BYTECODE(Name, _) k##Name, 43 #define DECLARE_BYTECODE(Name, ...) k##Name,
25 BYTECODE_LIST(DECLARE_BYTECODE) 44 BYTECODE_LIST(DECLARE_BYTECODE)
26 #undef DECLARE_BYTECODE 45 #undef DECLARE_BYTECODE
27 #define COUNT_BYTECODE(x, _) +1 46 #define COUNT_BYTECODE(x, ...) +1
28 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will 47 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will
29 // evaluate to the same value as the last real bytecode. 48 // evaluate to the same value as the last real bytecode.
30 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) 49 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE)
31 #undef COUNT_BYTECODE 50 #undef COUNT_BYTECODE
32 }; 51 };
33 52
53
34 class Bytecodes { 54 class Bytecodes {
35 public: 55 public:
36 // Returns string representation of |bytecode|. 56 // Returns string representation of |bytecode|.
37 static const char* ToString(Bytecode bytecode); 57 static const char* ToString(Bytecode bytecode);
38 58
39 // Returns the number of arguments expected by |bytecode|. 59 // Returns byte value of bytecode.
40 static const int NumberOfArguments(Bytecode bytecode); 60 static uint8_t ToByte(Bytecode bytecode);
61
62 // Returns bytecode for |value|,, checking validity in the process.
rmcilroy 2015/07/27 14:56:58 remove extra ','
oth 2015/07/27 16:59:00 Done.
63 static Bytecode FromByte(uint8_t value);
64
65 // Returns the number of operands expected by |bytecode|.
66 static const int NumberOfOperands(Bytecode bytecode);
67
68 // Return the i-th operand of |bytecode|.
rmcilroy 2015/07/27 14:56:58 Return the type of the i-th operand of |bytecode|
oth 2015/07/27 16:59:00 Done.
69 static const Operand GetOperand(Bytecode bytecode, int i);
rmcilroy 2015/07/27 14:56:58 GetOperandType
oth 2015/07/27 16:59:00 Done.
41 70
42 // Returns the size of the bytecode including its arguments. 71 // Returns the size of the bytecode including its arguments.
43 static const int Size(Bytecode bytecode); 72 static const int Size(Bytecode bytecode);
44 73
45 // The maximum number of arguments across all bytecodes. 74 // The maximum number of operands across all bytecodes.
46 static const int kMaximumNumberOfArguments = 1; 75 static const int MaximumNumberOfOperands();
47 76
48 // Maximum size of a bytecode and its arguments. 77 // Maximum size of a bytecode and its arguments.
49 static const int kMaximumSize = 1 + kMaximumNumberOfArguments; 78 static const int MaximumSize();
50 79
51 private: 80 private:
52 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); 81 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes);
53 }; 82 };
54 83
55 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); 84 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode);
56 85
57 } // namespace interpreter 86 } // namespace interpreter
58 } // namespace internal 87 } // namespace internal
59 } // namespace v8 88 } // namespace v8
60 89
61 #endif // V8_INTERPRETER_BYTECODES_H_ 90 #endif // V8_INTERPRETER_BYTECODES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698