Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: src/mksnapshot.cc

Issue 342054: Introduce a switch for the new snapshot code and switch... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/serialize.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/mksnapshot.cc
===================================================================
--- src/mksnapshot.cc (revision 3179)
+++ src/mksnapshot.cc (working copy)
@@ -109,6 +109,46 @@
}
+class CppByteSink : public i::SnapshotByteSink {
+ public:
+ explicit CppByteSink(const char* snapshot_file) : bytes_written_(0) {
+ fp_ = i::OS::FOpen(snapshot_file, "wb");
+ if (fp_ == NULL) {
+ i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
+ exit(1);
+ }
+ fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
+ fprintf(fp_, "#include \"v8.h\"\n");
+ fprintf(fp_, "#include \"platform.h\"\n\n");
+ fprintf(fp_, "#include \"snapshot.h\"\n\n");
+ fprintf(fp_, "namespace v8 {\nnamespace internal {\n\n");
+ fprintf(fp_, "const byte Snapshot::data_[] = {");
+ }
+ virtual ~CppByteSink() {
Mads Ager (chromium) 2009/10/30 10:17:11 Space between the methods?
+ if (fp_ != NULL) {
+ fprintf(fp_, "};\n\n");
+ fprintf(fp_, "int Snapshot::size_ = %d;\n\n", bytes_written_);
+ fprintf(fp_, "} } // namespace v8::internal\n");
+ fclose(fp_);
+ }
+ }
+ virtual void Put(int byte, const char* description) {
+ if (bytes_written_ != 0) {
+ fprintf(fp_, ",");
+ }
+ fprintf(fp_, "%d", byte);
+ bytes_written_++;
+ if ((bytes_written_ & 0x3f) == 0) {
+ fprintf(fp_, "\n");
+ }
+ }
+
+ private:
+ FILE* fp_;
+ int bytes_written_;
+};
+
+
// Write C++ code that defines Snapshot::snapshot_ to contain the snapshot
// to the file given by filename. Only the first size chars are written.
static int WriteInternalSnapshotToFile(const char* filename,
@@ -116,7 +156,7 @@
int size) {
FILE* f = i::OS::FOpen(filename, "wb");
if (f == NULL) {
- i::OS::PrintError("Cannot open file %s for reading.\n", filename);
+ i::OS::PrintError("Cannot open file %s for writing.\n", filename);
return 0;
}
fprintf(f, "// Autogenerated snapshot file. Do not edit.\n\n");
@@ -140,6 +180,23 @@
}
+int main2(int argc, char** argv) {
+ i::Serializer::Enable();
+ Persistent<Context> context = v8::Context::New();
+ // Make sure all builtin scripts are cached.
+ { HandleScope scope;
+ for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
+ i::Bootstrapper::NativesSourceLookup(i);
+ }
+ }
+ context.Dispose();
+ CppByteSink sink(argv[1]);
+ i::Serializer2 ser(&sink);
+ ser.Serialize();
+ return 0;
+}
+
+
int main(int argc, char** argv) {
#ifdef ENABLE_LOGGING_AND_PROFILING
// By default, log code create information in the snapshot.
@@ -154,6 +211,10 @@
return !i::FLAG_help;
}
+ if (i::FLAG_new_snapshot) {
+ return main2(argc, argv);
+ }
+
v8::V8::SetCounterFunction(counter_callback);
v8::HandleScope scope;
« no previous file with comments | « src/ia32/assembler-ia32.h ('k') | src/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698