| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <signal.h> | 6 #include <signal.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 exit(1); | 104 exit(1); |
| 105 } | 105 } |
| 106 return fp; | 106 return fp; |
| 107 } | 107 } |
| 108 | 108 |
| 109 FILE* fp_; | 109 FILE* fp_; |
| 110 FILE* startup_blob_file_; | 110 FILE* startup_blob_file_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 | 113 |
| 114 char* GetExtraCode(char* filename) { |
| 115 if (filename == NULL || strlen(filename) == 0) return NULL; |
| 116 ::printf("Embedding extra script: %s\n", filename); |
| 117 FILE* file = base::OS::FOpen(filename, "rb"); |
| 118 if (file == NULL) { |
| 119 fprintf(stderr, "Failed to open '%s': errno %d\n", filename, errno); |
| 120 exit(1); |
| 121 } |
| 122 fseek(file, 0, SEEK_END); |
| 123 int size = ftell(file); |
| 124 rewind(file); |
| 125 char* chars = new char[size + 1]; |
| 126 chars[size] = '\0'; |
| 127 for (int i = 0; i < size;) { |
| 128 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 129 if (read < 0) { |
| 130 fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno); |
| 131 exit(1); |
| 132 } |
| 133 i += read; |
| 134 } |
| 135 fclose(file); |
| 136 return chars; |
| 137 } |
| 138 |
| 139 |
| 114 int main(int argc, char** argv) { | 140 int main(int argc, char** argv) { |
| 115 // By default, log code create information in the snapshot. | 141 // By default, log code create information in the snapshot. |
| 116 i::FLAG_log_code = true; | 142 i::FLAG_log_code = true; |
| 117 | 143 |
| 118 // Omit from the snapshot natives for features that can be turned off | 144 // Omit from the snapshot natives for features that can be turned off |
| 119 // at runtime. | 145 // at runtime. |
| 120 i::FLAG_harmony_shipping = false; | 146 i::FLAG_harmony_shipping = false; |
| 121 | 147 |
| 122 i::FLAG_logfile_per_isolate = false; | 148 i::FLAG_logfile_per_isolate = false; |
| 123 | 149 |
| 124 // Print the usage if an error occurs when parsing the command line | 150 // Print the usage if an error occurs when parsing the command line |
| 125 // flags or if the help flag is set. | 151 // flags or if the help flag is set. |
| 126 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 152 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
| 127 if (result > 0 || argc != 2 || i::FLAG_help) { | 153 if (result > 0 || (argc != 2 && argc != 3) || i::FLAG_help) { |
| 128 ::printf("Usage: %s [flag] ... outfile\n", argv[0]); | 154 ::printf("Usage: %s [flag] ... outfile\n", argv[0]); |
| 129 i::FlagList::PrintHelp(); | 155 i::FlagList::PrintHelp(); |
| 130 return !i::FLAG_help; | 156 return !i::FLAG_help; |
| 131 } | 157 } |
| 132 | 158 |
| 133 i::CpuFeatures::Probe(true); | 159 i::CpuFeatures::Probe(true); |
| 134 V8::InitializeICU(); | 160 V8::InitializeICU(); |
| 135 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 161 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 136 v8::V8::InitializePlatform(platform); | 162 v8::V8::InitializePlatform(platform); |
| 137 v8::V8::Initialize(); | 163 v8::V8::Initialize(); |
| 138 | 164 |
| 139 { | 165 { |
| 140 SnapshotWriter writer(argv[1]); | 166 SnapshotWriter writer(argv[1]); |
| 141 if (i::FLAG_startup_blob) writer.SetStartupBlobFile(i::FLAG_startup_blob); | 167 if (i::FLAG_startup_blob) writer.SetStartupBlobFile(i::FLAG_startup_blob); |
| 142 StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 168 char* extra_code = GetExtraCode(argc == 3 ? argv[2] : NULL); |
| 169 StartupData blob = v8::V8::CreateSnapshotDataBlob(extra_code); |
| 143 CHECK(blob.data); | 170 CHECK(blob.data); |
| 144 writer.WriteSnapshot(blob); | 171 writer.WriteSnapshot(blob); |
| 172 delete[] extra_code; |
| 145 delete[] blob.data; | 173 delete[] blob.data; |
| 146 } | 174 } |
| 147 | 175 |
| 148 V8::Dispose(); | 176 V8::Dispose(); |
| 149 V8::ShutdownPlatform(); | 177 V8::ShutdownPlatform(); |
| 150 delete platform; | 178 delete platform; |
| 151 return 0; | 179 return 0; |
| 152 } | 180 } |
| OLD | NEW |