Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some clippy fixes #107

Merged
2 changes: 1 addition & 1 deletion plugin/src/arch/aarch64/aarch64data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub enum Command {
/// `immediate + prev_arg - 1` is encoded in a a bitfield of length `len` at offset `pos`
Usum(u8, u8),
/// format: `([offsets])`
/// `immediate is in the range `0 .. (1 << offsets.len())`
/// `immediate` is in the range `0 .. (1 << offsets.len())`
/// `immediate` is encoded with bit N of the number at offsets[N]
Ufields(&'static [u8]),

Expand Down
24 changes: 12 additions & 12 deletions plugin/src/arch/aarch64/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,20 @@ pub(super) fn compile_instruction(ctx: &mut Context, data: MatchData) -> Result<

if let Some((biased, _)) = static_range_check(value, 0, mask, 0)? {
for (i, &field) in bitfields.iter().rev().enumerate() {
statics.push((field as u8, (biased >> i) & 1));
statics.push((field, (biased >> i) & 1));
}

} else {
let check = dynamic_range_check_unsigned(value.span(), 0, mask, 0);

for (i, &field) in bitfields.iter().rev().enumerate() {
if i == 0 {
dynamics.push((field as u8, quote_spanned!{ value.span()=>
dynamics.push((field, quote_spanned!{ value.span()=>
{ let _dyn_imm: u32 = #value; #check; (_dyn_imm >> #i) & 1 }
}));

} else {
dynamics.push((field as u8, quote_spanned!{ value.span()=>
dynamics.push((field, quote_spanned!{ value.span()=>
(#value >> #i) & 1
}));
}
Expand Down Expand Up @@ -678,7 +678,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
match special {
SpecialComm::INVERTED_WIDE_IMMEDIATE_X => if let Some(number) = None::<u64> { // as_unsigned_number(imm) {
if let Some(encoded) = encoding_helpers::encode_wide_immediate_64bit(!number) {
statics.push((offset, encoded as u32));
statics.push((offset, encoded));
return Ok(());
}
} else {
Expand All @@ -697,9 +697,9 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
return Ok(());
},
SpecialComm::INVERTED_WIDE_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) {
if number <= u64::from(std::u32::MAX) {
if number <= u64::from(u32::MAX) {
if let Some(encoded) = encoding_helpers::encode_wide_immediate_32bit(!(number as u32)) {
statics.push((offset, encoded as u32));
statics.push((offset, encoded));
return Ok(());
}
}
Expand All @@ -720,7 +720,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
},
SpecialComm::WIDE_IMMEDIATE_X => if let Some(number) = as_unsigned_number(imm) {
if let Some(encoded) = encoding_helpers::encode_wide_immediate_64bit(number) {
statics.push((offset, encoded as u32));
statics.push((offset, encoded));
return Ok(());
}
} else {
Expand All @@ -739,9 +739,9 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
return Ok(());
},
SpecialComm::WIDE_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) {
if number <= u64::from(std::u32::MAX) {
if number <= u64::from(u32::MAX) {
if let Some(encoded) = encoding_helpers::encode_wide_immediate_32bit(number as u32) {
statics.push((offset, encoded as u32));
statics.push((offset, encoded));
return Ok(());
}
}
Expand All @@ -762,8 +762,8 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
},
SpecialComm::STRETCHED_IMMEDIATE => if let Some(number) = as_unsigned_number(imm) {
if let Some(encoded) = encoding_helpers::encode_stretched_immediate(number) {
statics.push((offset, encoded & 0x1F as u32));
statics.push((offset + 6, encoded & 0xE0 as u32));
statics.push((offset, encoded & 0x1F));
statics.push((offset + 6, encoded & 0xE0));
return Ok(());
}
} else {
Expand All @@ -788,7 +788,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr,
return Ok(());
},
SpecialComm::LOGICAL_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) {
if number <= u64::from(std::u32::MAX) {
if number <= u64::from(u32::MAX) {
if let Some(encoded) = encoding_helpers::encode_logical_immediate_32bit(number as u32) {
statics.push((offset, u32::from(encoded)));
return Ok(());
Expand Down
10 changes: 5 additions & 5 deletions plugin/src/arch/aarch64/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ pub fn format_opdata(name: &str, data: &Opdata) -> Vec<String> {
continue;
} else if let Matcher::Dot = matcher {
after_dot = true;
buf.push_str(".");
buf.push('.');
continue;
}

if first {
if !after_dot {
buf.push_str(" ");
buf.push(' ');
first = false;
}
after_dot = false;
Expand Down Expand Up @@ -656,13 +656,13 @@ pub fn extract_opdata(name: &str, data: &Opdata) -> Vec<String> {
continue;
} else if let Matcher::Dot = matcher {
after_dot = true;
buf.push_str(".");
buf.push('.');
continue;
}

if first {
if !after_dot {
buf.push_str(" ");
buf.push(' ');
first = false;
}
after_dot = false;
Expand Down Expand Up @@ -818,4 +818,4 @@ fn extract_constraints(args: &[ArgWithCommands]) -> Vec<String> {
}
}
constraints
}
}
2 changes: 1 addition & 1 deletion plugin/src/arch/aarch64/encoding_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn encode_wide_immediate_32bit(value: u32) -> Option<u32> {
let offset = value.trailing_zeros() & 0b1_0000;
let masked = 0xFFFF & (value >> offset);
if (masked << offset) == value {
Some((masked as u32) | (offset << 12))
Some(masked | (offset << 12))
} else {
None
}
Expand Down
8 changes: 1 addition & 7 deletions plugin/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ struct Context<'a, 'b: 'a> {
pub state: &'a mut State<'b>
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct ArchAarch64 {

}

impl Default for ArchAarch64 {
fn default() -> ArchAarch64 {
ArchAarch64 { }
}
}

impl Arch for ArchAarch64 {
fn set_features(&mut self, features: &[syn::Ident]) {
if let Some(feature) = features.first() {
Expand Down
52 changes: 26 additions & 26 deletions plugin/src/arch/x64/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a
let mut args = args.into_iter().map(clean_memoryref).collect::<Result<Vec<CleanArg>, _>>()?;

// sanitize memory references, determine address size, and size immediates/displacements if possible
let addr_size = sanitize_indirects_and_sizes(&ctx, &mut args)?;
let addr_size = sanitize_indirects_and_sizes(ctx, &mut args)?;
let addr_size = addr_size.unwrap_or(match ctx.mode {
X86Mode::Long => Size::B_8,
X86Mode::Protected => Size::B_4
Expand Down Expand Up @@ -141,7 +141,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a

match ctx.mode {
X86Mode::Protected => if op_size == Size::B_8 {
return Err(Some(format!("'{}': Does not support 64 bit operands in 32-bit mode", op.to_string())));
return Err(Some(format!("'{}': Does not support 64 bit operands in 32-bit mode", op)));
},
X86Mode::Long => ()
}
Expand All @@ -151,14 +151,14 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a
(Size::B_2, _) => pref_size = true,
(Size::B_8, X86Mode::Long) => (),
(Size::B_4, X86Mode::Protected) => (),
(Size::B_4, X86Mode::Long) => return Err(Some(format!("'{}': Does not support 32 bit operands in 64-bit mode", op.to_string()))),
(Size::B_4, X86Mode::Long) => return Err(Some(format!("'{}': Does not support 32 bit operands in 64-bit mode", op))),
(_, _) => panic!("bad formatting data"),
}
} else if data.flags.contains(Flags::AUTO_REXW) {
if op_size == Size::B_8 {
rex_w = true;
} else if op_size != Size::B_4 {
return Err(Some(format!("'{}': Does not support 16-bit operands", op.to_string())));
return Err(Some(format!("'{}': Does not support 16-bit operands", op)));
}
} else if data.flags.contains(Flags::AUTO_VEXL) {
if op_size == Size::B_32 {
Expand Down Expand Up @@ -241,7 +241,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a
// Certain SSE/AVX legacy encoded operations are not available in 32-bit mode
// as they require a REX.W prefix to be encoded, which is impossible. We catch those cases here
if ctx.mode == X86Mode::Protected {
return Err(Some(format!("'{}': Does not support 64 bit operand size in 32-bit mode", op.to_string())))
return Err(Some(format!("'{}': Does not support 64 bit operand size in 32-bit mode", op)))
}
compile_rex(buffer, rex_w, &reg, &rm);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a
};

// check addressing mode special cases
let mode_vsib = index.as_ref().map_or(false, |&(ref i, _, _)| i.kind.family() == RegFamily::XMM);
let mode_vsib = index.as_ref().map_or(false, |(i, _, _)| i.kind.family() == RegFamily::XMM);
let mode_16bit = addr_size == Size::B_2;
let mode_rip_relative = base.as_ref().map_or(false, |b| b.kind.family() == RegFamily::RIP);
let mode_rbp_base = base.as_ref().map_or(false, |b| b == &RegId::RBP || b == &RegId::R13 || b.kind.is_dynamic());
Expand Down Expand Up @@ -549,7 +549,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> {
let mut base_reg_index = None;
for (i, reg) in regs.iter().enumerate() {
if !(regs.iter().enumerate().any(|(j, other)| i != j && reg == other) ||
scaled.iter().any(|&(ref other, _)| reg == other)) {
scaled.iter().any(|(other, _)| reg == other)) {
base_reg_index = Some(i);
break;
}
Expand All @@ -561,7 +561,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> {
let mut joined_regs = Vec::new();
for (reg, s) in scaled {
// does this register already have a spot?
if let Some(i) = joined_regs.iter().position(|&(ref other, _)| &reg == other) {
if let Some(i) = joined_regs.iter().position(|(other, _)| &reg == other) {
joined_regs[i].1 += s;
} else {
joined_regs.push((reg, s));
Expand Down Expand Up @@ -626,7 +626,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> {
let mut joined_regs = Vec::new();
for (reg, s) in scaled {
// does this register already have a spot?
if let Some(i) = joined_regs.iter().position(|&(ref other, _)| &reg == other) {
if let Some(i) = joined_regs.iter().position(|(other, _)| &reg == other) {
joined_regs[i].1 += s;
} else {
joined_regs.push((reg, s));
Expand Down Expand Up @@ -1061,47 +1061,47 @@ fn match_format_string(ctx: &Context, fmt: &Opdata, args: &[CleanArg]) -> Result
(b'o', &CleanArg::JumpTarget{size, ..}) => size,

// specific legacy regs
(x @ b'A' ..= b'P', &CleanArg::Direct{ref reg, ..}) if
(x @ b'A' ..= b'P', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::LEGACY &&
reg.kind.code() == Some(x - b'A') => Some(reg.size()),

// specific segment regs
(x @ b'Q' ..= b'V', &CleanArg::Direct{ref reg, ..}) if
(x @ b'Q' ..= b'V', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::SEGMENT &&
reg.kind.code() == Some(x - b'Q') => Some(reg.size()),

// CR8 can be specially referenced
(b'W', &CleanArg::Direct{ref reg, ..}) if
(b'W', CleanArg::Direct{reg, ..}) if
reg.kind == RegId::CR8 => Some(reg.size()),

// top of the fp stack is also often used
(b'X', &CleanArg::Direct{ref reg, ..}) if
(b'X', CleanArg::Direct{reg, ..}) if
reg.kind == RegId::ST0 => Some(reg.size()),

// generic legacy regs
(b'r', &CleanArg::Direct{ref reg, ..}) |
(b'v', &CleanArg::Direct{ref reg, ..}) if
(b'r', CleanArg::Direct{reg, ..}) |
(b'v', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::LEGACY ||
reg.kind.family() == RegFamily::HIGHBYTE => Some(reg.size()),

// other reg types often mixed with memory refs
(b'x', &CleanArg::Direct{ref reg, ..}) |
(b'u', &CleanArg::Direct{ref reg, ..}) if
(b'x', CleanArg::Direct{reg, ..}) |
(b'u', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::MMX => Some(reg.size()),
(b'y', &CleanArg::Direct{ref reg, ..}) |
(b'w', &CleanArg::Direct{ref reg, ..}) if
(b'y', CleanArg::Direct{reg, ..}) |
(b'w', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::XMM => Some(reg.size()),

// other reg types
(b'f', &CleanArg::Direct{ref reg, ..}) if
(b'f', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::FP => Some(reg.size()),
(b's', &CleanArg::Direct{ref reg, ..}) if
(b's', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::SEGMENT => Some(reg.size()),
(b'c', &CleanArg::Direct{ref reg, ..}) if
(b'c', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::CONTROL => Some(reg.size()),
(b'd', &CleanArg::Direct{ref reg, ..}) if
(b'd', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::DEBUG => Some(reg.size()),
(b'b', &CleanArg::Direct{ref reg, ..}) if
(b'b', CleanArg::Direct{reg, ..}) if
reg.kind.family() == RegFamily::BOUND => Some(reg.size()),

// memory offsets
Expand Down Expand Up @@ -1178,7 +1178,7 @@ fn size_operands(fmt: &Opdata, args: Vec<CleanArg>) -> Result<(Option<Size>, Vec
let mut im_size = None;

// operand size determination loop
for (arg, (_, fsize)) in args.iter().zip(FormatStringIterator::new(&fmt.args)) {
for (arg, (_, fsize)) in args.iter().zip(FormatStringIterator::new(fmt.args)) {
if fsize != b'*' {
continue;
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ fn size_operands(fmt: &Opdata, args: Vec<CleanArg>) -> Result<(Option<Size>, Vec

// fill-in loop. default should never be used.
let mut new_args = Vec::new();
for (arg, (code, fsize)) in args.into_iter().zip(FormatStringIterator::new(&fmt.args)) {
for (arg, (code, fsize)) in args.into_iter().zip(FormatStringIterator::new(fmt.args)) {

//get the specified operand size from the format string
let size = match (fsize, code) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/arch/x64/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn format_opdata(name: &str, data: &Opdata) -> Vec<String> {
let mut first = true;
for (ty, size) in FormatStringIterator::new(data.args) {
if first {
buf.push_str(" ");
buf.push(' ');
first = false;
} else {
buf.push_str(", ");
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/arch/x64/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn parse_reg(ctx: &Context, expr: &syn::Expr) -> Option<(Span, Register)> {
return None;
}

let called = if let Some(called) = as_ident(&&*func) {
let called = if let Some(called) = as_ident(&*func) {
called
} else {
return None;
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn serialize(name: &TokenTree, stmts: Vec<Stmt>) -> TokenStream {
},
Size::B_8 => {
let mut buffer = [0u8; 8];
LittleEndian::write_u64(&mut buffer, value as u64);
LittleEndian::write_u64(&mut buffer, value);
const_buffer.extend(&buffer);
},
_ => unimplemented!()
Expand Down
10 changes: 5 additions & 5 deletions runtime/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl MemoryManager {

// copy over the data
new_buffer[.. old_asmoffset].copy_from_slice(&self.execbuffer.read().unwrap());
new_buffer[old_asmoffset..].copy_from_slice(&new);
new_buffer[old_asmoffset..].copy_from_slice(new);
let new_buffer_addr = new_buffer.as_ptr() as usize;

// allow modifications to be made
Expand All @@ -160,7 +160,7 @@ impl MemoryManager {

// update buffer and length
buffer.set_len(new_asmoffset);
buffer[old_asmoffset..].copy_from_slice(&new);
buffer[old_asmoffset..].copy_from_slice(new);

// ensure that no old data remains in the icache of what we just updated
cache_control::synchronize_icache(&buffer[old_asmoffset .. ]);
Expand Down Expand Up @@ -287,7 +287,7 @@ impl LabelRegistry {

/// Returns the offset at which the dynamic label `id` was defined, if one was defined.
pub fn resolve_dynamic(&self, id: DynamicLabel) -> Result<AssemblyOffset, DynasmError> {
self.dynamic_labels.get(id.0).and_then(|&e| e).ok_or_else(|| DynasmError::UnknownLabel(LabelKind::Dynamic(id)))
self.dynamic_labels.get(id.0).and_then(|&e| e).ok_or(DynasmError::UnknownLabel(LabelKind::Dynamic(id)))
}

/// Returns the offset at which the global label `label` was defined, if one was defined.
Expand Down Expand Up @@ -516,13 +516,13 @@ impl LitPool {

/// Add extra alignment for the next value in the literal pool
pub fn align(&mut self, size: usize, with: u8) {
let misalign = self.offset % (size as usize);
let misalign = self.offset % size;
if misalign == 0 {
return;
}

self.entries.push(LitPoolEntry::Align(with, size));
self.offset += size as usize - misalign;
self.offset += size - misalign;
}

/// Encode `value` into the literal pool.
Expand Down
Loading
Loading