Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 58 additions & 0 deletions aarchmrs-gen/src/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ pub fn gen_constructor(name: &str, desc: &[Bits], should_be_mask: u32) -> TokenS
let should_be_mask: syn::LitInt =
syn::parse_str(&format!("0b{:0w$b}u32", should_be_mask, w = 32))
.expect("internal error: malformed should_be_mask");
let arg_metas = desc
.iter()
.filter_map(|bits| match bits {
Bits::Bit { .. } => None,
Bits::Field { name, range } => Some((name, range)),
})
.map(|(name, range)| {
let name_offset = format_ident!("FIELD_{}_OFFSET", name.as_ref());
let name_width = format_ident!("FIELD_{}_WIDTH", name.as_ref());
let offset = range.start;
let width = range.width;
quote! {
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const #name_offset: u32 = #offset;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const #name_width: u32 = #width;
}
});
let expanded = quote! {
#[cfg(feature = "meta")]
pub const OPCODE_MASK: u32 = #mask;
Expand All @@ -38,6 +58,8 @@ pub fn gen_constructor(name: &str, desc: &[Bits], should_be_mask: u32) -> TokenS
#[cfg(feature = "meta")]
pub const NAME: &str = #name;

#(#arg_metas)*

#[inline]
pub const fn #fmt_name(#(#args),*) -> ::aarchmrs_types::InstructionCode {
::aarchmrs_types::InstructionCode::from_u32(#expr)
Expand Down Expand Up @@ -219,6 +241,42 @@ mod tests {
"pub const SHOULD_BE_MASK: u32 = 0b00000000000000000000000000000000u32;\n",
"#[cfg(feature = \"meta\")]\n",
"pub const NAME: &str = \"ADD_64_addsub_shift\";\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rd_OFFSET: u32 = 0u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rd_WIDTH: u32 = 5u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rn_OFFSET: u32 = 5u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rn_WIDTH: u32 = 5u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_im3_OFFSET: u32 = 10u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_im3_WIDTH: u32 = 3u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_option_OFFSET: u32 = 13u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_option_WIDTH: u32 = 3u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rm_OFFSET: u32 = 16u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_Rm_WIDTH: u32 = 5u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_s_OFFSET: u32 = 31u32;\n",
"#[cfg(feature = \"meta_field\")]\n",
"#[allow(nonstandard_style)]\n",
"pub const FIELD_s_WIDTH: u32 = 1u32;\n",
"#[inline]\n",
"pub const fn ADD_64_addsub_shift(\n",
" s: ::aarchmrs_types::BitValue<1>,\n",
Expand Down
1 change: 1 addition & 0 deletions aarchmrs-instructions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- README.md is module docstring.
- `meta_field` feature flag that adds field offsets and size constants.

## [0.2.1] - 2025-08-10

Expand Down
1 change: 1 addition & 0 deletions aarchmrs-instructions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aarchmrs-types = { workspace = true }
[features]
default = ["A64"]
meta = []
meta_field = []
A64 = []
A32 = []
T32 = []
36 changes: 36 additions & 0 deletions aarchmrs-instructions/src/A32/brblk/b_imm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ pub mod B_A1 {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000000000000000000000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "B_A1";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_WIDTH: u32 = 24u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_cond_OFFSET: u32 = 28u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_cond_WIDTH: u32 = 4u32;
#[inline]
pub const fn B_A1(
cond: ::aarchmrs_types::BitValue<4>,
Expand All @@ -31,6 +43,18 @@ pub mod BL_i_A1 {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000000000000000000000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "BL_i_A1";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_WIDTH: u32 = 24u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_cond_OFFSET: u32 = 28u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_cond_WIDTH: u32 = 4u32;
#[inline]
pub const fn BL_i_A1(
cond: ::aarchmrs_types::BitValue<4>,
Expand All @@ -50,6 +74,18 @@ pub mod BL_i_A2 {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000000000000000000000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "BL_i_A2";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_imm24_WIDTH: u32 = 24u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_H_OFFSET: u32 = 24u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_H_WIDTH: u32 = 1u32;
#[inline]
pub const fn BL_i_A2(
H: ::aarchmrs_types::BitValue<1>,
Expand Down
96 changes: 96 additions & 0 deletions aarchmrs-instructions/src/A32/brblk/ldstexcept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ pub mod RFEDA_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000001111111111111111u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "RFEDA_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_OFFSET: u32 = 16u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_WIDTH: u32 = 4u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn RFEDA_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -35,6 +47,18 @@ pub mod RFEDB_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000001111111111111111u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "RFEDB_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_OFFSET: u32 = 16u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_WIDTH: u32 = 4u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn RFEDB_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -58,6 +82,18 @@ pub mod RFEIA_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000001111111111111111u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "RFEIA_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_OFFSET: u32 = 16u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_WIDTH: u32 = 4u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn RFEIA_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -81,6 +117,18 @@ pub mod RFEIB_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000000001111111111111111u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "RFEIB_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_OFFSET: u32 = 16u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_Rn_WIDTH: u32 = 4u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn RFEIB_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -104,6 +152,18 @@ pub mod SRSDA_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000011111111111111100000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "SRSDA_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_WIDTH: u32 = 5u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn SRSDA_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -126,6 +186,18 @@ pub mod SRSDB_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000011111111111111100000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "SRSDB_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_WIDTH: u32 = 5u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn SRSDB_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -148,6 +220,18 @@ pub mod SRSIA_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000011111111111111100000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "SRSIA_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_WIDTH: u32 = 5u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn SRSIA_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand All @@ -170,6 +254,18 @@ pub mod SRSIB_A1_AS {
pub const SHOULD_BE_MASK: u32 = 0b00000000000011111111111111100000u32;
#[cfg(feature = "meta")]
pub const NAME: &str = "SRSIB_A1_AS";
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_OFFSET: u32 = 0u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_mode_WIDTH: u32 = 5u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_OFFSET: u32 = 21u32;
#[cfg(feature = "meta_field")]
#[allow(nonstandard_style)]
pub const FIELD_W_WIDTH: u32 = 1u32;
#[inline]
pub const fn SRSIB_A1_AS(
W: ::aarchmrs_types::BitValue<1>,
Expand Down
Loading