Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Friends | List of all members
dart::compiler::AssemblerBuffer Class Reference

#include <assembler_base.h>

Inheritance diagram for dart::compiler::AssemblerBuffer:
dart::ValueObject

Classes

class  EnsureCapacity
 

Public Member Functions

 AssemblerBuffer ()
 
 ~AssemblerBuffer ()
 
template<typename T >
void Emit (T value)
 
template<typename T >
void Remit ()
 
uword Address (intptr_t position)
 
template<typename T >
T Load (intptr_t position)
 
template<typename T >
void Store (intptr_t position, T value)
 
const ZoneGrowableArray< intptr_t > & pointer_offsets () const
 
void EmitFixup (AssemblerFixup *fixup)
 
intptr_t CountPointerOffsets () const
 
intptr_t Size () const
 
uword contents () const
 
void FinalizeInstructions (const MemoryRegion &region)
 
bool HasEnsuredCapacity () const
 
intptr_t GetPosition () const
 
void Reset ()
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Friends

class AssemblerFixup
 

Detailed Description

Definition at line 431 of file assembler_base.h.

Constructor & Destructor Documentation

◆ AssemblerBuffer()

dart::compiler::AssemblerBuffer::AssemblerBuffer ( )

Definition at line 468 of file assembler_base.cc.

469 : pointer_offsets_(new ZoneGrowableArray<intptr_t>(16)) {
470 const intptr_t kInitialBufferCapacity = 4 * KB;
471 contents_ = NewContents(kInitialBufferCapacity);
472 cursor_ = contents_;
473 limit_ = ComputeLimit(contents_, kInitialBufferCapacity);
474 fixup_ = nullptr;
475#if defined(DEBUG)
476 has_ensured_capacity_ = false;
477 fixups_processed_ = false;
478#endif
479
480 // Verify internal state.
481 ASSERT(Capacity() == kInitialBufferCapacity);
482 ASSERT(Size() == 0);
483}
#define ASSERT(E)
static uword NewContents(intptr_t capacity)
constexpr intptr_t KB
Definition: globals.h:528

◆ ~AssemblerBuffer()

dart::compiler::AssemblerBuffer::~AssemblerBuffer ( )

Definition at line 485 of file assembler_base.cc.

485{}

Member Function Documentation

◆ Address()

uword dart::compiler::AssemblerBuffer::Address ( intptr_t  position)
inline

Definition at line 459 of file assembler_base.h.

459{ return contents_ + position; }

◆ contents()

uword dart::compiler::AssemblerBuffer::contents ( ) const
inline

Definition at line 516 of file assembler_base.h.

516{ return contents_; }

◆ CountPointerOffsets()

intptr_t dart::compiler::AssemblerBuffer::CountPointerOffsets ( ) const

Definition at line 555 of file assembler_base.cc.

555 {
556 intptr_t count = 0;
557 AssemblerFixup* current = fixup_;
558 while (current != nullptr) {
559 if (current->IsPointerOffset()) ++count;
560 current = current->previous_;
561 }
562 return count;
563}
int count
Definition: FontMgrTest.cpp:50

◆ Emit()

template<typename T >
void dart::compiler::AssemblerBuffer::Emit ( T  value)
inline

Definition at line 438 of file assembler_base.h.

438 {
440#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
441 defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
442 // Variable-length instructions in ia32/x64 have unaligned immediates.
443 // Instruction parcels in RISC-V are only 2-byte aligned.
444 StoreUnaligned(reinterpret_cast<T*>(cursor_), value);
445#else
446 // Other architecture have aligned, fixed-length instructions.
447 *reinterpret_cast<T*>(cursor_) = value;
448#endif
449 cursor_ += sizeof(T);
450 }
uint8_t value
static void StoreUnaligned(T *ptr, T value)
Definition: unaligned.h:22
#define T
Definition: precompiler.cc:65

◆ EmitFixup()

void dart::compiler::AssemblerBuffer::EmitFixup ( AssemblerFixup fixup)
inline

Definition at line 504 of file assembler_base.h.

504 {
505 fixup->set_previous(fixup_);
506 fixup->set_position(Size());
507 fixup_ = fixup;
508 }

◆ FinalizeInstructions()

void dart::compiler::AssemblerBuffer::FinalizeInstructions ( const MemoryRegion region)

Definition at line 495 of file assembler_base.cc.

495 {
496 // Copy the instructions from the buffer.
497 MemoryRegion from(reinterpret_cast<void*>(contents()), Size());
498 instructions.CopyFrom(0, from);
499
500 // Process fixups in the instructions.
501 ProcessFixups(instructions);
502#if defined(DEBUG)
503 fixups_processed_ = true;
504#endif
505}

◆ GetPosition()

intptr_t dart::compiler::AssemblerBuffer::GetPosition ( ) const
inline

Definition at line 560 of file assembler_base.h.

560{ return cursor_ - contents_; }

◆ HasEnsuredCapacity()

bool dart::compiler::AssemblerBuffer::HasEnsuredCapacity ( ) const
inline

Definition at line 556 of file assembler_base.h.

556{ return true; }

◆ Load()

template<typename T >
T dart::compiler::AssemblerBuffer::Load ( intptr_t  position)
inline

Definition at line 462 of file assembler_base.h.

462 {
463 ASSERT(position >= 0 &&
464 position <= (Size() - static_cast<intptr_t>(sizeof(T))));
465#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
466 defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
467 // Variable-length instructions in ia32/x64 have unaligned immediates.
468 // Instruction parcels in RISC-V are only 2-byte aligned.
469 return LoadUnaligned(reinterpret_cast<T*>(contents_ + position));
470#else
471 // Other architecture have aligned, fixed-length instructions.
472 return *reinterpret_cast<T*>(contents_ + position);
473#endif
474 }
static T LoadUnaligned(const T *ptr)
Definition: unaligned.h:14

◆ pointer_offsets()

const ZoneGrowableArray< intptr_t > & dart::compiler::AssemblerBuffer::pointer_offsets ( ) const
inline

Definition at line 491 of file assembler_base.h.

491 {
492#if defined(DEBUG)
493 ASSERT(fixups_processed_);
494#endif
495 return *pointer_offsets_;
496 }

◆ Remit()

template<typename T >
void dart::compiler::AssemblerBuffer::Remit ( )
inline

Definition at line 453 of file assembler_base.h.

453 {
454 ASSERT(Size() >= static_cast<intptr_t>(sizeof(T)));
455 cursor_ -= sizeof(T);
456 }

◆ Reset()

void dart::compiler::AssemblerBuffer::Reset ( )
inline

Definition at line 562 of file assembler_base.h.

562{ cursor_ = contents_; }

◆ Size()

intptr_t dart::compiler::AssemblerBuffer::Size ( ) const
inline

Definition at line 515 of file assembler_base.h.

515{ return cursor_ - contents_; }

◆ Store()

template<typename T >
void dart::compiler::AssemblerBuffer::Store ( intptr_t  position,
T  value 
)
inline

Definition at line 477 of file assembler_base.h.

477 {
478 ASSERT(position >= 0 &&
479 position <= (Size() - static_cast<intptr_t>(sizeof(T))));
480#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
481 defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
482 // Variable-length instructions in ia32/x64 have unaligned immediates.
483 // Instruction parcels in RISC-V are only 2-byte aligned.
484 StoreUnaligned(reinterpret_cast<T*>(contents_ + position), value);
485#else
486 // Other architecture have aligned, fixed-length instructions.
487 *reinterpret_cast<T*>(contents_ + position) = value;
488#endif
489 }

Friends And Related Function Documentation

◆ AssemblerFixup

friend class AssemblerFixup
friend

Definition at line 597 of file assembler_base.h.


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