Chromium Code Reviews| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 97 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 98 Comment cmnt(masm_, "[ ExpressionStatement"); | 98 Comment cmnt(masm_, "[ ExpressionStatement"); |
| 99 SetStatementPosition(stmt); | 99 SetStatementPosition(stmt); |
| 100 Visit(stmt->expression()); | 100 Visit(stmt->expression()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 104 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 105 Comment cmnt(masm_, "[ ReturnStatement"); | 105 Comment cmnt(masm_, "[ ReturnStatement"); |
| 106 SetStatementPosition(stmt); | 106 SetStatementPosition(stmt); |
| 107 Visit(stmt->expression()); | 107 Expression* expr = stmt->expression(); |
| 108 __ pop(eax); | 108 Visit(expr); |
| 109 | |
| 110 // Complete the statement based on the location of the subexpression. | |
| 111 Location source = expr->location(); | |
| 112 ASSERT(!source.is_nowhere()); | |
| 113 if (source.is_temporary()) { | |
| 114 __ pop(eax); | |
| 115 } else { | |
| 116 ASSERT(source.is_constant()); | |
| 117 ASSERT(expr->AsLiteral() != NULL); | |
| 118 __ mov(eax, expr->AsLiteral()->handle()); | |
| 119 } | |
| 109 __ RecordJSReturn(); | 120 __ RecordJSReturn(); |
| 110 // Do not use the leave instruction here because it is too short to | 121 // Do not use the leave instruction here because it is too short to |
| 111 // patch with the code required by the debugger. | 122 // patch with the code required by the debugger. |
| 112 __ mov(esp, ebp); | 123 __ mov(esp, ebp); |
| 113 __ pop(ebp); | 124 __ pop(ebp); |
| 114 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); | 125 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
| 115 } | 126 } |
| 116 | 127 |
| 117 | 128 |
| 118 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { | 129 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 119 Comment cmnt(masm_, "[ VariableProxy"); | 130 Comment cmnt(masm_, "[ VariableProxy"); |
| 120 Expression* rewrite = expr->var()->rewrite(); | 131 Expression* rewrite = expr->var()->rewrite(); |
| 121 ASSERT(rewrite != NULL); | 132 ASSERT(rewrite != NULL); |
| 122 | 133 |
| 123 Slot* slot = rewrite->AsSlot(); | 134 Slot* slot = rewrite->AsSlot(); |
| 124 ASSERT(slot != NULL); | 135 ASSERT(slot != NULL); |
| 125 { Comment cmnt(masm_, "[ Slot"); | 136 { Comment cmnt(masm_, "[ Slot"); |
| 126 if (expr->location().is_temporary()) { | 137 if (expr->location().is_temporary()) { |
| 127 __ push(Operand(ebp, SlotOffset(slot))); | 138 __ push(Operand(ebp, SlotOffset(slot))); |
| 128 } else { | 139 } else { |
| 129 ASSERT(expr->location().is_nowhere()); | 140 ASSERT(expr->location().is_nowhere()); |
| 130 } | 141 } |
| 131 } | 142 } |
| 132 } | 143 } |
| 133 | 144 |
| 134 | 145 |
| 135 void FastCodeGenerator::VisitLiteral(Literal* expr) { | |
| 136 Comment cmnt(masm_, "[ Literal"); | |
| 137 if (expr->location().is_temporary()) { | |
| 138 __ push(Immediate(expr->handle())); | |
| 139 } else { | |
| 140 ASSERT(expr->location().is_nowhere()); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 | |
| 145 void FastCodeGenerator::VisitAssignment(Assignment* expr) { | 146 void FastCodeGenerator::VisitAssignment(Assignment* expr) { |
| 146 Comment cmnt(masm_, "[ Assignment"); | 147 Comment cmnt(masm_, "[ Assignment"); |
| 147 ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR); | 148 ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR); |
| 148 Visit(expr->value()); | 149 Expression* rhs = expr->value(); |
| 150 Visit(rhs); | |
| 149 | 151 |
| 152 // Left-hand side is always a (parameter or local) slot. | |
| 150 Variable* var = expr->target()->AsVariableProxy()->AsVariable(); | 153 Variable* var = expr->target()->AsVariableProxy()->AsVariable(); |
| 151 ASSERT(var != NULL && var->slot() != NULL); | 154 ASSERT(var != NULL && var->slot() != NULL); |
| 152 | 155 |
| 153 if (expr->location().is_temporary()) { | 156 // Complete the assignment based on the location of the right-hand-side |
| 154 __ mov(eax, Operand(esp, 0)); | 157 // value and the desired location of the assignment value. |
| 158 Location destination = expr->location(); | |
| 159 Location source = rhs->location(); | |
| 160 ASSERT(!destination.is_constant()); | |
| 161 ASSERT(!source.is_nowhere()); | |
| 162 | |
| 163 if (source.is_temporary()) { | |
| 164 if (destination.is_temporary()) { | |
| 165 // Case 'temp1 <- (var = temp0)'. Preserve right-hand-side temporary | |
| 166 // on the stack. | |
| 167 __ mov(eax, Operand(esp, 0)); | |
| 168 __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | |
| 169 } else { | |
| 170 ASSERT(destination.is_nowhere()); | |
| 171 // Case 'var = temp'. Discard right-hand-side temporary. | |
| 172 __ pop(Operand(ebp, SlotOffset(var->slot()))); | |
| 173 } | |
| 174 } else { | |
| 175 ASSERT(source.is_constant()); | |
| 176 ASSERT(rhs->AsLiteral() != NULL); | |
| 177 // Two cases: 'temp <- (var = constant)', or 'var = constant' with a | |
| 178 // discarded result. Always perform the assignment. | |
| 179 __ mov(eax, rhs->AsLiteral()->handle()); | |
| 155 __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 180 __ mov(Operand(ebp, SlotOffset(var->slot())), eax); |
| 156 } else { | 181 if (destination.is_temporary()) { |
| 157 ASSERT(expr->location().is_nowhere()); | 182 // Case 'temp <- (var = constant)'. Save result. |
| 158 __ pop(Operand(ebp, SlotOffset(var->slot()))); | 183 __ push(eax); |
|
fschneider
2009/10/19 09:21:38
LGTM. As a future optimization: Do we have to push
| |
| 184 } | |
| 159 } | 185 } |
| 160 } | 186 } |
| 161 | 187 |
| 162 | 188 |
| 163 } } // namespace v8::internal | 189 } } // namespace v8::internal |
| OLD | NEW |