OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_DATASTREAM_H_ | 5 #ifndef RUNTIME_VM_DATASTREAM_H_ |
6 #define RUNTIME_VM_DATASTREAM_H_ | 6 #define RUNTIME_VM_DATASTREAM_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 current_ = *buffer_; | 307 current_ = *buffer_; |
308 current_size_ = initial_size_; | 308 current_size_ = initial_size_; |
309 end_ = *buffer_ + initial_size_; | 309 end_ = *buffer_ + initial_size_; |
310 } | 310 } |
311 | 311 |
312 uint8_t* buffer() const { return *buffer_; } | 312 uint8_t* buffer() const { return *buffer_; } |
313 intptr_t bytes_written() const { return current_ - *buffer_; } | 313 intptr_t bytes_written() const { return current_ - *buffer_; } |
314 | 314 |
315 void set_current(uint8_t* value) { current_ = value; } | 315 void set_current(uint8_t* value) { current_ = value; } |
316 | 316 |
| 317 void Align(intptr_t alignment) { |
| 318 intptr_t position = current_ - *buffer_; |
| 319 position = Utils::RoundUp(position, alignment); |
| 320 current_ = *buffer_ + position; |
| 321 } |
| 322 |
317 template <int N, typename T> | 323 template <int N, typename T> |
318 class Raw {}; | 324 class Raw {}; |
319 | 325 |
320 template <typename T> | 326 template <typename T> |
321 class Raw<1, T> { | 327 class Raw<1, T> { |
322 public: | 328 public: |
323 static void Write(WriteStream* st, T value) { | 329 static void Write(WriteStream* st, T value) { |
324 st->WriteByte(bit_cast<int8_t>(value)); | 330 st->WriteByte(bit_cast<int8_t>(value)); |
325 } | 331 } |
326 }; | 332 }; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 intptr_t current_size_; | 456 intptr_t current_size_; |
451 ReAlloc alloc_; | 457 ReAlloc alloc_; |
452 intptr_t initial_size_; | 458 intptr_t initial_size_; |
453 | 459 |
454 DISALLOW_COPY_AND_ASSIGN(WriteStream); | 460 DISALLOW_COPY_AND_ASSIGN(WriteStream); |
455 }; | 461 }; |
456 | 462 |
457 } // namespace dart | 463 } // namespace dart |
458 | 464 |
459 #endif // RUNTIME_VM_DATASTREAM_H_ | 465 #endif // RUNTIME_VM_DATASTREAM_H_ |
OLD | NEW |