OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 TEST(PrimitiveExpressions) { | 229 TEST(PrimitiveExpressions) { |
230 InitializedHandleScope handle_scope; | 230 InitializedHandleScope handle_scope; |
231 BytecodeGeneratorHelper helper; | 231 BytecodeGeneratorHelper helper; |
232 | 232 |
233 ExpectedSnippet<int> snippets[] = { | 233 ExpectedSnippet<int> snippets[] = { |
234 {"var x = 0; return x;", | 234 {"var x = 0; return x;", |
235 kPointerSize, | 235 kPointerSize, |
236 1, | 236 1, |
237 6, | 237 6, |
238 { | 238 {B(LdaZero), // |
239 B(LdaZero), // | 239 B(Star), R(0), // |
240 B(Star), R(0), // | 240 B(Ldar), R(0), // |
241 B(Ldar), R(0), // | 241 B(Return)}, |
242 B(Return) // | |
243 }, | |
244 0}, | 242 0}, |
245 {"var x = 0; return x + 3;", | 243 {"var x = 0; return x + 3;", |
246 2 * kPointerSize, | 244 2 * kPointerSize, |
247 1, | 245 1, |
248 12, | 246 12, |
249 { | 247 {B(LdaZero), // |
250 B(LdaZero), // | 248 B(Star), R(0), // |
251 B(Star), R(0), // | 249 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
252 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 250 B(Star), R(1), // Dead store. |
253 B(Star), R(1), // Dead store. | 251 B(LdaSmi8), U8(3), // |
254 B(LdaSmi8), U8(3), // | 252 B(Add), R(1), // |
255 B(Add), R(1), // | 253 B(Return)}, |
256 B(Return) // | |
257 }, | |
258 0}, | 254 0}, |
259 {"var x = 0; return x - 3;", | 255 {"var x = 0; return x - 3;", |
260 2 * kPointerSize, | 256 2 * kPointerSize, |
261 1, | 257 1, |
262 12, | 258 12, |
263 { | 259 {B(LdaZero), // |
264 B(LdaZero), // | 260 B(Star), R(0), // |
265 B(Star), R(0), // | 261 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
266 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 262 B(Star), R(1), // Dead store. |
267 B(Star), R(1), // Dead store. | 263 B(LdaSmi8), U8(3), // |
268 B(LdaSmi8), U8(3), // | 264 B(Sub), R(1), // |
269 B(Sub), R(1), // | 265 B(Return)}, |
270 B(Return) // | |
271 }, | |
272 0}, | 266 0}, |
273 {"var x = 4; return x * 3;", | 267 {"var x = 4; return x * 3;", |
274 2 * kPointerSize, | 268 2 * kPointerSize, |
275 1, | 269 1, |
276 13, | 270 13, |
277 { | 271 {B(LdaSmi8), U8(4), // |
278 B(LdaSmi8), U8(4), // | 272 B(Star), R(0), // |
279 B(Star), R(0), // | 273 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
280 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 274 B(Star), R(1), // Dead store. |
281 B(Star), R(1), // Dead store. | 275 B(LdaSmi8), U8(3), // |
282 B(LdaSmi8), U8(3), // | 276 B(Mul), R(1), // |
283 B(Mul), R(1), // | 277 B(Return)}, |
284 B(Return) // | |
285 }, | |
286 0}, | 278 0}, |
287 {"var x = 4; return x / 3;", | 279 {"var x = 4; return x / 3;", |
288 2 * kPointerSize, | 280 2 * kPointerSize, |
289 1, | 281 1, |
290 13, | 282 13, |
291 { | 283 {B(LdaSmi8), U8(4), // |
292 B(LdaSmi8), U8(4), // | 284 B(Star), R(0), // |
293 B(Star), R(0), // | 285 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
294 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 286 B(Star), R(1), // Dead store. |
295 B(Star), R(1), // Dead store. | 287 B(LdaSmi8), U8(3), // |
296 B(LdaSmi8), U8(3), // | 288 B(Div), R(1), // |
297 B(Div), R(1), // | 289 B(Return)}, |
298 B(Return) // | |
299 }, | |
300 0}, | 290 0}, |
301 {"var x = 4; return x % 3;", | 291 {"var x = 4; return x % 3;", |
302 2 * kPointerSize, | 292 2 * kPointerSize, |
303 1, | 293 1, |
304 13, | 294 13, |
305 { | 295 {B(LdaSmi8), U8(4), // |
306 B(LdaSmi8), U8(4), // | 296 B(Star), R(0), // |
307 B(Star), R(0), // | 297 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
308 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 298 B(Star), R(1), // Dead store. |
309 B(Star), R(1), // Dead store. | 299 B(LdaSmi8), U8(3), // |
310 B(LdaSmi8), U8(3), // | 300 B(Mod), R(1), // |
311 B(Mod), R(1), // | 301 B(Return)}, |
312 B(Return) // | |
313 }, | |
314 0}, | 302 0}, |
315 {"var x = 1; return x | 2;", | 303 {"var x = 1; return x | 2;", |
316 2 * kPointerSize, | 304 2 * kPointerSize, |
317 1, | 305 1, |
318 13, | 306 13, |
319 { | 307 {B(LdaSmi8), U8(1), // |
320 B(LdaSmi8), U8(1), // | 308 B(Star), R(0), // |
321 B(Star), R(0), // | 309 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
322 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 310 B(Star), R(1), // Dead store. |
323 B(Star), R(1), // Dead store. | 311 B(LdaSmi8), U8(2), // |
324 B(LdaSmi8), U8(2), // | 312 B(BitwiseOr), R(1), // |
325 B(BitwiseOr), R(1), // | 313 B(Return)}, |
326 B(Return) // | |
327 }, | |
328 0}, | 314 0}, |
329 {"var x = 1; return x ^ 2;", | 315 {"var x = 1; return x ^ 2;", |
330 2 * kPointerSize, | 316 2 * kPointerSize, |
331 1, | 317 1, |
332 13, | 318 13, |
333 { | 319 {B(LdaSmi8), U8(1), // |
334 B(LdaSmi8), U8(1), // | 320 B(Star), R(0), // |
335 B(Star), R(0), // | 321 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
336 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 322 B(Star), R(1), // Dead store. |
337 B(Star), R(1), // Dead store. | 323 B(LdaSmi8), U8(2), // |
338 B(LdaSmi8), U8(2), // | 324 B(BitwiseXor), R(1), // |
339 B(BitwiseXor), R(1), // | 325 B(Return)}, |
340 B(Return) // | |
341 }, | |
342 0}, | 326 0}, |
343 {"var x = 1; return x & 2;", | 327 {"var x = 1; return x & 2;", |
344 2 * kPointerSize, | 328 2 * kPointerSize, |
345 1, | 329 1, |
346 13, | 330 13, |
347 { | 331 {B(LdaSmi8), U8(1), // |
348 B(LdaSmi8), U8(1), // | 332 B(Star), R(0), // |
349 B(Star), R(0), // | 333 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
350 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 334 B(Star), R(1), // Dead store. |
351 B(Star), R(1), // Dead store. | 335 B(LdaSmi8), U8(2), // |
352 B(LdaSmi8), U8(2), // | 336 B(BitwiseAnd), R(1), // |
353 B(BitwiseAnd), R(1), // | 337 B(Return)}, |
354 B(Return) // | |
355 }, | |
356 0}, | 338 0}, |
357 {"var x = 10; return x << 3;", | 339 {"var x = 10; return x << 3;", |
358 2 * kPointerSize, | 340 2 * kPointerSize, |
359 1, | 341 1, |
360 13, | 342 13, |
361 { | 343 {B(LdaSmi8), U8(10), // |
362 B(LdaSmi8), U8(10), // | 344 B(Star), R(0), // |
363 B(Star), R(0), // | 345 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
364 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 346 B(Star), R(1), // Dead store. |
365 B(Star), R(1), // Dead store. | 347 B(LdaSmi8), U8(3), // |
366 B(LdaSmi8), U8(3), // | 348 B(ShiftLeft), R(1), // |
367 B(ShiftLeft), R(1), // | 349 B(Return)}, |
368 B(Return) // | |
369 }, | |
370 0}, | 350 0}, |
371 {"var x = 10; return x >> 3;", | 351 {"var x = 10; return x >> 3;", |
372 2 * kPointerSize, | 352 2 * kPointerSize, |
373 1, | 353 1, |
374 13, | 354 13, |
375 { | 355 {B(LdaSmi8), U8(10), // |
376 B(LdaSmi8), U8(10), // | 356 B(Star), R(0), // |
377 B(Star), R(0), // | 357 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
378 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 358 B(Star), R(1), // Dead store. |
379 B(Star), R(1), // Dead store. | 359 B(LdaSmi8), U8(3), // |
380 B(LdaSmi8), U8(3), // | 360 B(ShiftRight), R(1), // |
381 B(ShiftRight), R(1), // | 361 B(Return)}, |
382 B(Return) // | |
383 }, | |
384 0}, | 362 0}, |
385 {"var x = 10; return x >>> 3;", | 363 {"var x = 10; return x >>> 3;", |
386 2 * kPointerSize, | 364 2 * kPointerSize, |
387 1, | 365 1, |
388 13, | 366 13, |
389 { | 367 {B(LdaSmi8), U8(10), // |
390 B(LdaSmi8), U8(10), // | 368 B(Star), R(0), // |
391 B(Star), R(0), // | 369 B(Ldar), R(0), // Easy to spot r1 not really needed here. |
392 B(Ldar), R(0), // Easy to spot r1 not really needed here. | 370 B(Star), R(1), // Dead store. |
393 B(Star), R(1), // Dead store. | 371 B(LdaSmi8), U8(3), // |
394 B(LdaSmi8), U8(3), // | 372 B(ShiftRightLogical), R(1), // |
395 B(ShiftRightLogical), R(1), // | 373 B(Return)}, |
396 B(Return) // | 374 0}, |
397 }, | 375 {"var x = 0; return (x, 3);", |
| 376 1 * kPointerSize, |
| 377 1, |
| 378 8, |
| 379 {B(LdaZero), // |
| 380 B(Star), R(0), // |
| 381 B(Ldar), R(0), // |
| 382 B(LdaSmi8), U8(3), // |
| 383 B(Return)}, |
398 0}}; | 384 0}}; |
399 | 385 |
400 for (size_t i = 0; i < arraysize(snippets); i++) { | 386 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 387 Handle<BytecodeArray> bytecode_array = |
| 388 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 389 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 390 } |
| 391 } |
| 392 |
| 393 |
| 394 TEST(LogicalExpressions) { |
| 395 InitializedHandleScope handle_scope; |
| 396 BytecodeGeneratorHelper helper; |
| 397 |
| 398 |
| 399 ExpectedSnippet<int> snippets[] = { |
| 400 {"var x = 0; return x || 3;", |
| 401 1 * kPointerSize, |
| 402 1, |
| 403 10, |
| 404 {B(LdaZero), // |
| 405 B(Star), R(0), // |
| 406 B(Ldar), R(0), // |
| 407 B(JumpIfToBooleanTrue), U8(4), // |
| 408 B(LdaSmi8), U8(3), // |
| 409 B(Return)}, |
| 410 0}, |
| 411 {"var x = 0; return x && 3;", |
| 412 1 * kPointerSize, |
| 413 1, |
| 414 10, |
| 415 {B(LdaZero), // |
| 416 B(Star), R(0), // |
| 417 B(Ldar), R(0), // |
| 418 B(JumpIfToBooleanFalse), U8(4), // |
| 419 B(LdaSmi8), U8(3), // |
| 420 B(Return)}, |
| 421 0}, |
| 422 {"var x = 1; var a = 2, b = 3; return x || (" |
| 423 #define X "a, b, a, b, " |
| 424 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X |
| 425 #undef X |
| 426 "3);", |
| 427 3 * kPointerSize, |
| 428 1, |
| 429 283, |
| 430 {B(LdaSmi8), U8(1), // |
| 431 B(Star), R(0), // |
| 432 B(LdaSmi8), U8(2), // |
| 433 B(Star), R(1), // |
| 434 B(LdaSmi8), U8(3), // |
| 435 B(Star), R(2), // |
| 436 B(Ldar), R(0), // |
| 437 B(JumpIfToBooleanTrueConstant), U8(0), // |
| 438 #define X B(Ldar), R(1), B(Ldar), R(2), B(Ldar), R(1), B(Ldar), R(2), |
| 439 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X |
| 440 #undef X |
| 441 B(LdaSmi8), U8(3), // |
| 442 B(Return)}, |
| 443 1, |
| 444 {268, 0, 0, 0}}, |
| 445 {"var x = 0; var a = 2, b = 3; return x && (" |
| 446 #define X "a, b, a, b, " |
| 447 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X |
| 448 #undef X |
| 449 "3);", |
| 450 3 * kPointerSize, |
| 451 1, |
| 452 282, |
| 453 {B(LdaZero), // |
| 454 B(Star), R(0), // |
| 455 B(LdaSmi8), U8(2), // |
| 456 B(Star), R(1), // |
| 457 B(LdaSmi8), U8(3), // |
| 458 B(Star), R(2), // |
| 459 B(Ldar), R(0), // |
| 460 B(JumpIfToBooleanFalseConstant), U8(0), // |
| 461 #define X B(Ldar), R(1), B(Ldar), R(2), B(Ldar), R(1), B(Ldar), R(2), |
| 462 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X |
| 463 #undef X |
| 464 B(LdaSmi8), U8(3), // |
| 465 B(Return)}, |
| 466 1, |
| 467 {268, 0, 0, 0}}, |
| 468 {"return 0 && 3;", |
| 469 0 * kPointerSize, |
| 470 1, |
| 471 2, |
| 472 {B(LdaZero), // |
| 473 B(Return)}, |
| 474 0}, |
| 475 {"return 1 || 3;", |
| 476 0 * kPointerSize, |
| 477 1, |
| 478 3, |
| 479 {B(LdaSmi8), U8(1), // |
| 480 B(Return)}, |
| 481 0}, |
| 482 {"var x = 1; return x && 3 || 0, 1;", |
| 483 1 * kPointerSize, |
| 484 1, |
| 485 16, |
| 486 {B(LdaSmi8), U8(1), // |
| 487 B(Star), R(0), // |
| 488 B(Ldar), R(0), // |
| 489 B(JumpIfToBooleanFalse), U8(4), // |
| 490 B(LdaSmi8), U8(3), // |
| 491 B(JumpIfToBooleanTrue), U8(3), // |
| 492 B(LdaZero), // |
| 493 B(LdaSmi8), U8(1), // |
| 494 B(Return)}, |
| 495 0}}; |
| 496 |
| 497 for (size_t i = 0; i < arraysize(snippets); i++) { |
401 Handle<BytecodeArray> bytecode_array = | 498 Handle<BytecodeArray> bytecode_array = |
402 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 499 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
403 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 500 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
404 } | 501 } |
405 } | 502 } |
406 | 503 |
407 | 504 |
408 TEST(Parameters) { | 505 TEST(Parameters) { |
409 InitializedHandleScope handle_scope; | 506 InitializedHandleScope handle_scope; |
410 BytecodeGeneratorHelper helper; | 507 BytecodeGeneratorHelper helper; |
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 for (size_t i = 0; i < arraysize(snippets); i++) { | 2144 for (size_t i = 0; i < arraysize(snippets); i++) { |
2048 Handle<BytecodeArray> bytecode_array = | 2145 Handle<BytecodeArray> bytecode_array = |
2049 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2146 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2050 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2147 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2051 } | 2148 } |
2052 } | 2149 } |
2053 | 2150 |
2054 } // namespace interpreter | 2151 } // namespace interpreter |
2055 } // namespace internal | 2152 } // namespace internal |
2056 } // namespace v8 | 2153 } // namespace v8 |
OLD | NEW |