Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
dart::kernel::Reader Class Reference

#include <kernel_binary.h>

Inheritance diagram for dart::kernel::Reader:
dart::ValueObject

Public Member Functions

 Reader (const TypedDataBase &typed_data)
 
uint32_t ReadFromIndex (intptr_t end_offset, intptr_t fields_before, intptr_t list_size, intptr_t list_index)
 
uint32_t ReadUInt32At (intptr_t offset) const
 
uint32_t ReadFromIndexNoReset (intptr_t end_offset, intptr_t fields_before, intptr_t list_size, intptr_t list_index)
 
uint32_t ReadUInt32 ()
 
double ReadDouble ()
 
uint32_t ReadUInt ()
 
intptr_t ReadSLEB128 ()
 
int64_t ReadSLEB128AsInt64 ()
 
TokenPosition ReadPosition ()
 
intptr_t ReadListLength ()
 
uint8_t ReadByte ()
 
uint8_t PeekByte ()
 
void ReadBytes (uint8_t *buffer, uint8_t size)
 
bool ReadBool ()
 
uint8_t ReadFlags ()
 
Tag ReadTag (uint8_t *payload=nullptr)
 
Tag PeekTag (uint8_t *payload=nullptr)
 
Nullability ReadNullability ()
 
Variance ReadVariance ()
 
void EnsureEnd ()
 
TokenPosition max_position ()
 
TokenPosition min_position ()
 
NameIndex ReadCanonicalNameReference ()
 
const TypedDataBasetyped_data ()
 
intptr_t offset () const
 
void set_offset (intptr_t offset)
 
intptr_t size () const
 
TypedDataViewPtr ViewFromTo (intptr_t start, intptr_t end)
 
const uint8_t * BufferAt (intptr_t offset)
 
TypedDataPtr ReadLineStartsData (intptr_t line_start_count)
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Static Public Member Functions

static const char * TagName (Tag tag)
 
static Nullability ConvertNullability (KernelNullability kernel_nullability)
 

Friends

class Program
 
class AlternativeReadingScopeWithNewData
 
class AlternativeReadingScope
 
class PositionScope
 

Detailed Description

Definition at line 286 of file kernel_binary.h.

Constructor & Destructor Documentation

◆ Reader()

dart::kernel::Reader::Reader ( const TypedDataBase typed_data)
inlineexplicit

Definition at line 288 of file kernel_binary.h.

289 : thread_(Thread::Current()), typed_data_(&typed_data) {
290 Init();
291 }
static Thread * Current()
Definition thread.h:361
const TypedDataBase * typed_data()

Member Function Documentation

◆ BufferAt()

const uint8_t * dart::kernel::Reader::BufferAt ( intptr_t  offset)
inline

Definition at line 491 of file kernel_binary.h.

491 {
492 ASSERT((offset >= 0) && (offset < size_));
493 return &raw_buffer_[offset];
494 }
intptr_t offset() const
#define ASSERT(E)

◆ ConvertNullability()

static Nullability dart::kernel::Reader::ConvertNullability ( KernelNullability  kernel_nullability)
inlinestatic

◆ EnsureEnd()

void dart::kernel::Reader::EnsureEnd ( )
inline

Definition at line 456 of file kernel_binary.h.

456 {
457 if (offset_ != size_) {
458 FATAL(
459 "Reading Kernel file: Expected to be at EOF "
460 "(offset: %" Pd ", size: %" Pd ")",
461 offset_, size_);
462 }
463 }
#define FATAL(error)
#define Pd
Definition globals.h:408

◆ max_position()

TokenPosition dart::kernel::Reader::max_position ( )
inline

Definition at line 468 of file kernel_binary.h.

468{ return max_position_; }

◆ min_position()

TokenPosition dart::kernel::Reader::min_position ( )
inline

Definition at line 472 of file kernel_binary.h.

472{ return min_position_; }

◆ offset()

intptr_t dart::kernel::Reader::offset ( ) const
inline

Definition at line 480 of file kernel_binary.h.

480{ return offset_; }

◆ PeekByte()

uint8_t dart::kernel::Reader::PeekByte ( )
inline

Definition at line 391 of file kernel_binary.h.

391{ return raw_buffer_[offset_]; }

◆ PeekTag()

Tag dart::kernel::Reader::PeekTag ( uint8_t *  payload = nullptr)
inline

Definition at line 419 of file kernel_binary.h.

419 {
420 uint8_t byte = PeekByte();
421 bool has_payload =
423 if (has_payload) {
424 if (payload != nullptr) {
425 *payload = byte & kSpecializedPayloadMask;
426 }
427 return static_cast<Tag>(byte & kSpecializedTagMask);
428 } else {
429 return static_cast<Tag>(byte);
430 }
431 }
static constexpr intptr_t kSpecializedPayloadMask
static constexpr intptr_t kSpecializedTagHighBits
static constexpr intptr_t kSpecializedTagMask

◆ ReadBool()

bool dart::kernel::Reader::ReadBool ( )
inline

Definition at line 399 of file kernel_binary.h.

399{ return (ReadByte() & 1) == 1; }

◆ ReadByte()

uint8_t dart::kernel::Reader::ReadByte ( )
inline

Definition at line 389 of file kernel_binary.h.

389{ return raw_buffer_[offset_++]; }

◆ ReadBytes()

void dart::kernel::Reader::ReadBytes ( uint8_t *  buffer,
uint8_t  size 
)
inline

Definition at line 393 of file kernel_binary.h.

393 {
394 for (int i = 0; i < size; i++) {
395 buffer[i] = ReadByte();
396 }
397 }
intptr_t size() const
static const uint8_t buffer[]

◆ ReadCanonicalNameReference()

NameIndex dart::kernel::Reader::ReadCanonicalNameReference ( )
inline

Definition at line 476 of file kernel_binary.h.

476{ return NameIndex(ReadUInt() - 1); }

◆ ReadDouble()

double dart::kernel::Reader::ReadDouble ( )
inline

Definition at line 325 of file kernel_binary.h.

325 {
326 ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
327 double value =
328 LoadUnaligned(reinterpret_cast<const double*>(&raw_buffer_[offset_]));
329 offset_ += 8;
330 return value;
331 }
uint8_t value
static T LoadUnaligned(const T *ptr)
Definition unaligned.h:14

◆ ReadFlags()

uint8_t dart::kernel::Reader::ReadFlags ( )
inline

Definition at line 401 of file kernel_binary.h.

401{ return ReadByte(); }

◆ ReadFromIndex()

uint32_t dart::kernel::Reader::ReadFromIndex ( intptr_t  end_offset,
intptr_t  fields_before,
intptr_t  list_size,
intptr_t  list_index 
)
inline

Definition at line 293 of file kernel_binary.h.

296 {
297 intptr_t org_offset = offset();
298 uint32_t result =
299 ReadFromIndexNoReset(end_offset, fields_before, list_size, list_index);
300 offset_ = org_offset;
301 return result;
302 }
uint32_t ReadFromIndexNoReset(intptr_t end_offset, intptr_t fields_before, intptr_t list_size, intptr_t list_index)
GAsyncResult * result

◆ ReadFromIndexNoReset()

uint32_t dart::kernel::Reader::ReadFromIndexNoReset ( intptr_t  end_offset,
intptr_t  fields_before,
intptr_t  list_size,
intptr_t  list_index 
)
inline

Definition at line 311 of file kernel_binary.h.

314 {
315 offset_ = end_offset - (fields_before + list_size - list_index) * 4;
316 return ReadUInt32();
317 }

◆ ReadLineStartsData()

TypedDataPtr dart::kernel::Reader::ReadLineStartsData ( intptr_t  line_start_count)

Definition at line 37 of file kernel_binary.cc.

37 {
38 const intptr_t start_offset = offset();
39
40 // Choose representation between Uint16 and Uint32 typed data.
41 intptr_t max_start = 0;
42 for (intptr_t i = 0; i < line_start_count; ++i) {
43 const intptr_t delta = ReadUInt();
44 max_start += delta;
45 }
46
47 const intptr_t cid = (max_start <= kMaxUint16) ? kTypedDataUint16ArrayCid
48 : kTypedDataUint32ArrayCid;
49 const TypedData& line_starts_data =
51
52 set_offset(start_offset);
53 intptr_t current_start = 0;
54 for (intptr_t i = 0; i < line_start_count; ++i) {
55 const intptr_t delta = ReadUInt();
56 current_start += delta;
57 if (cid == kTypedDataUint16ArrayCid) {
58 line_starts_data.SetUint16(i << 1, static_cast<uint16_t>(current_start));
59 } else {
60 line_starts_data.SetUint32(i << 2, current_start);
61 }
62 }
63
64 return line_starts_data.ptr();
65}
@ kOld
Definition heap.h:39
static Object & Handle()
Definition object.h:407
static TypedDataPtr New(intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
Definition object.cc:25666
void set_offset(intptr_t offset)
const intptr_t cid
constexpr uint16_t kMaxUint16
Definition globals.h:481

◆ ReadListLength()

intptr_t dart::kernel::Reader::ReadListLength ( )
inline

Definition at line 387 of file kernel_binary.h.

387{ return ReadUInt(); }

◆ ReadNullability()

Nullability dart::kernel::Reader::ReadNullability ( )
inline

Definition at line 446 of file kernel_binary.h.

446 {
447 const uint8_t byte = ReadByte();
448 return ConvertNullability(static_cast<KernelNullability>(byte));
449 }
static Nullability ConvertNullability(KernelNullability kernel_nullability)

◆ ReadPosition()

TokenPosition dart::kernel::Reader::ReadPosition ( )
inline

Read and return a TokenPosition from this reader.

Definition at line 377 of file kernel_binary.h.

377 {
378 // Position is saved as unsigned,
379 // but actually ranges from -1 and up (thus the -1)
380 intptr_t value = ReadUInt() - 1;
381 TokenPosition result = TokenPosition::Deserialize(value);
382 max_position_ = TokenPosition::Max(max_position_, result);
383 min_position_ = TokenPosition::Min(min_position_, result);
384 return result;
385 }
static const TokenPosition & Min(const TokenPosition &a, const TokenPosition &b)
static TokenPosition Deserialize(int32_t value)
static const TokenPosition & Max(const TokenPosition &a, const TokenPosition &b)

◆ ReadSLEB128()

intptr_t dart::kernel::Reader::ReadSLEB128 ( )
inline

Definition at line 360 of file kernel_binary.h.

360 {
361 ReadStream stream(raw_buffer_, size_, offset_);
362 const intptr_t result = stream.ReadSLEB128();
363 offset_ = stream.Position();
364 return result;
365 }

◆ ReadSLEB128AsInt64()

int64_t dart::kernel::Reader::ReadSLEB128AsInt64 ( )
inline

Definition at line 367 of file kernel_binary.h.

367 {
368 ReadStream stream(raw_buffer_, size_, offset_);
369 const int64_t result = stream.ReadSLEB128<int64_t>();
370 offset_ = stream.Position();
371 return result;
372 }

◆ ReadTag()

Tag dart::kernel::Reader::ReadTag ( uint8_t *  payload = nullptr)
inline

Definition at line 405 of file kernel_binary.h.

405 {
406 uint8_t byte = ReadByte();
407 bool has_payload =
409 if (has_payload) {
410 if (payload != nullptr) {
411 *payload = byte & kSpecializedPayloadMask;
412 }
413 return static_cast<Tag>(byte & kSpecializedTagMask);
414 } else {
415 return static_cast<Tag>(byte);
416 }
417 }

◆ ReadUInt()

uint32_t dart::kernel::Reader::ReadUInt ( )
inline

Definition at line 333 of file kernel_binary.h.

333 {
334 ASSERT((size_ >= 1) && (offset_ >= 0) && (offset_ <= size_ - 1));
335
336 const uint8_t* buffer = raw_buffer_;
337 uword byte0 = buffer[offset_];
338 if ((byte0 & 0x80) == 0) {
339 // 0...
340 offset_++;
341 return byte0;
342 } else if ((byte0 & 0xc0) == 0x80) {
343 // 10...
344 ASSERT((size_ >= 2) && (offset_ >= 0) && (offset_ <= size_ - 2));
345 uint32_t value =
346 ((byte0 & ~static_cast<uword>(0x80)) << 8) | (buffer[offset_ + 1]);
347 offset_ += 2;
348 return value;
349 } else {
350 // 11...
351 ASSERT((size_ >= 4) && (offset_ >= 0) && (offset_ <= size_ - 4));
352 uint32_t value = ((byte0 & ~static_cast<uword>(0xc0)) << 24) |
353 (buffer[offset_ + 1] << 16) |
354 (buffer[offset_ + 2] << 8) | (buffer[offset_ + 3] << 0);
355 offset_ += 4;
356 return value;
357 }
358 }
uintptr_t uword
Definition globals.h:501

◆ ReadUInt32()

uint32_t dart::kernel::Reader::ReadUInt32 ( )
inline

Definition at line 319 of file kernel_binary.h.

319 {
320 uint32_t value = ReadUInt32At(offset_);
321 offset_ += 4;
322 return value;
323 }
uint32_t ReadUInt32At(intptr_t offset) const

◆ ReadUInt32At()

uint32_t dart::kernel::Reader::ReadUInt32At ( intptr_t  offset) const
inline

Definition at line 304 of file kernel_binary.h.

304 {
305 ASSERT((size_ >= 4) && (offset >= 0) && (offset <= size_ - 4));
306 uint32_t value =
307 LoadUnaligned(reinterpret_cast<const uint32_t*>(raw_buffer_ + offset));
308 return Utils::BigEndianToHost32(value);
309 }
static uint32_t BigEndianToHost32(uint32_t be_value)
Definition utils.h:503

◆ ReadVariance()

Variance dart::kernel::Reader::ReadVariance ( )
inline

Definition at line 451 of file kernel_binary.h.

451 {
452 uint8_t byte = ReadByte();
453 return static_cast<Variance>(byte);
454 }

◆ set_offset()

void dart::kernel::Reader::set_offset ( intptr_t  offset)
inline

Definition at line 481 of file kernel_binary.h.

481 {
482 ASSERT(offset < size_);
483 offset_ = offset;
484 }

◆ size()

intptr_t dart::kernel::Reader::size ( ) const
inline

Definition at line 485 of file kernel_binary.h.

485{ return size_; }

◆ TagName()

const char * dart::kernel::Reader::TagName ( Tag  tag)
static

Definition at line 24 of file kernel_binary.cc.

24 {
25 switch (tag) {
26#define CASE(Name, value) \
27 case k##Name: \
28 return #Name;
30#undef CASE
31 default:
32 break;
33 }
34 return "Unknown";
35}
#define CASE(Arity, Mask, Name, Args, Result)
#define KERNEL_TAG_LIST(V)

◆ typed_data()

const TypedDataBase * dart::kernel::Reader::typed_data ( )
inline

Definition at line 478 of file kernel_binary.h.

478{ return typed_data_; }

◆ ViewFromTo()

TypedDataViewPtr dart::kernel::Reader::ViewFromTo ( intptr_t  start,
intptr_t  end 
)
inline

Definition at line 487 of file kernel_binary.h.

487 {
488 return typed_data_->ViewFromTo(start, end, Heap::kOld);
489 }
TypedDataViewPtr ViewFromTo(intptr_t start, intptr_t end, Heap::Space space=Heap::kNew) const
Definition object.cc:25761
glong glong end

Friends And Related Symbol Documentation

◆ AlternativeReadingScope

friend class AlternativeReadingScope
friend

Definition at line 501 of file kernel_binary.h.

◆ AlternativeReadingScopeWithNewData

Definition at line 500 of file kernel_binary.h.

◆ PositionScope

friend class PositionScope
friend

Definition at line 527 of file kernel_binary.h.

◆ Program

Program
friend

Definition at line 499 of file kernel_binary.h.


The documentation for this class was generated from the following files: