diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 3d4e51a..e901142 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -811,11 +811,11 @@ impl Ins { { write_asm!(out, self => { (op.mnemonic, rc, oe) -> mnemonic; - (d) -> fpr; - (ps_d) -> offset_unsigned; - (a) -> gpr; - (w) -> mode; - (ps_l) -> qr; + d -> fpr; + ps_d -> offset_unsigned; + a -> gpr; + w -> mode; + ps_l -> qr; }); Ok(()) } diff --git a/macros/src/writer.rs b/macros/src/writer.rs index 0a63bf5..d6280eb 100644 --- a/macros/src/writer.rs +++ b/macros/src/writer.rs @@ -8,7 +8,7 @@ use syn::parse::{Parse, ParseStream}; use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::token::Semi; -use syn::{Expr, Ident}; +use syn::{Expr, ExprPath, Ident}; struct Arguments { 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 { - sources: Punctuated, + sources: Vec, target: Ident, } impl Parse for Argument { fn parse(input: ParseStream) -> syn::Result { - let content; - syn::parenthesized!(content in input); - let sources = content.parse_terminated(Expr::parse)?; + // Parse source part. + let lookahead = input.lookahead1(); + let sources; + if lookahead.peek(syn::token::Paren) { + // Parse multiple if we found a parenthesis. + let content; + syn::parenthesized!(content in input); + sources = content + .parse_terminated::(Expr::parse)? + .into_iter() + .collect(); + } else { + let expr = input.parse::()?.into(); + sources = vec![expr]; + } input.parse::()?; let target = input.parse()?; Ok(Self { sources, target })