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

Side by Side Diff: pkg/compiler/lib/src/ssa/graph_builder.dart

Issue 2637483002: Implement switch statement, without the "complex switch statement" (aka switch statement with conti… (Closed)
Patch Set: . Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import '../closure.dart'; 5 import '../closure.dart';
6 import '../common.dart'; 6 import '../common.dart';
7 import '../common/codegen.dart' show CodegenRegistry; 7 import '../common/codegen.dart' show CodegenRegistry;
8 import '../compiler.dart'; 8 import '../compiler.dart';
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../elements/resolution_types.dart'; 10 import '../elements/resolution_types.dart';
(...skipping 17 matching lines...) Expand all
28 /// This contains helpers for building the graph and tracking information about 28 /// This contains helpers for building the graph and tracking information about
29 /// the current state of the graph being built. 29 /// the current state of the graph being built.
30 abstract class GraphBuilder { 30 abstract class GraphBuilder {
31 /// Holds the resulting SSA graph. 31 /// Holds the resulting SSA graph.
32 final HGraph graph = new HGraph(); 32 final HGraph graph = new HGraph();
33 33
34 // TODO(het): remove this 34 // TODO(het): remove this
35 /// A reference to the compiler. 35 /// A reference to the compiler.
36 Compiler compiler; 36 Compiler compiler;
37 37
38 /// True if the builder is processing nodes inside a try statement. This is
39 /// important for generating control flow out of a try block like returns or
40 /// breaks.
41 bool inTryStatement = false;
42
38 /// The tree elements for the element being built into an SSA graph. 43 /// The tree elements for the element being built into an SSA graph.
39 TreeElements get elements; 44 TreeElements get elements;
40 45
41 /// The JavaScript backend we are targeting in this compilation. 46 /// The JavaScript backend we are targeting in this compilation.
42 JavaScriptBackend get backend; 47 JavaScriptBackend get backend;
43 48
44 CodegenRegistry get registry; 49 CodegenRegistry get registry;
45 50
46 ClosedWorld get closedWorld; 51 ClosedWorld get closedWorld;
47 52
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 HParameterValue result = new HParameterValue(parameter, type); 178 HParameterValue result = new HParameterValue(parameter, type);
174 if (lastAddedParameter == null) { 179 if (lastAddedParameter == null) {
175 graph.entry.addBefore(graph.entry.first, result); 180 graph.entry.addBefore(graph.entry.first, result);
176 } else { 181 } else {
177 graph.entry.addAfter(lastAddedParameter, result); 182 graph.entry.addAfter(lastAddedParameter, result);
178 } 183 }
179 lastAddedParameter = result; 184 lastAddedParameter = result;
180 return result; 185 return result;
181 } 186 }
182 187
183 void handleIf(
184 {ast.Node node,
185 void visitCondition(),
186 void visitThen(),
187 void visitElse(),
188 SourceInformation sourceInformation}) {
189 SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, compiler, node);
190 branchBuilder.handleIf(visitCondition, visitThen, visitElse,
191 sourceInformation: sourceInformation);
192 }
193
194 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { 188 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) {
195 if (statements == null) return null; 189 if (statements == null) return null;
196 return new HSubGraphBlockInformation(statements); 190 return new HSubGraphBlockInformation(statements);
197 } 191 }
198 192
199 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { 193 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) {
200 if (expression == null) return null; 194 if (expression == null) return null;
201 return new HSubExpressionBlockInformation(expression); 195 return new HSubExpressionBlockInformation(expression);
202 } 196 }
203 197
(...skipping 26 matching lines...) Expand all
230 224
231 HInstruction typeInfo = new HTypeInfoExpression( 225 HInstruction typeInfo = new HTypeInfoExpression(
232 TypeInfoExpressionKind.INSTANCE, 226 TypeInfoExpressionKind.INSTANCE,
233 (type.element as ClassElement).thisType, 227 (type.element as ClassElement).thisType,
234 rtiInputs, 228 rtiInputs,
235 closedWorld.commonMasks.dynamicType); 229 closedWorld.commonMasks.dynamicType);
236 add(typeInfo); 230 add(typeInfo);
237 return callSetRuntimeTypeInfo(typeInfo, newObject); 231 return callSetRuntimeTypeInfo(typeInfo, newObject);
238 } 232 }
239 233
234 /// Called when control flow is about to change, in which case we need to
235 /// specify special successors if we are already in a try/catch/finally block.
236 void handleInTryStatement() {
237 if (!inTryStatement) return;
238 HBasicBlock block = close(new HExitTry());
239 HBasicBlock newBlock = graph.addNewBlock();
240 block.addSuccessor(newBlock);
241 open(newBlock);
242 }
243
240 HInstruction callSetRuntimeTypeInfo( 244 HInstruction callSetRuntimeTypeInfo(
241 HInstruction typeInfo, HInstruction newObject); 245 HInstruction typeInfo, HInstruction newObject);
242 246
243 /// The element for which this SSA builder is being used. 247 /// The element for which this SSA builder is being used.
244 Element get targetElement; 248 Element get targetElement;
245 TypeBuilder get typeBuilder; 249 TypeBuilder get typeBuilder;
246 } 250 }
247 251
248 class ReifiedTypeRepresentationBuilder 252 class ReifiedTypeRepresentationBuilder
249 implements DartTypeVisitor<dynamic, GraphBuilder> { 253 implements DartTypeVisitor<dynamic, GraphBuilder> {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (unaliased is ResolutionTypedefType) throw 'unable to unalias $type'; 335 if (unaliased is ResolutionTypedefType) throw 'unable to unalias $type';
332 unaliased.accept(this, builder); 336 unaliased.accept(this, builder);
333 } 337 }
334 338
335 void visitDynamicType(ResolutionDynamicType type, GraphBuilder builder) { 339 void visitDynamicType(ResolutionDynamicType type, GraphBuilder builder) {
336 JavaScriptBackend backend = builder.compiler.backend; 340 JavaScriptBackend backend = builder.compiler.backend;
337 ClassElement cls = backend.helpers.DynamicRuntimeType; 341 ClassElement cls = backend.helpers.DynamicRuntimeType;
338 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); 342 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld)));
339 } 343 }
340 } 344 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder_kernel.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698