Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_ | |
| 6 #define V8_SNAPSHOT_SOURCE_SINK_H_ | |
| 7 | |
| 8 #include "checks.h" | |
| 9 #include "utils.h" | |
| 10 | |
| 11 namespace v8 { | |
| 12 namespace internal { | |
| 13 | |
| 14 | |
| 15 /** | |
| 16 * Source to read snapshot and builtins files from. | |
| 17 * | |
| 18 * Note: Memory ownership remains with callee. | |
| 19 */ | |
| 20 class SnapshotByteSource { | |
| 21 public: | |
| 22 SnapshotByteSource(const byte* array, int length); | |
|
jochen (gone - plz use gerrit)
2014/05/23 11:44:44
please add a dtor
vogelheim
2014/05/26 12:36:03
Done.
| |
| 23 | |
| 24 bool HasMore() { return position_ < length_; } | |
| 25 | |
| 26 int Get() { | |
| 27 ASSERT(position_ < length_); | |
| 28 return data_[position_++]; | |
| 29 } | |
| 30 | |
| 31 int32_t GetUnalignedInt(); | |
| 32 | |
| 33 void Advance(int by) { position_ += by; } | |
| 34 | |
| 35 void CopyRaw(byte* to, int number_of_bytes); | |
| 36 | |
| 37 inline int GetInt() { | |
| 38 // This way of variable-length encoding integers does not suffer from branch | |
| 39 // mispredictions. | |
| 40 uint32_t answer = GetUnalignedInt(); | |
| 41 int bytes = answer & 3; | |
| 42 Advance(bytes); | |
| 43 uint32_t mask = 0xffffffffu; | |
| 44 mask >>= 32 - (bytes << 3); | |
| 45 answer &= mask; | |
| 46 answer >>= 2; | |
| 47 return answer; | |
| 48 } | |
| 49 | |
| 50 bool GetBlob(const byte** data, int* number_of_bytes); | |
| 51 | |
| 52 bool AtEOF(); | |
| 53 | |
| 54 int position() { return position_; } | |
| 55 | |
| 56 private: | |
| 57 const byte* data_; | |
| 58 int length_; | |
| 59 int position_; | |
| 60 }; | |
|
jochen (gone - plz use gerrit)
2014/05/23 11:44:44
disallow copy and assign
vogelheim
2014/05/26 12:36:03
Done.
| |
| 61 | |
| 62 | |
| 63 /** | |
| 64 * Sink to write snapshot files to. | |
| 65 * | |
| 66 * Subclasses must implement actual storage or i/o. | |
| 67 */ | |
| 68 class SnapshotByteSink { | |
| 69 public: | |
| 70 virtual ~SnapshotByteSink() { } | |
| 71 virtual void Put(int byte, const char* description) = 0; | |
| 72 virtual void PutSection(int byte, const char* description) { | |
| 73 Put(byte, description); | |
| 74 } | |
| 75 void PutInt(uintptr_t integer, const char* description); | |
| 76 void PutRaw(byte* data, int number_of_bytes, const char* description); | |
| 77 void PutBlob(byte* data, int number_of_bytes, const char* description); | |
| 78 virtual int Position() = 0; | |
| 79 }; | |
| 80 | |
| 81 | |
| 82 } // namespace v8::internal | |
| 83 } // namespace v8 | |
| 84 | |
| 85 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ | |
| OLD | NEW |