Skip to content

Commit

Permalink
assembler: Allow cursor to be moved forwards
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Nov 1, 2024
1 parent 918ef34 commit c660341
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 12 additions & 0 deletions include/biscuit/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ class Assembler {
m_buffer.RewindCursor(offset);
}

/**
* Allows advancing of the code buffer cursor.
*
* @param offset The offset to advance the cursor by.
*
* @note The offset may not be smaller than the current cursor offset
* and may not be larger than the current buffer capacity.
*/
void AdvanceBuffer(ptrdiff_t offset) {
m_buffer.AdvanceCursor(offset);
}

/// Retrieves the cursor pointer for the underlying code buffer.
[[nodiscard]] uint8_t* GetCursorPointer() noexcept {
return m_buffer.GetCursorPointer();
Expand Down
24 changes: 20 additions & 4 deletions include/biscuit/code_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ class CodeBuffer {

/// Retrieves the pointer to an arbitrary location within the buffer.
[[nodiscard]] uint8_t* GetOffsetPointer(ptrdiff_t offset) noexcept {
BISCUIT_ASSERT(offset >= 0 && offset <= GetCursorOffset());
return m_buffer + offset;
auto pointer = m_buffer + offset;
BISCUIT_ASSERT(pointer >= m_buffer && pointer < m_buffer + m_capacity);
return pointer;
}

/// Retrieves the pointer to an arbitrary location within the buffer.
[[nodiscard]] const uint8_t* GetOffsetPointer(ptrdiff_t offset) const noexcept {
BISCUIT_ASSERT(offset >= 0 && offset <= GetCursorOffset());
return m_buffer + offset;
auto pointer = m_buffer + offset;
BISCUIT_ASSERT(pointer >= m_buffer && pointer < m_buffer + m_capacity);
return pointer;
}

/**
Expand All @@ -115,6 +117,20 @@ class CodeBuffer {
m_cursor = rewound;
}

/**
* Allows advancing of the code buffer cursor.
*
* @param offset The offset to advance the cursor by.
*
* @note The offset may not be smaller than the current cursor offset
* and may not be larger than the current buffer capacity.
*/
void AdvanceCursor(ptrdiff_t offset) noexcept {
auto* forward = m_buffer + offset;
BISCUIT_ASSERT(m_cursor <= forward && forward < m_buffer + m_capacity);
m_cursor = forward;
}

/**
* Whether or not the underlying buffer has enough room for the
* given number of bytes.
Expand Down

0 comments on commit c660341

Please sign in to comment.