| 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 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 methodName = name.slowToString(); | 1519 methodName = name.slowToString(); |
| 1520 } else if (!node.isInterceptorCall) { | 1520 } else if (!node.isInterceptorCall) { |
| 1521 if (target == backend.jsArrayAdd) { | 1521 if (target == backend.jsArrayAdd) { |
| 1522 methodName = 'push'; | 1522 methodName = 'push'; |
| 1523 } else if (target == backend.jsArrayRemoveLast) { | 1523 } else if (target == backend.jsArrayRemoveLast) { |
| 1524 methodName = 'pop'; | 1524 methodName = 'pop'; |
| 1525 } else if (target == backend.jsStringSplit) { | 1525 } else if (target == backend.jsStringSplit) { |
| 1526 methodName = 'split'; | 1526 methodName = 'split'; |
| 1527 // Split returns a List, so we make sure the backend knows the | 1527 // Split returns a List, so we make sure the backend knows the |
| 1528 // list class is instantiated. | 1528 // list class is instantiated. |
| 1529 world.registerInstantiatedClass(compiler.listClass); | 1529 world.registerInstantiatedClass( |
| 1530 compiler.listClass, compiler.globalDependencies); |
| 1530 } else if (target == backend.jsStringConcat) { | 1531 } else if (target == backend.jsStringConcat) { |
| 1531 push(new js.Binary('+', object, arguments[0]), node); | 1532 push(new js.Binary('+', object, arguments[0]), node); |
| 1532 return; | 1533 return; |
| 1533 } else if (target.isNative() | 1534 } else if (target.isNative() |
| 1534 && !compiler.enableTypeAssertions | 1535 && !compiler.enableTypeAssertions |
| 1535 && target.isFunction()) { | 1536 && target.isFunction()) { |
| 1536 // Enable direct calls to a native method only if we don't | 1537 // Enable direct calls to a native method only if we don't |
| 1537 // run in checked mode, where the Dart version may have | 1538 // run in checked mode, where the Dart version may have |
| 1538 // type annotations on parameters and return type that it | 1539 // type annotations on parameters and return type that it |
| 1539 // should check. | 1540 // should check. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 HType valueType = node.isInterceptorCall | 1641 HType valueType = node.isInterceptorCall |
| 1641 ? node.inputs[2].instructionType | 1642 ? node.inputs[2].instructionType |
| 1642 : node.inputs[1].instructionType; | 1643 : node.inputs[1].instructionType; |
| 1643 backend.addedDynamicSetter(selector, valueType); | 1644 backend.addedDynamicSetter(selector, valueType); |
| 1644 registerInvoke(node, selector); | 1645 registerInvoke(node, selector); |
| 1645 } | 1646 } |
| 1646 | 1647 |
| 1647 void registerGetter(HInvokeDynamic node) { | 1648 void registerGetter(HInvokeDynamic node) { |
| 1648 Selector selector = getOptimizedSelectorFor(node, node.selector); | 1649 Selector selector = getOptimizedSelectorFor(node, node.selector); |
| 1649 world.registerDynamicGetter(selector.name, selector); | 1650 world.registerDynamicGetter(selector.name, selector); |
| 1650 world.registerInstantiatedClass(compiler.functionClass); | 1651 world.registerInstantiatedClass( |
| 1652 compiler.functionClass, compiler.globalDependencies); |
| 1651 registerInvoke(node, selector); | 1653 registerInvoke(node, selector); |
| 1652 } | 1654 } |
| 1653 | 1655 |
| 1654 visitInvokeDynamicSetter(HInvokeDynamicSetter node) { | 1656 visitInvokeDynamicSetter(HInvokeDynamicSetter node) { |
| 1655 use(node.receiver); | 1657 use(node.receiver); |
| 1656 String name = backend.namer.invocationName(node.selector); | 1658 String name = backend.namer.invocationName(node.selector); |
| 1657 push(jsPropertyCall(pop(), name, visitArguments(node.inputs)), node); | 1659 push(jsPropertyCall(pop(), name, visitArguments(node.inputs)), node); |
| 1658 registerSetter(node); | 1660 registerSetter(node); |
| 1659 } | 1661 } |
| 1660 | 1662 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 use(node.value); | 1770 use(node.value); |
| 1769 assignVariable(variableNames.getName(node.receiver), pop()); | 1771 assignVariable(variableNames.getName(node.receiver), pop()); |
| 1770 } | 1772 } |
| 1771 | 1773 |
| 1772 void registerForeignType(HType type) { | 1774 void registerForeignType(HType type) { |
| 1773 DartType dartType = type.computeType(compiler); | 1775 DartType dartType = type.computeType(compiler); |
| 1774 if (dartType == null) { | 1776 if (dartType == null) { |
| 1775 assert(type == HType.UNKNOWN); | 1777 assert(type == HType.UNKNOWN); |
| 1776 return; | 1778 return; |
| 1777 } | 1779 } |
| 1778 world.registerInstantiatedClass(dartType.element); | 1780 world.registerInstantiatedClass( |
| 1781 dartType.element, compiler.globalDependencies); |
| 1779 } | 1782 } |
| 1780 | 1783 |
| 1781 visitForeign(HForeign node) { | 1784 visitForeign(HForeign node) { |
| 1782 String code = node.code.slowToString(); | 1785 String code = node.code.slowToString(); |
| 1783 List<HInstruction> inputs = node.inputs; | 1786 List<HInstruction> inputs = node.inputs; |
| 1784 if (node.isJsStatement()) { | 1787 if (node.isJsStatement()) { |
| 1785 if (!inputs.isEmpty) { | 1788 if (!inputs.isEmpty) { |
| 1786 compiler.internalError("foreign statement with inputs: $code", | 1789 compiler.internalError("foreign statement with inputs: $code", |
| 1787 instruction: node); | 1790 instruction: node); |
| 1788 } | 1791 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 } | 1835 } |
| 1833 | 1836 |
| 1834 visitConstant(HConstant node) { | 1837 visitConstant(HConstant node) { |
| 1835 assert(isGenerateAtUseSite(node)); | 1838 assert(isGenerateAtUseSite(node)); |
| 1836 generateConstant(node.constant); | 1839 generateConstant(node.constant); |
| 1837 DartType type = node.constant.computeType(compiler); | 1840 DartType type = node.constant.computeType(compiler); |
| 1838 if (node.constant is ConstructedConstant) { | 1841 if (node.constant is ConstructedConstant) { |
| 1839 ConstantHandler handler = compiler.constantHandler; | 1842 ConstantHandler handler = compiler.constantHandler; |
| 1840 handler.registerCompileTimeConstant(node.constant); | 1843 handler.registerCompileTimeConstant(node.constant); |
| 1841 } | 1844 } |
| 1842 world.registerInstantiatedClass(type.element); | 1845 world.registerInstantiatedClass( |
| 1846 type.element, compiler.globalDependencies); |
| 1843 } | 1847 } |
| 1844 | 1848 |
| 1845 visitNot(HNot node) { | 1849 visitNot(HNot node) { |
| 1846 assert(node.inputs.length == 1); | 1850 assert(node.inputs.length == 1); |
| 1847 generateNot(node.inputs[0]); | 1851 generateNot(node.inputs[0]); |
| 1848 attachLocationToLast(node); | 1852 attachLocationToLast(node); |
| 1849 } | 1853 } |
| 1850 | 1854 |
| 1851 static String mapRelationalOperator(String op, bool inverse) { | 1855 static String mapRelationalOperator(String op, bool inverse) { |
| 1852 Map<String, String> inverseOperator = const <String, String>{ | 1856 Map<String, String> inverseOperator = const <String, String>{ |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 // Switches are handled using [visitSwitchInfo]. | 2045 // Switches are handled using [visitSwitchInfo]. |
| 2042 } | 2046 } |
| 2043 | 2047 |
| 2044 void visitStatic(HStatic node) { | 2048 void visitStatic(HStatic node) { |
| 2045 // Check whether this static is used for anything else than as a target in | 2049 // Check whether this static is used for anything else than as a target in |
| 2046 // a static call. | 2050 // a static call. |
| 2047 node.usedBy.forEach((HInstruction instr) { | 2051 node.usedBy.forEach((HInstruction instr) { |
| 2048 if (instr is !HInvokeStatic) { | 2052 if (instr is !HInvokeStatic) { |
| 2049 backend.registerNonCallStaticUse(node); | 2053 backend.registerNonCallStaticUse(node); |
| 2050 if (node.element.isFunction()) { | 2054 if (node.element.isFunction()) { |
| 2051 world.registerInstantiatedClass(compiler.functionClass); | 2055 world.registerInstantiatedClass( |
| 2056 compiler.functionClass, compiler.globalDependencies); |
| 2052 } | 2057 } |
| 2053 } else if (instr.target != node) { | 2058 } else if (instr.target != node) { |
| 2054 backend.registerNonCallStaticUse(node); | 2059 backend.registerNonCallStaticUse(node); |
| 2055 } | 2060 } |
| 2056 }); | 2061 }); |
| 2057 Element element = node.element; | 2062 Element element = node.element; |
| 2058 world.registerStaticUse(element); | 2063 world.registerStaticUse(element); |
| 2059 ClassElement cls = element.getEnclosingClass(); | 2064 ClassElement cls = element.getEnclosingClass(); |
| 2060 if (element.isGenerativeConstructor() | 2065 if (element.isGenerativeConstructor() |
| 2061 || (element.isFactoryConstructor() && cls == compiler.listClass)) { | 2066 || (element.isFactoryConstructor() && cls == compiler.listClass)) { |
| 2062 world.registerInstantiatedClass(cls); | 2067 world.registerInstantiatedClass(cls, compiler.globalDependencies); |
| 2063 } | 2068 } |
| 2064 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); | 2069 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); |
| 2065 } | 2070 } |
| 2066 | 2071 |
| 2067 void visitLazyStatic(HLazyStatic node) { | 2072 void visitLazyStatic(HLazyStatic node) { |
| 2068 Element element = node.element; | 2073 Element element = node.element; |
| 2069 world.registerStaticUse(element); | 2074 world.registerStaticUse(element); |
| 2070 String lazyGetter = backend.namer.isolateLazyInitializerAccess(element); | 2075 String lazyGetter = backend.namer.isolateLazyInitializerAccess(element); |
| 2071 js.VariableUse target = new js.VariableUse(lazyGetter); | 2076 js.VariableUse target = new js.VariableUse(lazyGetter); |
| 2072 js.Call call = new js.Call(target, <js.Expression>[]); | 2077 js.Call call = new js.Call(target, <js.Expression>[]); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 Element convertToString = backend.getStringInterpolationHelper(); | 2113 Element convertToString = backend.getStringInterpolationHelper(); |
| 2109 world.registerStaticUse(convertToString); | 2114 world.registerStaticUse(convertToString); |
| 2110 js.VariableUse variableUse = | 2115 js.VariableUse variableUse = |
| 2111 new js.VariableUse(backend.namer.isolateAccess(convertToString)); | 2116 new js.VariableUse(backend.namer.isolateAccess(convertToString)); |
| 2112 use(node); | 2117 use(node); |
| 2113 push(new js.Call(variableUse, <js.Expression>[pop()]), node); | 2118 push(new js.Call(variableUse, <js.Expression>[pop()]), node); |
| 2114 } | 2119 } |
| 2115 } | 2120 } |
| 2116 | 2121 |
| 2117 void visitLiteralList(HLiteralList node) { | 2122 void visitLiteralList(HLiteralList node) { |
| 2118 world.registerInstantiatedClass(compiler.listClass); | 2123 world.registerInstantiatedClass( |
| 2124 compiler.listClass, compiler.globalDependencies); |
| 2119 generateArrayLiteral(node); | 2125 generateArrayLiteral(node); |
| 2120 } | 2126 } |
| 2121 | 2127 |
| 2122 void generateArrayLiteral(HLiteralList node) { | 2128 void generateArrayLiteral(HLiteralList node) { |
| 2123 int len = node.inputs.length; | 2129 int len = node.inputs.length; |
| 2124 List<js.ArrayElement> elements = <js.ArrayElement>[]; | 2130 List<js.ArrayElement> elements = <js.ArrayElement>[]; |
| 2125 for (int i = 0; i < len; i++) { | 2131 for (int i = 0; i < len; i++) { |
| 2126 use(node.inputs[i]); | 2132 use(node.inputs[i]); |
| 2127 elements.add(new js.ArrayElement(i, pop())); | 2133 elements.add(new js.ArrayElement(i, pop())); |
| 2128 } | 2134 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2242 js.Expression objectTest = pop(); | 2248 js.Expression objectTest = pop(); |
| 2243 checkType(input, type); | 2249 checkType(input, type); |
| 2244 push(new js.Binary('||', | 2250 push(new js.Binary('||', |
| 2245 functionTest, | 2251 functionTest, |
| 2246 new js.Binary('&&', objectTest, pop()))); | 2252 new js.Binary('&&', objectTest, pop()))); |
| 2247 } | 2253 } |
| 2248 | 2254 |
| 2249 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2255 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
| 2250 assert(invariant(input, !type.isMalformed, | 2256 assert(invariant(input, !type.isMalformed, |
| 2251 message: 'Attempt to check malformed type $type')); | 2257 message: 'Attempt to check malformed type $type')); |
| 2252 world.registerIsCheck(type); | 2258 world.registerIsCheck(type, compiler.globalDependencies); |
| 2253 Element element = type.element; | 2259 Element element = type.element; |
| 2254 use(input); | 2260 use(input); |
| 2255 js.PropertyAccess field = | 2261 js.PropertyAccess field = |
| 2256 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); | 2262 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); |
| 2257 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { | 2263 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { |
| 2258 push(new js.Call(field, <js.Expression>[])); | 2264 push(new js.Call(field, <js.Expression>[])); |
| 2259 if (negative) push(new js.Prefix('!', pop())); | 2265 if (negative) push(new js.Prefix('!', pop())); |
| 2260 } else { | 2266 } else { |
| 2261 // We always negate at least once so that the result is boolified. | 2267 // We always negate at least once so that the result is boolified. |
| 2262 push(new js.Prefix('!', field)); | 2268 push(new js.Prefix('!', field)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 checkArray(input, '==='); | 2310 checkArray(input, '==='); |
| 2305 js.Expression arrayTest = pop(); | 2311 js.Expression arrayTest = pop(); |
| 2306 checkType(input, type); | 2312 checkType(input, type); |
| 2307 push(new js.Binary('&&', | 2313 push(new js.Binary('&&', |
| 2308 objectTest, | 2314 objectTest, |
| 2309 new js.Binary('||', arrayTest, pop()))); | 2315 new js.Binary('||', arrayTest, pop()))); |
| 2310 } | 2316 } |
| 2311 | 2317 |
| 2312 void visitIs(HIs node) { | 2318 void visitIs(HIs node) { |
| 2313 DartType type = node.typeExpression; | 2319 DartType type = node.typeExpression; |
| 2314 world.registerIsCheck(type); | 2320 world.registerIsCheck(type, compiler.globalDependencies); |
| 2315 Element element = type.element; | 2321 Element element = type.element; |
| 2316 if (identical(element.kind, ElementKind.TYPE_VARIABLE)) { | 2322 if (identical(element.kind, ElementKind.TYPE_VARIABLE)) { |
| 2317 compiler.unimplemented("visitIs for type variables", | 2323 compiler.unimplemented("visitIs for type variables", |
| 2318 instruction: node.expression); | 2324 instruction: node.expression); |
| 2319 } | 2325 } |
| 2320 LibraryElement coreLibrary = compiler.coreLibrary; | 2326 LibraryElement coreLibrary = compiler.coreLibrary; |
| 2321 ClassElement objectClass = compiler.objectClass; | 2327 ClassElement objectClass = compiler.objectClass; |
| 2322 HInstruction input = node.expression; | 2328 HInstruction input = node.expression; |
| 2323 | 2329 |
| 2324 if (identical(element, objectClass) || | 2330 if (identical(element, objectClass) || |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2377 if (node.nullOk) { | 2383 if (node.nullOk) { |
| 2378 checkNull(input); | 2384 checkNull(input); |
| 2379 push(new js.Binary('||', pop(), pop()), node); | 2385 push(new js.Binary('||', pop(), pop()), node); |
| 2380 } | 2386 } |
| 2381 } | 2387 } |
| 2382 | 2388 |
| 2383 void visitTypeConversion(HTypeConversion node) { | 2389 void visitTypeConversion(HTypeConversion node) { |
| 2384 if (node.isChecked) { | 2390 if (node.isChecked) { |
| 2385 DartType type = node.instructionType.computeType(compiler); | 2391 DartType type = node.instructionType.computeType(compiler); |
| 2386 Element element = type.element; | 2392 Element element = type.element; |
| 2387 world.registerIsCheck(type); | 2393 world.registerIsCheck(type, compiler.globalDependencies); |
| 2388 | 2394 |
| 2389 if (node.isArgumentTypeCheck) { | 2395 if (node.isArgumentTypeCheck) { |
| 2390 if (element == backend.jsIntClass) { | 2396 if (element == backend.jsIntClass) { |
| 2391 checkInt(node.checkedInput, '!=='); | 2397 checkInt(node.checkedInput, '!=='); |
| 2392 } else { | 2398 } else { |
| 2393 assert(element == backend.jsNumberClass); | 2399 assert(element == backend.jsNumberClass); |
| 2394 checkNum(node.checkedInput, '!=='); | 2400 checkNum(node.checkedInput, '!=='); |
| 2395 } | 2401 } |
| 2396 js.Expression test = pop(); | 2402 js.Expression test = pop(); |
| 2397 js.Block oldContainer = currentContainer; | 2403 js.Block oldContainer = currentContainer; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2962 if (leftType.canBeNull() && rightType.canBeNull()) { | 2968 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2963 if (left.isConstantNull() || right.isConstantNull() || | 2969 if (left.isConstantNull() || right.isConstantNull() || |
| 2964 (leftType.isPrimitive() && leftType == rightType)) { | 2970 (leftType.isPrimitive() && leftType == rightType)) { |
| 2965 return '=='; | 2971 return '=='; |
| 2966 } | 2972 } |
| 2967 return null; | 2973 return null; |
| 2968 } else { | 2974 } else { |
| 2969 return '==='; | 2975 return '==='; |
| 2970 } | 2976 } |
| 2971 } | 2977 } |
| OLD | NEW |