OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <iostream> |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/process/memory.h" |
| 14 #include "dart/runtime/include/dart_api.h" |
| 15 #include "sky/tools/packager/loader.h" |
| 16 #include "sky/tools/packager/logging.h" |
| 17 #include "sky/tools/packager/scope.h" |
| 18 #include "sky/tools/packager/switches.h" |
| 19 #include "sky/tools/packager/vm.h" |
| 20 |
| 21 void WriteSnapshot(base::FilePath path) { |
| 22 uint8_t* buffer; |
| 23 intptr_t size; |
| 24 CHECK(!LogIfError(Dart_CreateScriptSnapshot(&buffer, &size))); |
| 25 |
| 26 CHECK_EQ(base::WriteFile(path, reinterpret_cast<const char*>(buffer), size), |
| 27 size); |
| 28 |
| 29 std::cout << "Successfully wrote snapshot to " << path.LossyDisplayName() |
| 30 << " (" << size << " bytes)." << std::endl; |
| 31 } |
| 32 |
| 33 int main(int argc, const char* argv[]) { |
| 34 base::AtExitManager exit_manager; |
| 35 base::EnableTerminationOnHeapCorruption(); |
| 36 base::CommandLine::Init(argc, argv); |
| 37 |
| 38 InitDartVM(); |
| 39 Dart_Isolate isolate = CreateDartIsolate(); |
| 40 CHECK(isolate); |
| 41 |
| 42 const base::CommandLine& command_line = |
| 43 *base::CommandLine::ForCurrentProcess(); |
| 44 |
| 45 DartIsolateScope scope(isolate); |
| 46 DartApiScope api_scope; |
| 47 |
| 48 auto args = command_line.GetArgs(); |
| 49 CHECK(args.size() == 1); |
| 50 LoadScript(args[0]); |
| 51 |
| 52 CHECK(!LogIfError(Dart_FinalizeLoading(true))); |
| 53 |
| 54 CHECK(command_line.HasSwitch(kSnapshot)) << "Need --snapshot"; |
| 55 WriteSnapshot(command_line.GetSwitchValuePath(kSnapshot)); |
| 56 |
| 57 return 0; |
| 58 } |
OLD | NEW |