|
|
|
@ -5,32 +5,14 @@ use crate::asm::data::reg::parse_reg; |
|
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
|
use crate::asm::instr::op::OpKind; |
|
|
|
|
use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_rd, parse_reg_alias, parse_value, parse_u64, parse_label_str}; |
|
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_rd, parse_reg_alias, parse_value, parse_label_str}; |
|
|
|
|
use crate::asm::parse::sexp_expect::expect_string_atom; |
|
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp}; |
|
|
|
|
use crate::module::{CrsnExtension, ParseRes}; |
|
|
|
|
use crate::utils::A; |
|
|
|
|
use std::convert::TryFrom; |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)] |
|
|
|
|
pub struct BuiltinOps { |
|
|
|
|
_internal: () |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl BuiltinOps { |
|
|
|
|
pub fn new() -> Box<dyn CrsnExtension> { |
|
|
|
|
Box::new(Self { |
|
|
|
|
_internal: () |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl CrsnExtension for BuiltinOps { |
|
|
|
|
fn name(&self) -> &'static str { |
|
|
|
|
"builtin" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn parse_op<'a>(&self, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
|
pub(crate) fn parse_op<'a>(keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
|
let pcx = args.pcx; |
|
|
|
|
|
|
|
|
|
Ok(ParseRes::Parsed(OpKind::BuiltIn(match keyword { |
|
|
|
@ -222,7 +204,6 @@ impl CrsnExtension for BuiltinOps { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub(crate) fn parse_routine_name(name: String) -> Result<RoutineName, CrsnError> { |
|
|
|
@ -304,16 +285,16 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|
mod test { |
|
|
|
|
use std::any::Any; |
|
|
|
|
use std::cell::RefCell; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::sync::atomic::AtomicU32; |
|
|
|
|
|
|
|
|
|
use crate::asm::instr::{Flatten, InstrWithBranches}; |
|
|
|
|
use crate::asm::instr::{Flatten}; |
|
|
|
|
use crate::asm::parse::{parse_instructions, ParserContext}; |
|
|
|
|
use crate::asm::parse::sexp_expect::expect_list; |
|
|
|
|
use crate::builtin::defs::BuiltinOp; |
|
|
|
|
use crate::builtin::parse::BuiltinOps; |
|
|
|
|
|
|
|
|
|
use crate::module::OpTrait; |
|
|
|
|
use crate::builtin::BuiltinOps; |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn roundtrip() { |
|
|
|
@ -374,7 +355,7 @@ mod test { |
|
|
|
|
let parsers = &[parser]; |
|
|
|
|
|
|
|
|
|
for (sample, expected) in samples { |
|
|
|
|
let mut pcx = ParserContext { |
|
|
|
|
let pcx = ParserContext { |
|
|
|
|
parsers, |
|
|
|
|
state: Default::default(), |
|
|
|
|
}; |
|
|
|
@ -386,7 +367,7 @@ mod test { |
|
|
|
|
.expect("parse sexp"); |
|
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
|
let num = AtomicU32::new(0); |
|
|
|
|
let mut parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
|
let parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
|
.expect("parse instr").flatten(&num) |
|
|
|
|
.expect("flatten").remove(0); |
|
|
|
|
|
|
|
|
@ -402,7 +383,7 @@ mod test { |
|
|
|
|
.expect("parse sexp (2c)"); |
|
|
|
|
let list = expect_list(Some(s), false).unwrap(); |
|
|
|
|
let num = AtomicU32::new(0); |
|
|
|
|
let mut parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
|
let parsed = parse_instructions(list.into_iter(), &pcx) |
|
|
|
|
.expect("parse instr (2c)").flatten(&num) |
|
|
|
|
.expect("flatten (2c)").remove(0); |
|
|
|
|
|
|
|
|
|