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 SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
8 | 8 |
9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
10 | 10 |
(...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 world.registerStaticUse(helper); | 2239 world.registerStaticUse(helper); |
2240 String helperName = backend.namer.isolateAccess(helper); | 2240 String helperName = backend.namer.isolateAccess(helper); |
2241 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2241 push(new js.Call(new js.VariableUse(helperName), arguments)); |
2242 if (negative) push(new js.Prefix('!', pop())); | 2242 if (negative) push(new js.Prefix('!', pop())); |
2243 } | 2243 } |
2244 | 2244 |
2245 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2245 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
2246 assert(invariant(input, !type.isMalformed, | 2246 assert(invariant(input, !type.isMalformed, |
2247 message: 'Attempt to check malformed type $type')); | 2247 message: 'Attempt to check malformed type $type')); |
2248 Element element = type.element; | 2248 Element element = type.element; |
2249 | |
2250 if (element == backend.jsArrayClass) { | 2249 if (element == backend.jsArrayClass) { |
2251 checkArray(input, negative ? '!==': '==='); | 2250 checkArray(input, negative ? '!==': '==='); |
2252 return; | 2251 return; |
2253 } else if (element == backend.jsMutableArrayClass) { | 2252 } else if (element == backend.jsMutableArrayClass) { |
2254 if (negative) { | 2253 if (negative) { |
2255 checkImmutableArray(input); | 2254 checkImmutableArray(input); |
2256 } else { | 2255 } else { |
2257 checkMutableArray(input); | 2256 checkMutableArray(input); |
2258 } | 2257 } |
2259 return; | 2258 return; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2542 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2541 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
2543 DartType type = node.typeExpression; | 2542 DartType type = node.typeExpression; |
2544 if (type.kind == TypeKind.FUNCTION) { | 2543 if (type.kind == TypeKind.FUNCTION) { |
2545 // TODO(5022): We currently generate $isFunction checks for | 2544 // TODO(5022): We currently generate $isFunction checks for |
2546 // function types. | 2545 // function types. |
2547 world.registerIsCheck( | 2546 world.registerIsCheck( |
2548 compiler.functionClass.computeType(compiler), work.resolutionTree); | 2547 compiler.functionClass.computeType(compiler), work.resolutionTree); |
2549 } | 2548 } |
2550 world.registerIsCheck(type, work.resolutionTree); | 2549 world.registerIsCheck(type, work.resolutionTree); |
2551 | 2550 |
| 2551 CheckedModeHelper helper; |
2552 FunctionElement helperElement; | 2552 FunctionElement helperElement; |
2553 if (node.isBooleanConversionCheck) { | 2553 if (node.isBooleanConversionCheck) { |
2554 helperElement = | 2554 helper = |
2555 compiler.findHelper(const SourceString('boolConversionCheck')); | 2555 const CheckedModeHelper(const SourceString('boolConversionCheck')); |
2556 } else { | 2556 } else { |
2557 helperElement = backend.getCheckedModeHelper(type, | 2557 helper = |
2558 typeCast: node.isCastTypeCheck); | 2558 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); |
2559 } | 2559 } |
2560 world.registerStaticUse(helperElement); | 2560 |
| 2561 push(helper.generateCall(this, node)); |
| 2562 /*world.registerStaticUse(helper.getElement(compiler)); |
2561 List<js.Expression> arguments = <js.Expression>[]; | 2563 List<js.Expression> arguments = <js.Expression>[]; |
2562 use(node.checkedInput); | 2564 use(node.checkedInput); |
2563 arguments.add(pop()); | 2565 arguments.add(pop()); |
2564 int parameterCount = | 2566 int parameterCount = |
2565 helperElement.computeSignature(compiler).parameterCount; | 2567 helperElement.computeSignature(compiler).parameterCount; |
2566 // TODO(johnniwinther): Refactor this to avoid using the parameter count | 2568 // TODO(johnniwinther): Refactor this to avoid using the parameter count |
2567 // to determine how the helper should be called. | 2569 // to determine how the helper should be called. |
2568 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) { | 2570 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) { |
2569 assert(parameterCount == 2); | 2571 assert(parameterCount == 2); |
2570 use(node.typeRepresentation); | 2572 use(node.typeRepresentation); |
2571 arguments.add(pop()); | 2573 arguments.add(pop()); |
2572 } else if (parameterCount == 2) { | 2574 } else if (parameterCount == 2) { |
2573 // 2 arguments implies that the method is either [propertyTypeCheck], | 2575 // 2 arguments implies that the method is either [propertyTypeCheck], |
2574 // [propertyTypeCast] or [assertObjectIsSubtype]. | 2576 // [propertyTypeCast] or [assertObjectIsSubtype]. |
2575 assert(!type.isMalformed); | 2577 assert(!type.isMalformed); |
2576 String additionalArgument = backend.namer.operatorIs(type.element); | 2578 String additionalArgument = backend.namer.operatorIsType(type); |
2577 arguments.add(js.string(additionalArgument)); | 2579 arguments.add(js.string(additionalArgument)); |
2578 } else if (parameterCount == 3) { | 2580 } else if (parameterCount == 3) { |
2579 // 3 arguments implies that the method is [malformedTypeCheck]. | 2581 // 3 arguments implies that the method is [malformedTypeCheck]. |
2580 assert(type.isMalformed); | 2582 assert(type.isMalformed); |
2581 String reasons = Types.fetchReasonsFromMalformedType(type); | 2583 String reasons = Types.fetchReasonsFromMalformedType(type); |
2582 arguments.add(js.string('$type')); | 2584 arguments.add(js.string('$type')); |
2583 // TODO(johnniwinther): Handle escaping correctly. | 2585 // TODO(johnniwinther): Handle escaping correctly. |
2584 arguments.add(js.string(reasons)); | 2586 arguments.add(js.string(reasons)); |
2585 } else if (parameterCount == 4) { | 2587 } else if (parameterCount == 4) { |
2586 Element element = type.element; | 2588 Element element = type.element; |
2587 String isField = backend.namer.operatorIs(element); | 2589 String isField = backend.namer.operatorIs(element); |
2588 arguments.add(js.string(isField)); | 2590 arguments.add(js.string(isField)); |
2589 use(node.typeRepresentation); | 2591 use(node.typeRepresentation); |
2590 arguments.add(pop()); | 2592 arguments.add(pop()); |
2591 String asField = backend.namer.substitutionName(element); | 2593 String asField = backend.namer.substitutionName(element); |
2592 arguments.add(js.string(asField)); | 2594 arguments.add(js.string(asField)); |
2593 } else { | 2595 } else { |
2594 assert(!type.isMalformed); | 2596 assert(!type.isMalformed); |
2595 // No additional arguments needed. | 2597 // No additional arguments needed. |
2596 } | 2598 } |
2597 String helperName = backend.namer.isolateAccess(helperElement); | 2599 String helperName = backend.namer.isolateAccess(helperElement); |
2598 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2600 push(new js.Call(new js.VariableUse(helperName), arguments));*/ |
2599 } | 2601 } |
2600 } | 2602 } |
2601 | 2603 |
2602 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2604 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
2603 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); | 2605 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); |
2604 | 2606 |
2605 HBasicBlock beginGraph(HGraph graph) { | 2607 HBasicBlock beginGraph(HGraph graph) { |
2606 return graph.entry; | 2608 return graph.entry; |
2607 } | 2609 } |
2608 | 2610 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 if (leftType.canBeNull() && rightType.canBeNull()) { | 3038 if (leftType.canBeNull() && rightType.canBeNull()) { |
3037 if (left.isConstantNull() || right.isConstantNull() || | 3039 if (left.isConstantNull() || right.isConstantNull() || |
3038 (leftType.isPrimitive() && leftType == rightType)) { | 3040 (leftType.isPrimitive() && leftType == rightType)) { |
3039 return '=='; | 3041 return '=='; |
3040 } | 3042 } |
3041 return null; | 3043 return null; |
3042 } else { | 3044 } else { |
3043 return '==='; | 3045 return '==='; |
3044 } | 3046 } |
3045 } | 3047 } |
OLD | NEW |