Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: src/fast-codegen.cc

Issue 340058: Add conditional expressions (ternary choice operator) to fast compiler. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/fast-codegen.cc
===================================================================
--- src/fast-codegen.cc (revision 3191)
+++ src/fast-codegen.cc (working copy)
@@ -380,7 +380,36 @@
void FastCodeGenerator::VisitConditional(Conditional* expr) {
- UNREACHABLE();
+ ASSERT_EQ(Expression::kTest, expr->condition()->context());
+ ASSERT_EQ(expr->context(), expr->then_expression()->context());
+ ASSERT_EQ(expr->context(), expr->else_expression()->context());
+
+
+ Label true_case, false_case, done;
+ Label* saved_true = true_label_;
+ Label* saved_false = false_label_;
+
+ true_label_ = &true_case;
+ false_label_ = &false_case;
+ Visit(expr->condition());
+ true_label_ = saved_true;
+ false_label_ = saved_false;
+
+ __ bind(&true_case);
+ Visit(expr->then_expression());
+ // If control flow falls through Visit, jump to done.
+ if (expr->context() == Expression::kEffect ||
+ expr->context() == Expression::kValue) {
+ __ jmp(&done);
+ }
+
+ __ bind(&false_case);
+ Visit(expr->else_expression());
+ // If control flow falls through Visit, merge it with true case here.
+ if (expr->context() == Expression::kEffect ||
+ expr->context() == Expression::kValue) {
+ __ bind(&done);
+ }
}
« no previous file with comments | « src/compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698