OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
6 #include "src/snapshot-source-sink.h" | 6 #include "src/snapshot-source-sink.h" |
7 | 7 |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/handles-inl.h" | 9 #include "src/handles-inl.h" |
10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF() | 10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF() |
11 | 11 |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 | 16 |
17 SnapshotByteSource::SnapshotByteSource(const byte* array, int length) | 17 SnapshotByteSource::SnapshotByteSource(const byte* array, int length) |
18 : data_(array), length_(length), position_(0) { | 18 : data_(array), length_(length), position_(0) { |
19 } | 19 } |
20 | 20 |
21 | 21 |
22 SnapshotByteSource::~SnapshotByteSource() { } | 22 SnapshotByteSource::~SnapshotByteSource() { } |
23 | 23 |
24 | 24 |
25 int32_t SnapshotByteSource::GetUnalignedInt() { | 25 int32_t SnapshotByteSource::GetUnalignedInt() { |
26 ASSERT(position_ < length_); // Require at least one byte left. | 26 DCHECK(position_ < length_); // Require at least one byte left. |
27 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN | 27 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN |
28 int32_t answer = *reinterpret_cast<const int32_t*>(data_ + position_); | 28 int32_t answer = *reinterpret_cast<const int32_t*>(data_ + position_); |
29 #else | 29 #else |
30 int32_t answer = data_[position_]; | 30 int32_t answer = data_[position_]; |
31 answer |= data_[position_ + 1] << 8; | 31 answer |= data_[position_ + 1] << 8; |
32 answer |= data_[position_ + 2] << 16; | 32 answer |= data_[position_ + 2] << 16; |
33 answer |= data_[position_ + 3] << 24; | 33 answer |= data_[position_ + 3] << 24; |
34 #endif | 34 #endif |
35 return answer; | 35 return answer; |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) { | 39 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) { |
40 MemCopy(to, data_ + position_, number_of_bytes); | 40 MemCopy(to, data_ + position_, number_of_bytes); |
41 position_ += number_of_bytes; | 41 position_ += number_of_bytes; |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) { | 45 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) { |
46 ASSERT(integer < 1 << 22); | 46 DCHECK(integer < 1 << 22); |
47 integer <<= 2; | 47 integer <<= 2; |
48 int bytes = 1; | 48 int bytes = 1; |
49 if (integer > 0xff) bytes = 2; | 49 if (integer > 0xff) bytes = 2; |
50 if (integer > 0xffff) bytes = 3; | 50 if (integer > 0xffff) bytes = 3; |
51 integer |= bytes; | 51 integer |= bytes; |
52 Put(static_cast<int>(integer & 0xff), "IntPart1"); | 52 Put(static_cast<int>(integer & 0xff), "IntPart1"); |
53 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2"); | 53 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2"); |
54 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3"); | 54 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3"); |
55 } | 55 } |
56 | 56 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 void DebugSnapshotSink::Put(byte b, const char* description) { | 95 void DebugSnapshotSink::Put(byte b, const char* description) { |
96 PrintF("%24s: %x\n", description, b); | 96 PrintF("%24s: %x\n", description, b); |
97 sink_->Put(b, description); | 97 sink_->Put(b, description); |
98 } | 98 } |
99 | 99 |
100 } // namespace v8::internal | 100 } // namespace v8::internal |
101 } // namespace v8 | 101 } // namespace v8 |
OLD | NEW |