| 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 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
| 7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 8 : this.backend = backend, | 8 : this.backend = backend, |
| 9 super(backend.compiler); | 9 super(backend.compiler); |
| 10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
| (...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2278 buffer.add(" || "); | 2278 buffer.add(" || "); |
| 2279 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); | 2279 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); |
| 2280 checkObject(input, '==='); | 2280 checkObject(input, '==='); |
| 2281 buffer.add(" && "); | 2281 buffer.add(" && "); |
| 2282 checkType(input, element); | 2282 checkType(input, element); |
| 2283 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); | 2283 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); |
| 2284 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); | 2284 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); |
| 2285 } | 2285 } |
| 2286 | 2286 |
| 2287 void checkType(HInstruction input, Element element) { | 2287 void checkType(HInstruction input, Element element) { |
| 2288 world.registerIsCheck(element); |
| 2288 bool requiresNativeIsCheck = | 2289 bool requiresNativeIsCheck = |
| 2289 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); | 2290 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); |
| 2290 if (!requiresNativeIsCheck) buffer.add('!!'); | 2291 if (!requiresNativeIsCheck) buffer.add('!!'); |
| 2291 use(input, JSPrecedence.MEMBER_PRECEDENCE); | 2292 use(input, JSPrecedence.MEMBER_PRECEDENCE); |
| 2292 buffer.add('.'); | 2293 buffer.add('.'); |
| 2293 buffer.add(compiler.namer.operatorIs(element)); | 2294 buffer.add(compiler.namer.operatorIs(element)); |
| 2294 if (requiresNativeIsCheck) buffer.add('()'); | 2295 if (requiresNativeIsCheck) buffer.add('()'); |
| 2295 } | 2296 } |
| 2296 | 2297 |
| 2297 void handleStringSupertypeCheck(HInstruction input, Element element) { | 2298 void handleStringSupertypeCheck(HInstruction input, Element element) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2328 } | 2329 } |
| 2329 | 2330 |
| 2330 void visitIs(HIs node) { | 2331 void visitIs(HIs node) { |
| 2331 Type type = node.typeExpression; | 2332 Type type = node.typeExpression; |
| 2332 Element element = type.element; | 2333 Element element = type.element; |
| 2333 if (element.kind === ElementKind.TYPE_VARIABLE) { | 2334 if (element.kind === ElementKind.TYPE_VARIABLE) { |
| 2334 compiler.unimplemented("visitIs for type variables", instruction: node); | 2335 compiler.unimplemented("visitIs for type variables", instruction: node); |
| 2335 } else if (element.kind === ElementKind.TYPEDEF) { | 2336 } else if (element.kind === ElementKind.TYPEDEF) { |
| 2336 compiler.unimplemented("visitIs for typedefs", instruction: node); | 2337 compiler.unimplemented("visitIs for typedefs", instruction: node); |
| 2337 } | 2338 } |
| 2338 world.registerIsCheck(type.element); | |
| 2339 LibraryElement coreLibrary = compiler.coreLibrary; | 2339 LibraryElement coreLibrary = compiler.coreLibrary; |
| 2340 ClassElement objectClass = compiler.objectClass; | 2340 ClassElement objectClass = compiler.objectClass; |
| 2341 HInstruction input = node.expression; | 2341 HInstruction input = node.expression; |
| 2342 | 2342 |
| 2343 if (node.nullOk) { | 2343 if (node.nullOk) { |
| 2344 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); | 2344 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); |
| 2345 checkNull(input); | 2345 checkNull(input); |
| 2346 buffer.add(' || '); | 2346 buffer.add(' || '); |
| 2347 } | 2347 } |
| 2348 if (element === objectClass || element === compiler.dynamicClass) { | 2348 if (element === objectClass || element === compiler.dynamicClass) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2504 // JS engine fill them in for us. | 2504 // JS engine fill them in for us. |
| 2505 for (; i < maxBailoutParameters; i++) { | 2505 for (; i < maxBailoutParameters; i++) { |
| 2506 buffer.add(', 0'); | 2506 buffer.add(', 0'); |
| 2507 } | 2507 } |
| 2508 buffer.add(')'); | 2508 buffer.add(')'); |
| 2509 } | 2509 } |
| 2510 | 2510 |
| 2511 void visitTypeGuard(HTypeGuard node) { | 2511 void visitTypeGuard(HTypeGuard node) { |
| 2512 addIndentation(); | 2512 addIndentation(); |
| 2513 HInstruction input = node.guarded; | 2513 HInstruction input = node.guarded; |
| 2514 Element indexingBehavior = compiler.jsIndexingBehaviorInterface; |
| 2514 if (node.isInteger()) { | 2515 if (node.isInteger()) { |
| 2515 buffer.add('if ('); | 2516 buffer.add('if ('); |
| 2516 checkInt(input, '!=='); | 2517 checkInt(input, '!=='); |
| 2517 buffer.add(') '); | 2518 buffer.add(') '); |
| 2518 bailout(node, 'Not an integer'); | 2519 bailout(node, 'Not an integer'); |
| 2519 } else if (node.isNumber()) { | 2520 } else if (node.isNumber()) { |
| 2520 buffer.add('if ('); | 2521 buffer.add('if ('); |
| 2521 checkNum(input, '!=='); | 2522 checkNum(input, '!=='); |
| 2522 buffer.add(') '); | 2523 buffer.add(') '); |
| 2523 bailout(node, 'Not a number'); | 2524 bailout(node, 'Not a number'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2536 checkObject(input, '!=='); | 2537 checkObject(input, '!=='); |
| 2537 buffer.add('||'); | 2538 buffer.add('||'); |
| 2538 checkArray(input, '!=='); | 2539 checkArray(input, '!=='); |
| 2539 buffer.add('||'); | 2540 buffer.add('||'); |
| 2540 checkExtendableArray(input); | 2541 checkExtendableArray(input); |
| 2541 buffer.add(') '); | 2542 buffer.add(') '); |
| 2542 bailout(node, 'Not an extendable array'); | 2543 bailout(node, 'Not an extendable array'); |
| 2543 } else if (node.isMutableArray()) { | 2544 } else if (node.isMutableArray()) { |
| 2544 buffer.add('if ('); | 2545 buffer.add('if ('); |
| 2545 checkObject(input, '!=='); | 2546 checkObject(input, '!=='); |
| 2546 buffer.add('||'); | 2547 buffer.add(' || '); |
| 2547 checkArray(input, '!=='); | 2548 checkArray(input, '!=='); |
| 2548 buffer.add('||'); | 2549 buffer.add(' || '); |
| 2549 checkImmutableArray(input); | 2550 checkImmutableArray(input); |
| 2551 buffer.add(' || !'); |
| 2552 checkType(input, indexingBehavior); |
| 2550 buffer.add(') '); | 2553 buffer.add(') '); |
| 2551 bailout(node, 'Not a mutable array'); | 2554 bailout(node, 'Not a mutable array'); |
| 2552 } else if (node.isReadableArray()) { | 2555 } else if (node.isReadableArray()) { |
| 2553 buffer.add('if ('); | 2556 buffer.add('if ('); |
| 2554 checkObject(input, '!=='); | 2557 checkObject(input, '!=='); |
| 2555 buffer.add('||'); | 2558 buffer.add(' || '); |
| 2556 checkArray(input, '!=='); | 2559 checkArray(input, '!=='); |
| 2560 buffer.add(' || !'); |
| 2561 checkType(input, indexingBehavior); |
| 2557 buffer.add(') '); | 2562 buffer.add(') '); |
| 2558 bailout(node, 'Not an array'); | 2563 bailout(node, 'Not an array'); |
| 2559 } else if (node.isIndexablePrimitive()) { | 2564 } else if (node.isIndexablePrimitive()) { |
| 2560 buffer.add('if ('); | 2565 buffer.add('if ('); |
| 2561 checkString(input, '!=='); | 2566 checkString(input, '!=='); |
| 2562 buffer.add(' && ('); | 2567 buffer.add(' && ('); |
| 2563 checkObject(input, '!=='); | 2568 checkObject(input, '!=='); |
| 2564 buffer.add('||'); | 2569 buffer.add(' || '); |
| 2565 checkArray(input, '!=='); | 2570 checkArray(input, '!=='); |
| 2571 buffer.add(' || !'); |
| 2572 checkType(input, indexingBehavior); |
| 2566 buffer.add(')) '); | 2573 buffer.add(')) '); |
| 2567 bailout(node, 'Not a string or array'); | 2574 bailout(node, 'Not a string or array'); |
| 2568 } else { | 2575 } else { |
| 2569 compiler.internalError('Unexpected type guard', instruction: input); | 2576 compiler.internalError('Unexpected type guard', instruction: input); |
| 2570 } | 2577 } |
| 2571 buffer.add(';\n'); | 2578 buffer.add(';\n'); |
| 2572 } | 2579 } |
| 2573 | 2580 |
| 2574 void beginLoop(HBasicBlock block) { | 2581 void beginLoop(HBasicBlock block) { |
| 2575 addIndentation(); | 2582 addIndentation(); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2816 startBailoutSwitch(); | 2823 startBailoutSwitch(); |
| 2817 } | 2824 } |
| 2818 } | 2825 } |
| 2819 | 2826 |
| 2820 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2827 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2821 if (labeledBlockInfo.body.start.hasGuards()) { | 2828 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2822 endBailoutSwitch(); | 2829 endBailoutSwitch(); |
| 2823 } | 2830 } |
| 2824 } | 2831 } |
| 2825 } | 2832 } |
| OLD | NEW |