OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_ | 5 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_ |
6 #define V8_SNAPSHOT_SOURCE_SINK_H_ | 6 #define V8_SNAPSHOT_SOURCE_SINK_H_ |
7 | 7 |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/utils.h" | 9 #include "src/utils.h" |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 }; | 63 }; |
64 | 64 |
65 | 65 |
66 /** | 66 /** |
67 * Sink to write snapshot files to. | 67 * Sink to write snapshot files to. |
68 * | 68 * |
69 * Subclasses must implement actual storage or i/o. | 69 * Subclasses must implement actual storage or i/o. |
70 */ | 70 */ |
71 class SnapshotByteSink { | 71 class SnapshotByteSink { |
72 public: | 72 public: |
73 virtual ~SnapshotByteSink() { } | 73 SnapshotByteSink() {} |
74 virtual void Put(byte b, const char* description) = 0; | 74 explicit SnapshotByteSink(int initial_size) : data_(initial_size) {} |
75 virtual void PutSection(int b, const char* description) { | 75 |
| 76 ~SnapshotByteSink() {} |
| 77 |
| 78 void Put(byte b, const char* description) { data_.Add(b); } |
| 79 |
| 80 void PutSection(int b, const char* description) { |
76 DCHECK_LE(b, kMaxUInt8); | 81 DCHECK_LE(b, kMaxUInt8); |
77 Put(static_cast<byte>(b), description); | 82 Put(static_cast<byte>(b), description); |
78 } | 83 } |
| 84 |
79 void PutInt(uintptr_t integer, const char* description); | 85 void PutInt(uintptr_t integer, const char* description); |
80 void PutRaw(byte* data, int number_of_bytes, const char* description); | 86 void PutRaw(byte* data, int number_of_bytes, const char* description); |
81 void PutBlob(byte* data, int number_of_bytes, const char* description); | 87 void PutBlob(byte* data, int number_of_bytes, const char* description); |
82 virtual int Position() = 0; | 88 int Position() { return data_.length(); } |
83 }; | |
84 | 89 |
85 | 90 const List<byte>& data() const { return data_; } |
86 class DummySnapshotSink : public SnapshotByteSink { | |
87 public: | |
88 DummySnapshotSink() : length_(0) {} | |
89 virtual ~DummySnapshotSink() {} | |
90 virtual void Put(byte b, const char* description) { length_++; } | |
91 virtual int Position() { return length_; } | |
92 | 91 |
93 private: | 92 private: |
94 int length_; | 93 List<byte> data_; |
95 }; | |
96 | |
97 | |
98 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. | |
99 class DebugSnapshotSink : public SnapshotByteSink { | |
100 public: | |
101 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} | |
102 virtual void Put(byte b, const char* description) OVERRIDE; | |
103 virtual int Position() OVERRIDE { return sink_->Position(); } | |
104 | |
105 private: | |
106 SnapshotByteSink* sink_; | |
107 }; | |
108 | |
109 | |
110 class ListSnapshotSink : public i::SnapshotByteSink { | |
111 public: | |
112 explicit ListSnapshotSink(i::List<byte>* data) : data_(data) {} | |
113 virtual void Put(byte b, const char* description) OVERRIDE { | |
114 data_->Add(b); | |
115 } | |
116 virtual int Position() OVERRIDE { return data_->length(); } | |
117 | |
118 private: | |
119 i::List<byte>* data_; | |
120 }; | 94 }; |
121 | 95 |
122 } // namespace v8::internal | 96 } // namespace v8::internal |
123 } // namespace v8 | 97 } // namespace v8 |
124 | 98 |
125 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ | 99 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ |
OLD | NEW |