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 3399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3410 TypeMask type = | 3410 TypeMask type = |
3411 TypeMaskFactory.inferredTypeForElement(field, compiler); | 3411 TypeMaskFactory.inferredTypeForElement(field, compiler); |
3412 if (!type.containsAll(compiler.world) && | 3412 if (!type.containsAll(compiler.world) && |
3413 !instruction.isConstantNull()) { | 3413 !instruction.isConstantNull()) { |
3414 // TODO(13429): The inferrer should know that an element | 3414 // TODO(13429): The inferrer should know that an element |
3415 // cannot be null. | 3415 // cannot be null. |
3416 instruction.instructionType = type.nonNullable(); | 3416 instruction.instructionType = type.nonNullable(); |
3417 } | 3417 } |
3418 } | 3418 } |
3419 | 3419 |
| 3420 @override |
| 3421 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) { |
| 3422 generateIsDeferredLoadedCheckIfNeeded(prefix, node); |
| 3423 } |
| 3424 |
3420 /// Read a static or top level [field]. | 3425 /// Read a static or top level [field]. |
3421 void generateStaticFieldGet(ast.Send node, FieldElement field) { | 3426 void generateStaticFieldGet(ast.Send node, FieldElement field) { |
3422 generateIsDeferredLoadedCheckOfSend(node); | |
3423 | |
3424 ConstantExpression constant = | 3427 ConstantExpression constant = |
3425 backend.constants.getConstantForVariable(field); | 3428 backend.constants.getConstantForVariable(field); |
3426 SourceInformation sourceInformation = | 3429 SourceInformation sourceInformation = |
3427 sourceInformationBuilder.buildGet(node); | 3430 sourceInformationBuilder.buildGet(node); |
3428 if (constant != null) { | 3431 if (constant != null) { |
3429 if (!field.isAssignable) { | 3432 if (!field.isAssignable) { |
3430 // A static final or const. Get its constant value and inline it if | 3433 // A static final or const. Get its constant value and inline it if |
3431 // the value can be compiled eagerly. | 3434 // the value can be compiled eagerly. |
3432 generateStaticConstGet(node, field, constant, sourceInformation); | 3435 generateStaticConstGet(node, field, constant, sourceInformation); |
3433 } else { | 3436 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
3448 } | 3451 } |
3449 } | 3452 } |
3450 | 3453 |
3451 /// Generate a getter invocation of the static or top level [getter]. | 3454 /// Generate a getter invocation of the static or top level [getter]. |
3452 void generateStaticGetterGet(ast.Send node, MethodElement getter) { | 3455 void generateStaticGetterGet(ast.Send node, MethodElement getter) { |
3453 SourceInformation sourceInformation = | 3456 SourceInformation sourceInformation = |
3454 sourceInformationBuilder.buildGet(node); | 3457 sourceInformationBuilder.buildGet(node); |
3455 if (getter.isDeferredLoaderGetter) { | 3458 if (getter.isDeferredLoaderGetter) { |
3456 generateDeferredLoaderGet(node, getter, sourceInformation); | 3459 generateDeferredLoaderGet(node, getter, sourceInformation); |
3457 } else { | 3460 } else { |
3458 generateIsDeferredLoadedCheckOfSend(node); | |
3459 pushInvokeStatic(node, getter, <HInstruction>[], | 3461 pushInvokeStatic(node, getter, <HInstruction>[], |
3460 sourceInformation: sourceInformation); | 3462 sourceInformation: sourceInformation); |
3461 } | 3463 } |
3462 } | 3464 } |
3463 | 3465 |
3464 /// Generate a dynamic getter invocation. | 3466 /// Generate a dynamic getter invocation. |
3465 void generateDynamicGet(ast.Send node) { | 3467 void generateDynamicGet(ast.Send node) { |
3466 HInstruction receiver = generateInstanceSendReceiver(node); | 3468 HInstruction receiver = generateInstanceSendReceiver(node); |
3467 generateInstanceGetterWithCompiledReceiver( | 3469 generateInstanceGetterWithCompiledReceiver( |
3468 node, elements.getSelector(node), elements.getTypeMask(node), receiver); | 3470 node, elements.getSelector(node), elements.getTypeMask(node), receiver); |
3469 } | 3471 } |
3470 | 3472 |
3471 /// Generate a closurization of the static or top level [function]. | 3473 /// Generate a closurization of the static or top level [function]. |
3472 void generateStaticFunctionGet(ast.Send node, MethodElement function) { | 3474 void generateStaticFunctionGet(ast.Send node, MethodElement function) { |
3473 generateIsDeferredLoadedCheckOfSend(node); | |
3474 // TODO(5346): Try to avoid the need for calling [declaration] before | 3475 // TODO(5346): Try to avoid the need for calling [declaration] before |
3475 // creating an [HStatic]. | 3476 // creating an [HStatic]. |
3476 SourceInformation sourceInformation = | 3477 SourceInformation sourceInformation = |
3477 sourceInformationBuilder.buildGet(node); | 3478 sourceInformationBuilder.buildGet(node); |
3478 push(new HStatic(function.declaration, backend.nonNullType) | 3479 push(new HStatic(function.declaration, backend.nonNullType) |
3479 ..sourceInformation = sourceInformation); | 3480 ..sourceInformation = sourceInformation); |
3480 } | 3481 } |
3481 | 3482 |
3482 /// Read a local variable, function or parameter. | 3483 /// Read a local variable, function or parameter. |
3483 void buildLocalGet(LocalElement local, SourceInformation sourceInformation) { | 3484 void buildLocalGet(LocalElement local, SourceInformation sourceInformation) { |
(...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5178 | 5179 |
5179 visitStaticSend(ast.Send node) { | 5180 visitStaticSend(ast.Send node) { |
5180 internalError(node, "Unexpected visitStaticSend"); | 5181 internalError(node, "Unexpected visitStaticSend"); |
5181 } | 5182 } |
5182 | 5183 |
5183 /// Generate an invocation to the static or top level [function]. | 5184 /// Generate an invocation to the static or top level [function]. |
5184 void generateStaticFunctionInvoke( | 5185 void generateStaticFunctionInvoke( |
5185 ast.Send node, | 5186 ast.Send node, |
5186 FunctionElement function, | 5187 FunctionElement function, |
5187 CallStructure callStructure) { | 5188 CallStructure callStructure) { |
5188 generateIsDeferredLoadedCheckOfSend(node); | |
5189 | |
5190 List<HInstruction> inputs = makeStaticArgumentList( | 5189 List<HInstruction> inputs = makeStaticArgumentList( |
5191 callStructure, | 5190 callStructure, |
5192 node.arguments, | 5191 node.arguments, |
5193 function.implementation); | 5192 function.implementation); |
5194 | 5193 |
5195 if (function == compiler.identicalFunction) { | 5194 if (function == compiler.identicalFunction) { |
5196 pushWithPosition( | 5195 pushWithPosition( |
5197 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); | 5196 new HIdentity(inputs[0], inputs[1], null, backend.boolType), node); |
5198 return; | 5197 return; |
5199 } else { | 5198 } else { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5450 ConstantExpression constant, | 5449 ConstantExpression constant, |
5451 ast.NodeList arguments, | 5450 ast.NodeList arguments, |
5452 CallStructure callStructure, | 5451 CallStructure callStructure, |
5453 _) { | 5452 _) { |
5454 generateConstantTypeLiteral(node); | 5453 generateConstantTypeLiteral(node); |
5455 generateTypeLiteralCall(node); | 5454 generateTypeLiteralCall(node); |
5456 } | 5455 } |
5457 | 5456 |
5458 /// Generate the constant value for a constant type literal. | 5457 /// Generate the constant value for a constant type literal. |
5459 void generateConstantTypeLiteral(ast.Send node) { | 5458 void generateConstantTypeLiteral(ast.Send node) { |
5460 generateIsDeferredLoadedCheckOfSend(node); | |
5461 // TODO(karlklose): add type representation | 5459 // TODO(karlklose): add type representation |
5462 if (node.isCall) { | 5460 if (node.isCall) { |
5463 // The node itself is not a constant but we register the selector (the | 5461 // The node itself is not a constant but we register the selector (the |
5464 // identifier that refers to the class/typedef) as a constant. | 5462 // identifier that refers to the class/typedef) as a constant. |
5465 stack.add(addConstant(node.selector)); | 5463 stack.add(addConstant(node.selector)); |
5466 } else { | 5464 } else { |
5467 stack.add(addConstant(node)); | 5465 stack.add(addConstant(node)); |
5468 } | 5466 } |
5469 } | 5467 } |
5470 | 5468 |
(...skipping 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8859 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8857 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
8860 unaliased.accept(this, builder); | 8858 unaliased.accept(this, builder); |
8861 } | 8859 } |
8862 | 8860 |
8863 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8861 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
8864 JavaScriptBackend backend = builder.compiler.backend; | 8862 JavaScriptBackend backend = builder.compiler.backend; |
8865 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8863 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
8866 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8864 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
8867 } | 8865 } |
8868 } | 8866 } |
OLD | NEW |