make clippy happy

This commit is contained in:
Richard Patel 2022-04-07 02:14:11 +02:00
parent 1f5fec522a
commit b6ad3f4f2c
4 changed files with 32 additions and 24 deletions

View File

@ -6,25 +6,24 @@ pub struct FormattedIns(pub Ins);
impl Display for FormattedIns { impl Display for FormattedIns {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{} ", self.0.op.mnemonic(), self.0.modifiers())?; let simple = self.0.clone().simplified();
let fields = self.0.fields(); write!(f, "{}{} ", simple.mnemonic, simple.modifiers)?;
let mut writing_offset = false; let mut writing_offset = false;
for (i, field) in fields.iter().enumerate() { for (i, arg) in simple.args.iter().enumerate() {
if let Some(argument) = field.argument() { if i > 0 {
write!(f, "{}", argument)?; write!(f, ", ")?;
} }
if let offset(_) = field { if let Argument::Offset(_) = arg {
write!(f, "(")?; write!(f, "(")?;
writing_offset = true; writing_offset = true;
continue; continue;
} else {
write!(f, "{}", arg)?;
} }
if writing_offset { if writing_offset {
write!(f, ")")?; write!(f, ")")?;
writing_offset = false; writing_offset = false;
} }
if i != fields.len() - 1 {
write!(f, ", ")?;
}
} }
Ok(()) Ok(())
} }

View File

@ -225,6 +225,7 @@ pub enum Opcode {
Xori, Xori,
Xoris, Xoris,
} }
#[allow(clippy::all)]
impl Opcode { impl Opcode {
pub(crate) fn _mnemonic(self) -> &'static str { pub(crate) fn _mnemonic(self) -> &'static str {
match self { match self {
@ -1165,6 +1166,7 @@ pub enum Field {
ctr, ctr,
lr, lr,
} }
#[allow(clippy::all)]
impl Ins { impl Ins {
pub(crate) fn _fields(&self) -> Vec<Field> { pub(crate) fn _fields(&self) -> Vec<Field> {
match self.op { match self.op {
@ -5272,11 +5274,6 @@ impl Ins {
} }
_ => {} _ => {}
} }
SimplifiedIns { SimplifiedIns::basic_form(self)
mnemonic: self.op.mnemonic(),
modifiers: self._modifiers(),
args: vec![],
ins: self,
}
} }
} }

View File

@ -345,3 +345,18 @@ impl Display for SimplifiedIns {
Ok(()) Ok(())
} }
} }
impl SimplifiedIns {
pub(crate) fn basic_form(ins: Ins) -> Self {
Self {
mnemonic: ins.op.mnemonic(),
modifiers: ins.modifiers(),
args: ins
.fields()
.iter()
.flat_map(|field| field.argument())
.collect(),
ins,
}
}
}

View File

@ -232,6 +232,7 @@ impl Isa {
Illegal = -1, Illegal = -1,
#enum_variants #enum_variants
} }
#[allow(clippy::all)]
impl Opcode { impl Opcode {
#mnemonic_fn #mnemonic_fn
#detect_fn #detect_fn
@ -328,7 +329,7 @@ impl Isa {
for simple in &self.mnemonics { for simple in &self.mnemonics {
mnemonics_by_opcode mnemonics_by_opcode
.entry(&simple.opcode) .entry(&simple.opcode)
.or_insert_with(|| Vec::new()) .or_insert_with(Vec::new)
.push(simple) .push(simple)
} }
// Generate match arms for each opcode. // Generate match arms for each opcode.
@ -444,7 +445,7 @@ impl Isa {
for arg in &mnemonic.args { for arg in &mnemonic.args {
let field = field_by_name let field = field_by_name
.get(arg) .get(arg)
.expect(&format!("field not found: {}", arg)); .unwrap_or_else(|| panic!("field not found: {}", arg));
let variant = Ident::new(field.arg.as_ref().unwrap(), Span::call_site()); let variant = Ident::new(field.arg.as_ref().unwrap(), Span::call_site());
let value = field.express_value_self(); let value = field.express_value_self();
args.push(quote!(Argument::#variant(#variant(#value as _)),)); args.push(quote!(Argument::#variant(#variant(#value as _)),));
@ -476,6 +477,7 @@ impl Isa {
let simplified_ins_match_arms = token_stream!(simplified_ins_match_arms); let simplified_ins_match_arms = token_stream!(simplified_ins_match_arms);
// Generate final fields function. // Generate final fields function.
let ins_impl = quote! { let ins_impl = quote! {
#[allow(clippy::all)]
impl Ins { impl Ins {
pub(crate) fn _fields(&self) -> Vec<Field> { pub(crate) fn _fields(&self) -> Vec<Field> {
match self.op { match self.op {
@ -513,12 +515,7 @@ impl Isa {
#simplified_ins_match_arms #simplified_ins_match_arms
_ => {} _ => {}
} }
SimplifiedIns { SimplifiedIns::basic_form(self)
mnemonic: self.op.mnemonic(),
modifiers: self._modifiers(),
args: vec![],
ins: self,
}
} }
} }
}; };
@ -528,7 +525,7 @@ impl Isa {
/// Converts the given key into an identifier. /// Converts the given key into an identifier.
fn to_rust_ident(key: &str) -> TokenTree { fn to_rust_ident(key: &str) -> TokenTree {
TokenTree::Ident(Ident::new(&key.replace(".", "_"), Span::call_site())) TokenTree::Ident(Ident::new(&key.replace('.', "_"), Span::call_site()))
} }
/// Converts the given key into an enum variant key. /// Converts the given key into an enum variant key.