| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
| 10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 // Emit cast operator invocations. | 158 // Emit cast operator invocations. |
| 159 builder.CastAccumulatorToNumber() | 159 builder.CastAccumulatorToNumber() |
| 160 .CastAccumulatorToJSObject() | 160 .CastAccumulatorToJSObject() |
| 161 .CastAccumulatorToName(); | 161 .CastAccumulatorToName(); |
| 162 | 162 |
| 163 // Emit control flow. Return must be the last instruction. | 163 // Emit control flow. Return must be the last instruction. |
| 164 BytecodeLabel start; | 164 BytecodeLabel start; |
| 165 builder.Bind(&start); | 165 builder.Bind(&start); |
| 166 // Short jumps with Imm8 operands | 166 // Short jumps with Imm8 operands |
| 167 builder.Jump(&start) | 167 builder.Jump(&start).JumpIfNull(&start).JumpIfUndefined(&start); |
| 168 .JumpIfNull(&start) | |
| 169 .JumpIfUndefined(&start); | |
| 170 // Perform an operation that returns boolean value to | 168 // Perform an operation that returns boolean value to |
| 171 // generate JumpIfTrue/False | 169 // generate JumpIfTrue/False |
| 172 builder.CompareOperation(Token::Value::EQ, reg, Strength::WEAK) | 170 builder.CompareOperation(Token::Value::EQ, reg, Strength::WEAK) |
| 173 .JumpIfTrue(&start) | 171 .JumpIfTrue(&start) |
| 174 .CompareOperation(Token::Value::EQ, reg, Strength::WEAK) | 172 .CompareOperation(Token::Value::EQ, reg, Strength::WEAK) |
| 175 .JumpIfFalse(&start); | 173 .JumpIfFalse(&start); |
| 176 // Perform an operation that returns a non-boolean operation to | 174 // Perform an operation that returns a non-boolean operation to |
| 177 // generate JumpIfToBooleanTrue/False. | 175 // generate JumpIfToBooleanTrue/False. |
| 178 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) | 176 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
| 179 .JumpIfTrue(&start) | 177 .JumpIfTrue(&start) |
| 180 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) | 178 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
| 181 .JumpIfFalse(&start); | 179 .JumpIfFalse(&start); |
| 182 // Insert dummy ops to force longer jumps | 180 // Insert dummy ops to force longer jumps |
| 183 for (int i = 0; i < 128; i++) { | 181 for (int i = 0; i < 128; i++) { |
| 184 builder.LoadTrue(); | 182 builder.LoadTrue(); |
| 185 } | 183 } |
| 186 // Longer jumps requiring Constant operand | 184 // Longer jumps requiring Constant operand |
| 187 builder.Jump(&start) | 185 builder.Jump(&start).JumpIfNull(&start).JumpIfUndefined(&start); |
| 188 .JumpIfNull(&start) | |
| 189 .JumpIfUndefined(&start); | |
| 190 // Perform an operation that returns boolean value to | 186 // Perform an operation that returns boolean value to |
| 191 // generate JumpIfTrue/False | 187 // generate JumpIfTrue/False |
| 192 builder.CompareOperation(Token::Value::EQ, reg, Strength::WEAK) | 188 builder.CompareOperation(Token::Value::EQ, reg, Strength::WEAK) |
| 193 .JumpIfTrue(&start) | 189 .JumpIfTrue(&start) |
| 194 .CompareOperation(Token::Value::EQ, reg, Strength::WEAK) | 190 .CompareOperation(Token::Value::EQ, reg, Strength::WEAK) |
| 195 .JumpIfFalse(&start); | 191 .JumpIfFalse(&start); |
| 196 // Perform an operation that returns a non-boolean operation to | 192 // Perform an operation that returns a non-boolean operation to |
| 197 // generate JumpIfToBooleanTrue/False. | 193 // generate JumpIfToBooleanTrue/False. |
| 198 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) | 194 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
| 199 .JumpIfTrue(&start) | 195 .JumpIfTrue(&start) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) | 274 builder.BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
| 279 .JumpIfTrue(&start) | 275 .JumpIfTrue(&start) |
| 280 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) | 276 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
| 281 .JumpIfFalse(&start); | 277 .JumpIfFalse(&start); |
| 282 | 278 |
| 283 builder.Return(); | 279 builder.Return(); |
| 284 | 280 |
| 285 // Generate BytecodeArray. | 281 // Generate BytecodeArray. |
| 286 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); | 282 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); |
| 287 CHECK_EQ(the_array->frame_size(), | 283 CHECK_EQ(the_array->frame_size(), |
| 288 builder.fixed_register_count() * kPointerSize); | 284 (builder.fixed_and_temporary_register_count() + |
| 285 builder.translation_register_count()) * |
| 286 kPointerSize); |
| 289 | 287 |
| 290 // Build scorecard of bytecodes encountered in the BytecodeArray. | 288 // Build scorecard of bytecodes encountered in the BytecodeArray. |
| 291 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); | 289 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); |
| 292 Bytecode final_bytecode = Bytecode::kLdaZero; | 290 Bytecode final_bytecode = Bytecode::kLdaZero; |
| 293 int i = 0; | 291 int i = 0; |
| 294 while (i < the_array->length()) { | 292 while (i < the_array->length()) { |
| 295 uint8_t code = the_array->get(i); | 293 uint8_t code = the_array->get(i); |
| 296 scorecard[code] += 1; | 294 scorecard[code] += 1; |
| 297 final_bytecode = Bytecodes::FromByte(code); | 295 final_bytecode = Bytecodes::FromByte(code); |
| 298 i += Bytecodes::Size(Bytecodes::FromByte(code)); | 296 i += Bytecodes::Size(Bytecodes::FromByte(code)); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 iterator.Advance(); | 678 iterator.Advance(); |
| 681 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 679 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
| 682 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 680 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
| 683 iterator.Advance(); | 681 iterator.Advance(); |
| 684 } | 682 } |
| 685 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 683 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
| 686 iterator.Advance(); | 684 iterator.Advance(); |
| 687 CHECK(iterator.done()); | 685 CHECK(iterator.done()); |
| 688 } | 686 } |
| 689 | 687 |
| 690 | |
| 691 } // namespace interpreter | 688 } // namespace interpreter |
| 692 } // namespace internal | 689 } // namespace internal |
| 693 } // namespace v8 | 690 } // namespace v8 |
| OLD | NEW |