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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 | 14 |
15 /** | 15 /** |
16 * Source to read snapshot and builtins files from. | 16 * Source to read snapshot and builtins files from. |
17 * | 17 * |
18 * Note: Memory ownership remains with callee. | 18 * Note: Memory ownership remains with callee. |
19 */ | 19 */ |
20 class SnapshotByteSource V8_FINAL { | 20 class SnapshotByteSource FINAL { |
21 public: | 21 public: |
22 SnapshotByteSource(const byte* array, int length); | 22 SnapshotByteSource(const byte* array, int length); |
23 ~SnapshotByteSource(); | 23 ~SnapshotByteSource(); |
24 | 24 |
25 bool HasMore() { return position_ < length_; } | 25 bool HasMore() { return position_ < length_; } |
26 | 26 |
27 int Get() { | 27 int Get() { |
28 DCHECK(position_ < length_); | 28 DCHECK(position_ < length_); |
29 return data_[position_++]; | 29 return data_[position_++]; |
30 } | 30 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 private: | 93 private: |
94 int length_; | 94 int length_; |
95 }; | 95 }; |
96 | 96 |
97 | 97 |
98 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. | 98 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. |
99 class DebugSnapshotSink : public SnapshotByteSink { | 99 class DebugSnapshotSink : public SnapshotByteSink { |
100 public: | 100 public: |
101 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} | 101 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} |
102 virtual void Put(byte b, const char* description) V8_OVERRIDE; | 102 virtual void Put(byte b, const char* description) OVERRIDE; |
103 virtual int Position() V8_OVERRIDE { return sink_->Position(); } | 103 virtual int Position() OVERRIDE { return sink_->Position(); } |
104 | 104 |
105 private: | 105 private: |
106 SnapshotByteSink* sink_; | 106 SnapshotByteSink* sink_; |
107 }; | 107 }; |
108 | 108 |
109 | 109 |
110 class ListSnapshotSink : public i::SnapshotByteSink { | 110 class ListSnapshotSink : public i::SnapshotByteSink { |
111 public: | 111 public: |
112 explicit ListSnapshotSink(i::List<byte>* data) : data_(data) {} | 112 explicit ListSnapshotSink(i::List<byte>* data) : data_(data) {} |
113 virtual void Put(byte b, const char* description) V8_OVERRIDE { | 113 virtual void Put(byte b, const char* description) OVERRIDE { |
114 data_->Add(b); | 114 data_->Add(b); |
115 } | 115 } |
116 virtual int Position() V8_OVERRIDE { return data_->length(); } | 116 virtual int Position() OVERRIDE { return data_->length(); } |
117 | 117 |
118 private: | 118 private: |
119 i::List<byte>* data_; | 119 i::List<byte>* data_; |
120 }; | 120 }; |
121 | 121 |
122 } // namespace v8::internal | 122 } // namespace v8::internal |
123 } // namespace v8 | 123 } // namespace v8 |
124 | 124 |
125 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ | 125 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ |
OLD | NEW |