pub struct MachBuffer<I: VCodeInst> { /* private fields */ }
Expand description

A buffer of output to be produced, fixed up, and then emitted to a CodeSink in bulk.

This struct uses SmallVecs to support small-ish function bodies without any heap allocation. As such, it will be several kilobytes large. This is likely fine as long as it is stack-allocated for function emission then thrown away; but beware if many buffer objects are retained persistently.

Implementations§

Create a new section, known to start at start_offset and with a size limited to length_limit.

Current offset from start of buffer.

Add a byte.

Add 2 bytes.

Add 4 bytes.

Add 8 bytes.

Add a slice of bytes.

Reserve appended space and return a mutable slice referring to it.

Align up to the given alignment.

Allocate a Label to refer to some offset. May not be bound to a fixed offset yet.

Reserve the first N MachLabels for blocks.

Reserve the next N MachLabels for constants.

Retrieve the reserved label for a constant.

Bind a label to the current offset. A label can only be bound once.

Emit a reference to the given label with the given reference type (i.e., branch-instruction format) at the current offset. This is like a relocation, but handled internally.

This can be called before the branch is actually emitted; fixups will not happen until an island is emitted or the buffer is finished.

Inform the buffer of an unconditional branch at the given offset, targetting the given label. May be used to optimize branches. The last added label-use must correspond to this branch. This must be called when the current offset is equal to start; i.e., before actually emitting the branch. This implies that for a branch that uses a label and is eligible for optimizations by the MachBuffer, the proper sequence is:

  • Call use_label_at_offset() to emit the fixup record.
  • Call add_uncond_branch() to make note of the branch.
  • Emit the bytes for the branch’s machine code.

Additional requirement: no labels may be bound between start and end (exclusive on both ends).

Inform the buffer of a conditional branch at the given offset, targetting the given label. May be used to optimize branches. The last added label-use must correspond to this branch.

Additional requirement: no labels may be bound between start and end (exclusive on both ends).

Emit a constant at some point in the future, binding the given label to its offset. The constant will be placed at most max_distance from the current offset.

Is an island needed within the next N bytes?

Emit all pending constants and required pending veneers.

Should only be called if island_needed() returns true, i.e., if we actually reach a deadline. It’s not necessarily a problem to do so otherwise but it may result in unnecessary work during emission.

Finish any deferred emissions and/or fixups.

Add an external relocation at the current offset.

Add a trap record at the current offset.

Add a call-site record at the current offset.

Add an unwind record at the current offset.

Set the SourceLoc for code from this offset until the offset at the next call to end_srcloc().

Mark the end of the SourceLoc segment started at the last start_srcloc() call.

Add stack map metadata for this program point: a set of stack offsets (from SP upward) that contain live references.

The offset_to_fp value is the offset from the nominal SP (at which the stack_offsets are based) and the FP value. By subtracting offset_to_fp from each stack_offsets element, one can obtain live-reference offsets from FP instead.

Trait Implementations§

Add 1 byte to the code section.
Add 2 bytes to the code section.
Add 4 bytes to the code section.
Add 8 bytes to the code section.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.