mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-04 00:21:57 +00:00
Changes from 3fc494759e6decc7b7692ee2cbbe13dd16676974 are now formatted.
This commit is contained in:
parent
6b3528507f
commit
8ac0df949a
@ -3,7 +3,7 @@
|
||||
// Imports
|
||||
use crate::inst::{
|
||||
basic::{Decode, Encode, ModifiesReg},
|
||||
exec::{ExecError, ExecCtx, Executable},
|
||||
exec::{ExecCtx, ExecError, Executable},
|
||||
parse::LineArg,
|
||||
DisplayCtx, InstDisplay, InstFmtArg, Parsable, ParseCtx, ParseError, Register,
|
||||
};
|
||||
|
||||
@ -169,7 +169,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let inst = match mnemonic {
|
||||
"cop0" | "cop1" | "cop2" | "cop3" => {
|
||||
let n = mnemonic[3..].parse().expect("Unable to parse 0..=3");
|
||||
|
||||
@ -122,7 +122,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
// Note: Literals are absolute, not relative
|
||||
|
||||
// Calculates the offset between an argument's position and the current one
|
||||
|
||||
@ -8,7 +8,7 @@ pub mod reg;
|
||||
use super::ModifiesReg;
|
||||
use crate::inst::{
|
||||
basic::{Decode, Encode},
|
||||
exec::{ExecError, ExecCtx, Executable},
|
||||
exec::{ExecCtx, ExecError, Executable},
|
||||
parse::LineArg,
|
||||
DisplayCtx, InstDisplay, InstFmtArg, Parsable, ParseCtx, ParseError, Register,
|
||||
};
|
||||
@ -41,7 +41,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
match imm::Inst::parse(mnemonic, args, ctx) {
|
||||
Ok(inst) => Ok(Self::Imm(inst)),
|
||||
Err(ParseError::UnknownMnemonic) => reg::Inst::parse(mnemonic, args, ctx).map(Self::Reg),
|
||||
|
||||
@ -90,7 +90,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let (pos, kind) = match mnemonic {
|
||||
"j" => match args {
|
||||
[arg] => (ctx.arg_pos(arg)?, Kind::Jump),
|
||||
|
||||
@ -135,7 +135,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let kind = Kind::from_mnemonic(mnemonic).ok_or(ParseError::UnknownMnemonic)?;
|
||||
|
||||
let (value, addr, offset) = match *args {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
use super::ModifiesReg;
|
||||
use crate::inst::{
|
||||
basic::{Decode, Encode},
|
||||
exec::{ExecError, ExecCtx, Executable},
|
||||
exec::{ExecCtx, ExecError, Executable},
|
||||
parse::LineArg,
|
||||
DisplayCtx, InstDisplay, InstFmtArg, Parsable, ParseCtx, ParseError, Register,
|
||||
};
|
||||
@ -48,7 +48,9 @@ impl Encode for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
if mnemonic != "lui" {
|
||||
return Err(ParseError::UnknownMnemonic);
|
||||
}
|
||||
|
||||
@ -79,7 +79,9 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let kind = match mnemonic {
|
||||
"lbi" => Kind::Byte,
|
||||
"lhi" => Kind::HalfWord,
|
||||
|
||||
@ -155,7 +155,9 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let to_kind = match mnemonic {
|
||||
"li" => |ctx: &Ctx, arg: &LineArg| match arg {
|
||||
// Try `i16`, `u16` then `u32` for the literal
|
||||
|
||||
@ -47,7 +47,9 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
if mnemonic != "nop" {
|
||||
return Err(ParseError::UnknownMnemonic);
|
||||
}
|
||||
|
||||
@ -78,7 +78,9 @@ impl Encodable for Inst {
|
||||
}
|
||||
|
||||
impl<'a> Parsable<'a> for Inst {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx) -> Result<Self, ParseError> {
|
||||
fn parse<Ctx: ?Sized + ParseCtx<'a>>(
|
||||
mnemonic: &'a str, args: &'a [LineArg], ctx: &Ctx,
|
||||
) -> Result<Self, ParseError> {
|
||||
let kind = match mnemonic {
|
||||
"sbi" => Kind::Byte,
|
||||
"shi" => Kind::HalfWord,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user