Chromium Code Reviews| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 const bool USE_CPS_IR = const bool.fromEnvironment("USE_CPS_IR"); | 9 const bool USE_CPS_IR = const bool.fromEnvironment("USE_CPS_IR"); |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 canBeInlined[element] = false; | 56 canBeInlined[element] = false; |
| 57 canBeInlinedInsideLoop[element] = false; | 57 canBeInlinedInsideLoop[element] = false; |
| 58 } else { | 58 } else { |
| 59 canBeInlined[element] = false; | 59 canBeInlined[element] = false; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 class JavaScriptBackend extends Backend { | 64 class JavaScriptBackend extends Backend { |
| 65 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); | 65 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
| 66 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); | |
|
Johnni Winther
2015/02/02 10:45:10
Not needed (exists on [Compiler]).
sigurdm
2015/02/03 16:59:27
Done
| |
| 66 static final Uri DART_INTERCEPTORS = | 67 static final Uri DART_INTERCEPTORS = |
| 67 new Uri(scheme: 'dart', path: '_interceptors'); | 68 new Uri(scheme: 'dart', path: '_interceptors'); |
| 68 static final Uri DART_INTERNAL = | 69 static final Uri DART_INTERNAL = |
| 69 new Uri(scheme: 'dart', path: '_internal'); | 70 new Uri(scheme: 'dart', path: '_internal'); |
| 70 static final Uri DART_FOREIGN_HELPER = | 71 static final Uri DART_FOREIGN_HELPER = |
| 71 new Uri(scheme: 'dart', path: '_foreign_helper'); | 72 new Uri(scheme: 'dart', path: '_foreign_helper'); |
| 72 static final Uri DART_JS_MIRRORS = | 73 static final Uri DART_JS_MIRRORS = |
| 73 new Uri(scheme: 'dart', path: '_js_mirrors'); | 74 new Uri(scheme: 'dart', path: '_js_mirrors'); |
| 74 static final Uri DART_JS_NAMES = | 75 static final Uri DART_JS_NAMES = |
| 75 new Uri(scheme: 'dart', path: '_js_names'); | 76 new Uri(scheme: 'dart', path: '_js_names'); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 /** | 116 /** |
| 116 * The generated code as a js AST for compiled methods. | 117 * The generated code as a js AST for compiled methods. |
| 117 */ | 118 */ |
| 118 Map<Element, jsAst.Expression> get generatedCode { | 119 Map<Element, jsAst.Expression> get generatedCode { |
| 119 return compiler.enqueuer.codegen.generatedCode; | 120 return compiler.enqueuer.codegen.generatedCode; |
| 120 } | 121 } |
| 121 | 122 |
| 122 FunctionInlineCache inlineCache = new FunctionInlineCache(); | 123 FunctionInlineCache inlineCache = new FunctionInlineCache(); |
| 123 | 124 |
| 124 LibraryElement jsHelperLibrary; | 125 LibraryElement jsHelperLibrary; |
| 126 LibraryElement asyncLibrary; | |
| 125 LibraryElement interceptorsLibrary; | 127 LibraryElement interceptorsLibrary; |
| 126 LibraryElement foreignLibrary; | 128 LibraryElement foreignLibrary; |
| 127 LibraryElement isolateHelperLibrary; | 129 LibraryElement isolateHelperLibrary; |
| 128 | 130 |
| 129 ClassElement closureClass; | 131 ClassElement closureClass; |
| 130 ClassElement boundClosureClass; | 132 ClassElement boundClosureClass; |
| 131 Element assertMethod; | 133 Element assertMethod; |
| 132 Element invokeOnMethod; | 134 Element invokeOnMethod; |
| 133 | 135 |
| 134 ClassElement jsInterceptorClass; | 136 ClassElement jsInterceptorClass; |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 // will instantiate those two classes. | 936 // will instantiate those two classes. |
| 935 addInterceptors(jsBoolClass, world, registry); | 937 addInterceptors(jsBoolClass, world, registry); |
| 936 addInterceptors(jsNullClass, world, registry); | 938 addInterceptors(jsNullClass, world, registry); |
| 937 if (compiler.enableTypeAssertions) { | 939 if (compiler.enableTypeAssertions) { |
| 938 // Unconditionally register the helper that checks if the | 940 // Unconditionally register the helper that checks if the |
| 939 // expression in an if/while/for is a boolean. | 941 // expression in an if/while/for is a boolean. |
| 940 // TODO(ngeoffray): Should we have the resolver register those instead? | 942 // TODO(ngeoffray): Should we have the resolver register those instead? |
| 941 Element e = findHelper('boolConversionCheck'); | 943 Element e = findHelper('boolConversionCheck'); |
| 942 if (e != null) enqueue(world, e, registry); | 944 if (e != null) enqueue(world, e, registry); |
| 943 } | 945 } |
| 946 | |
| 944 if (TRACE_CALLS) { | 947 if (TRACE_CALLS) { |
| 945 traceHelper = findHelper('traceHelper'); | 948 traceHelper = findHelper('traceHelper'); |
| 946 assert(traceHelper != null); | 949 assert(traceHelper != null); |
| 947 enqueueInResolution(traceHelper, registry); | 950 enqueueInResolution(traceHelper, registry); |
| 948 } | 951 } |
| 949 registerCheckedModeHelpers(registry); | 952 registerCheckedModeHelpers(registry); |
| 950 } | 953 } |
| 951 | 954 |
| 952 onResolutionComplete() { | 955 onResolutionComplete() { |
| 953 super.onResolutionComplete(); | 956 super.onResolutionComplete(); |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1590 } | 1593 } |
| 1591 | 1594 |
| 1592 Element getCreateInvocationMirror() { | 1595 Element getCreateInvocationMirror() { |
| 1593 return findHelper(Compiler.CREATE_INVOCATION_MIRROR); | 1596 return findHelper(Compiler.CREATE_INVOCATION_MIRROR); |
| 1594 } | 1597 } |
| 1595 | 1598 |
| 1596 Element getCyclicThrowHelper() { | 1599 Element getCyclicThrowHelper() { |
| 1597 return findHelper("throwCyclicInit"); | 1600 return findHelper("throwCyclicInit"); |
| 1598 } | 1601 } |
| 1599 | 1602 |
| 1603 Element getFuture() { | |
|
Johnni Winther
2015/02/02 10:45:10
This is [Compiler.futureClass].
sigurdm
2015/02/03 16:59:27
And was not used anymore.
Thanks.
| |
| 1604 return asyncLibrary.find("Future"); | |
| 1605 } | |
| 1606 | |
| 1607 Element getThenHelper() { | |
| 1608 return findHelper("thenHelper"); | |
| 1609 } | |
| 1610 | |
| 1611 Element getSyncStarYieldStar() { | |
| 1612 ClassElement classElement = findHelper("IterationMarker"); | |
| 1613 classElement.ensureResolved(compiler); | |
| 1614 return classElement.lookupLocalMember("yieldStar"); | |
| 1615 } | |
| 1616 | |
| 1617 Element getYieldSingle() { | |
| 1618 ClassElement classElement = findHelper("IterationMarker"); | |
| 1619 classElement.ensureResolved(compiler); | |
| 1620 return classElement.lookupLocalMember("yieldSingle"); | |
| 1621 } | |
| 1622 | |
| 1623 Element getStreamHelper() { | |
| 1624 return findHelper("streamHelper"); | |
| 1625 } | |
| 1626 | |
| 1627 Element getEndOfIteration() { | |
| 1628 ClassElement classElement = findHelper("IterationMarker"); | |
| 1629 classElement.ensureResolved(compiler); | |
| 1630 return classElement.lookupLocalMember("endOfIteration"); | |
| 1631 } | |
| 1632 | |
| 1633 Element getSyncStarIterable() { | |
| 1634 ClassElement classElement = findHelper("SyncStarIterable"); | |
| 1635 classElement.ensureResolved(compiler); | |
| 1636 return classElement; | |
| 1637 } | |
| 1638 | |
| 1639 Element getSyncStarIterableConstructor() { | |
| 1640 ClassElement classElement = getSyncStarIterable(); | |
| 1641 classElement.ensureResolved(compiler); | |
| 1642 return classElement.lookupConstructor(""); | |
| 1643 } | |
| 1644 | |
| 1645 Element getCompleterConstructor() { | |
| 1646 ClassElement classElement = find(asyncLibrary, "Completer"); | |
| 1647 classElement.ensureResolved(compiler); | |
| 1648 return classElement | |
| 1649 .lookupConstructor(""); | |
| 1650 } | |
| 1651 | |
| 1652 Element getMakeController() { | |
| 1653 return findHelper("makeAsyncStarController"); | |
| 1654 } | |
| 1655 | |
| 1656 Element getStreamIteratorConstructor() { | |
| 1657 ClassElement classElement = find(asyncLibrary, "StreamIterator"); | |
| 1658 classElement.ensureResolved(compiler); | |
| 1659 return classElement | |
| 1660 .lookupConstructor(""); | |
| 1661 } | |
| 1662 | |
| 1600 bool isNullImplementation(ClassElement cls) { | 1663 bool isNullImplementation(ClassElement cls) { |
| 1601 return cls == jsNullClass; | 1664 return cls == jsNullClass; |
| 1602 } | 1665 } |
| 1603 | 1666 |
| 1604 ClassElement get intImplementation => jsIntClass; | 1667 ClassElement get intImplementation => jsIntClass; |
| 1605 ClassElement get uint32Implementation => jsUInt32Class; | 1668 ClassElement get uint32Implementation => jsUInt32Class; |
| 1606 ClassElement get uint31Implementation => jsUInt31Class; | 1669 ClassElement get uint31Implementation => jsUInt31Class; |
| 1607 ClassElement get positiveIntImplementation => jsPositiveIntClass; | 1670 ClassElement get positiveIntImplementation => jsPositiveIntClass; |
| 1608 ClassElement get doubleImplementation => jsDoubleClass; | 1671 ClassElement get doubleImplementation => jsDoubleClass; |
| 1609 ClassElement get numImplementation => jsNumberClass; | 1672 ClassElement get numImplementation => jsNumberClass; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1689 } | 1752 } |
| 1690 return true; | 1753 return true; |
| 1691 } | 1754 } |
| 1692 return false; | 1755 return false; |
| 1693 } | 1756 } |
| 1694 | 1757 |
| 1695 void onLibraryCreated(LibraryElement library) { | 1758 void onLibraryCreated(LibraryElement library) { |
| 1696 Uri uri = library.canonicalUri; | 1759 Uri uri = library.canonicalUri; |
| 1697 if (uri == DART_JS_HELPER) { | 1760 if (uri == DART_JS_HELPER) { |
| 1698 jsHelperLibrary = library; | 1761 jsHelperLibrary = library; |
| 1762 } else if (uri == DART_ASYNC) { | |
| 1763 asyncLibrary = library; | |
|
Johnni Winther
2015/02/02 10:45:10
Not needed.
sigurdm
2015/02/03 16:59:27
Done
| |
| 1699 } else if (uri == DART_INTERNAL) { | 1764 } else if (uri == DART_INTERNAL) { |
| 1700 internalLibrary = library; | 1765 internalLibrary = library; |
| 1701 } else if (uri == DART_INTERCEPTORS) { | 1766 } else if (uri == DART_INTERCEPTORS) { |
| 1702 interceptorsLibrary = library; | 1767 interceptorsLibrary = library; |
| 1703 } else if (uri == DART_FOREIGN_HELPER) { | 1768 } else if (uri == DART_FOREIGN_HELPER) { |
| 1704 foreignLibrary = library; | 1769 foreignLibrary = library; |
| 1705 } else if (uri == DART_ISOLATE_HELPER) { | 1770 } else if (uri == DART_ISOLATE_HELPER) { |
| 1706 isolateHelperLibrary = library; | 1771 isolateHelperLibrary = library; |
| 1707 } | 1772 } |
| 1708 } | 1773 } |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2324 /// If [addExtension] is false, the ".part.js" suffix is left out. | 2389 /// If [addExtension] is false, the ".part.js" suffix is left out. |
| 2325 String deferredPartFileName(String name, {bool addExtension: true}) { | 2390 String deferredPartFileName(String name, {bool addExtension: true}) { |
| 2326 assert(name != ""); | 2391 assert(name != ""); |
| 2327 String outPath = compiler.outputUri != null | 2392 String outPath = compiler.outputUri != null |
| 2328 ? compiler.outputUri.path | 2393 ? compiler.outputUri.path |
| 2329 : "out"; | 2394 : "out"; |
| 2330 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); | 2395 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); |
| 2331 String extension = addExtension ? ".part.js" : ""; | 2396 String extension = addExtension ? ".part.js" : ""; |
| 2332 return "${outName}_$name$extension"; | 2397 return "${outName}_$name$extension"; |
| 2333 } | 2398 } |
| 2399 | |
| 2400 void registerAsyncMarker(FunctionElement element, | |
| 2401 Enqueuer enqueuer, | |
| 2402 Registry registry) { | |
| 2403 if (element.asyncMarker == AsyncMarker.ASYNC) { | |
| 2404 enqueue(enqueuer, getThenHelper(), registry); | |
| 2405 enqueue(enqueuer, getCompleterConstructor(), registry); | |
| 2406 enqueue(enqueuer, getStreamIteratorConstructor(), registry); | |
| 2407 } else if (element.asyncMarker == AsyncMarker.SYNC_STAR) { | |
| 2408 enqueuer.registerInstantiatedClass(getSyncStarIterable(), registry); | |
| 2409 enqueue(enqueuer, getSyncStarIterableConstructor(), registry); | |
| 2410 enqueue(enqueuer, getEndOfIteration(), registry); | |
| 2411 enqueue(enqueuer, getSyncStarYieldStar(), registry); | |
| 2412 } else if (element.asyncMarker == AsyncMarker.ASYNC_STAR) { | |
| 2413 enqueue(enqueuer, getStreamHelper(), registry); | |
| 2414 enqueue(enqueuer, getYieldSingle(), registry); | |
| 2415 enqueue(enqueuer, getMakeController(), registry); | |
| 2416 enqueue(enqueuer, getStreamIteratorConstructor(), registry); | |
| 2417 } | |
| 2418 } | |
| 2334 } | 2419 } |
| 2335 | 2420 |
| 2336 class JavaScriptResolutionCallbacks extends ResolutionCallbacks { | 2421 class JavaScriptResolutionCallbacks extends ResolutionCallbacks { |
| 2337 final JavaScriptBackend backend; | 2422 final JavaScriptBackend backend; |
| 2338 | 2423 |
| 2339 JavaScriptResolutionCallbacks(this.backend); | 2424 JavaScriptResolutionCallbacks(this.backend); |
| 2340 | 2425 |
| 2341 void registerBackendStaticInvocation(Element element, Registry registry) { | 2426 void registerBackendStaticInvocation(Element element, Registry registry) { |
| 2342 registry.registerStaticInvocation(backend.registerBackendUse(element)); | 2427 registry.registerStaticInvocation(backend.registerBackendUse(element)); |
| 2343 } | 2428 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2530 } | 2615 } |
| 2531 } | 2616 } |
| 2532 | 2617 |
| 2533 /// Records that [constant] is used by the element behind [registry]. | 2618 /// Records that [constant] is used by the element behind [registry]. |
| 2534 class Dependency { | 2619 class Dependency { |
| 2535 final ConstantValue constant; | 2620 final ConstantValue constant; |
| 2536 final Element annotatedElement; | 2621 final Element annotatedElement; |
| 2537 | 2622 |
| 2538 const Dependency(this.constant, this.annotatedElement); | 2623 const Dependency(this.constant, this.annotatedElement); |
| 2539 } | 2624 } |
| OLD | NEW |