Use clippy (#276)
* cton-util: fix some clippy unnecessary pass-by-value warnings * clippy: ignore too many arguments / cyclomatic complexity in module since these functions are taking args coming from the command line, i dont think this is actually a valid lint, morally the arguments are all from one structure * cton-util: take care of remaining clippy warnings * cton-reader: fix all non-suspicious clippy warnings * cton-reader: disable clippy at site of suspicious lint * cton-frontend: disable clippy at the site of an invalid lint * cton-frontend: fix clippy warnings, or ignore benign ones * clippy: ignore the camelcase word WebAssembly in docs * cton-wasm: fix clippy complaints or ignore benign ones * cton-wasm tests: fix clippy complaints * cretonne: starting point turns off all clippy warnings * cretonne: clippy fixes, or lower allow() to source of problem * cretonne: more clippy fixes * cretonne: fix or disable needless_lifetimes lint this linter is buggy when the declared lifetime is used for another type constraint. * cretonne: fix clippy complaint about Pass::NoPass * rustfmt * fix prev minor api changes clippy suggested * add clippy to test-all * cton-filetests: clippy fixes * simplify clippy reporting in test-all * cretonne: document clippy allows better * cretonne: fix some more clippy lints * cretonne: fix clippy lints (mostly doc comments) * cretonne: allow all needless_lifetimes clippy warnings remove overrides at the false positives * rustfmt
This commit is contained in:
@@ -7,7 +7,7 @@ use cton_reader::parse_functions;
|
||||
use CommandResult;
|
||||
use utils::read_to_string;
|
||||
|
||||
pub fn run(files: Vec<String>) -> CommandResult {
|
||||
pub fn run(files: &[String]) -> CommandResult {
|
||||
for (i, f) in files.into_iter().enumerate() {
|
||||
if i != 0 {
|
||||
println!();
|
||||
@@ -17,7 +17,7 @@ pub fn run(files: Vec<String>) -> CommandResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cat_one(filename: String) -> CommandResult {
|
||||
fn cat_one(filename: &str) -> CommandResult {
|
||||
let buffer = read_to_string(&filename).map_err(
|
||||
|e| format!("{}: {}", filename, e),
|
||||
)?;
|
||||
|
||||
@@ -49,23 +49,23 @@ impl binemit::RelocSink for PrintRelocs {
|
||||
pub fn run(
|
||||
files: Vec<String>,
|
||||
flag_print: bool,
|
||||
flag_set: Vec<String>,
|
||||
flag_isa: String,
|
||||
flag_set: &[String],
|
||||
flag_isa: &str,
|
||||
) -> Result<(), String> {
|
||||
let parsed = parse_sets_and_isa(flag_set, flag_isa)?;
|
||||
|
||||
for filename in files {
|
||||
let path = Path::new(&filename);
|
||||
let name = String::from(path.as_os_str().to_string_lossy());
|
||||
handle_module(flag_print, path.to_path_buf(), name, parsed.as_fisa())?;
|
||||
handle_module(flag_print, &path.to_path_buf(), &name, parsed.as_fisa())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_module(
|
||||
flag_print: bool,
|
||||
path: PathBuf,
|
||||
name: String,
|
||||
path: &PathBuf,
|
||||
name: &str,
|
||||
fisa: FlagsOrIsa,
|
||||
) -> Result<(), String> {
|
||||
let buffer = read_to_string(&path).map_err(
|
||||
|
||||
@@ -86,15 +86,20 @@ fn cton_util() -> CommandResult {
|
||||
|
||||
// Find the sub-command to execute.
|
||||
let result = if args.cmd_test {
|
||||
cton_filetests::run(args.flag_verbose, args.arg_file).map(|_time| ())
|
||||
cton_filetests::run(args.flag_verbose, &args.arg_file).map(|_time| ())
|
||||
} else if args.cmd_cat {
|
||||
cat::run(args.arg_file)
|
||||
cat::run(&args.arg_file)
|
||||
} else if args.cmd_filecheck {
|
||||
rsfilecheck::run(args.arg_file, args.flag_verbose)
|
||||
rsfilecheck::run(&args.arg_file, args.flag_verbose)
|
||||
} else if args.cmd_print_cfg {
|
||||
print_cfg::run(args.arg_file)
|
||||
print_cfg::run(&args.arg_file)
|
||||
} else if args.cmd_compile {
|
||||
compile::run(args.arg_file, args.flag_print, args.flag_set, args.flag_isa)
|
||||
compile::run(
|
||||
args.arg_file,
|
||||
args.flag_print,
|
||||
&args.flag_set,
|
||||
&args.flag_isa,
|
||||
)
|
||||
} else if args.cmd_wasm {
|
||||
wasm::run(
|
||||
args.arg_file,
|
||||
@@ -102,8 +107,8 @@ fn cton_util() -> CommandResult {
|
||||
args.flag_just_decode,
|
||||
args.flag_check_translation,
|
||||
args.flag_print,
|
||||
args.flag_set,
|
||||
args.flag_isa,
|
||||
&args.flag_set,
|
||||
&args.flag_isa,
|
||||
args.flag_print_size,
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@ use cretonne::cfg_printer::CFGPrinter;
|
||||
use cton_reader::parse_functions;
|
||||
use utils::read_to_string;
|
||||
|
||||
pub fn run(files: Vec<String>) -> CommandResult {
|
||||
pub fn run(files: &[String]) -> CommandResult {
|
||||
for (i, f) in files.into_iter().enumerate() {
|
||||
if i != 0 {
|
||||
println!();
|
||||
@@ -18,8 +18,8 @@ pub fn run(files: Vec<String>) -> CommandResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_cfg(filename: String) -> CommandResult {
|
||||
let buffer = read_to_string(&filename).map_err(
|
||||
fn print_cfg(filename: &str) -> CommandResult {
|
||||
let buffer = read_to_string(filename).map_err(
|
||||
|e| format!("{}: {}", filename, e),
|
||||
)?;
|
||||
let items = parse_functions(&buffer).map_err(
|
||||
|
||||
@@ -7,7 +7,7 @@ use utils::read_to_string;
|
||||
use filecheck::{CheckerBuilder, Checker, NO_VARIABLES};
|
||||
use std::io::{self, Read};
|
||||
|
||||
pub fn run(files: Vec<String>, verbose: bool) -> CommandResult {
|
||||
pub fn run(files: &[String], verbose: bool) -> CommandResult {
|
||||
if files.is_empty() {
|
||||
return Err("No check files".to_string());
|
||||
}
|
||||
|
||||
@@ -41,10 +41,7 @@ impl OwnedFlagsOrIsa {
|
||||
}
|
||||
|
||||
/// Parse "set" and "isa" commands.
|
||||
pub fn parse_sets_and_isa(
|
||||
flag_set: Vec<String>,
|
||||
flag_isa: String,
|
||||
) -> Result<OwnedFlagsOrIsa, String> {
|
||||
pub fn parse_sets_and_isa(flag_set: &[String], flag_isa: &str) -> Result<OwnedFlagsOrIsa, String> {
|
||||
let mut flag_builder = settings::builder();
|
||||
parse_options(
|
||||
flag_set.iter().map(|x| x.as_str()),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! CLI tool to use the functions provided by the [cretonne-wasm](../cton_wasm/index.html) crate.
|
||||
//!
|
||||
//! Reads Wasm binary files, translates the functions' code to Cretonne IL.
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, cyclomatic_complexity))]
|
||||
|
||||
use cton_wasm::{translate_module, DummyEnvironment, ModuleEnvironment};
|
||||
use std::path::PathBuf;
|
||||
@@ -38,8 +39,8 @@ pub fn run(
|
||||
flag_just_decode: bool,
|
||||
flag_check_translation: bool,
|
||||
flag_print: bool,
|
||||
flag_set: Vec<String>,
|
||||
flag_isa: String,
|
||||
flag_set: &[String],
|
||||
flag_isa: &str,
|
||||
flag_print_size: bool,
|
||||
) -> Result<(), String> {
|
||||
let parsed = parse_sets_and_isa(flag_set, flag_isa)?;
|
||||
@@ -53,8 +54,8 @@ pub fn run(
|
||||
flag_check_translation,
|
||||
flag_print,
|
||||
flag_print_size,
|
||||
path.to_path_buf(),
|
||||
name,
|
||||
&path.to_path_buf(),
|
||||
&name,
|
||||
parsed.as_fisa(),
|
||||
)?;
|
||||
}
|
||||
@@ -67,8 +68,8 @@ fn handle_module(
|
||||
flag_check_translation: bool,
|
||||
flag_print: bool,
|
||||
flag_print_size: bool,
|
||||
path: PathBuf,
|
||||
name: String,
|
||||
path: &PathBuf,
|
||||
name: &str,
|
||||
fisa: FlagsOrIsa,
|
||||
) -> Result<(), String> {
|
||||
let mut terminal = term::stdout().unwrap();
|
||||
@@ -153,29 +154,27 @@ fn handle_module(
|
||||
context.func = func.clone();
|
||||
if flag_check_translation {
|
||||
context.verify(fisa).map_err(|err| {
|
||||
pretty_verifier_error(&context.func, fisa.isa, err)
|
||||
pretty_verifier_error(&context.func, fisa.isa, &err)
|
||||
})?;
|
||||
} else {
|
||||
if let Some(isa) = fisa.isa {
|
||||
let compiled_size = context.compile(isa).map_err(|err| {
|
||||
pretty_error(&context.func, fisa.isa, err)
|
||||
})?;
|
||||
if flag_print_size {
|
||||
println!(
|
||||
"Function #{} code size: {} bytes",
|
||||
func_index,
|
||||
compiled_size
|
||||
);
|
||||
total_module_code_size += compiled_size;
|
||||
println!(
|
||||
"Function #{} bytecode size: {} bytes",
|
||||
func_index,
|
||||
dummy_environ.func_bytecode_sizes[func_index]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Err(String::from("compilation requires a target isa"));
|
||||
} else if let Some(isa) = fisa.isa {
|
||||
let compiled_size = context.compile(isa).map_err(|err| {
|
||||
pretty_error(&context.func, fisa.isa, err)
|
||||
})?;
|
||||
if flag_print_size {
|
||||
println!(
|
||||
"Function #{} code size: {} bytes",
|
||||
func_index,
|
||||
compiled_size
|
||||
);
|
||||
total_module_code_size += compiled_size;
|
||||
println!(
|
||||
"Function #{} bytecode size: {} bytes",
|
||||
func_index,
|
||||
dummy_environ.func_bytecode_sizes[func_index]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Err(String::from("compilation requires a target isa"));
|
||||
}
|
||||
if flag_print {
|
||||
vprintln!(flag_verbose, "");
|
||||
@@ -194,10 +193,7 @@ fn handle_module(
|
||||
|
||||
if !flag_check_translation && flag_print_size {
|
||||
println!("Total module code size: {} bytes", total_module_code_size);
|
||||
let total_bytecode_size = dummy_environ.func_bytecode_sizes.iter().fold(
|
||||
0,
|
||||
|sum, x| sum + x,
|
||||
);
|
||||
let total_bytecode_size: usize = dummy_environ.func_bytecode_sizes.iter().sum();
|
||||
println!("Total module bytecode size: {} bytes", total_bytecode_size);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user