| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1651 CHECK_RESULT(result); | 1651 CHECK_RESULT(result); |
| 1652 | 1652 |
| 1653 UriResolverIsolateScope::isolate = isolate; | 1653 UriResolverIsolateScope::isolate = isolate; |
| 1654 Dart_ExitScope(); | 1654 Dart_ExitScope(); |
| 1655 Dart_ExitIsolate(); | 1655 Dart_ExitIsolate(); |
| 1656 | 1656 |
| 1657 // Now we create an isolate into which we load all the code that needs to | 1657 // Now we create an isolate into which we load all the code that needs to |
| 1658 // be in the snapshot. | 1658 // be in the snapshot. |
| 1659 isolate_data = new IsolateData(app_script_name, commandline_package_root, | 1659 isolate_data = new IsolateData(app_script_name, commandline_package_root, |
| 1660 commandline_packages_file, NULL); | 1660 commandline_packages_file, NULL); |
| 1661 const uint8_t* kernel = NULL; | |
| 1662 intptr_t kernel_length = 0; | |
| 1663 const bool is_kernel_file = | |
| 1664 dfe.TryReadKernelFile(app_script_name, &kernel, &kernel_length); | |
| 1665 | |
| 1666 if ((dependencies_filename != NULL) || print_dependencies) { | 1661 if ((dependencies_filename != NULL) || print_dependencies) { |
| 1667 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | 1662 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
| 1668 } | 1663 } |
| 1669 | 1664 |
| 1670 void* kernel_program = NULL; | 1665 Dart_Isolate isolate = NULL; |
| 1671 if (is_kernel_file) { | 1666 void* kernel_program = dfe.ReadScript(app_script_name); |
| 1672 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); | 1667 if (kernel_program != NULL) { |
| 1673 free(const_cast<uint8_t*>(kernel)); | 1668 isolate = Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
| 1669 isolate_data, &error); |
| 1670 } else { |
| 1671 isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
| 1672 isolate_snapshot_instructions, NULL, |
| 1673 isolate_data, &error); |
| 1674 } | 1674 } |
| 1675 | |
| 1676 Dart_Isolate isolate = | |
| 1677 is_kernel_file | |
| 1678 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, | |
| 1679 isolate_data, &error) | |
| 1680 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, | |
| 1681 isolate_snapshot_instructions, NULL, | |
| 1682 isolate_data, &error); | |
| 1683 if (isolate == NULL) { | 1675 if (isolate == NULL) { |
| 1684 Log::PrintErr("%s\n", error); | 1676 Log::PrintErr("%s\n", error); |
| 1685 free(error); | 1677 free(error); |
| 1686 exit(kErrorExitCode); | 1678 exit(kErrorExitCode); |
| 1687 } | 1679 } |
| 1688 Dart_EnterScope(); | 1680 Dart_EnterScope(); |
| 1689 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1681 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1690 CHECK_RESULT(result); | 1682 CHECK_RESULT(result); |
| 1691 | 1683 |
| 1692 // Set up the library tag handler in such a manner that it will use the | 1684 // Set up the library tag handler in such a manner that it will use the |
| 1693 // URL mapping specified on the command line to load the libraries. | 1685 // URL mapping specified on the command line to load the libraries. |
| 1694 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1686 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 1695 CHECK_RESULT(result); | 1687 CHECK_RESULT(result); |
| 1696 | 1688 |
| 1697 if (commandline_packages_file != NULL) { | 1689 if (commandline_packages_file != NULL) { |
| 1698 AddDependency(commandline_packages_file); | 1690 AddDependency(commandline_packages_file); |
| 1699 } | 1691 } |
| 1700 | 1692 |
| 1701 Dart_QualifiedFunctionName* entry_points = | 1693 Dart_QualifiedFunctionName* entry_points = |
| 1702 ParseEntryPointsManifestIfPresent(); | 1694 ParseEntryPointsManifestIfPresent(); |
| 1703 | 1695 |
| 1704 if (is_kernel_file) { | 1696 if (kernel_program != NULL) { |
| 1705 Dart_Handle library = Dart_LoadKernel(kernel_program); | 1697 Dart_Handle library = Dart_LoadKernel(kernel_program); |
| 1706 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); | 1698 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); |
| 1707 } else { | 1699 } else { |
| 1708 // Set up the library tag handler in such a manner that it will use the | 1700 // Set up the library tag handler in such a manner that it will use the |
| 1709 // URL mapping specified on the command line to load the libraries. | 1701 // URL mapping specified on the command line to load the libraries. |
| 1710 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1702 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 1711 CHECK_RESULT(result); | 1703 CHECK_RESULT(result); |
| 1712 } | 1704 } |
| 1713 | 1705 |
| 1714 SetupStubNativeResolversForPrecompilation(entry_points); | 1706 SetupStubNativeResolversForPrecompilation(entry_points); |
| 1715 | 1707 |
| 1716 SetupStubNativeResolvers(); | 1708 SetupStubNativeResolvers(); |
| 1717 | 1709 |
| 1718 if (!is_kernel_file) { | 1710 if (kernel_program == NULL) { |
| 1719 // Load the specified script. | 1711 // Load the specified script. |
| 1720 library = LoadSnapshotCreationScript(app_script_name); | 1712 library = LoadSnapshotCreationScript(app_script_name); |
| 1721 CHECK_RESULT(library); | 1713 CHECK_RESULT(library); |
| 1722 | 1714 |
| 1723 ImportNativeEntryPointLibrariesIntoRoot(entry_points); | 1715 ImportNativeEntryPointLibrariesIntoRoot(entry_points); |
| 1724 } | 1716 } |
| 1725 | 1717 |
| 1726 // Ensure that we mark all libraries as loaded. | 1718 // Ensure that we mark all libraries as loaded. |
| 1727 result = Dart_FinalizeLoading(false); | 1719 result = Dart_FinalizeLoading(false); |
| 1728 CHECK_RESULT(result); | 1720 CHECK_RESULT(result); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 delete mapped_isolate_snapshot_data; | 1775 delete mapped_isolate_snapshot_data; |
| 1784 return 0; | 1776 return 0; |
| 1785 } | 1777 } |
| 1786 | 1778 |
| 1787 } // namespace bin | 1779 } // namespace bin |
| 1788 } // namespace dart | 1780 } // namespace dart |
| 1789 | 1781 |
| 1790 int main(int argc, char** argv) { | 1782 int main(int argc, char** argv) { |
| 1791 return dart::bin::main(argc, argv); | 1783 return dart::bin::main(argc, argv); |
| 1792 } | 1784 } |
| OLD | NEW |