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

Side by Side Diff: src/interpreter/bytecode-array-builder.h

Issue 1325983002: [Intepreter] Extend and move Register class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test, bug spotted by bots. Created 5 years, 3 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 | « no previous file | src/interpreter/bytecode-array-builder.cc » ('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 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "src/ast.h" 10 #include "src/ast.h"
11 #include "src/frames.h"
12 #include "src/identity-map.h" 11 #include "src/identity-map.h"
13 #include "src/interpreter/bytecodes.h" 12 #include "src/interpreter/bytecodes.h"
14 #include "src/zone.h" 13 #include "src/zone.h"
15 #include "src/zone-containers.h" 14 #include "src/zone-containers.h"
16 15
17 namespace v8 { 16 namespace v8 {
18 namespace internal { 17 namespace internal {
19 18
20 class Isolate; 19 class Isolate;
21 20
(...skipping 29 matching lines...) Expand all
51 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg); 50 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg);
52 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg); 51 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg);
53 52
54 // Operators. 53 // Operators.
55 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); 54 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg);
56 55
57 // Flow Control. 56 // Flow Control.
58 BytecodeArrayBuilder& Return(); 57 BytecodeArrayBuilder& Return();
59 58
60 private: 59 private:
61 static const int kLastParamRegisterIndex =
62 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
63
64 static Bytecode BytecodeForBinaryOperation(Token::Value op); 60 static Bytecode BytecodeForBinaryOperation(Token::Value op);
65 61
66 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2); 62 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2);
67 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); 63 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1);
68 void Output(Bytecode bytecode, uint8_t r0); 64 void Output(Bytecode bytecode, uint8_t r0);
69 void Output(Bytecode bytecode); 65 void Output(Bytecode bytecode);
70 66
71 bool OperandIsValid(Bytecode bytecode, int operand_index, 67 bool OperandIsValid(Bytecode bytecode, int operand_index,
72 uint8_t operand_value) const; 68 uint8_t operand_value) const;
73 69
(...skipping 11 matching lines...) Expand all
85 81
86 int parameter_count_; 82 int parameter_count_;
87 int local_register_count_; 83 int local_register_count_;
88 int temporary_register_count_; 84 int temporary_register_count_;
89 int temporary_register_next_; 85 int temporary_register_next_;
90 86
91 friend class TemporaryRegisterScope; 87 friend class TemporaryRegisterScope;
92 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); 88 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder);
93 }; 89 };
94 90
95 // An interpreter register which is located in the function's register file
96 // in its stack-frame.
97 class Register {
98 public:
99 static const int kMaxRegisterIndex = 128;
100 static const int kMinRegisterIndex = -127;
101
102 explicit Register(int index) : index_(index) {
103 DCHECK_LE(index_, kMaxRegisterIndex);
104 DCHECK_GE(index_, kMinRegisterIndex);
105 }
106
107 int index() { return index_; }
108
109 uint8_t ToOperand() { return static_cast<uint8_t>(-index_); }
110 static Register FromOperand(uint8_t operand) {
111 return Register(-static_cast<int8_t>(operand));
112 }
113
114 private:
115 void* operator new(size_t size);
116 void operator delete(void* p);
117
118 int index_;
119 };
120
121 // A stack-allocated class than allows the instantiator to allocate 91 // A stack-allocated class than allows the instantiator to allocate
122 // temporary registers that are cleaned up when scope is closed. 92 // temporary registers that are cleaned up when scope is closed.
123 class TemporaryRegisterScope { 93 class TemporaryRegisterScope {
124 public: 94 public:
125 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); 95 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder);
126 ~TemporaryRegisterScope(); 96 ~TemporaryRegisterScope();
127 Register NewRegister(); 97 Register NewRegister();
128 98
129 private: 99 private:
130 void* operator new(size_t size); 100 void* operator new(size_t size);
131 void operator delete(void* p); 101 void operator delete(void* p);
132 102
133 BytecodeArrayBuilder* builder_; 103 BytecodeArrayBuilder* builder_;
134 int count_; 104 int count_;
135 int last_register_index_; 105 int last_register_index_;
136 106
137 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); 107 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope);
138 }; 108 };
139 109
140 110
141 } // namespace interpreter 111 } // namespace interpreter
142 } // namespace internal 112 } // namespace internal
143 } // namespace v8 113 } // namespace v8
144 114
145 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 115 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
OLDNEW
« no previous file with comments | « no previous file | src/interpreter/bytecode-array-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698