|
|
@ -8,7 +8,7 @@ use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_label_str, parse_rd, parse_reg_alias, parse_value}; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_label_str, parse_rd, parse_reg_alias, parse_value}; |
|
|
|
use crate::asm::parse::sexp_expect::{expect_any_string_atom}; |
|
|
|
use crate::asm::parse::sexp_expect::{expect_any_string_atom}; |
|
|
|
use crate::asm::patches::ErrWithPos; |
|
|
|
use crate::asm::patches::ErrWithPos; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp, SleepUnit, LdsValue}; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp, SleepUnit, LdsValue, BitSlice}; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::utils::A; |
|
|
|
use crate::utils::A; |
|
|
|
use crate::asm::data::{Rd, RdData, RdObj}; |
|
|
|
use crate::asm::data::{Rd, RdData, RdObj}; |
|
|
@ -190,27 +190,6 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ld32" => { |
|
|
|
|
|
|
|
BuiltinOp::Load32 { |
|
|
|
|
|
|
|
dst: args.next_rdwr()?, |
|
|
|
|
|
|
|
src: args.next_rd()?, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ld16" => { |
|
|
|
|
|
|
|
BuiltinOp::Load16 { |
|
|
|
|
|
|
|
dst: args.next_rdwr()?, |
|
|
|
|
|
|
|
src: args.next_rd()?, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ld8" => { |
|
|
|
|
|
|
|
BuiltinOp::Load8 { |
|
|
|
|
|
|
|
dst: args.next_rdwr()?, |
|
|
|
|
|
|
|
src: args.next_rd()?, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ldn" => { |
|
|
|
"ldn" => { |
|
|
|
BuiltinOp::LoadMultiple { |
|
|
|
BuiltinOp::LoadMultiple { |
|
|
|
dst: args.next_wr()?, |
|
|
|
dst: args.next_wr()?, |
|
|
@ -263,6 +242,7 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
BuiltinOp::Exchange { |
|
|
|
BuiltinOp::Exchange { |
|
|
|
a: args.next_rdwr()?, |
|
|
|
a: args.next_rdwr()?, |
|
|
|
b: args.next_rdwr()?, |
|
|
|
b: args.next_rdwr()?, |
|
|
|
|
|
|
|
slice: BitSlice::full(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -296,6 +276,26 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
other => { |
|
|
|
other => { |
|
|
|
|
|
|
|
if let Some(s) = other.strip_prefix("ld") { |
|
|
|
|
|
|
|
if let Some(slice) = BitSlice::parse(s, op_pos)? { |
|
|
|
|
|
|
|
return Ok(ParseRes::builtin(BuiltinOp::LoadBits { |
|
|
|
|
|
|
|
dst: args.next_rdwr()?, |
|
|
|
|
|
|
|
src: args.next_rd()?, |
|
|
|
|
|
|
|
slice, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(s) = other.strip_prefix("xch") { |
|
|
|
|
|
|
|
if let Some(slice) = BitSlice::parse(s, op_pos)? { |
|
|
|
|
|
|
|
return Ok(ParseRes::builtin(BuiltinOp::Exchange { |
|
|
|
|
|
|
|
a: args.next_rdwr()?, |
|
|
|
|
|
|
|
b: args.next_rdwr()?, |
|
|
|
|
|
|
|
slice, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if other.starts_with(':') { |
|
|
|
if other.starts_with(':') { |
|
|
|
BuiltinOp::Label(parse_label_str(other, &op_pos)?) |
|
|
|
BuiltinOp::Label(parse_label_str(other, &op_pos)?) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -378,21 +378,21 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
BuiltinOp::Delete(obj) => sexp::list(&[A("del"), A(obj)]), |
|
|
|
BuiltinOp::Delete(obj) => sexp::list(&[A("del"), A(obj)]), |
|
|
|
BuiltinOp::Load { dst, src } => sexp::list(&[A("ld"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Load { dst, src, } => { |
|
|
|
BuiltinOp::Load32 { dst, src } => sexp::list(&[A("ld32"), A(dst), A(src)]), |
|
|
|
sexp::list(&[A("ld"), A(dst), A(src)]) |
|
|
|
BuiltinOp::Load16 { dst, src } => sexp::list(&[A("ld16"), A(dst), A(src)]), |
|
|
|
}, |
|
|
|
BuiltinOp::Load8 { dst, src } => sexp::list(&[A("ld8"), A(dst), A(src)]), |
|
|
|
BuiltinOp::LoadBits { dst, src, slice, } => { |
|
|
|
|
|
|
|
sexp::list(&[A(format!("ld{}", slice)), A(dst), A(src)]) |
|
|
|
|
|
|
|
}, |
|
|
|
BuiltinOp::LoadMultiple { dst, src, count } => sexp::list(&[A("ldn"), A(dst), A(src), A(count)]), |
|
|
|
BuiltinOp::LoadMultiple { dst, src, count } => sexp::list(&[A("ldn"), A(dst), A(src), A(count)]), |
|
|
|
BuiltinOp::Exchange { a, b } => sexp::list(&[A("xch"), A(a), A(b)]), |
|
|
|
BuiltinOp::Exchange { a, b, slice } => sexp::list(&[A(format!("xch{}", slice)), A(a), A(b)]), |
|
|
|
BuiltinOp::StoreFlags { dst } => sexp::list(&[A("stf"), A(dst)]), |
|
|
|
BuiltinOp::StoreFlags { dst } => sexp::list(&[A("stf"), A(dst)]), |
|
|
|
BuiltinOp::LoadFlags { src } => sexp::list(&[A("ldf"), A(src)]), |
|
|
|
BuiltinOp::LoadFlags { src } => sexp::list(&[A("ldf"), A(src)]), |
|
|
|
BuiltinOp::LoadSequence { dst, value } => { |
|
|
|
BuiltinOp::LoadSequence { dst, value } => { |
|
|
|
match value { |
|
|
|
match value { |
|
|
|
LdsValue::Values(vals) => { |
|
|
|
LdsValue::Values(vals) => { |
|
|
|
let mut vals: Vec<_> = vals.iter().map(A).collect(); |
|
|
|
let vals: Vec<_> = vals.iter().map(A).collect(); |
|
|
|
vals.insert(0, A(dst)); |
|
|
|
sexp::list(&[A("lds"), A(dst), sexp::list(&vals)]) |
|
|
|
vals.insert(0, A("lds")); |
|
|
|
|
|
|
|
sexp::list(&vals) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
LdsValue::Chars(str) => { |
|
|
|
LdsValue::Chars(str) => { |
|
|
|
sexp::list(&[A("lds"), A(dst), atom_qs(str)]) |
|
|
|
sexp::list(&[A("lds"), A(dst), atom_qs(str)]) |
|
|
@ -469,15 +469,20 @@ mod test { |
|
|
|
("(fault kur*a)", "(fault kur*a)"), |
|
|
|
("(fault kur*a)", "(fault kur*a)"), |
|
|
|
("(fault \"do pr*ele\")", "(fault \"do pr*ele\")"), |
|
|
|
("(fault \"do pr*ele\")", "(fault \"do pr*ele\")"), |
|
|
|
("(xch r0 r1)", "(xch r0 r1)"), |
|
|
|
("(xch r0 r1)", "(xch r0 r1)"), |
|
|
|
|
|
|
|
("(xch32 r0 r1)", "(xch32 r0 r1)"), |
|
|
|
|
|
|
|
("(xch32/8/16 r0 r1)", "(xch32/8/16 r0 r1)"), |
|
|
|
("(ld r0 r0)", "(ld r0 r0)"), |
|
|
|
("(ld r0 r0)", "(ld r0 r0)"), |
|
|
|
("(ld8 r0 r1)", "(ld8 r0 r1)"), |
|
|
|
("(ld8 r0 r1)", "(ld8 r0 r1)"), |
|
|
|
("(ld16 r0 r1)", "(ld16 r0 r1)"), |
|
|
|
("(ld16 r0 r1)", "(ld16 r0 r1)"), |
|
|
|
("(ld32 r0 r1)", "(ld32 r0 r1)"), |
|
|
|
("(ld32 r0 r1)", "(ld32 r0 r1)"), |
|
|
|
|
|
|
|
("(ld32/32 r0 r1)", "(ld32/32 r0 r1)"), |
|
|
|
|
|
|
|
("(ld32/32/5 r0 r1)", "(ld32/32/5 r0 r1)"), |
|
|
|
|
|
|
|
("(ld32/0/16 r0 r1)", "(ld32/0/16 r0 r1)"), |
|
|
|
("(ld r0 156)", "(ld r0 156)"), |
|
|
|
("(ld r0 156)", "(ld r0 156)"), |
|
|
|
("(ld _ -32767)", "(ld _ -32767)"), |
|
|
|
("(ld _ -32767)", "(ld _ -32767)"), |
|
|
|
("(ldn _ @r0 7)", "(ldn _ @r0 7)"), |
|
|
|
("(ldn _ @r0 7)", "(ldn _ @r0 7)"), |
|
|
|
("(lds @r0 \"ahoj jak se mas\")", "(lds @r0 \"ahoj jak se mas\")"), |
|
|
|
("(lds @r0 \"ahoj jak se mas\")", "(lds @r0 \"ahoj jak se mas\")"), |
|
|
|
("(lds @r0 (1 2 3 4 0x123 r6))", "(lds @r0 (1 2 3 4 0x123 r6))"), |
|
|
|
("(lds @r0 (1 2 3 4 0x123 r6))", "(lds @r0 (1 2 3 4 291 r6))"), |
|
|
|
("(stf r0)", "(stf r0)"), |
|
|
|
("(stf r0)", "(stf r0)"), |
|
|
|
("(ldf r0)", "(ldf r0)"), |
|
|
|
("(ldf r0)", "(ldf r0)"), |
|
|
|
("(far :label)", "(far :label)"), |
|
|
|
("(far :label)", "(far :label)"), |
|
|
|