macros/writer: relax syntax

This commit is contained in:
Richard Patel 2021-08-15 10:58:55 +02:00
parent 4853c12054
commit 32394a4905
2 changed files with 29 additions and 10 deletions

View File

@ -811,11 +811,11 @@ impl Ins {
{ {
write_asm!(out, self => { write_asm!(out, self => {
(op.mnemonic, rc, oe) -> mnemonic; (op.mnemonic, rc, oe) -> mnemonic;
(d) -> fpr; d -> fpr;
(ps_d) -> offset_unsigned; ps_d -> offset_unsigned;
(a) -> gpr; a -> gpr;
(w) -> mode; w -> mode;
(ps_l) -> qr; ps_l -> qr;
}); });
Ok(()) Ok(())
} }

View File

@ -8,7 +8,7 @@ use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
use syn::spanned::Spanned; use syn::spanned::Spanned;
use syn::token::Semi; use syn::token::Semi;
use syn::{Expr, Ident}; use syn::{Expr, ExprPath, Ident};
struct Arguments { struct Arguments {
formatter: Expr, formatter: Expr,
@ -33,16 +33,35 @@ impl Parse for Arguments {
} }
} }
/// A single part of an instruction.
///
/// Examples:
/// ```ignore
/// (op.mnemonic, rc, oe) -> mnemonic;
/// d -> fpr;
/// ```
struct Argument { struct Argument {
sources: Punctuated<Expr, syn::token::Comma>, sources: Vec<Expr>,
target: Ident, target: Ident,
} }
impl Parse for Argument { impl Parse for Argument {
fn parse(input: ParseStream) -> syn::Result<Self> { fn parse(input: ParseStream) -> syn::Result<Self> {
// Parse source part.
let lookahead = input.lookahead1();
let sources;
if lookahead.peek(syn::token::Paren) {
// Parse multiple if we found a parenthesis.
let content; let content;
syn::parenthesized!(content in input); syn::parenthesized!(content in input);
let sources = content.parse_terminated(Expr::parse)?; sources = content
.parse_terminated::<Expr, syn::token::Comma>(Expr::parse)?
.into_iter()
.collect();
} else {
let expr = input.parse::<ExprPath>()?.into();
sources = vec![expr];
}
input.parse::<syn::token::RArrow>()?; input.parse::<syn::token::RArrow>()?;
let target = input.parse()?; let target = input.parse()?;
Ok(Self { sources, target }) Ok(Self { sources, target })