Flutter Engine
The Flutter Engine
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 280 of file kernel_binary.h.

Constructor & Destructor Documentation

◆ Reader()

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

Definition at line 282 of file kernel_binary.h.

283 : thread_(Thread::Current()), typed_data_(&typed_data) {
284 Init();
285 }
static Thread * Current()
Definition: thread.h:362
const TypedDataBase * typed_data()

Member Function Documentation

◆ BufferAt()

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

Definition at line 485 of file kernel_binary.h.

485 {
486 ASSERT((offset >= 0) && (offset < size_));
487 return &raw_buffer_[offset];
488 }
intptr_t offset() const
#define ASSERT(E)

◆ ConvertNullability()

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

Definition at line 427 of file kernel_binary.h.

427 {
428 switch (kernel_nullability) {
435 FATAL("Legacy nullability is not supported.");
436 }
437 UNREACHABLE();
438 }
#define UNREACHABLE()
Definition: assert.h:248
#define FATAL(error)

◆ EnsureEnd()

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

Definition at line 450 of file kernel_binary.h.

450 {
451 if (offset_ != size_) {
452 FATAL(
453 "Reading Kernel file: Expected to be at EOF "
454 "(offset: %" Pd ", size: %" Pd ")",
455 offset_, size_);
456 }
457 }
#define Pd
Definition: globals.h:408

◆ max_position()

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

Definition at line 462 of file kernel_binary.h.

462{ return max_position_; }

◆ min_position()

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

Definition at line 466 of file kernel_binary.h.

466{ return min_position_; }

◆ offset()

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

Definition at line 474 of file kernel_binary.h.

474{ return offset_; }

◆ PeekByte()

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

Definition at line 385 of file kernel_binary.h.

385{ return raw_buffer_[offset_]; }

◆ PeekTag()

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

Definition at line 413 of file kernel_binary.h.

413 {
414 uint8_t byte = PeekByte();
415 bool has_payload =
417 if (has_payload) {
418 if (payload != nullptr) {
419 *payload = byte & kSpecializedPayloadMask;
420 }
421 return static_cast<Tag>(byte & kSpecializedTagMask);
422 } else {
423 return static_cast<Tag>(byte);
424 }
425 }
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 393 of file kernel_binary.h.

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

◆ ReadByte()

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

Definition at line 383 of file kernel_binary.h.

383{ return raw_buffer_[offset_++]; }

◆ ReadBytes()

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

Definition at line 387 of file kernel_binary.h.

387 {
388 for (int i = 0; i < size; i++) {
389 buffer[i] = ReadByte();
390 }
391 }
intptr_t size() const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ ReadCanonicalNameReference()

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

Definition at line 470 of file kernel_binary.h.

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

◆ ReadDouble()

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

Definition at line 319 of file kernel_binary.h.

319 {
320 ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
321 double value =
322 LoadUnaligned(reinterpret_cast<const double*>(&raw_buffer_[offset_]));
323 offset_ += 8;
324 return value;
325 }
uint8_t value
static T LoadUnaligned(const T *ptr)
Definition: unaligned.h:14

◆ ReadFlags()

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

Definition at line 395 of file kernel_binary.h.

395{ 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 287 of file kernel_binary.h.

290 {
291 intptr_t org_offset = offset();
292 uint32_t result =
293 ReadFromIndexNoReset(end_offset, fields_before, list_size, list_index);
294 offset_ = org_offset;
295 return result;
296 }
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 305 of file kernel_binary.h.

308 {
309 offset_ = end_offset - (fields_before + list_size - list_index) * 4;
310 return ReadUInt32();
311 }

◆ 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:25587
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 381 of file kernel_binary.h.

381{ return ReadUInt(); }

◆ ReadNullability()

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

Definition at line 440 of file kernel_binary.h.

440 {
441 const uint8_t byte = ReadByte();
442 return ConvertNullability(static_cast<KernelNullability>(byte));
443 }
static Nullability ConvertNullability(KernelNullability kernel_nullability)

◆ ReadPosition()

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

Read and return a TokenPosition from this reader.

Definition at line 371 of file kernel_binary.h.

371 {
372 // Position is saved as unsigned,
373 // but actually ranges from -1 and up (thus the -1)
374 intptr_t value = ReadUInt() - 1;
375 TokenPosition result = TokenPosition::Deserialize(value);
376 max_position_ = TokenPosition::Max(max_position_, result);
377 min_position_ = TokenPosition::Min(min_position_, result);
378 return result;
379 }
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 354 of file kernel_binary.h.

354 {
355 ReadStream stream(raw_buffer_, size_, offset_);
356 const intptr_t result = stream.ReadSLEB128();
357 offset_ = stream.Position();
358 return result;
359 }

◆ ReadSLEB128AsInt64()

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

Definition at line 361 of file kernel_binary.h.

361 {
362 ReadStream stream(raw_buffer_, size_, offset_);
363 const int64_t result = stream.ReadSLEB128<int64_t>();
364 offset_ = stream.Position();
365 return result;
366 }

◆ ReadTag()

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

Definition at line 399 of file kernel_binary.h.

399 {
400 uint8_t byte = ReadByte();
401 bool has_payload =
403 if (has_payload) {
404 if (payload != nullptr) {
405 *payload = byte & kSpecializedPayloadMask;
406 }
407 return static_cast<Tag>(byte & kSpecializedTagMask);
408 } else {
409 return static_cast<Tag>(byte);
410 }
411 }

◆ ReadUInt()

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

Definition at line 327 of file kernel_binary.h.

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

◆ ReadUInt32()

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

Definition at line 313 of file kernel_binary.h.

313 {
314 uint32_t value = ReadUInt32At(offset_);
315 offset_ += 4;
316 return value;
317 }
uint32_t ReadUInt32At(intptr_t offset) const

◆ ReadUInt32At()

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

Definition at line 298 of file kernel_binary.h.

298 {
299 ASSERT((size_ >= 4) && (offset >= 0) && (offset <= size_ - 4));
300 uint32_t value =
301 LoadUnaligned(reinterpret_cast<const uint32_t*>(raw_buffer_ + offset));
303 }
static uint32_t BigEndianToHost32(uint32_t be_value)
Definition: utils.h:518

◆ ReadVariance()

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

Definition at line 445 of file kernel_binary.h.

445 {
446 uint8_t byte = ReadByte();
447 return static_cast<Variance>(byte);
448 }

◆ set_offset()

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

Definition at line 475 of file kernel_binary.h.

475 {
476 ASSERT(offset < size_);
477 offset_ = offset;
478 }

◆ size()

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

Definition at line 479 of file kernel_binary.h.

479{ 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(Name, value)
#define KERNEL_TAG_LIST(V)
Definition: kernel_binary.h:24

◆ typed_data()

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

Definition at line 472 of file kernel_binary.h.

472{ return typed_data_; }

◆ ViewFromTo()

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

Definition at line 481 of file kernel_binary.h.

481 {
482 return typed_data_->ViewFromTo(start, end, Heap::kOld);
483 }
TypedDataViewPtr ViewFromTo(intptr_t start, intptr_t end, Heap::Space space=Heap::kNew) const
Definition: object.cc:25682

Friends And Related Function Documentation

◆ AlternativeReadingScope

friend class AlternativeReadingScope
friend

Definition at line 495 of file kernel_binary.h.

◆ AlternativeReadingScopeWithNewData

Definition at line 494 of file kernel_binary.h.

◆ PositionScope

friend class PositionScope
friend

Definition at line 521 of file kernel_binary.h.

◆ Program

Program
friend

Definition at line 493 of file kernel_binary.h.


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