|
|
|
@ -1,31 +1,13 @@ |
|
|
|
|
use crsn::asm::data::{Rd, Wr}; |
|
|
|
|
use crsn::asm::error::Error; |
|
|
|
|
use crsn::asm::error::CrsnError; |
|
|
|
|
use crsn::asm::instr::Op; |
|
|
|
|
use crsn::asm::parse::arg_parser::ArgParser; |
|
|
|
|
use crsn::module::{CrsnExtension, ParseOpRes}; |
|
|
|
|
use crsn::module::{ParseOpRes}; |
|
|
|
|
|
|
|
|
|
use crate::defs::ArithOp; |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)] |
|
|
|
|
pub struct ArithOps { |
|
|
|
|
_internal: () |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ArithOps { |
|
|
|
|
pub fn new() -> Box<dyn CrsnExtension> { |
|
|
|
|
Box::new(Self { |
|
|
|
|
_internal: () |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl CrsnExtension for ArithOps { |
|
|
|
|
fn name(&self) -> &'static str { |
|
|
|
|
"arith" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn parse_op(&self, keyword: &str, mut args: ArgParser) -> Result<ParseOpRes<Op>, Error> { |
|
|
|
|
Ok(ParseOpRes::parsed(match keyword { |
|
|
|
|
pub(crate) fn parse(keyword: &str, mut args: ArgParser) -> Result<ParseOpRes<Op>, CrsnError> { |
|
|
|
|
Ok(ParseOpRes::ext(match keyword { |
|
|
|
|
"cmp" => { |
|
|
|
|
ArithOp::Compare { |
|
|
|
|
a: args.next_rd()?, |
|
|
|
@ -74,7 +56,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Add requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Add requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -97,7 +79,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Sub requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Sub requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -120,7 +102,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Mul requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Mul requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -147,7 +129,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("DivR requires 3 or 4 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("DivR requires 3 or 4 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -173,7 +155,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Div requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Div requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -197,7 +179,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Mod requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Mod requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -220,7 +202,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("And requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("And requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -243,7 +225,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Or requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Or requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -266,7 +248,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Xor requires 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Xor requires 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -287,7 +269,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Cpl requires 1 or 2 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Cpl requires 1 or 2 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -318,7 +300,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Rol requires 1, 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Rol requires 1, 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -349,7 +331,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Ror requires 1, 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Ror requires 1, 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -380,7 +362,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Lsl requires 1, 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Lsl requires 1, 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -411,7 +393,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Lsr requires 1, 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Lsr requires 1, 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -442,7 +424,7 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
return Err(Error::Parse("Asr requires 1, 2 or 3 arguments".into())); |
|
|
|
|
return Err(CrsnError::Parse("Asr requires 1, 2 or 3 arguments".into())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -452,4 +434,4 @@ impl CrsnExtension for ArithOps { |
|
|
|
|
} |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|