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/api.h" | 7 #include "src/api.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/interpreter/bytecode-array-writer.h" | 9 #include "src/interpreter/bytecode-array-writer.h" |
10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { | 158 TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { |
159 static const uint8_t expected_bytes[] = { | 159 static const uint8_t expected_bytes[] = { |
160 // clang-format off | 160 // clang-format off |
161 /* 0 30 E> */ B(StackCheck), | 161 /* 0 30 E> */ B(StackCheck), |
162 /* 1 42 S> */ B(LdaConstant), U8(0), | 162 /* 1 42 S> */ B(LdaConstant), U8(0), |
163 /* 3 42 E> */ B(Star), R8(1), | 163 /* 3 42 E> */ B(Star), R8(1), |
164 /* 5 68 S> */ B(JumpIfUndefined), U8(38), | 164 /* 5 68 S> */ B(JumpIfUndefined), U8(38), |
165 /* 7 */ B(JumpIfNull), U8(36), | 165 /* 7 */ B(JumpIfNull), U8(36), |
166 /* 9 */ B(ToObject), | 166 /* 9 */ B(ToObject), R8(3), |
167 /* 10 */ B(Star), R8(3), | 167 /* 11 */ B(ForInPrepare), R8(3), R8(4), |
168 /* 12 */ B(ForInPrepare), R8(4), | |
169 /* 14 */ B(LdaZero), | 168 /* 14 */ B(LdaZero), |
170 /* 15 */ B(Star), R8(7), | 169 /* 15 */ B(Star), R8(7), |
171 /* 17 63 S> */ B(ForInDone), R8(7), R8(6), | 170 /* 17 63 S> */ B(ForInDone), R8(7), R8(6), |
172 /* 20 */ B(JumpIfTrue), U8(23), | 171 /* 20 */ B(JumpIfTrue), U8(23), |
173 /* 22 */ B(ForInNext), R8(3), R8(7), R8(4), U8(1), | 172 /* 22 */ B(ForInNext), R8(3), R8(7), R8(4), U8(1), |
174 /* 27 */ B(JumpIfUndefined), U8(10), | 173 /* 27 */ B(JumpIfUndefined), U8(10), |
175 /* 29 */ B(Star), R8(0), | 174 /* 29 */ B(Star), R8(0), |
176 /* 31 54 E> */ B(StackCheck), | 175 /* 31 54 E> */ B(StackCheck), |
177 /* 32 */ B(Ldar), R8(0), | 176 /* 32 */ B(Ldar), R8(0), |
178 /* 34 */ B(Star), R8(2), | 177 /* 34 */ B(Star), R8(2), |
(...skipping 13 matching lines...) Expand all Loading... |
192 BytecodeLabel back_jump, jump_for_in, jump_end_1, jump_end_2, jump_end_3; | 191 BytecodeLabel back_jump, jump_for_in, jump_end_1, jump_end_2, jump_end_3; |
193 | 192 |
194 #define R(i) static_cast<uint32_t>(Register(i).ToOperand()) | 193 #define R(i) static_cast<uint32_t>(Register(i).ToOperand()) |
195 Write(Bytecode::kStackCheck, {30, false}); | 194 Write(Bytecode::kStackCheck, {30, false}); |
196 Write(Bytecode::kLdaConstant, U8(0), {42, true}); | 195 Write(Bytecode::kLdaConstant, U8(0), {42, true}); |
197 CHECK_EQ(max_register_count(), 0); | 196 CHECK_EQ(max_register_count(), 0); |
198 Write(Bytecode::kStar, R(1), {42, false}); | 197 Write(Bytecode::kStar, R(1), {42, false}); |
199 CHECK_EQ(max_register_count(), 2); | 198 CHECK_EQ(max_register_count(), 2); |
200 WriteJump(Bytecode::kJumpIfUndefined, &jump_end_1, {68, true}); | 199 WriteJump(Bytecode::kJumpIfUndefined, &jump_end_1, {68, true}); |
201 WriteJump(Bytecode::kJumpIfNull, &jump_end_2); | 200 WriteJump(Bytecode::kJumpIfNull, &jump_end_2); |
202 Write(Bytecode::kToObject); | 201 Write(Bytecode::kToObject, R(3)); |
203 CHECK_EQ(max_register_count(), 2); | |
204 Write(Bytecode::kStar, R(3)); | |
205 CHECK_EQ(max_register_count(), 4); | 202 CHECK_EQ(max_register_count(), 4); |
206 Write(Bytecode::kForInPrepare, R(4)); | 203 Write(Bytecode::kForInPrepare, R(3), R(4)); |
207 CHECK_EQ(max_register_count(), 7); | 204 CHECK_EQ(max_register_count(), 7); |
208 Write(Bytecode::kLdaZero); | 205 Write(Bytecode::kLdaZero); |
209 CHECK_EQ(max_register_count(), 7); | 206 CHECK_EQ(max_register_count(), 7); |
210 Write(Bytecode::kStar, R(7)); | 207 Write(Bytecode::kStar, R(7)); |
211 CHECK_EQ(max_register_count(), 8); | 208 CHECK_EQ(max_register_count(), 8); |
212 writer()->BindLabel(&back_jump); | 209 writer()->BindLabel(&back_jump); |
213 Write(Bytecode::kForInDone, R(7), R(6), {63, true}); | 210 Write(Bytecode::kForInDone, R(7), R(6), {63, true}); |
214 CHECK_EQ(max_register_count(), 8); | 211 CHECK_EQ(max_register_count(), 8); |
215 WriteJump(Bytecode::kJumpIfTrue, &jump_end_3); | 212 WriteJump(Bytecode::kJumpIfTrue, &jump_end_3); |
216 Write(Bytecode::kForInNext, R(3), R(7), R(4), U8(1)); | 213 Write(Bytecode::kForInNext, R(3), R(7), R(4), U8(1)); |
(...skipping 30 matching lines...) Expand all Loading... |
247 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 244 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
248 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 245 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
249 source_iterator.Advance(); | 246 source_iterator.Advance(); |
250 } | 247 } |
251 CHECK(source_iterator.done()); | 248 CHECK(source_iterator.done()); |
252 } | 249 } |
253 | 250 |
254 } // namespace interpreter | 251 } // namespace interpreter |
255 } // namespace internal | 252 } // namespace internal |
256 } // namespace v8 | 253 } // namespace v8 |
OLD | NEW |