From f67c330e78d3ba2eff0cabd205b2f538fee07f4c Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Fri, 17 Jan 2020 03:21:05 -0500 Subject: [PATCH] Upgrade toolchain to ISA v0.2 --- toolchain/src/inst.rs | 31 +++++---- toolchain/src/inst/decode.rs | 75 ++++++++++++++------- toolchain/src/inst/encode.rs | 39 +++++------ toolchain/src/inst/format.rs | 32 ++++----- toolchain/src/inst/parse.rs | 66 ++++++++++++------- toolchain/src/inst/test.rs | 122 ++++++++++++++++++++++------------- toolchain/src/lib.rs | 5 +- 7 files changed, 230 insertions(+), 140 deletions(-) diff --git a/toolchain/src/inst.rs b/toolchain/src/inst.rs index 4c986d2..e04b339 100644 --- a/toolchain/src/inst.rs +++ b/toolchain/src/inst.rs @@ -47,7 +47,7 @@ pub enum OpI3 { Lsr, Asr, Clr, - Set, + Ins, Tog, Ext, } @@ -89,10 +89,10 @@ pub enum AluI { #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(test, derive(Arbitrary))] -pub enum Target { - Abs, - Off, - OffImm(i8), +#[repr(u8)] +pub enum LdSt { + Ld, + St, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -100,20 +100,25 @@ pub enum Target { #[cfg_attr(test, proptest(no_params))] pub enum Inst { Trap, - Jump(Target), - Call(Target), - Swap(Reg), - GetR(Reg), - SetR(Reg), + Nope, + Prnt, + CAbA, + COfA, + Alu1(Op1), Get(Special), Set(Special), - Alu1(Op1), + GetR(Reg), + SetR(Reg), + Swap(Reg), IsLt(Reg), AluR(OpR, Reg), - LdD(Data, Reg, bool), - StD(Data, Reg, bool), + Mem(LdSt, Data, Reg, bool), AluI(AluI), BEzI(i8), + JOfI(i8), + CAbI(u8), + COfI(i8), + GetI(u8), } impl Inst { diff --git a/toolchain/src/inst/decode.rs b/toolchain/src/inst/decode.rs index 61b1ded..a83d8fc 100644 --- a/toolchain/src/inst/decode.rs +++ b/toolchain/src/inst/decode.rs @@ -1,4 +1,4 @@ -use super::{AddImm, AluI, Data, Inst, Op1, OpI3, OpR, Reg, Special, Target, U3}; +use super::{AddImm, AluI, Data, Inst, LdSt, Op1, OpI3, OpR, Reg, Special, U3}; use std::io::{self, Read}; pub trait Decode: Sized { @@ -64,36 +64,48 @@ fn op_compact(x: u8) -> OpI3 { 0b010 => OpI3::Lsr, 0b011 => OpI3::Asr, 0b100 => OpI3::Clr, - 0b101 => OpI3::Set, + 0b101 => OpI3::Ins, 0b110 => OpI3::Tog, 0b111 => OpI3::Ext, _ => unreachable!(), } } +fn ldst(o: u8) -> LdSt { + if o & 0x1 == 0 { + LdSt::Ld + } else { + LdSt::St + } +} + +fn data(o: u8) -> Data { + if o & 0x4 == 0 { + Data::D1 + } else { + Data::D2 + } +} + impl Decode for Inst { fn decode(reader: &mut impl Read) -> io::Result { - use Data::*; let mut op_byte = [0]; reader.read_exact(&mut op_byte)?; Ok(match (op_byte[0] >> 3, op_byte[0] & 7) { - (0b0000_0, 0..=2) => Inst::Trap, - (0b0000_0, 0b100) => Inst::Jump(Target::Abs), - (0b0000_0, 0b101) => Inst::Call(Target::Abs), - (0b0000_0, 0b110) => Inst::Jump(Target::Off), - (0b0000_0, 0b111) => Inst::Call(Target::Off), - (0b0000_1, r) => Inst::Swap(reg(r)), - (0b0001_0, r) => Inst::GetR(reg(r)), - (0b0001_1, r) => Inst::SetR(reg(r)), - (0b0010_0, s) => Inst::Get(special(s)?), - (0b0010_1, s) => Inst::Set(special(s)?), - (0b0011_0, o) => Inst::Alu1(op1(o)), + (0b0000_0, 0b000) => Inst::Trap, + (0b0000_0, 0b001) => Inst::Nope, + (0b0000_0, 0b010) => Inst::Prnt, + (0b0000_0, 0b110) => Inst::CAbA, + (0b0000_0, 0b111) => Inst::COfA, + (0b0000_1, o) => Inst::Alu1(op1(o)), + (0b0001_0, s) => Inst::Get(special(s)?), + (0b0001_1, s) => Inst::Set(special(s)?), + (0b0010_0, r) => Inst::GetR(reg(r)), + (0b0010_1, r) => Inst::SetR(reg(r)), + (0b0011_0, r) => Inst::Swap(reg(r)), (0b0011_1, r) => Inst::IsLt(reg(r)), (o @ 0b0100_0..=0b0111_1, r) => Inst::AluR(op_r(o), reg(r)), - (o @ 0b1000_0, r) | (o @ 0b1001_0, r) => Inst::LdD(D1, reg(r), flag(o)), - (o @ 0b1000_1, r) | (o @ 0b1001_1, r) => Inst::StD(D1, reg(r), flag(o)), - (o @ 0b1010_0, r) | (o @ 0b1011_0, r) => Inst::LdD(D2, reg(r), flag(o)), - (o @ 0b1010_1, r) | (o @ 0b1011_1, r) => Inst::StD(D2, reg(r), flag(o)), + (o @ 0b1000_0..=0b1011_1, r) => Inst::Mem(ldst(o), data(o), reg(r), flag(o)), (0b1111_0..=0b1111_1, _) => { let mut imm_byte = [0]; reader @@ -121,13 +133,30 @@ impl Decode for Inst { _ => unreachable!(), }, 0b0100 => Inst::BEzI(imm as i8), - 0b0101 => Inst::Trap, /* reserved branch */ - 0b0110 => Inst::Jump(Target::OffImm(imm as i8)), - 0b0111 => Inst::Call(Target::OffImm(imm as i8)), - _ => Inst::Trap, /* reserved with immediate */ + 0b0101 => Inst::JOfI(imm as i8), /* reserved branch */ + 0b0110 => Inst::CAbI(imm), + 0b0111 => Inst::COfI(imm as i8), + 0b1110 => Inst::GetI(imm), + 0b1111 => { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "reserved extended EXT1", + )) + } /* reserved with immediate */ + _ => { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "reseved with immediate", + )) + } /* reserved with immediate */ } } - _ => Inst::Trap, + _ => { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "invalid instruction", + )) + } }) } } diff --git a/toolchain/src/inst/encode.rs b/toolchain/src/inst/encode.rs index f23c53a..6515aa6 100644 --- a/toolchain/src/inst/encode.rs +++ b/toolchain/src/inst/encode.rs @@ -1,4 +1,4 @@ -use super::{AluI, Data, Inst, Reg, Special, Target, U3}; +use super::{AluI, Data, Inst, Reg, Special, U3}; use std::io::{self, Write}; pub trait Encode { @@ -21,24 +21,23 @@ impl Encode for Inst { fn encode(&self, writer: &mut impl Write) -> io::Result<()> { match *self { Inst::Trap => writer.write(&[0x00])?, - Inst::Jump(Target::Abs) => writer.write(&[0x04])?, - Inst::Call(Target::Abs) => writer.write(&[0x05])?, - Inst::Jump(Target::Off) => writer.write(&[0x06])?, - Inst::Call(Target::Off) => writer.write(&[0x07])?, - Inst::Swap(r) => writer.write(&[0x08 | reg(r)])?, - Inst::GetR(r) => writer.write(&[0x10 | reg(r)])?, - Inst::SetR(r) => writer.write(&[0x18 | reg(r)])?, - Inst::Get(s) => writer.write(&[0x20 | sp(s)])?, - Inst::Set(s) => writer.write(&[0x28 | sp(s)])?, - Inst::Alu1(op) => writer.write(&[0x30 | op as u8])?, + Inst::Nope => writer.write(&[0x01])?, + Inst::Prnt => writer.write(&[0x02])?, + Inst::CAbA => writer.write(&[0x06])?, + Inst::COfA => writer.write(&[0x07])?, + Inst::Alu1(op) => writer.write(&[0x08 | op as u8])?, + Inst::Get(s) => writer.write(&[0x10 | sp(s)])?, + Inst::Set(s) => writer.write(&[0x18 | sp(s)])?, + Inst::GetR(r) => writer.write(&[0x20 | reg(r)])?, + Inst::SetR(r) => writer.write(&[0x28 | reg(r)])?, + Inst::Swap(r) => writer.write(&[0x30 | reg(r)])?, Inst::IsLt(r) => writer.write(&[0x38 | reg(r)])?, Inst::AluR(op, r) => writer.write(&[0x40 | (op as u8) << 3 | reg(r)])?, - Inst::LdD(d, r, inc) => { - writer.write(&[0x80 | (d as u8) << 5 | (inc as u8) << 4 | reg(r)])? - } - Inst::StD(d, r, inc) => { - writer.write(&[0x88 | (d as u8) << 5 | (inc as u8) << 4 | reg(r)])? - } + Inst::Mem(op, d, r, inc) => writer.write(&[0x80 + | (d as u8) << 5 + | (inc as u8) << 4 + | (op as u8) << 3 + | reg(r)])?, Inst::AluI(alu) => match alu { AluI::And(imm) => writer.write(&[0xf0, imm])?, AluI::Ior(imm) => writer.write(&[0xf1, imm])?, @@ -47,8 +46,10 @@ impl Encode for Inst { AluI::Compact(op, imm) => writer.write(&[0xf3, 0x80 | (op as u8) << 3 | imm.0])?, }, Inst::BEzI(off) => writer.write(&[0xf4, off as u8])?, - Inst::Jump(Target::OffImm(off)) => writer.write(&[0xf6, off as u8])?, - Inst::Call(Target::OffImm(off)) => writer.write(&[0xf7, off as u8])?, + Inst::JOfI(off) => writer.write(&[0xf5, off as u8])?, + Inst::CAbI(imm) => writer.write(&[0xf6, imm])?, + Inst::COfI(off) => writer.write(&[0xf7, off as u8])?, + Inst::GetI(imm) => writer.write(&[0xfe, imm])?, }; Ok(()) } diff --git a/toolchain/src/inst/format.rs b/toolchain/src/inst/format.rs index f9f9028..c840e04 100644 --- a/toolchain/src/inst/format.rs +++ b/toolchain/src/inst/format.rs @@ -1,4 +1,4 @@ -use super::{AddImm, AluI as OpI, Data, Inst, Op1, OpI3, OpR, Reg, Special, Target, U3}; +use super::{AddImm, AluI as OpI, Data, Inst, LdSt, Op1, OpI3, OpR, Reg, Special, U3}; use std::fmt::{self, Display, Formatter}; fn data(d: Data) -> &'static str { @@ -28,15 +28,10 @@ impl Display for Inst { use Inst::*; match *self { Trap => write!(fmt, "TRAP"), - Jump(Target::Abs) => write!(fmt, "JABS"), - Call(Target::Abs) => write!(fmt, "CABS"), - Jump(Target::Off) => write!(fmt, "JOFF"), - Call(Target::Off) => write!(fmt, "COFF"), - Swap(r) => write!(fmt, "SWAP {}", r), - GetR(r) => write!(fmt, "GETR {}", r), - SetR(r) => write!(fmt, "SETR {}", r), - Get(s) => write!(fmt, "GET{}", special(s)), - Set(s) => write!(fmt, "SET{}", special(s)), + Nope => write!(fmt, "NOPE"), + Prnt => write!(fmt, "PRNT"), + CAbA => write!(fmt, "CABA"), + COfA => write!(fmt, "COFA"), Alu1(Op1::Zero) => write!(fmt, "ZERO"), Alu1(Op1::Lsl1) => write!(fmt, "LSL1"), Alu1(Op1::Lsr1) => write!(fmt, "LSR1"), @@ -45,6 +40,11 @@ impl Display for Inst { Alu1(Op1::Decr) => write!(fmt, "DECR"), Alu1(Op1::Comp) => write!(fmt, "COMP"), Alu1(Op1::Negt) => write!(fmt, "NEGT"), + Get(s) => write!(fmt, "GET{}", special(s)), + Set(s) => write!(fmt, "SET{}", special(s)), + GetR(r) => write!(fmt, "GETR {}", r), + SetR(r) => write!(fmt, "SETR {}", r), + Swap(r) => write!(fmt, "SWAP {}", r), IsLt(r) => write!(fmt, "ISLT {}", r), AluR(OpR::Add, r) => write!(fmt, "ADDR {}", r), AluR(OpR::Sub, r) => write!(fmt, "SUBR {}", r), @@ -54,8 +54,8 @@ impl Display for Inst { AluR(OpR::Lsl, r) => write!(fmt, "LSLR {}", r), AluR(OpR::Lsr, r) => write!(fmt, "LSRR {}", r), AluR(OpR::Asr, r) => write!(fmt, "ASRR {}", r), - LdD(d, r, i) => write!(fmt, "LD{}U {}{}", data(d), r, flag(i)), - StD(d, r, i) => write!(fmt, "ST{}U {}{}", data(d), r, flag(i)), + Mem(LdSt::Ld, d, r, i) => write!(fmt, "LD{}U {}{}", data(d), r, flag(i)), + Mem(LdSt::St, d, r, i) => write!(fmt, "ST{}U {}{}", data(d), r, flag(i)), AluI(OpI::And(i)) => write!(fmt, "ANDI #x{:02X}", i), AluI(OpI::Ior(i)) => write!(fmt, "IORI #x{:02X}", i), AluI(OpI::Xor(i)) => write!(fmt, "XORI #x{:02X}", i), @@ -66,13 +66,15 @@ impl Display for Inst { OpI3::Lsr => write!(fmt, "LSRI #{}", i), OpI3::Asr => write!(fmt, "ASRI #{}", i), OpI3::Clr => write!(fmt, "CLRI #{}", i), - OpI3::Set => write!(fmt, "SETI #{}", i), + OpI3::Ins => write!(fmt, "INSI #{}", i), OpI3::Tog => write!(fmt, "TOGI #{}", i), OpI3::Ext => write!(fmt, "EXTI #{}", i), }, BEzI(off) => write!(fmt, "BEZI #{}", off), - Jump(Target::OffImm(i)) => write!(fmt, "JOFI #{}", i), - Call(Target::OffImm(i)) => write!(fmt, "COFI #{}", i), + JOfI(i) => write!(fmt, "JOFI #{}", i), + CAbI(i) => write!(fmt, "CABI #{}", i), + COfI(i) => write!(fmt, "COFI #{}", i), + GetI(i) => write!(fmt, "GETI #{}", i), } } } diff --git a/toolchain/src/inst/parse.rs b/toolchain/src/inst/parse.rs index d761c00..87d1669 100644 --- a/toolchain/src/inst/parse.rs +++ b/toolchain/src/inst/parse.rs @@ -1,4 +1,4 @@ -use super::{AddImm, AluI, Data, Inst, Op1, OpI3, OpR, Reg, Special, Target, U3}; +use super::{AddImm, AluI, Data, Inst, LdSt, Op1, OpI3, OpR, Reg, Special, U3}; use nom::{ branch::alt, bytes::complete::tag_no_case, @@ -18,23 +18,12 @@ pub fn inst(s: &str) -> IResult<&str, Inst> { alt(( alt(( fixed("TRAP", Inst::Trap), - fixed("JABS", Inst::Jump(Target::Abs)), - fixed("CABS", Inst::Call(Target::Abs)), - fixed("JOFF", Inst::Jump(Target::Off)), - fixed("COFF", Inst::Call(Target::Off)), + fixed("NOPE", Inst::Nope), + fixed("PRNT", Inst::Prnt), + fixed("CABA", Inst::CAbA), + fixed("COFA", Inst::COfA), )), alt(( - with_reg("SWAP", |r| Inst::Swap(r)), - with_reg("GETR", |r| Inst::GetR(r)), - with_reg("SETR", |r| Inst::SetR(r)), - )), - alt(( - fixed("GET1", Inst::Get(Special::Data(Data::D1))), - fixed("GET2", Inst::Get(Special::Data(Data::D2))), - fixed("GETC", Inst::Get(Special::Code)), - fixed("SET1", Inst::Set(Special::Data(Data::D1))), - fixed("SET2", Inst::Set(Special::Data(Data::D2))), - fixed("SETC", Inst::Set(Special::Code)), fixed("ZERO", Inst::Alu1(Op1::Zero)), fixed("LSL1", Inst::Alu1(Op1::Lsl1)), fixed("LSR1", Inst::Alu1(Op1::Lsr1)), @@ -45,7 +34,20 @@ pub fn inst(s: &str) -> IResult<&str, Inst> { fixed("NEGT", Inst::Alu1(Op1::Negt)), )), alt(( + fixed("GET1", Inst::Get(Special::Data(Data::D1))), + fixed("GET2", Inst::Get(Special::Data(Data::D2))), + fixed("GETC", Inst::Get(Special::Code)), + fixed("SET1", Inst::Set(Special::Data(Data::D1))), + fixed("SET2", Inst::Set(Special::Data(Data::D2))), + fixed("SETC", Inst::Set(Special::Code)), + )), + alt(( + with_reg("GETR", |r| Inst::GetR(r)), + with_reg("SETR", |r| Inst::SetR(r)), + with_reg("SWAP", |r| Inst::Swap(r)), with_reg("ISLT", |r| Inst::IsLt(r)), + )), + alt(( with_reg("ADDR", |r| Inst::AluR(OpR::Add, r)), with_reg("SUBR", |r| Inst::AluR(OpR::Sub, r)), with_reg("ANDR", |r| Inst::AluR(OpR::And, r)), @@ -56,10 +58,10 @@ pub fn inst(s: &str) -> IResult<&str, Inst> { with_reg("ASRR", |r| Inst::AluR(OpR::Asr, r)), )), alt(( - with_reg_bang("LD1U", |r, b| Inst::LdD(Data::D1, r, b)), - with_reg_bang("ST1U", |r, b| Inst::StD(Data::D1, r, b)), - with_reg_bang("LD2U", |r, b| Inst::LdD(Data::D2, r, b)), - with_reg_bang("ST2U", |r, b| Inst::StD(Data::D2, r, b)), + with_reg_bang("LD1U", |r, b| Inst::Mem(LdSt::Ld, Data::D1, r, b)), + with_reg_bang("ST1U", |r, b| Inst::Mem(LdSt::St, Data::D1, r, b)), + with_reg_bang("LD2U", |r, b| Inst::Mem(LdSt::Ld, Data::D2, r, b)), + with_reg_bang("ST2U", |r, b| Inst::Mem(LdSt::St, Data::D2, r, b)), )), alt(( with_imm8("ANDI", |imm| Inst::AluI(AluI::And(imm))), @@ -73,14 +75,16 @@ pub fn inst(s: &str) -> IResult<&str, Inst> { with_imm3("LSRI", |imm| Inst::AluI(AluI::Compact(OpI3::Lsr, imm))), with_imm3("ASRI", |imm| Inst::AluI(AluI::Compact(OpI3::Asr, imm))), with_imm3("CLRI", |imm| Inst::AluI(AluI::Compact(OpI3::Clr, imm))), - with_imm3("SETI", |imm| Inst::AluI(AluI::Compact(OpI3::Set, imm))), + with_imm3("INSI", |imm| Inst::AluI(AluI::Compact(OpI3::Ins, imm))), with_imm3("TOGI", |imm| Inst::AluI(AluI::Compact(OpI3::Tog, imm))), with_imm3("EXTI", |imm| Inst::AluI(AluI::Compact(OpI3::Ext, imm))), )), alt(( with_off("BEZI", |off| Inst::BEzI(off)), - with_off("JOFI", |off| Inst::Jump(Target::OffImm(off))), - with_off("COFI", |off| Inst::Call(Target::OffImm(off))), + with_off("JOFI", |off| Inst::JOfI(off)), + with_imm8("CABI", |imm| Inst::CAbI(imm)), + with_off("COFI", |off| Inst::COfI(off)), + with_fimm8("GETI", |imm| Inst::GetI(imm)), )), ))(s) } @@ -130,6 +134,14 @@ fn imm8(s: &str) -> IResult<&str, u8> { map_res(imm, TryFrom::try_from)(s) } +fn simm8(s: &str) -> IResult<&str, i8> { + map_res(imm, TryFrom::try_from)(s) +} + +fn fimm8(s: &str) -> IResult<&str, u8> { + alt((imm8, map(simm8, |x| x as u8)))(s) +} + fn add_imm(s: &str) -> IResult<&str, AddImm> { map_opt(map_res(imm, TryFrom::try_from), AddImm::new)(s) } @@ -192,3 +204,11 @@ fn with_off<'s>( let imm = preceded(pair(tag_no_case(tag), space1), imm_off); map(imm, make_inst) } + +fn with_fimm8<'s>( + tag: &'s str, + make_inst: impl Fn(u8) -> Inst, +) -> impl Fn(&'s str) -> IResult<&'s str, Inst> { + let imm = preceded(pair(tag_no_case(tag), space1), fimm8); + map(imm, make_inst) +} diff --git a/toolchain/src/inst/test.rs b/toolchain/src/inst/test.rs index 1c1b5dd..3422b5e 100644 --- a/toolchain/src/inst/test.rs +++ b/toolchain/src/inst/test.rs @@ -71,70 +71,83 @@ fn trap() { } #[test] -fn jump_call() { +fn nope() { test_parse! { - "JABS" => "0000_0100", - "CABS" => "0000_0101", - "JOFF" => "0000_0110", - "COFF" => "0000_0111", + "NOPE" => "0000_0001", } } #[test] -fn swap() { +fn prnt() { test_parse! { - "swap r0" => "0000_1000", - "SWAP r1" => "0000_1001", - "Swap\tr2" => "0000_1010", - "SWAP\t\tr3" => "0000_1011", - "SWAP r4" => "0000_1100", - "SWAP r5" => "0000_1101", - "SWAP r6" => "0000_1110", - "SWAP r7" => "0000_1111", - "SWAP r8" => !, - "swapr0" => !, - "swap 0" => !, - "swap g0" => !, - "swap" => !, + "PRNT" => "0000_0010", } } #[test] -fn getr_setr() { +fn jump_call() { test_parse! { - "getr r3" => "0001_0011", - "GETR r7" => "0001_0111", - "GETR r9" => !, + "CABA" => "0000_0110", + "COFA" => "0000_0111", + } +} - "SETR r0" => "0001_1000", - "SETR r7" => "0001_1111", +#[test] +fn alu1() { + test_parse! { + "zero" => "0000_1000", + "lsl1" => "0000_1001", + "lsr1" => "0000_1010", + "asr1" => "0000_1011", + "incr" => "0000_1100", + "decr" => "0000_1101", + "comp" => "0000_1110", + "negt" => "0000_1111", } } #[test] fn get_set_special() { test_parse! { - "GET1" => "0010_0000", - "GET2" => "0010_0001", - "GETC" => "0010_0010", + "GET1" => "0001_0000", + "GET2" => "0001_0001", + "GETC" => "0001_0010", - "SET1" => "0010_1000", - "SET2" => "0010_1001", - "SETC" => "0010_1010", + "SET1" => "0001_1000", + "SET2" => "0001_1001", + "SETC" => "0001_1010", } } #[test] -fn alu1() { +fn getr_setr() { + test_parse! { + "getr r3" => "0010_0011", + "GETR r7" => "0010_0111", + "GETR r9" => !, + "GETRr0" => !, + + "SETR r0" => "0010_1000", + "SETR r7" => "0010_1111", + } +} + +#[test] +fn swap() { test_parse! { - "zero" => "0011_0000", - "lsl1" => "0011_0001", - "lsr1" => "0011_0010", - "asr1" => "0011_0011", - "incr" => "0011_0100", - "decr" => "0011_0101", - "comp" => "0011_0110", - "negt" => "0011_0111", + "swap r0" => "0011_0000", + "SWAP r1" => "0011_0001", + "Swap\tr2" => "0011_0010", + "SWAP\t\tr3" => "0011_0011", + "SWAP r4" => "0011_0100", + "SWAP r5" => "0011_0101", + "SWAP r6" => "0011_0110", + "SWAP r7" => "0011_0111", + "SWAP r8" => !, + "swapr0" => !, + "swap 0" => !, + "swap g0" => !, + "swap" => !, } } @@ -254,8 +267,8 @@ fn alu_compact() { "clri #0" => "1111_0011 1010_0000", "clri #7" => "1111_0011 1010_0111", - "seti #0" => "1111_0011 1010_1000", - "seti #7" => "1111_0011 1010_1111", + "insi #0" => "1111_0011 1010_1000", + "insi #7" => "1111_0011 1010_1111", "togi #0" => "1111_0011 1011_0000", "togi #7" => "1111_0011 1011_0111", "exti #0" => "1111_0011 1011_1000", @@ -264,7 +277,7 @@ fn alu_compact() { } #[test] -fn branch() { +fn imm_jumps() { test_parse! { "bezi #0" => "1111_0100 0000_0000", "bezi #1" => "1111_0100 0000_0001", @@ -274,12 +287,29 @@ fn branch() { "bezi #-129" => !, "bezi #128" => !, - "jofi #0" => "1111_0110 0000_0000", - "jofi #1" => "1111_0110 0000_0001", - "jofi #-1" => "1111_0110 1111_1111", + "jofi #0" => "1111_0101 0000_0000", + "jofi #1" => "1111_0101 0000_0001", + "jofi #-1" => "1111_0101 1111_1111", + + "cabi #0" => "1111_0110 0000_0000", + "cabi #1" => "1111_0110 0000_0001", + "cabi #-1" => !, "cofi #0" => "1111_0111 0000_0000", "cofi #1" => "1111_0111 0000_0001", "cofi #-1" => "1111_0111 1111_1111", } } + +#[test] +fn geti() { + test_parse! { + "geti #0" => "1111_1110 0000_0000", + "geti #1" => "1111_1110 0000_0001", + "geti #xFF" => "1111_1110 1111_1111", + "geti #x100" => !, + "geti #-1" => "1111_1110 1111_1111", + "geti #-128" => "1111_1110 1000_0000", + "geti #-129" => !, + } +} diff --git a/toolchain/src/lib.rs b/toolchain/src/lib.rs index ee96f75..612fb59 100644 --- a/toolchain/src/lib.rs +++ b/toolchain/src/lib.rs @@ -57,6 +57,9 @@ mod test { let mut cursor = Cursor::new(&[0xff]); let err = Inst::decode(&mut cursor).unwrap_err(); assert_eq!(err.kind(), io::ErrorKind::InvalidInput); - assert_eq!(err.get_ref().map(|x| x.to_string()), Some("Extended instruction missing operand".into())); + assert_eq!( + err.get_ref().map(|x| x.to_string()), + Some("Extended instruction missing operand".into()) + ); } } -- 2.47.0