| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 expected = (expr->op() == Token::OR) | 219 expected = (expr->op() == Token::OR) |
| 220 ? Expression::kTest | 220 ? Expression::kTest |
| 221 : Expression::kTestValue; | 221 : Expression::kTestValue; |
| 222 break; | 222 break; |
| 223 } | 223 } |
| 224 ASSERT_EQ(expected, expr->left()->context()); | 224 ASSERT_EQ(expected, expr->left()->context()); |
| 225 ASSERT_EQ(expr->context(), expr->right()->context()); | 225 ASSERT_EQ(expr->context(), expr->right()->context()); |
| 226 #endif | 226 #endif |
| 227 | 227 |
| 228 Label eval_right, done; | 228 Label eval_right, done; |
| 229 Label* saved_true = true_label_; | |
| 230 Label* saved_false = false_label_; | |
| 231 | 229 |
| 232 // Set up the appropriate context for the left subexpression based on the | 230 // Set up the appropriate context for the left subexpression based |
| 233 // operation and our own context. | 231 // on the operation and our own context. Initially assume we can |
| 232 // inherit both true and false labels from our context. |
| 233 Label* if_true = true_label_; |
| 234 Label* if_false = false_label_; |
| 234 if (expr->op() == Token::OR) { | 235 if (expr->op() == Token::OR) { |
| 235 // If there is no usable true label in the OR expression's context, use | 236 // If we are not in some kind of a test context, we did not inherit a |
| 236 // the end of this expression, otherwise inherit the same true label. | 237 // true label from our context. Use the end of the expression. |
| 237 if (expr->context() == Expression::kEffect || | 238 if (expr->context() == Expression::kEffect || |
| 238 expr->context() == Expression::kValue) { | 239 expr->context() == Expression::kValue) { |
| 239 true_label_ = &done; | 240 if_true = &done; |
| 240 } | 241 } |
| 241 // The false label is the label of the second subexpression. | 242 // The false label is the label of the right subexpression. |
| 242 false_label_ = &eval_right; | 243 if_false = &eval_right; |
| 243 } else { | 244 } else { |
| 244 ASSERT_EQ(Token::AND, expr->op()); | 245 ASSERT_EQ(Token::AND, expr->op()); |
| 245 // The true label is the label of the second subexpression. | 246 // The true label is the label of the right subexpression. |
| 246 true_label_ = &eval_right; | 247 if_true = &eval_right; |
| 247 // If there is no usable false label in the AND expression's context, | 248 // If we are not in some kind of a test context, we did not inherit a |
| 248 // use the end of the expression, otherwise inherit the same false | 249 // false label from our context. Use the end of the expression. |
| 249 // label. | |
| 250 if (expr->context() == Expression::kEffect || | 250 if (expr->context() == Expression::kEffect || |
| 251 expr->context() == Expression::kValue) { | 251 expr->context() == Expression::kValue) { |
| 252 false_label_ = &done; | 252 if_false = &done; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 VisitForControl(expr->left(), if_true, if_false); |
| 256 Visit(expr->left()); | |
| 257 true_label_ = saved_true; | |
| 258 false_label_ = saved_false; | |
| 259 | 256 |
| 260 __ bind(&eval_right); | 257 __ bind(&eval_right); |
| 261 Visit(expr->right()); | 258 Visit(expr->right()); |
| 262 | 259 |
| 263 __ bind(&done); | 260 __ bind(&done); |
| 264 } | 261 } |
| 265 | 262 |
| 266 | 263 |
| 267 void FastCodeGenerator::VisitBlock(Block* stmt) { | 264 void FastCodeGenerator::VisitBlock(Block* stmt) { |
| 268 Comment cmnt(masm_, "[ Block"); | 265 Comment cmnt(masm_, "[ Block"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 281 | 278 |
| 282 | 279 |
| 283 void FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { | 280 void FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
| 284 Comment cmnt(masm_, "[ EmptyStatement"); | 281 Comment cmnt(masm_, "[ EmptyStatement"); |
| 285 SetStatementPosition(stmt); | 282 SetStatementPosition(stmt); |
| 286 } | 283 } |
| 287 | 284 |
| 288 | 285 |
| 289 void FastCodeGenerator::VisitIfStatement(IfStatement* stmt) { | 286 void FastCodeGenerator::VisitIfStatement(IfStatement* stmt) { |
| 290 Comment cmnt(masm_, "[ IfStatement"); | 287 Comment cmnt(masm_, "[ IfStatement"); |
| 291 // Expressions cannot recursively enter statements, there are no labels in | |
| 292 // the state. | |
| 293 ASSERT_EQ(NULL, true_label_); | |
| 294 ASSERT_EQ(NULL, false_label_); | |
| 295 Label then_part, else_part, done; | 288 Label then_part, else_part, done; |
| 296 | 289 |
| 297 // Do not worry about optimizing for empty then or else bodies. | 290 // Do not worry about optimizing for empty then or else bodies. |
| 298 true_label_ = &then_part; | 291 VisitForControl(stmt->condition(), &then_part, &else_part); |
| 299 false_label_ = &else_part; | |
| 300 ASSERT(stmt->condition()->context() == Expression::kTest); | |
| 301 Visit(stmt->condition()); | |
| 302 true_label_ = NULL; | |
| 303 false_label_ = NULL; | |
| 304 | 292 |
| 305 __ bind(&then_part); | 293 __ bind(&then_part); |
| 306 Visit(stmt->then_statement()); | 294 Visit(stmt->then_statement()); |
| 307 __ jmp(&done); | 295 __ jmp(&done); |
| 308 | 296 |
| 309 __ bind(&else_part); | 297 __ bind(&else_part); |
| 310 Visit(stmt->else_statement()); | 298 Visit(stmt->else_statement()); |
| 311 | 299 |
| 312 __ bind(&done); | 300 __ bind(&done); |
| 313 } | 301 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 Iteration loop_statement(this, stmt); | 399 Iteration loop_statement(this, stmt); |
| 412 increment_loop_depth(); | 400 increment_loop_depth(); |
| 413 | 401 |
| 414 __ bind(&body); | 402 __ bind(&body); |
| 415 Visit(stmt->body()); | 403 Visit(stmt->body()); |
| 416 | 404 |
| 417 // Check stack before looping. | 405 // Check stack before looping. |
| 418 __ StackLimitCheck(&stack_limit_hit); | 406 __ StackLimitCheck(&stack_limit_hit); |
| 419 __ bind(&stack_check_success); | 407 __ bind(&stack_check_success); |
| 420 | 408 |
| 421 // We are not in an expression context because we have been compiling | |
| 422 // statements. Set up a test expression context for the condition. | |
| 423 __ bind(loop_statement.continue_target()); | 409 __ bind(loop_statement.continue_target()); |
| 424 ASSERT_EQ(NULL, true_label_); | 410 VisitForControl(stmt->cond(), &body, loop_statement.break_target()); |
| 425 ASSERT_EQ(NULL, false_label_); | |
| 426 true_label_ = &body; | |
| 427 false_label_ = loop_statement.break_target(); | |
| 428 ASSERT(stmt->cond()->context() == Expression::kTest); | |
| 429 Visit(stmt->cond()); | |
| 430 true_label_ = NULL; | |
| 431 false_label_ = NULL; | |
| 432 | 411 |
| 433 __ bind(&stack_limit_hit); | 412 __ bind(&stack_limit_hit); |
| 434 StackCheckStub stack_stub; | 413 StackCheckStub stack_stub; |
| 435 __ CallStub(&stack_stub); | 414 __ CallStub(&stack_stub); |
| 436 __ jmp(&stack_check_success); | 415 __ jmp(&stack_check_success); |
| 437 | 416 |
| 438 __ bind(loop_statement.break_target()); | 417 __ bind(loop_statement.break_target()); |
| 439 | 418 |
| 440 decrement_loop_depth(); | 419 decrement_loop_depth(); |
| 441 } | 420 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 452 __ jmp(loop_statement.continue_target()); | 431 __ jmp(loop_statement.continue_target()); |
| 453 | 432 |
| 454 __ bind(&body); | 433 __ bind(&body); |
| 455 Visit(stmt->body()); | 434 Visit(stmt->body()); |
| 456 | 435 |
| 457 __ bind(loop_statement.continue_target()); | 436 __ bind(loop_statement.continue_target()); |
| 458 // Check stack before looping. | 437 // Check stack before looping. |
| 459 __ StackLimitCheck(&stack_limit_hit); | 438 __ StackLimitCheck(&stack_limit_hit); |
| 460 __ bind(&stack_check_success); | 439 __ bind(&stack_check_success); |
| 461 | 440 |
| 462 // We are not in an expression context because we have been compiling | 441 VisitForControl(stmt->cond(), &body, loop_statement.break_target()); |
| 463 // statements. Set up a test expression context for the condition. | |
| 464 ASSERT_EQ(NULL, true_label_); | |
| 465 ASSERT_EQ(NULL, false_label_); | |
| 466 true_label_ = &body; | |
| 467 false_label_ = loop_statement.break_target(); | |
| 468 ASSERT(stmt->cond()->context() == Expression::kTest); | |
| 469 Visit(stmt->cond()); | |
| 470 true_label_ = NULL; | |
| 471 false_label_ = NULL; | |
| 472 | 442 |
| 473 __ bind(&stack_limit_hit); | 443 __ bind(&stack_limit_hit); |
| 474 StackCheckStub stack_stub; | 444 StackCheckStub stack_stub; |
| 475 __ CallStub(&stack_stub); | 445 __ CallStub(&stack_stub); |
| 476 __ jmp(&stack_check_success); | 446 __ jmp(&stack_check_success); |
| 477 | 447 |
| 478 __ bind(loop_statement.break_target()); | 448 __ bind(loop_statement.break_target()); |
| 479 decrement_loop_depth(); | 449 decrement_loop_depth(); |
| 480 } | 450 } |
| 481 | 451 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 585 |
| 616 | 586 |
| 617 void FastCodeGenerator::VisitConditional(Conditional* expr) { | 587 void FastCodeGenerator::VisitConditional(Conditional* expr) { |
| 618 Comment cmnt(masm_, "[ Conditional"); | 588 Comment cmnt(masm_, "[ Conditional"); |
| 619 ASSERT_EQ(Expression::kTest, expr->condition()->context()); | 589 ASSERT_EQ(Expression::kTest, expr->condition()->context()); |
| 620 ASSERT_EQ(expr->context(), expr->then_expression()->context()); | 590 ASSERT_EQ(expr->context(), expr->then_expression()->context()); |
| 621 ASSERT_EQ(expr->context(), expr->else_expression()->context()); | 591 ASSERT_EQ(expr->context(), expr->else_expression()->context()); |
| 622 | 592 |
| 623 | 593 |
| 624 Label true_case, false_case, done; | 594 Label true_case, false_case, done; |
| 625 Label* saved_true = true_label_; | 595 VisitForControl(expr->condition(), &true_case, &false_case); |
| 626 Label* saved_false = false_label_; | |
| 627 | |
| 628 true_label_ = &true_case; | |
| 629 false_label_ = &false_case; | |
| 630 Visit(expr->condition()); | |
| 631 true_label_ = saved_true; | |
| 632 false_label_ = saved_false; | |
| 633 | 596 |
| 634 __ bind(&true_case); | 597 __ bind(&true_case); |
| 635 Visit(expr->then_expression()); | 598 Visit(expr->then_expression()); |
| 636 // If control flow falls through Visit, jump to done. | 599 // If control flow falls through Visit, jump to done. |
| 637 if (expr->context() == Expression::kEffect || | 600 if (expr->context() == Expression::kEffect || |
| 638 expr->context() == Expression::kValue) { | 601 expr->context() == Expression::kValue) { |
| 639 __ jmp(&done); | 602 __ jmp(&done); |
| 640 } | 603 } |
| 641 | 604 |
| 642 __ bind(&false_case); | 605 __ bind(&false_case); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 __ Drop(stack_depth); | 745 __ Drop(stack_depth); |
| 783 __ PopTryHandler(); | 746 __ PopTryHandler(); |
| 784 return 0; | 747 return 0; |
| 785 } | 748 } |
| 786 | 749 |
| 787 | 750 |
| 788 #undef __ | 751 #undef __ |
| 789 | 752 |
| 790 | 753 |
| 791 } } // namespace v8::internal | 754 } } // namespace v8::internal |
| OLD | NEW |