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_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" |
11 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 class Isolate; | 17 class Isolate; |
17 | 18 |
18 namespace interpreter { | 19 namespace interpreter { |
19 | 20 |
20 class Register; | 21 class Register; |
21 | 22 |
22 class BytecodeArrayBuilder { | 23 class BytecodeArrayBuilder { |
23 public: | 24 public: |
24 explicit BytecodeArrayBuilder(Isolate* isolate); | 25 explicit BytecodeArrayBuilder(Isolate* isolate); |
25 Handle<BytecodeArray> ToBytecodeArray(); | 26 Handle<BytecodeArray> ToBytecodeArray(); |
26 | 27 |
| 28 // Set number of parameters expected by function. |
| 29 void set_parameter_count(int number_of_params); |
| 30 int parameter_count() const; |
| 31 |
27 // Set number of locals required for bytecode array. | 32 // Set number of locals required for bytecode array. |
28 void set_locals_count(int number_of_locals); | 33 void set_locals_count(int number_of_locals); |
29 int locals_count() const; | 34 int locals_count() const; |
30 | 35 |
| 36 Register Parameter(int parameter_index); |
| 37 |
31 // Constant loads to accumulator. | 38 // Constant loads to accumulator. |
32 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); | 39 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); |
33 BytecodeArrayBuilder& LoadUndefined(); | 40 BytecodeArrayBuilder& LoadUndefined(); |
34 BytecodeArrayBuilder& LoadNull(); | 41 BytecodeArrayBuilder& LoadNull(); |
35 BytecodeArrayBuilder& LoadTheHole(); | 42 BytecodeArrayBuilder& LoadTheHole(); |
36 BytecodeArrayBuilder& LoadTrue(); | 43 BytecodeArrayBuilder& LoadTrue(); |
37 BytecodeArrayBuilder& LoadFalse(); | 44 BytecodeArrayBuilder& LoadFalse(); |
38 | 45 |
39 // Register-accumulator transfers. | 46 // Register-accumulator transfers. |
40 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg); | 47 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg); |
41 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg); | 48 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg); |
42 | 49 |
43 // Operators. | 50 // Operators. |
44 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); | 51 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); |
45 | 52 |
46 // Flow Control. | 53 // Flow Control. |
47 BytecodeArrayBuilder& Return(); | 54 BytecodeArrayBuilder& Return(); |
48 | 55 |
49 private: | 56 private: |
| 57 static const int kLastParamRegisterIndex = |
| 58 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; |
| 59 |
50 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 60 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
51 | 61 |
52 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); |
53 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); | 63 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); |
54 void Output(Bytecode bytecode, uint8_t r0); | 64 void Output(Bytecode bytecode, uint8_t r0); |
55 void Output(Bytecode bytecode); | 65 void Output(Bytecode bytecode); |
56 | 66 |
57 bool OperandIsValid(Bytecode bytecode, int operand_index, | 67 bool OperandIsValid(Bytecode bytecode, int operand_index, |
58 uint8_t operand_value) const; | 68 uint8_t operand_value) const; |
59 | 69 |
60 int BorrowTemporaryRegister(); | 70 int BorrowTemporaryRegister(); |
61 void ReturnTemporaryRegister(int reg_index); | 71 void ReturnTemporaryRegister(int reg_index); |
62 | 72 |
63 Isolate* isolate_; | 73 Isolate* isolate_; |
64 std::vector<uint8_t> bytecodes_; | 74 std::vector<uint8_t> bytecodes_; |
65 bool bytecode_generated_; | 75 bool bytecode_generated_; |
66 | 76 |
| 77 int parameter_count_; |
67 int local_register_count_; | 78 int local_register_count_; |
68 int temporary_register_count_; | 79 int temporary_register_count_; |
69 int temporary_register_next_; | 80 int temporary_register_next_; |
70 | 81 |
71 friend class TemporaryRegisterScope; | 82 friend class TemporaryRegisterScope; |
72 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); | 83 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); |
73 }; | 84 }; |
74 | 85 |
75 // An interpreter register which is located in the function's regsiter file | 86 // An interpreter register which is located in the function's register file |
76 // in its stack-frame. | 87 // in its stack-frame. |
77 class Register { | 88 class Register { |
78 public: | 89 public: |
79 static const int kMaxRegisterIndex = 128; | 90 static const int kMaxRegisterIndex = 128; |
| 91 static const int kMinRegisterIndex = -127; |
80 | 92 |
81 explicit Register(int index) : index_(index) { | 93 explicit Register(int index) : index_(index) { |
82 DCHECK_LE(index_, kMaxRegisterIndex); | 94 DCHECK_LE(index_, kMaxRegisterIndex); |
| 95 DCHECK_GE(index_, kMinRegisterIndex); |
83 } | 96 } |
84 | 97 |
85 int index() { return index_; } | 98 int index() { return index_; } |
| 99 |
86 uint8_t ToOperand() { return static_cast<uint8_t>(-index_); } | 100 uint8_t ToOperand() { return static_cast<uint8_t>(-index_); } |
87 static Register FromOperand(uint8_t operand) { | 101 static Register FromOperand(uint8_t operand) { |
88 return Register(-static_cast<int8_t>(operand)); | 102 return Register(-static_cast<int8_t>(operand)); |
89 } | 103 } |
90 | 104 |
91 private: | 105 private: |
92 void* operator new(size_t size); | 106 void* operator new(size_t size); |
93 void operator delete(void* p); | 107 void operator delete(void* p); |
94 | 108 |
95 int index_; | 109 int index_; |
(...skipping 17 matching lines...) Expand all Loading... |
113 | 127 |
114 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 128 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
115 }; | 129 }; |
116 | 130 |
117 | 131 |
118 } // namespace interpreter | 132 } // namespace interpreter |
119 } // namespace internal | 133 } // namespace internal |
120 } // namespace v8 | 134 } // namespace v8 |
121 | 135 |
122 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 136 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |