Skip to content

Commit

Permalink
patterns/includes: Update standard library and patterns to support th…
Browse files Browse the repository at this point in the history
…e new bitfields (WerWolv#102)

* Add `current_bit_offset()` and `read_bits(...)` to `std::mem`

* Replace deprecated BitfieldOrder enum values with new clearer names

This adds new options named `MostToLeastSignificant` and `LeastToMostSignificant` to replace the old `LeftToRight` and `RightToLeft` names. These names should be much clearer about what they affect and how.

* Throw errors when `std::core::(get|set)_bitfield_order()` are called

* Update all patterns to work with the new bitfield behaviors
  • Loading branch information
Zaggy1024 authored Apr 1, 2023
1 parent d42b87d commit 1cd7f92
Show file tree
Hide file tree
Showing 23 changed files with 2,482 additions and 2,433 deletions.
24 changes: 16 additions & 8 deletions includes/std/core.pat
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
namespace std::core {

/**
The default ordering of bitfield members
The layout order of each field after byte-endianness has been handled.
`LeftToRight` and `RightToLeft` are deprecated in favor of the clearer `MostToLeastSignificant` and `LeastToMostSignificant` names.
*/
enum BitfieldOrder : u8 {
/**
@warning deprecated
*/
LeftToRight = 0,
RightToLeft = 1
/**
@warning deprecated
*/
RightToLeft = 1,
MostToLeastSignificant = 0,
LeastToMostSignificant = 1
};


Expand Down Expand Up @@ -56,19 +66,17 @@ namespace std::core {


/**
Sets the default bitfield order.
@param order The new default bitfield order
@warning Removed in 1.28.0
*/
fn set_bitfield_order(BitfieldOrder order) {
builtin::std::core::set_bitfield_order(u32(order));
builtin::std::error("Runtime default bitfield order is no longer supported.\nConsider using `be` or `le` on your bitfield variables,\nor attach attribute `bitfield_order` to the bitfield.");
};

/**
Gets thee current default bitfield order
@return The currently set default bitfield order
@warning Removed in 1.28.0
*/
fn get_bitfield_order() {
return builtin::std::core::get_bitfield_order();
builtin::std::error("Runtime default bitfield order is no longer supported.\nConsider using `be` or `le` on your bitfield variables,\nor attach attribute `bitfield_order` to the bitfield.");
};


Expand Down
21 changes: 21 additions & 0 deletions includes/std/mem.pat
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ namespace std::mem {
};


/**
Gets the current bit offset within the current byte that a bitfield will read.
*/
fn current_bit_offset() {
return builtin::std::mem::current_bit_offset();
};

/**
Reads a number of bits from the specified bit offset within the specified byte
@param byteOffset The byte offset within the data
@param bitOffset The bit offset to start the read at within the current byte
@param bitSize The total number of bits to read
@return A u128 containing the value read
*/
fn read_bits(u128 byteOffset, u128 bitOffset, u64 bitSize) {
byteOffset += bitOffset >> 3;
bitOffset = bitOffset & 0x7;
return builtin::std::mem::read_bits(byteOffset, bitOffset, bitSize);
};


/**
Creates a new custom section with the given name
@param name The name of the section
Expand Down
Loading

0 comments on commit 1cd7f92

Please sign in to comment.