| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/ast-loop-assignment-analyzer.h" | 8 #include "src/compiler/ast-loop-assignment-analyzer.h" |
| 9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
| 10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 | 1197 |
| 1198 void AstGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) { | 1198 void AstGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) { |
| 1199 ZoneList<CaseClause*>* clauses = stmt->cases(); | 1199 ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 1200 SwitchBuilder compare_switch(this, clauses->length()); | 1200 SwitchBuilder compare_switch(this, clauses->length()); |
| 1201 ControlScopeForBreakable scope(this, stmt, &compare_switch); | 1201 ControlScopeForBreakable scope(this, stmt, &compare_switch); |
| 1202 compare_switch.BeginSwitch(); | 1202 compare_switch.BeginSwitch(); |
| 1203 int default_index = -1; | 1203 int default_index = -1; |
| 1204 | 1204 |
| 1205 // Keep the switch value on the stack until a case matches. | 1205 // Keep the switch value on the stack until a case matches. |
| 1206 VisitForValue(stmt->tag()); | 1206 VisitForValue(stmt->tag()); |
| 1207 Node* tag = environment()->Top(); | |
| 1208 | 1207 |
| 1209 // Iterate over all cases and create nodes for label comparison. | 1208 // Iterate over all cases and create nodes for label comparison. |
| 1210 for (int i = 0; i < clauses->length(); i++) { | 1209 for (int i = 0; i < clauses->length(); i++) { |
| 1211 CaseClause* clause = clauses->at(i); | 1210 CaseClause* clause = clauses->at(i); |
| 1212 | 1211 |
| 1213 // The default is not a test, remember index. | 1212 // The default is not a test, remember index. |
| 1214 if (clause->is_default()) { | 1213 if (clause->is_default()) { |
| 1215 default_index = i; | 1214 default_index = i; |
| 1216 continue; | 1215 continue; |
| 1217 } | 1216 } |
| 1218 | 1217 |
| 1219 // Create nodes to perform label comparison as if via '==='. The switch | 1218 // Create nodes to perform label comparison as if via '==='. The switch |
| 1220 // value is still on the operand stack while the label is evaluated. | 1219 // value is still on the operand stack while the label is evaluated. |
| 1221 VisitForValue(clause->label()); | 1220 VisitForValue(clause->label()); |
| 1222 Node* label = environment()->Pop(); | 1221 Node* label = environment()->Pop(); |
| 1222 Node* tag = environment()->Top(); |
| 1223 const Operator* op = javascript()->StrictEqual(); | 1223 const Operator* op = javascript()->StrictEqual(); |
| 1224 Node* condition = NewNode(op, tag, label); | 1224 Node* condition = NewNode(op, tag, label); |
| 1225 compare_switch.BeginLabel(i, condition); | 1225 compare_switch.BeginLabel(i, condition); |
| 1226 | 1226 |
| 1227 // Discard the switch value at label match. | 1227 // Discard the switch value at label match. |
| 1228 environment()->Pop(); | 1228 environment()->Pop(); |
| 1229 compare_switch.EndLabel(); | 1229 compare_switch.EndLabel(); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 // Discard the switch value and mark the default case. | 1232 // Discard the switch value and mark the default case. |
| (...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4296 // Phi does not exist yet, introduce one. | 4296 // Phi does not exist yet, introduce one. |
| 4297 value = NewPhi(inputs, value, control); | 4297 value = NewPhi(inputs, value, control); |
| 4298 value->ReplaceInput(inputs - 1, other); | 4298 value->ReplaceInput(inputs - 1, other); |
| 4299 } | 4299 } |
| 4300 return value; | 4300 return value; |
| 4301 } | 4301 } |
| 4302 | 4302 |
| 4303 } // namespace compiler | 4303 } // namespace compiler |
| 4304 } // namespace internal | 4304 } // namespace internal |
| 4305 } // namespace v8 | 4305 } // namespace v8 |
| OLD | NEW |