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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~SnapshotByteSink() { } |
74 virtual void Put(int byte, const char* description) = 0; | 74 virtual void Put(byte b, const char* description) = 0; |
75 virtual void PutSection(int byte, const char* description) { | 75 virtual void PutSection(int b, const char* description) { |
76 Put(byte, description); | 76 ASSERT_LE(b, kMaxUInt8); |
| 77 Put(static_cast<byte>(b), description); |
77 } | 78 } |
78 void PutInt(uintptr_t integer, const char* description); | 79 void PutInt(uintptr_t integer, const char* description); |
79 void PutRaw(byte* data, int number_of_bytes, const char* description); | 80 void PutRaw(byte* data, int number_of_bytes, const char* description); |
80 void PutBlob(byte* data, int number_of_bytes, const char* description); | 81 void PutBlob(byte* data, int number_of_bytes, const char* description); |
81 virtual int Position() = 0; | 82 virtual int Position() = 0; |
82 }; | 83 }; |
83 | 84 |
84 | 85 |
85 class DummySnapshotSink : public SnapshotByteSink { | 86 class DummySnapshotSink : public SnapshotByteSink { |
86 public: | 87 public: |
87 DummySnapshotSink() : length_(0) {} | 88 DummySnapshotSink() : length_(0) {} |
88 virtual ~DummySnapshotSink() {} | 89 virtual ~DummySnapshotSink() {} |
89 virtual void Put(int byte, const char* description) { length_++; } | 90 virtual void Put(byte b, const char* description) { length_++; } |
90 virtual int Position() { return length_; } | 91 virtual int Position() { return length_; } |
91 | 92 |
92 private: | 93 private: |
93 int length_; | 94 int length_; |
94 }; | 95 }; |
95 | 96 |
96 | 97 |
97 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. | 98 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. |
98 class DebugSnapshotSink : public SnapshotByteSink { | 99 class DebugSnapshotSink : public SnapshotByteSink { |
99 public: | 100 public: |
100 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} | 101 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} |
101 virtual void Put(int byte, const char* description) V8_OVERRIDE; | 102 virtual void Put(byte b, const char* description) V8_OVERRIDE; |
102 virtual int Position() V8_OVERRIDE { return sink_->Position(); } | 103 virtual int Position() V8_OVERRIDE { return sink_->Position(); } |
103 | 104 |
104 private: | 105 private: |
105 SnapshotByteSink* sink_; | 106 SnapshotByteSink* sink_; |
106 }; | 107 }; |
107 | 108 |
108 | 109 |
109 class ListSnapshotSink : public i::SnapshotByteSink { | 110 class ListSnapshotSink : public i::SnapshotByteSink { |
110 public: | 111 public: |
111 explicit ListSnapshotSink(i::List<char>* data) : data_(data) {} | 112 explicit ListSnapshotSink(i::List<byte>* data) : data_(data) {} |
112 virtual void Put(int byte, const char* description) V8_OVERRIDE { | 113 virtual void Put(byte b, const char* description) V8_OVERRIDE { |
113 data_->Add(byte); | 114 data_->Add(b); |
114 } | 115 } |
115 virtual int Position() V8_OVERRIDE { return data_->length(); } | 116 virtual int Position() V8_OVERRIDE { return data_->length(); } |
116 | 117 |
117 private: | 118 private: |
118 i::List<char>* data_; | 119 i::List<byte>* data_; |
119 }; | 120 }; |
120 | 121 |
121 } // namespace v8::internal | 122 } // namespace v8::internal |
122 } // namespace v8 | 123 } // namespace v8 |
123 | 124 |
124 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ | 125 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ |
OLD | NEW |