macro_rules! mmio_registerfields {
($(
$reg:ident $type:ty [$(
// move the $size in $(, ...)? to test for presence
$field:ident [$offset:expr $(, $size:expr)? ] $({
$($key:ident = $value:expr),+
})?
)*]
),+) => {
// not sure what you were trying to do here,
// so I simply converted it all into text
stringify!($(
$reg $type [$(
$field [$offset, 1 $(* $size)?] $({
// start with 1 and multiply by size, if there's any
$($key = $value),+
})?
)*]
),+)
};
}
fn main() {
let text = mmio_registerfields!(
UART_RBR u32 [],
UART_THR u32
[
DATA_OUTPUT [0, 8]
],
UART_IER u32
[
RECEIVE_DATA_AVAILABLE_INT_EN [0] // size of 1 inferred
{
DISABLED = 0,
ENABLED = 1
}
]
);
println!("text: {}", text);
}