| 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 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 buffer.add(" || "); | 2057 buffer.add(" || "); |
| 2058 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); | 2058 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); |
| 2059 checkObject(input, '==='); | 2059 checkObject(input, '==='); |
| 2060 buffer.add(" && "); | 2060 buffer.add(" && "); |
| 2061 checkType(input, element); | 2061 checkType(input, element); |
| 2062 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); | 2062 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); |
| 2063 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); | 2063 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); |
| 2064 } | 2064 } |
| 2065 | 2065 |
| 2066 void checkType(HInstruction input, Element element) { | 2066 void checkType(HInstruction input, Element element) { |
| 2067 world.registerIsCheck(element); |
| 2067 bool requiresNativeIsCheck = | 2068 bool requiresNativeIsCheck = |
| 2068 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); | 2069 backend.emitter.nativeEmitter.requiresNativeIsCheck(element); |
| 2069 if (!requiresNativeIsCheck) buffer.add('!!'); | 2070 if (!requiresNativeIsCheck) buffer.add('!!'); |
| 2070 use(input, JSPrecedence.MEMBER_PRECEDENCE); | 2071 use(input, JSPrecedence.MEMBER_PRECEDENCE); |
| 2071 buffer.add('.'); | 2072 buffer.add('.'); |
| 2072 buffer.add(compiler.namer.operatorIs(element)); | 2073 buffer.add(compiler.namer.operatorIs(element)); |
| 2073 if (requiresNativeIsCheck) buffer.add('()'); | 2074 if (requiresNativeIsCheck) buffer.add('()'); |
| 2074 } | 2075 } |
| 2075 | 2076 |
| 2076 void handleStringSupertypeCheck(HInstruction input, Element element) { | 2077 void handleStringSupertypeCheck(HInstruction input, Element element) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2107 } | 2108 } |
| 2108 | 2109 |
| 2109 void visitIs(HIs node) { | 2110 void visitIs(HIs node) { |
| 2110 Type type = node.typeExpression; | 2111 Type type = node.typeExpression; |
| 2111 Element element = type.element; | 2112 Element element = type.element; |
| 2112 if (element.kind === ElementKind.TYPE_VARIABLE) { | 2113 if (element.kind === ElementKind.TYPE_VARIABLE) { |
| 2113 compiler.unimplemented("visitIs for type variables", instruction: node); | 2114 compiler.unimplemented("visitIs for type variables", instruction: node); |
| 2114 } else if (element.kind === ElementKind.TYPEDEF) { | 2115 } else if (element.kind === ElementKind.TYPEDEF) { |
| 2115 compiler.unimplemented("visitIs for typedefs", instruction: node); | 2116 compiler.unimplemented("visitIs for typedefs", instruction: node); |
| 2116 } | 2117 } |
| 2117 world.registerIsCheck(type.element); | |
| 2118 LibraryElement coreLibrary = compiler.coreLibrary; | 2118 LibraryElement coreLibrary = compiler.coreLibrary; |
| 2119 ClassElement objectClass = compiler.objectClass; | 2119 ClassElement objectClass = compiler.objectClass; |
| 2120 HInstruction input = node.expression; | 2120 HInstruction input = node.expression; |
| 2121 | 2121 |
| 2122 if (node.nullOk) { | 2122 if (node.nullOk) { |
| 2123 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); | 2123 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); |
| 2124 checkNull(input); | 2124 checkNull(input); |
| 2125 buffer.add(' || '); | 2125 buffer.add(' || '); |
| 2126 } | 2126 } |
| 2127 if (element === objectClass || element === compiler.dynamicClass) { | 2127 if (element === objectClass || element === compiler.dynamicClass) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2273 } else { | 2273 } else { |
| 2274 assert(guard.guarded is HParameterValue); | 2274 assert(guard.guarded is HParameterValue); |
| 2275 buffer.add(' 0'); | 2275 buffer.add(' 0'); |
| 2276 } | 2276 } |
| 2277 buffer.add(')'); | 2277 buffer.add(')'); |
| 2278 } | 2278 } |
| 2279 | 2279 |
| 2280 void visitTypeGuard(HTypeGuard node) { | 2280 void visitTypeGuard(HTypeGuard node) { |
| 2281 addIndentation(); | 2281 addIndentation(); |
| 2282 HInstruction input = node.guarded; | 2282 HInstruction input = node.guarded; |
| 2283 Element indexingBehavior = compiler.javaScriptIndexingBehaviorInterface; |
| 2283 if (node.isInteger()) { | 2284 if (node.isInteger()) { |
| 2284 buffer.add('if ('); | 2285 buffer.add('if ('); |
| 2285 checkInt(input, '!=='); | 2286 checkInt(input, '!=='); |
| 2286 buffer.add(') '); | 2287 buffer.add(') '); |
| 2287 bailout(node, 'Not an integer'); | 2288 bailout(node, 'Not an integer'); |
| 2288 } else if (node.isNumber()) { | 2289 } else if (node.isNumber()) { |
| 2289 buffer.add('if ('); | 2290 buffer.add('if ('); |
| 2290 checkNum(input, '!=='); | 2291 checkNum(input, '!=='); |
| 2291 buffer.add(') '); | 2292 buffer.add(') '); |
| 2292 bailout(node, 'Not a number'); | 2293 bailout(node, 'Not a number'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2305 checkObject(input, '!=='); | 2306 checkObject(input, '!=='); |
| 2306 buffer.add('||'); | 2307 buffer.add('||'); |
| 2307 checkArray(input, '!=='); | 2308 checkArray(input, '!=='); |
| 2308 buffer.add('||'); | 2309 buffer.add('||'); |
| 2309 checkExtendableArray(input); | 2310 checkExtendableArray(input); |
| 2310 buffer.add(') '); | 2311 buffer.add(') '); |
| 2311 bailout(node, 'Not an extendable array'); | 2312 bailout(node, 'Not an extendable array'); |
| 2312 } else if (node.isMutableArray()) { | 2313 } else if (node.isMutableArray()) { |
| 2313 buffer.add('if ('); | 2314 buffer.add('if ('); |
| 2314 checkObject(input, '!=='); | 2315 checkObject(input, '!=='); |
| 2315 buffer.add('||'); | 2316 buffer.add(' || '); |
| 2316 checkArray(input, '!=='); | 2317 checkArray(input, '!=='); |
| 2317 buffer.add('||'); | 2318 buffer.add(' || '); |
| 2318 checkImmutableArray(input); | 2319 checkImmutableArray(input); |
| 2320 buffer.add(' || !'); |
| 2321 checkType(input, indexingBehavior); |
| 2319 buffer.add(') '); | 2322 buffer.add(') '); |
| 2320 bailout(node, 'Not a mutable array'); | 2323 bailout(node, 'Not a mutable array'); |
| 2321 } else if (node.isReadableArray()) { | 2324 } else if (node.isReadableArray()) { |
| 2322 buffer.add('if ('); | 2325 buffer.add('if ('); |
| 2323 checkObject(input, '!=='); | 2326 checkObject(input, '!=='); |
| 2324 buffer.add('||'); | 2327 buffer.add(' || '); |
| 2325 checkArray(input, '!=='); | 2328 checkArray(input, '!=='); |
| 2329 buffer.add(' || !'); |
| 2330 checkType(input, indexingBehavior); |
| 2326 buffer.add(') '); | 2331 buffer.add(') '); |
| 2327 bailout(node, 'Not an array'); | 2332 bailout(node, 'Not an array'); |
| 2328 } else if (node.isIndexablePrimitive()) { | 2333 } else if (node.isIndexablePrimitive()) { |
| 2329 buffer.add('if ('); | 2334 buffer.add('if ('); |
| 2330 checkString(input, '!=='); | 2335 checkString(input, '!=='); |
| 2331 buffer.add(' && ('); | 2336 buffer.add(' && ('); |
| 2332 checkObject(input, '!=='); | 2337 checkObject(input, '!=='); |
| 2333 buffer.add('||'); | 2338 buffer.add(' || '); |
| 2334 checkArray(input, '!=='); | 2339 checkArray(input, '!=='); |
| 2340 buffer.add(' || !'); |
| 2341 checkType(input, indexingBehavior); |
| 2335 buffer.add(')) '); | 2342 buffer.add(')) '); |
| 2336 bailout(node, 'Not a string or array'); | 2343 bailout(node, 'Not a string or array'); |
| 2337 } else { | 2344 } else { |
| 2338 compiler.internalError('Unexpected type guard', instruction: input); | 2345 compiler.internalError('Unexpected type guard', instruction: input); |
| 2339 } | 2346 } |
| 2340 buffer.add(';\n'); | 2347 buffer.add(';\n'); |
| 2341 } | 2348 } |
| 2342 | 2349 |
| 2343 void beginLoop(HBasicBlock block) { | 2350 void beginLoop(HBasicBlock block) { |
| 2344 addIndentation(); | 2351 addIndentation(); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2632 startBailoutSwitch(); | 2639 startBailoutSwitch(); |
| 2633 } | 2640 } |
| 2634 } | 2641 } |
| 2635 | 2642 |
| 2636 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2643 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2637 if (labeledBlockInfo.body.start.hasGuards()) { | 2644 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2638 endBailoutSwitch(); | 2645 endBailoutSwitch(); |
| 2639 } | 2646 } |
| 2640 } | 2647 } |
| 2641 } | 2648 } |
| OLD | NEW |