OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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-pipeline.h" | 7 #include "src/interpreter/bytecode-pipeline.h" |
8 #include "src/interpreter/bytecode-register-allocator.h" | 8 #include "src/interpreter/bytecode-register-allocator.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 TEST_F(BytecodeNodeTest, Constructor0) { | 54 TEST_F(BytecodeNodeTest, Constructor0) { |
55 BytecodeNode node; | 55 BytecodeNode node; |
56 CHECK_EQ(node.bytecode(), Bytecode::kIllegal); | 56 CHECK_EQ(node.bytecode(), Bytecode::kIllegal); |
57 CHECK(!node.source_info().is_valid()); | 57 CHECK(!node.source_info().is_valid()); |
58 } | 58 } |
59 | 59 |
60 TEST_F(BytecodeNodeTest, Constructor1) { | 60 TEST_F(BytecodeNodeTest, Constructor1) { |
61 BytecodeNode node(Bytecode::kLdaZero); | 61 BytecodeNode node(Bytecode::kLdaZero); |
62 CHECK_EQ(node.bytecode(), Bytecode::kLdaZero); | 62 CHECK_EQ(node.bytecode(), Bytecode::kLdaZero); |
63 CHECK_EQ(node.operand_count(), 0); | 63 CHECK_EQ(node.operand_count(), 0); |
64 CHECK_EQ(node.operand_scale(), OperandScale::kSingle); | |
65 CHECK(!node.source_info().is_valid()); | 64 CHECK(!node.source_info().is_valid()); |
66 CHECK_EQ(node.Size(), 1); | |
67 } | 65 } |
68 | 66 |
69 TEST_F(BytecodeNodeTest, Constructor2) { | 67 TEST_F(BytecodeNodeTest, Constructor2) { |
70 uint32_t operands[] = {0x11}; | 68 uint32_t operands[] = {0x11}; |
71 BytecodeNode node(Bytecode::kJumpIfTrue, operands[0], OperandScale::kDouble); | 69 BytecodeNode node(Bytecode::kJumpIfTrue, operands[0]); |
72 CHECK_EQ(node.bytecode(), Bytecode::kJumpIfTrue); | 70 CHECK_EQ(node.bytecode(), Bytecode::kJumpIfTrue); |
73 CHECK_EQ(node.operand_count(), 1); | 71 CHECK_EQ(node.operand_count(), 1); |
74 CHECK_EQ(node.operand(0), operands[0]); | 72 CHECK_EQ(node.operand(0), operands[0]); |
75 CHECK_EQ(node.operand_scale(), OperandScale::kDouble); | |
76 CHECK(!node.source_info().is_valid()); | 73 CHECK(!node.source_info().is_valid()); |
77 CHECK_EQ(node.Size(), 4); | |
78 } | 74 } |
79 | 75 |
80 TEST_F(BytecodeNodeTest, Constructor3) { | 76 TEST_F(BytecodeNodeTest, Constructor3) { |
81 uint32_t operands[] = {0x11, 0x22}; | 77 uint32_t operands[] = {0x11, 0x22}; |
82 BytecodeNode node(Bytecode::kLdaGlobal, operands[0], operands[1], | 78 BytecodeNode node(Bytecode::kLdaGlobal, operands[0], operands[1]); |
83 OperandScale::kQuadruple); | |
84 CHECK_EQ(node.bytecode(), Bytecode::kLdaGlobal); | 79 CHECK_EQ(node.bytecode(), Bytecode::kLdaGlobal); |
85 CHECK_EQ(node.operand_count(), 2); | 80 CHECK_EQ(node.operand_count(), 2); |
86 CHECK_EQ(node.operand(0), operands[0]); | 81 CHECK_EQ(node.operand(0), operands[0]); |
87 CHECK_EQ(node.operand(1), operands[1]); | 82 CHECK_EQ(node.operand(1), operands[1]); |
88 CHECK_EQ(node.operand_scale(), OperandScale::kQuadruple); | |
89 CHECK(!node.source_info().is_valid()); | 83 CHECK(!node.source_info().is_valid()); |
90 CHECK_EQ(node.Size(), 10); | |
91 } | 84 } |
92 | 85 |
93 TEST_F(BytecodeNodeTest, Constructor4) { | 86 TEST_F(BytecodeNodeTest, Constructor4) { |
94 uint32_t operands[] = {0x11, 0x22, 0x33}; | 87 uint32_t operands[] = {0x11, 0x22, 0x33}; |
95 BytecodeNode node(Bytecode::kLdaNamedProperty, operands[0], operands[1], | 88 BytecodeNode node(Bytecode::kLdaNamedProperty, operands[0], operands[1], |
96 operands[2], OperandScale::kSingle); | 89 operands[2]); |
97 CHECK_EQ(node.operand_count(), 3); | 90 CHECK_EQ(node.operand_count(), 3); |
98 CHECK_EQ(node.bytecode(), Bytecode::kLdaNamedProperty); | 91 CHECK_EQ(node.bytecode(), Bytecode::kLdaNamedProperty); |
99 CHECK_EQ(node.operand(0), operands[0]); | 92 CHECK_EQ(node.operand(0), operands[0]); |
100 CHECK_EQ(node.operand(1), operands[1]); | 93 CHECK_EQ(node.operand(1), operands[1]); |
101 CHECK_EQ(node.operand(2), operands[2]); | 94 CHECK_EQ(node.operand(2), operands[2]); |
102 CHECK_EQ(node.operand_scale(), OperandScale::kSingle); | |
103 CHECK(!node.source_info().is_valid()); | 95 CHECK(!node.source_info().is_valid()); |
104 CHECK_EQ(node.Size(), 4); | |
105 } | 96 } |
106 | 97 |
107 TEST_F(BytecodeNodeTest, Constructor5) { | 98 TEST_F(BytecodeNodeTest, Constructor5) { |
108 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 99 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
109 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 100 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
110 operands[3], OperandScale::kDouble); | 101 operands[3]); |
111 CHECK_EQ(node.operand_count(), 4); | 102 CHECK_EQ(node.operand_count(), 4); |
112 CHECK_EQ(node.bytecode(), Bytecode::kForInNext); | 103 CHECK_EQ(node.bytecode(), Bytecode::kForInNext); |
113 CHECK_EQ(node.operand(0), operands[0]); | 104 CHECK_EQ(node.operand(0), operands[0]); |
114 CHECK_EQ(node.operand(1), operands[1]); | 105 CHECK_EQ(node.operand(1), operands[1]); |
115 CHECK_EQ(node.operand(2), operands[2]); | 106 CHECK_EQ(node.operand(2), operands[2]); |
116 CHECK_EQ(node.operand(3), operands[3]); | 107 CHECK_EQ(node.operand(3), operands[3]); |
117 CHECK_EQ(node.operand_scale(), OperandScale::kDouble); | |
118 CHECK(!node.source_info().is_valid()); | 108 CHECK(!node.source_info().is_valid()); |
119 CHECK_EQ(node.Size(), 10); | |
120 } | 109 } |
121 | 110 |
122 TEST_F(BytecodeNodeTest, Equality) { | 111 TEST_F(BytecodeNodeTest, Equality) { |
123 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 112 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
124 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 113 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
125 operands[3], OperandScale::kDouble); | 114 operands[3]); |
126 CHECK_EQ(node, node); | 115 CHECK_EQ(node, node); |
127 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 116 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
128 operands[2], operands[3], OperandScale::kDouble); | 117 operands[2], operands[3]); |
129 CHECK_EQ(node, other); | 118 CHECK_EQ(node, other); |
130 } | 119 } |
131 | 120 |
132 TEST_F(BytecodeNodeTest, EqualityWithSourceInfo) { | 121 TEST_F(BytecodeNodeTest, EqualityWithSourceInfo) { |
133 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 122 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
134 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 123 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
135 operands[3], OperandScale::kDouble); | 124 operands[3]); |
136 node.source_info().Update({3, true}); | 125 node.source_info().Update({3, true}); |
137 CHECK_EQ(node, node); | 126 CHECK_EQ(node, node); |
138 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 127 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
139 operands[2], operands[3], OperandScale::kDouble); | 128 operands[2], operands[3]); |
140 other.source_info().Update({3, true}); | 129 other.source_info().Update({3, true}); |
141 CHECK_EQ(node, other); | 130 CHECK_EQ(node, other); |
142 } | 131 } |
143 | 132 |
144 TEST_F(BytecodeNodeTest, NoEqualityWithDifferentSourceInfo) { | 133 TEST_F(BytecodeNodeTest, NoEqualityWithDifferentSourceInfo) { |
145 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 134 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
146 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 135 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
147 operands[3], OperandScale::kDouble); | 136 operands[3]); |
148 node.source_info().Update({3, true}); | 137 node.source_info().Update({3, true}); |
149 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 138 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
150 operands[2], operands[3], OperandScale::kDouble); | 139 operands[2], operands[3]); |
151 CHECK_NE(node, other); | 140 CHECK_NE(node, other); |
152 } | 141 } |
153 | 142 |
154 TEST_F(BytecodeNodeTest, Clone) { | 143 TEST_F(BytecodeNodeTest, Clone) { |
155 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 144 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
156 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 145 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
157 operands[3], OperandScale::kDouble); | 146 operands[3]); |
158 BytecodeNode clone; | 147 BytecodeNode clone; |
159 clone.Clone(&node); | 148 clone.Clone(&node); |
160 CHECK_EQ(clone, node); | 149 CHECK_EQ(clone, node); |
161 } | 150 } |
162 | 151 |
163 TEST_F(BytecodeNodeTest, SetBytecode0) { | 152 TEST_F(BytecodeNodeTest, SetBytecode0) { |
164 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 153 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
165 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 154 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
166 operands[3], OperandScale::kDouble); | 155 operands[3]); |
167 BytecodeSourceInfo source_info(77, false); | 156 BytecodeSourceInfo source_info(77, false); |
168 node.source_info().Update(source_info); | 157 node.source_info().Update(source_info); |
169 | 158 |
170 BytecodeNode clone; | 159 BytecodeNode clone; |
171 clone.Clone(&node); | 160 clone.Clone(&node); |
172 clone.set_bytecode(Bytecode::kNop); | 161 clone.set_bytecode(Bytecode::kNop); |
173 CHECK_EQ(clone.bytecode(), Bytecode::kNop); | 162 CHECK_EQ(clone.bytecode(), Bytecode::kNop); |
174 CHECK_EQ(clone.operand_count(), 0); | 163 CHECK_EQ(clone.operand_count(), 0); |
175 CHECK_EQ(clone.operand_scale(), OperandScale::kSingle); | |
176 CHECK_EQ(clone.source_info(), source_info); | 164 CHECK_EQ(clone.source_info(), source_info); |
177 } | 165 } |
178 | 166 |
179 TEST_F(BytecodeNodeTest, SetBytecode1) { | 167 TEST_F(BytecodeNodeTest, SetBytecode1) { |
180 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 168 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
181 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 169 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
182 operands[3], OperandScale::kDouble); | 170 operands[3]); |
183 BytecodeSourceInfo source_info(77, false); | 171 BytecodeSourceInfo source_info(77, false); |
184 node.source_info().Update(source_info); | 172 node.source_info().Update(source_info); |
185 | 173 |
186 BytecodeNode clone; | 174 BytecodeNode clone; |
187 clone.Clone(&node); | 175 clone.Clone(&node); |
188 clone.set_bytecode(Bytecode::kJump, 0x01aabbcc, OperandScale::kQuadruple); | 176 clone.set_bytecode(Bytecode::kJump, 0x01aabbcc); |
189 CHECK_EQ(clone.bytecode(), Bytecode::kJump); | 177 CHECK_EQ(clone.bytecode(), Bytecode::kJump); |
190 CHECK_EQ(clone.operand_count(), 1); | 178 CHECK_EQ(clone.operand_count(), 1); |
191 CHECK_EQ(clone.operand(0), 0x01aabbcc); | 179 CHECK_EQ(clone.operand(0), 0x01aabbcc); |
192 CHECK_EQ(clone.operand_scale(), OperandScale::kQuadruple); | |
193 CHECK_EQ(clone.source_info(), source_info); | 180 CHECK_EQ(clone.source_info(), source_info); |
194 } | 181 } |
195 | 182 |
196 } // namespace interpreter | 183 } // namespace interpreter |
197 } // namespace internal | 184 } // namespace internal |
198 } // namespace v8 | 185 } // namespace v8 |
OLD | NEW |