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 {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{} ", self.0.op.mnemonic(), self.0.modifiers())?;
let fields = self.0.fields();
let simple = self.0.clone().simplified();
write!(f, "{}{} ", simple.mnemonic, simple.modifiers)?;
let mut writing_offset = false;
for (i, field) in fields.iter().enumerate() {
if let Some(argument) = field.argument() {
write!(f, "{}", argument)?;
for (i, arg) in simple.args.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
if let offset(_) = field {
if let Argument::Offset(_) = arg {
write!(f, "(")?;
writing_offset = true;
continue;
} else {
write!(f, "{}", arg)?;
}
if writing_offset {
write!(f, ")")?;
writing_offset = false;
}
if i != fields.len() - 1 {
write!(f, ", ")?;
}
}
Ok(())
}

View File

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

View File

@ -345,3 +345,18 @@ impl Display for SimplifiedIns {
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,
#enum_variants
}
#[allow(clippy::all)]
impl Opcode {
#mnemonic_fn
#detect_fn
@ -328,7 +329,7 @@ impl Isa {
for simple in &self.mnemonics {
mnemonics_by_opcode
.entry(&simple.opcode)
.or_insert_with(|| Vec::new())
.or_insert_with(Vec::new)
.push(simple)
}
// Generate match arms for each opcode.
@ -444,7 +445,7 @@ impl Isa {
for arg in &mnemonic.args {
let field = field_by_name
.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 value = field.express_value_self();
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);
// Generate final fields function.
let ins_impl = quote! {
#[allow(clippy::all)]
impl Ins {
pub(crate) fn _fields(&self) -> Vec<Field> {
match self.op {
@ -513,12 +515,7 @@ impl Isa {
#simplified_ins_match_arms
_ => {}
}
SimplifiedIns {
mnemonic: self.op.mnemonic(),
modifiers: self._modifiers(),
args: vec![],
ins: self,
}
SimplifiedIns::basic_form(self)
}
}
};
@ -528,7 +525,7 @@ impl Isa {
/// Converts the given key into an identifier.
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.