use structopt::StructOpt;
#[derive(Clone, Debug)]
#[derive(StructOpt)]
#[structopt(about = "\n`twiggy` is a code size profiler.\n\nIt analyzes a binary's call graph to answer questions like:\n\n* Why was this function included in the binary in the first place?\n\n* What is the retained size of this function? I.e. how much space\n would be saved if I removed it and all the functions that become\n dead code after its removal.\n\nUse `twiggy` to make your binaries slim!")]
pub enum Options {
#[structopt(name = "top")]
Top(Top),
#[structopt(name = "dominators")]
Dominators(Dominators),
#[structopt(name = "paths")]
Paths(Paths),
#[structopt(name = "monos")]
Monos(Monos),
#[structopt(name = "diff")]
Diff(Diff),
#[structopt(name = "garbage")]
Garbage(Garbage),
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(StructOpt)]
pub struct Top {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
#[structopt(short = "n", default_value = "4294967295")]
max_items: u32,
#[structopt(short = "r", long = "retaining-paths")]
retaining_paths: bool,
#[structopt(long = "retained")]
retained: bool,
}
impl Default for Top {
fn default() -> Top {
Top {
#[cfg(feature = "cli")]
input: Default::default(),
#[cfg(feature = "cli")]
parse_mode: Default::default(),
#[cfg(feature = "cli")]
output_destination: Default::default(),
#[cfg(feature = "cli")]
output_format: Default::default(),
max_items: 4_294_967_295,
retaining_paths: false,
retained: false,
}
}
}
#[wasm_bindgen]
impl Top {
pub fn new() -> Top {
Top::default()
}
pub fn max_items(&self) -> u32 {
self.max_items
}
pub fn retaining_paths(&self) -> bool {
self.retaining_paths
}
pub fn retained(&self) -> bool {
self.retained
}
pub fn set_max_items(&mut self, n: u32) {
self.max_items = n;
}
pub fn set_retaining_paths(&mut self, do_it: bool) {
self.retaining_paths = do_it;
}
pub fn set_retained(&mut self, do_it: bool) {
self.retained = do_it;
}
}
#[wasm_bindgen]
#[derive(Clone, Debug, Default)]
#[derive(StructOpt)]
pub struct Dominators {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
items: Vec<String>,
#[structopt(short = "d")]
max_depth: Option<u32>,
#[structopt(short = "r")]
max_rows: Option<u32>,
#[structopt(long = "regex")]
using_regexps: bool,
}
impl Dominators {
pub fn items(&self) -> &[String] {
&self.items
}
}
#[wasm_bindgen]
impl Dominators {
pub fn new() -> Dominators {
Dominators::default()
}
pub fn max_depth(&self) -> u32 {
self.max_depth.unwrap_or(u32::MAX)
}
pub fn max_rows(&self) -> u32 {
self.max_rows.unwrap_or(u32::MAX)
}
pub fn using_regexps(&self) -> bool {
self.using_regexps
}
pub fn set_max_depth(&mut self, max_depth: u32) {
self.max_depth = Some(max_depth);
}
pub fn set_max_rows(&mut self, max_rows: u32) {
self.max_rows = Some(max_rows);
}
pub fn set_using_regexps(&mut self, using_regexps: bool) {
self.using_regexps = using_regexps;
}
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(StructOpt)]
pub struct Paths {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
functions: Vec<String>,
#[structopt(short = "d", default_value = "10")]
max_depth: u32,
#[structopt(short = "r", default_value = "10")]
max_paths: u32,
#[structopt(long = "descending")]
descending: bool,
#[structopt(long = "regex")]
using_regexps: bool,
}
impl Default for Paths {
fn default() -> Paths {
Paths {
#[cfg(feature = "cli")]
input: Default::default(),
#[cfg(feature = "cli")]
parse_mode: Default::default(),
#[cfg(feature = "cli")]
output_destination: Default::default(),
#[cfg(feature = "cli")]
output_format: Default::default(),
functions: Default::default(),
max_depth: 10,
max_paths: 10,
descending: false,
using_regexps: false,
}
}
}
impl Paths {
pub fn functions(&self) -> &[String] {
&self.functions
}
}
#[wasm_bindgen]
impl Paths {
pub fn new() -> Paths {
Paths::default()
}
pub fn add_function(&mut self, function: String) {
self.functions.push(function);
}
pub fn max_depth(&self) -> u32 {
self.max_depth
}
pub fn max_paths(&self) -> u32 {
self.max_paths
}
pub fn descending(&self) -> bool {
self.descending
}
pub fn using_regexps(&self) -> bool {
self.using_regexps
}
pub fn set_max_depth(&mut self, max_depth: u32) {
self.max_depth = max_depth;
}
pub fn set_max_paths(&mut self, max_paths: u32) {
self.max_paths = max_paths;
}
pub fn set_descending(&mut self, descending: bool) {
self.descending = descending;
}
pub fn set_using_regexps(&mut self, using_regexps: bool) {
self.using_regexps = using_regexps;
}
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(StructOpt)]
pub struct Monos {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
input: path::PathBuf,
functions: Vec<String>,
#[cfg(feature = "cli")]
#[structopt(short = "d", long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
#[structopt(short = "g", long = "only-generics")]
only_generics: bool,
#[structopt(short = "m", long = "max-generics", default_value = "10")]
max_generics: u32,
#[structopt(short = "n", long = "max-monos", default_value = "10")]
max_monos: u32,
#[structopt(short = "a", long = "all")]
all_generics_and_monos: bool,
#[structopt(long = "all-generics")]
all_generics: bool,
#[structopt(long = "all-monos")]
all_monos: bool,
#[structopt(long = "regex")]
using_regexps: bool,
}
impl Default for Monos {
fn default() -> Monos {
Monos {
#[cfg(feature = "cli")]
input: Default::default(),
#[cfg(feature = "cli")]
parse_mode: Default::default(),
#[cfg(feature = "cli")]
output_destination: Default::default(),
#[cfg(feature = "cli")]
output_format: Default::default(),
functions: Default::default(),
only_generics: false,
max_generics: 10,
max_monos: 10,
all_generics_and_monos: false,
all_generics: false,
all_monos: false,
using_regexps: false,
}
}
}
impl Monos {
pub fn functions(&self) -> &[String] {
&self.functions
}
}
#[wasm_bindgen]
impl Monos {
pub fn new() -> Monos {
Monos::default()
}
pub fn only_generics(&self) -> bool {
self.only_generics
}
pub fn max_generics(&self) -> u32 {
if self.all_generics_and_monos || self.all_generics {
u32::MAX
} else {
self.max_generics
}
}
pub fn max_monos(&self) -> u32 {
if self.all_generics_and_monos || self.all_monos {
u32::MAX
} else {
self.max_monos
}
}
pub fn using_regexps(&self) -> bool {
self.using_regexps
}
pub fn set_only_generics(&mut self, do_it: bool) {
self.only_generics = do_it;
}
pub fn set_max_generics(&mut self, max: u32) {
self.max_generics = max;
self.all_generics = false;
if self.all_generics_and_monos {
self.all_generics_and_monos = false;
self.all_monos = true;
}
}
pub fn set_max_monos(&mut self, max: u32) {
self.max_monos = max;
self.all_monos = false;
if self.all_generics_and_monos {
self.all_generics_and_monos = false;
self.all_generics = true;
}
}
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(StructOpt)]
pub struct Diff {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
old_input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
new_input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
items: Vec<String>,
#[structopt(short = "n", default_value = "20")]
max_items: u32,
#[structopt(long = "regex")]
using_regexps: bool,
#[structopt(short = "a", long = "all")]
all_items: bool,
}
impl Default for Diff {
fn default() -> Diff {
Diff {
#[cfg(feature = "cli")]
old_input: Default::default(),
#[cfg(feature = "cli")]
parse_mode: Default::default(),
#[cfg(feature = "cli")]
new_input: Default::default(),
#[cfg(feature = "cli")]
output_destination: Default::default(),
#[cfg(feature = "cli")]
output_format: Default::default(),
items: Default::default(),
max_items: 20,
using_regexps: false,
all_items: false,
}
}
}
impl Diff {
pub fn items(&self) -> &[String] {
&self.items
}
}
#[wasm_bindgen]
impl Diff {
pub fn max_items(&self) -> u32 {
if self.all_items {
u32::MAX
} else {
self.max_items
}
}
pub fn using_regexps(&self) -> bool {
self.using_regexps
}
pub fn set_max_items(&mut self, n: u32) {
self.max_items = n;
self.all_items = false;
}
pub fn set_using_regexps(&mut self, using_regexps: bool) {
self.using_regexps = using_regexps;
}
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(StructOpt)]
pub struct Garbage {
#[cfg(feature = "cli")]
#[structopt(parse(from_os_str))]
input: path::PathBuf,
#[cfg(feature = "cli")]
#[structopt(long = "mode", default_value = "auto")]
parse_mode: traits::ParseMode,
#[cfg(feature = "cli")]
#[structopt(short = "o", default_value = "-")]
output_destination: OutputDestination,
#[cfg(feature = "cli")]
#[structopt(short = "f", long = "format", default_value = "text")]
output_format: traits::OutputFormat,
#[structopt(short = "n", default_value = "10")]
max_items: u32,
#[structopt(short = "a", long = "all")]
all_items: bool,
#[structopt(long = "show-data-segments")]
show_data_segments: bool,
}
impl Default for Garbage {
fn default() -> Garbage {
Garbage {
#[cfg(feature = "cli")]
input: Default::default(),
#[cfg(feature = "cli")]
parse_mode: Default::default(),
#[cfg(feature = "cli")]
output_destination: Default::default(),
#[cfg(feature = "cli")]
output_format: Default::default(),
max_items: 10,
all_items: false,
show_data_segments: false,
}
}
}
#[wasm_bindgen]
impl Garbage {
pub fn new() -> Garbage {
Garbage::default()
}
pub fn max_items(&self) -> u32 {
if self.all_items {
u32::MAX
} else {
self.max_items
}
}
pub fn set_max_items(&mut self, max: u32) {
self.max_items = max;
self.all_items = false;
}
pub fn show_data_segments(&self) -> bool {
self.show_data_segments
}
}