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

Side by Side Diff: src/snapshot-source-sink.h

Issue 293993021: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Final rebase (I hope) w/ various fixes. Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/snapshot-external.cc ('k') | src/snapshot-source-sink.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "src/checks.h"
9 #include "src/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 V8_FINAL {
21 public:
22 SnapshotByteSource(const byte* array, int length);
23 ~SnapshotByteSource();
24
25 bool HasMore() { return position_ < length_; }
26
27 int Get() {
28 ASSERT(position_ < length_);
29 return data_[position_++];
30 }
31
32 int32_t GetUnalignedInt();
33
34 void Advance(int by) { position_ += by; }
35
36 void CopyRaw(byte* to, int number_of_bytes);
37
38 inline int GetInt() {
39 // This way of variable-length encoding integers does not suffer from branch
40 // mispredictions.
41 uint32_t answer = GetUnalignedInt();
42 int bytes = answer & 3;
43 Advance(bytes);
44 uint32_t mask = 0xffffffffu;
45 mask >>= 32 - (bytes << 3);
46 answer &= mask;
47 answer >>= 2;
48 return answer;
49 }
50
51 bool GetBlob(const byte** data, int* number_of_bytes);
52
53 bool AtEOF();
54
55 int position() { return position_; }
56
57 private:
58 const byte* data_;
59 int length_;
60 int position_;
61
62 DISALLOW_COPY_AND_ASSIGN(SnapshotByteSource);
63 };
64
65
66 /**
67 * Sink to write snapshot files to.
68 *
69 * Subclasses must implement actual storage or i/o.
70 */
71 class SnapshotByteSink {
72 public:
73 virtual ~SnapshotByteSink() { }
74 virtual void Put(int byte, const char* description) = 0;
75 virtual void PutSection(int byte, const char* description) {
76 Put(byte, description);
77 }
78 void PutInt(uintptr_t integer, const char* description);
79 void PutRaw(byte* data, int number_of_bytes, const char* description);
80 void PutBlob(byte* data, int number_of_bytes, const char* description);
81 virtual int Position() = 0;
82 };
83
84
85 } // namespace v8::internal
86 } // namespace v8
87
88 #endif // V8_SNAPSHOT_SOURCE_SINK_H_
OLDNEW
« no previous file with comments | « src/snapshot-external.cc ('k') | src/snapshot-source-sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698