Skip to content

Commit cb7d881

Browse files
authored
Use a clap helper to reduce parsing in objdump (#10440)
TIL about `ValueEnum`.
1 parent 5b07689 commit cb7d881

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/commands/objdump.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use pulley_interpreter::disas::Disassembler;
1212
use std::io::{IsTerminal, Read, Write};
1313
use std::iter::{self, Peekable};
1414
use std::path::{Path, PathBuf};
15-
use std::str::FromStr;
1615
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
1716
use wasmtime::Engine;
1817
use wasmtime_environ::{obj, FilePos, StackMap, Trap};
@@ -35,8 +34,8 @@ pub struct ObjdumpCommand {
3534
#[arg(long)]
3635
address_jumps: bool,
3736

38-
/// What functions should be printed (all|wasm|trampoline|builtin|libcall, default: wasm)
39-
#[arg(long, value_parser = Func::from_str, value_name = "KIND")]
37+
/// What functions should be printed
38+
#[arg(long, default_value = "wasm", value_name = "KIND")]
4039
funcs: Vec<Func>,
4140

4241
/// String filter to apply to function names to only print some functions.
@@ -481,7 +480,7 @@ struct Inst {
481480
bytes: Vec<u8>,
482481
}
483482

484-
#[derive(Clone, Copy, PartialEq, Eq)]
483+
#[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq)]
485484
enum Func {
486485
All,
487486
Wasm,
@@ -490,26 +489,6 @@ enum Func {
490489
Libcall,
491490
}
492491

493-
impl FromStr for Func {
494-
type Err = anyhow::Error;
495-
496-
fn from_str(s: &str) -> Result<Func> {
497-
Ok(match s {
498-
"all" => Func::All,
499-
"wasm" => Func::Wasm,
500-
"trampoline" => Func::Trampoline,
501-
"builtin" => Func::Builtin,
502-
"libcall" => Func::Libcall,
503-
other => {
504-
bail!(
505-
"unknown function kind `{other}`, \
506-
must be [all|wasm|trampoline|builtin|libcall]"
507-
)
508-
}
509-
})
510-
}
511-
}
512-
513492
struct Decorator<'a> {
514493
objdump: &'a ObjdumpCommand,
515494
addrmap: Option<Peekable<Box<dyn Iterator<Item = (u32, FilePos)> + 'a>>>,

0 commit comments

Comments
 (0)