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

Side by Side Diff: test/unittests/interpreter/bytecode-array-builder-unittest.cc

Issue 1507683005: [Interpreter] Removes ToBoolean bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased the patch. Created 5 years 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 | « test/cctest/interpreter/test-interpreter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "test/unittests/test-utils.h" 9 #include "test/unittests/test-utils.h"
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 .CompareOperation(Token::Value::NE_STRICT, reg, Strength::WEAK) 152 .CompareOperation(Token::Value::NE_STRICT, reg, Strength::WEAK)
153 .CompareOperation(Token::Value::LT, reg, Strength::WEAK) 153 .CompareOperation(Token::Value::LT, reg, Strength::WEAK)
154 .CompareOperation(Token::Value::GT, reg, Strength::WEAK) 154 .CompareOperation(Token::Value::GT, reg, Strength::WEAK)
155 .CompareOperation(Token::Value::LTE, reg, Strength::WEAK) 155 .CompareOperation(Token::Value::LTE, reg, Strength::WEAK)
156 .CompareOperation(Token::Value::GTE, reg, Strength::WEAK) 156 .CompareOperation(Token::Value::GTE, reg, Strength::WEAK)
157 .CompareOperation(Token::Value::INSTANCEOF, reg, Strength::WEAK) 157 .CompareOperation(Token::Value::INSTANCEOF, reg, Strength::WEAK)
158 .CompareOperation(Token::Value::IN, reg, Strength::WEAK); 158 .CompareOperation(Token::Value::IN, reg, Strength::WEAK);
159 159
160 // Emit cast operator invocations. 160 // Emit cast operator invocations.
161 builder.CastAccumulatorToNumber() 161 builder.CastAccumulatorToNumber()
162 .CastAccumulatorToBoolean()
163 .CastAccumulatorToJSObject() 162 .CastAccumulatorToJSObject()
164 .CastAccumulatorToName(); 163 .CastAccumulatorToName();
165 164
166 // Emit control flow. Return must be the last instruction. 165 // Emit control flow. Return must be the last instruction.
167 BytecodeLabel start; 166 BytecodeLabel start;
168 builder.Bind(&start); 167 builder.Bind(&start);
169 // Short jumps with Imm8 operands 168 // Short jumps with Imm8 operands
170 builder.Jump(&start) 169 builder.Jump(&start)
171 .JumpIfNull(&start) 170 .JumpIfNull(&start)
172 .JumpIfUndefined(&start); 171 .JumpIfUndefined(&start);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 iterator.Advance(); 650 iterator.Advance();
652 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 651 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
653 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 652 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
654 iterator.Advance(); 653 iterator.Advance();
655 } 654 }
656 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); 655 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
657 iterator.Advance(); 656 iterator.Advance();
658 CHECK(iterator.done()); 657 CHECK(iterator.done());
659 } 658 }
660 659
661
662 TEST_F(BytecodeArrayBuilderTest, ToBoolean) {
663 BytecodeArrayBuilder builder(isolate(), zone());
664 builder.set_parameter_count(0);
665 builder.set_locals_count(0);
666 builder.set_context_count(0);
667
668 // Check ToBoolean emitted at start of a basic block.
669 builder.CastAccumulatorToBoolean();
670
671 // Check ToBoolean emitted preceding bytecode is non-boolean.
672 builder.LoadNull().CastAccumulatorToBoolean();
673
674 // Check ToBoolean omitted if preceding bytecode is boolean.
675 builder.LoadFalse().CastAccumulatorToBoolean();
676
677 // Check ToBoolean emitted if it is at the start of a basic block caused by a
678 // bound label.
679 BytecodeLabel label;
680 builder.LoadFalse()
681 .Bind(&label)
682 .CastAccumulatorToBoolean();
683
684 // Check ToBoolean emitted if it is at the start of a basic block caused by a
685 // jump.
686 builder.LoadFalse()
687 .JumpIfTrue(&label)
688 .CastAccumulatorToBoolean();
689
690 builder.Return();
691
692 Handle<BytecodeArray> array = builder.ToBytecodeArray();
693 BytecodeArrayIterator iterator(array);
694 CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
695 iterator.Advance();
696
697 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaNull);
698 iterator.Advance();
699 CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
700 iterator.Advance();
701
702 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
703 iterator.Advance();
704
705 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
706 iterator.Advance();
707 CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
708 iterator.Advance();
709
710 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
711 iterator.Advance();
712 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
713 iterator.Advance();
714 CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
715 iterator.Advance();
716
717 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
718 iterator.Advance();
719 CHECK(iterator.done());
720 }
721
722
723 } // namespace interpreter 660 } // namespace interpreter
724 } // namespace internal 661 } // namespace internal
725 } // namespace v8 662 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698