Skip to content

Commit

Permalink
isa: macro asm support constant ident in put argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Apr 20, 2024
1 parent 6eabff9 commit c8edb06
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/isa/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ macro_rules! aluasm_inner {
$code.push($crate::instr!{ $op $arg [ $idx ] , $arglit });
$crate::aluasm_inner! { $code => $( $tt )* }
};
{ $code:ident => $op:ident $arg:ident [ $idx:literal ] , $arglit:ident ; $($tt:tt)* } => {
$code.push($crate::instr!{ $op $arg [ $idx ] , $arglit });
$crate::aluasm_inner! { $code => $( $tt )* }
};
{ $code:ident => $op:ident . $flag:ident $arg:ident [ $idx:literal ], $arglit:expr ; $($tt:tt)* } => {
$code.push($crate::instr!{ $op . $flag $arg [ $idx ], $arglit });
$crate::aluasm_inner! { $code => $( $tt )* }
Expand Down Expand Up @@ -221,6 +225,9 @@ macro_rules! instr {
$crate::_reg_idx16!($offset_idx),
))
};
(put s16[$idx:literal], $val:ident) => {{
Instr::Bytes(BytesOp::Put(RegS::from($idx), Box::new(ByteStr::with(&$val)), false))
}};
(put s16[$idx:literal], $val:literal) => {{
Instr::Bytes(BytesOp::Put(RegS::from($idx), Box::new(ByteStr::with(&$val)), false))
}};
Expand Down Expand Up @@ -281,6 +288,13 @@ macro_rules! instr {
num.reshape(reg.layout());
Instr::Put($crate::_reg_sfx!(PutOp, Put, $reg)(reg, $crate::_reg_idx!($idx), Box::new(num)))
}};
(put $reg:ident[$idx:literal], $val:ident) => {{
let s = stringify!($val);
let mut num = s.parse::<MaybeNumber>().expect(&format!("invalid number literal `{}`", s));
let reg = $crate::_reg_ty!(Reg, $reg);
num.reshape(reg.layout());
Instr::Put($crate::_reg_sfx!(PutOp, Put, $reg)(reg, $crate::_reg_idx!($idx), Box::new(num)))
}};
(putif $reg:ident[$idx:literal], $val:literal) => {{
let s = stringify!($val);
let mut num = s.parse::<MaybeNumber>().expect(&format!("invalid number literal `{}`", s));
Expand All @@ -292,6 +306,17 @@ macro_rules! instr {
Box::new(num),
))
}};
(putif $reg:ident[$idx:literal], $val:ident) => {{
let s = stringify!($val);
let mut num = s.parse::<MaybeNumber>().expect(&format!("invalid number literal `{}`", s));
let reg = $crate::_reg_ty!(Reg, $reg);
num.reshape(reg.layout());
Instr::Put($crate::_reg_sfx!(PutOp, PutIf, $reg)(
reg,
$crate::_reg_idx!($idx),
Box::new(num),
))
}};

(swp $reg1:ident[$idx1:literal], $reg2:ident[$idx2:literal]) => {{
if $crate::_reg_ty!(Reg, $reg1) != $crate::_reg_ty!(Reg, $reg2) {
Expand Down

0 comments on commit c8edb06

Please sign in to comment.