OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
8 SsaCodeGeneratorTask generator; | 8 SsaCodeGeneratorTask generator; |
9 SsaBuilderTask builder; | 9 SsaBuilderTask builder; |
10 SsaOptimizerTask optimizer; | 10 SsaOptimizerTask optimizer; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 /// A synthetic local variable only used with the SSA graph. | 83 /// A synthetic local variable only used with the SSA graph. |
84 /// | 84 /// |
85 /// For instance used for holding return value of function or the exception of a | 85 /// For instance used for holding return value of function or the exception of a |
86 /// try-catch statement. | 86 /// try-catch statement. |
87 class SyntheticLocal extends Local { | 87 class SyntheticLocal extends Local { |
88 final String name; | 88 final String name; |
89 final ExecutableElement executableContext; | 89 final ExecutableElement executableContext; |
90 | 90 |
91 SyntheticLocal(this.name, this.executableContext); | 91 SyntheticLocal(this.name, this.executableContext); |
| 92 |
| 93 toString() => 'SyntheticLocal($name)'; |
92 } | 94 } |
93 | 95 |
94 class SsaBuilderTask extends CompilerTask { | 96 class SsaBuilderTask extends CompilerTask { |
95 final CodeEmitterTask emitter; | 97 final CodeEmitterTask emitter; |
96 final JavaScriptBackend backend; | 98 final JavaScriptBackend backend; |
97 final bool generateSourceMap; | 99 final bool generateSourceMap; |
98 | 100 |
99 String get name => 'SSA builder'; | 101 String get name => 'SSA builder'; |
100 | 102 |
101 SsaBuilderTask(JavaScriptBackend backend, this.generateSourceMap) | 103 SsaBuilderTask(JavaScriptBackend backend, this.generateSourceMap) |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // 'upgrades' the native subclass object by initializing the Dart fields. | 384 // 'upgrades' the native subclass object by initializing the Dart fields. |
383 bool isNativeUpgradeFactory = element.isGenerativeConstructor | 385 bool isNativeUpgradeFactory = element.isGenerativeConstructor |
384 && Elements.isNativeOrExtendsNative(cls); | 386 && Elements.isNativeOrExtendsNative(cls); |
385 if (backend.isInterceptedMethod(element)) { | 387 if (backend.isInterceptedMethod(element)) { |
386 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); | 388 bool isInterceptorClass = backend.isInterceptorClass(cls.declaration); |
387 String name = isInterceptorClass ? 'receiver' : '_'; | 389 String name = isInterceptorClass ? 'receiver' : '_'; |
388 SyntheticLocal parameter = new SyntheticLocal(name, executableContext); | 390 SyntheticLocal parameter = new SyntheticLocal(name, executableContext); |
389 HParameterValue value = | 391 HParameterValue value = |
390 new HParameterValue(parameter, builder.getTypeOfThis()); | 392 new HParameterValue(parameter, builder.getTypeOfThis()); |
391 builder.graph.explicitReceiverParameter = value; | 393 builder.graph.explicitReceiverParameter = value; |
392 builder.graph.entry.addAfter( | 394 builder.graph.entry.addAfter(directLocals[closureData.thisLocal], value); |
393 directLocals[closureData.thisLocal], value); | 395 if (builder.lastAddedParameter == null) { |
| 396 // If this is the first parameter inserted, make sure it stays first. |
| 397 builder.lastAddedParameter = value; |
| 398 } |
394 if (isInterceptorClass) { | 399 if (isInterceptorClass) { |
395 // Only use the extra parameter in intercepted classes. | 400 // Only use the extra parameter in intercepted classes. |
396 directLocals[closureData.thisLocal] = value; | 401 directLocals[closureData.thisLocal] = value; |
397 } | 402 } |
398 } else if (isNativeUpgradeFactory) { | 403 } else if (isNativeUpgradeFactory) { |
399 SyntheticLocal parameter = | 404 SyntheticLocal parameter = |
400 new SyntheticLocal('receiver', executableContext); | 405 new SyntheticLocal('receiver', executableContext); |
401 // Unlike `this`, receiver is nullable since direct calls to generative | 406 // Unlike `this`, receiver is nullable since direct calls to generative |
402 // constructor call the constructor with `null`. | 407 // constructor call the constructor with `null`. |
403 ClassWorld classWorld = compiler.world; | 408 ClassWorld classWorld = compiler.world; |
(...skipping 6543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6947 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 6952 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
6948 unaliased.accept(this, builder); | 6953 unaliased.accept(this, builder); |
6949 } | 6954 } |
6950 | 6955 |
6951 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 6956 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
6952 JavaScriptBackend backend = builder.compiler.backend; | 6957 JavaScriptBackend backend = builder.compiler.backend; |
6953 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 6958 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
6954 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 6959 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
6955 } | 6960 } |
6956 } | 6961 } |
OLD | NEW |