OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/interpreter/bytecode-pipeline.h" |
| 8 #include "src/interpreter/bytecode-register-allocator.h" |
| 9 #include "src/isolate.h" |
| 10 #include "test/unittests/test-utils.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 namespace interpreter { |
| 15 |
| 16 using BytecodeNodeTest = TestWithIsolateAndZone; |
| 17 |
| 18 TEST(BytecodeSourceInfo, Operations) { |
| 19 BytecodeSourceInfo x(0, true); |
| 20 CHECK_EQ(x.source_position(), 0); |
| 21 CHECK_EQ(x.is_statement(), true); |
| 22 CHECK_EQ(x.is_valid(), true); |
| 23 x.set_invalid(); |
| 24 CHECK_EQ(x.is_statement(), false); |
| 25 CHECK_EQ(x.is_valid(), false); |
| 26 |
| 27 x.Update({1, true}); |
| 28 BytecodeSourceInfo y(1, true); |
| 29 CHECK(x == y); |
| 30 CHECK(!(x != y)); |
| 31 |
| 32 x.set_invalid(); |
| 33 CHECK(!(x == y)); |
| 34 CHECK(x != y); |
| 35 |
| 36 y.Update({2, false}); |
| 37 CHECK_EQ(y.source_position(), 1); |
| 38 CHECK_EQ(y.is_statement(), true); |
| 39 |
| 40 y.Update({2, true}); |
| 41 CHECK_EQ(y.source_position(), 2); |
| 42 CHECK_EQ(y.is_statement(), true); |
| 43 |
| 44 y.set_invalid(); |
| 45 y.Update({3, false}); |
| 46 CHECK_EQ(y.source_position(), 3); |
| 47 CHECK_EQ(y.is_statement(), false); |
| 48 |
| 49 y.Update({3, true}); |
| 50 CHECK_EQ(y.source_position(), 3); |
| 51 CHECK_EQ(y.is_statement(), true); |
| 52 } |
| 53 |
| 54 TEST_F(BytecodeNodeTest, Constructor0) { |
| 55 BytecodeNode node; |
| 56 CHECK_EQ(node.bytecode(), Bytecode::kIllegal); |
| 57 CHECK(!node.source_info().is_valid()); |
| 58 } |
| 59 |
| 60 TEST_F(BytecodeNodeTest, Constructor1) { |
| 61 BytecodeNode node(Bytecode::kLdaZero); |
| 62 CHECK_EQ(node.bytecode(), Bytecode::kLdaZero); |
| 63 CHECK_EQ(node.operand_count(), 0); |
| 64 CHECK_EQ(node.operand_scale(), OperandScale::kSingle); |
| 65 CHECK(!node.source_info().is_valid()); |
| 66 CHECK_EQ(node.Size(), 1); |
| 67 } |
| 68 |
| 69 TEST_F(BytecodeNodeTest, Constructor2) { |
| 70 uint32_t operands[] = {0x11}; |
| 71 BytecodeNode node(Bytecode::kJumpIfTrue, operands[0], OperandScale::kDouble); |
| 72 CHECK_EQ(node.bytecode(), Bytecode::kJumpIfTrue); |
| 73 CHECK_EQ(node.operand_count(), 1); |
| 74 CHECK_EQ(node.operand(0), operands[0]); |
| 75 CHECK_EQ(node.operand_scale(), OperandScale::kDouble); |
| 76 CHECK(!node.source_info().is_valid()); |
| 77 CHECK_EQ(node.Size(), 4); |
| 78 } |
| 79 |
| 80 TEST_F(BytecodeNodeTest, Constructor3) { |
| 81 uint32_t operands[] = {0x11, 0x22}; |
| 82 BytecodeNode node(Bytecode::kLdaGlobal, operands[0], operands[1], |
| 83 OperandScale::kQuadruple); |
| 84 CHECK_EQ(node.bytecode(), Bytecode::kLdaGlobal); |
| 85 CHECK_EQ(node.operand_count(), 2); |
| 86 CHECK_EQ(node.operand(0), operands[0]); |
| 87 CHECK_EQ(node.operand(1), operands[1]); |
| 88 CHECK_EQ(node.operand_scale(), OperandScale::kQuadruple); |
| 89 CHECK(!node.source_info().is_valid()); |
| 90 CHECK_EQ(node.Size(), 10); |
| 91 } |
| 92 |
| 93 TEST_F(BytecodeNodeTest, Constructor4) { |
| 94 uint32_t operands[] = {0x11, 0x22, 0x33}; |
| 95 BytecodeNode node(Bytecode::kLoadIC, operands[0], operands[1], operands[2], |
| 96 OperandScale::kSingle); |
| 97 CHECK_EQ(node.operand_count(), 3); |
| 98 CHECK_EQ(node.bytecode(), Bytecode::kLoadIC); |
| 99 CHECK_EQ(node.operand(0), operands[0]); |
| 100 CHECK_EQ(node.operand(1), operands[1]); |
| 101 CHECK_EQ(node.operand(2), operands[2]); |
| 102 CHECK_EQ(node.operand_scale(), OperandScale::kSingle); |
| 103 CHECK(!node.source_info().is_valid()); |
| 104 CHECK_EQ(node.Size(), 4); |
| 105 } |
| 106 |
| 107 TEST_F(BytecodeNodeTest, Constructor5) { |
| 108 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 109 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 110 operands[3], OperandScale::kDouble); |
| 111 CHECK_EQ(node.operand_count(), 4); |
| 112 CHECK_EQ(node.bytecode(), Bytecode::kForInNext); |
| 113 CHECK_EQ(node.operand(0), operands[0]); |
| 114 CHECK_EQ(node.operand(1), operands[1]); |
| 115 CHECK_EQ(node.operand(2), operands[2]); |
| 116 CHECK_EQ(node.operand(3), operands[3]); |
| 117 CHECK_EQ(node.operand_scale(), OperandScale::kDouble); |
| 118 CHECK(!node.source_info().is_valid()); |
| 119 CHECK_EQ(node.Size(), 10); |
| 120 } |
| 121 |
| 122 TEST_F(BytecodeNodeTest, Equality) { |
| 123 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 124 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 125 operands[3], OperandScale::kDouble); |
| 126 CHECK_EQ(node, node); |
| 127 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
| 128 operands[2], operands[3], OperandScale::kDouble); |
| 129 CHECK_EQ(node, other); |
| 130 } |
| 131 |
| 132 TEST_F(BytecodeNodeTest, EqualityWithSourceInfo) { |
| 133 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 134 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 135 operands[3], OperandScale::kDouble); |
| 136 node.source_info().Update({3, true}); |
| 137 CHECK_EQ(node, node); |
| 138 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
| 139 operands[2], operands[3], OperandScale::kDouble); |
| 140 other.source_info().Update({3, true}); |
| 141 CHECK_EQ(node, other); |
| 142 } |
| 143 |
| 144 TEST_F(BytecodeNodeTest, NoEqualityWithDifferentSourceInfo) { |
| 145 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 146 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 147 operands[3], OperandScale::kDouble); |
| 148 node.source_info().Update({3, true}); |
| 149 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
| 150 operands[2], operands[3], OperandScale::kDouble); |
| 151 CHECK_NE(node, other); |
| 152 } |
| 153 |
| 154 TEST_F(BytecodeNodeTest, Clone) { |
| 155 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 156 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 157 operands[3], OperandScale::kDouble); |
| 158 BytecodeNode clone; |
| 159 clone.Clone(&node); |
| 160 CHECK_EQ(clone, node); |
| 161 } |
| 162 |
| 163 TEST_F(BytecodeNodeTest, SetBytecode0) { |
| 164 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 165 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 166 operands[3], OperandScale::kDouble); |
| 167 BytecodeSourceInfo source_info(77, false); |
| 168 node.source_info().Update(source_info); |
| 169 |
| 170 BytecodeNode clone; |
| 171 clone.Clone(&node); |
| 172 clone.set_bytecode(Bytecode::kNop); |
| 173 CHECK_EQ(clone.bytecode(), Bytecode::kNop); |
| 174 CHECK_EQ(clone.operand_count(), 0); |
| 175 CHECK_EQ(clone.operand_scale(), OperandScale::kSingle); |
| 176 CHECK_EQ(clone.source_info(), source_info); |
| 177 } |
| 178 |
| 179 TEST_F(BytecodeNodeTest, SetBytecode1) { |
| 180 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
| 181 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
| 182 operands[3], OperandScale::kDouble); |
| 183 BytecodeSourceInfo source_info(77, false); |
| 184 node.source_info().Update(source_info); |
| 185 |
| 186 BytecodeNode clone; |
| 187 clone.Clone(&node); |
| 188 clone.set_bytecode(Bytecode::kJump, 0x01aabbcc, OperandScale::kQuadruple); |
| 189 CHECK_EQ(clone.bytecode(), Bytecode::kJump); |
| 190 CHECK_EQ(clone.operand_count(), 1); |
| 191 CHECK_EQ(clone.operand(0), 0x01aabbcc); |
| 192 CHECK_EQ(clone.operand_scale(), OperandScale::kQuadruple); |
| 193 CHECK_EQ(clone.source_info(), source_info); |
| 194 } |
| 195 |
| 196 } // namespace interpreter |
| 197 } // namespace internal |
| 198 } // namespace v8 |
OLD | NEW |