rapx/cli/analyze.rs
1use clap::{Args, Subcommand, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Args)]
5pub struct AdgArgs {
6 #[arg(long)]
7 /// Include private APIs in the API graph. By default, only public APIs are included.
8 pub include_private: bool,
9 #[arg(long)]
10 /// Include unsafe APIs in API graph. By default, only safe APIs are included.
11 pub include_unsafe: bool,
12 /// Include Drop trait in API graph. By default, Drop is not included.
13 #[arg(long)]
14 pub include_drop: bool,
15 /// The maximum number of iterations to search for generic APIs.
16 #[arg(long, default_value_t = 10)]
17 pub max_iteration: usize,
18 /// The path to dump the API graph to. Output format is decided by extension suffix.
19 /// default PATH = `./api_graph.dot`.
20 #[arg(long, default_missing_value = "./api_graph.dot", value_name = "PATH")]
21 pub dump: Option<PathBuf>,
22}
23
24#[derive(Debug, Clone, Copy, ValueEnum)]
25pub enum AliasStrategyKind {
26 /// meet-over-paths (default)
27 Mop,
28 /// maximum-fixed-point
29 Mfp,
30}
31
32// use command string to automatically generate help messages
33#[derive(Debug, Clone, Subcommand)]
34pub enum AnalysisKind {
35 /// perform alias analysis (meet-over-paths by default)
36 Alias {
37 /// specify the alias analysis strategy
38 #[arg(short, long, default_value = "mop")]
39 strategy: AliasStrategyKind,
40 },
41 /// generate API dependency graphs
42 Adg(AdgArgs),
43 /// perform safety flow analysis (unsafety propagation graph)
44 #[clap(name = "safetyflow")]
45 SafetyFlow {
46 /// render safety flow graphs as PNG images (requires Graphviz)
47 #[arg(short, long)]
48 draw: bool,
49 },
50 /// perform safety flow analysis on the Rust standard library
51 #[clap(name = "safetyflowstd")]
52 SafetyFlowStd {
53 /// render safety flow graphs as PNG images (requires Graphviz)
54 #[arg(short, long)]
55 draw: bool,
56 },
57 /// generate callgraphs
58 Callgraph,
59 /// generate dataflow graphs
60 Dataflow {
61 /// print debug information during dataflow analysis
62 #[arg(short, long)]
63 debug: bool,
64 /// render dataflow graphs as PNG images (requires Graphviz)
65 #[arg(short, long)]
66 draw: bool,
67 },
68 /// analyze if the type holds a piece of memory on heap
69 #[clap(name = "ownedheap")]
70 OwnedHeap,
71 /// extract path-sensitive CFG paths
72 Paths {
73 /// allow repeated SCC postfix segments (default 0)
74 #[arg(long, default_value_t = 0)]
75 postfix_repeat: usize,
76 },
77 /// extract path constraints
78 Pathcond,
79 /// perform range analysis
80 Range {
81 /// print debug information during range analysis
82 #[arg(short, long)]
83 debug: bool,
84 },
85 /// print basic information of the crate, e.g., the number of APIs
86 Scan,
87 /// print the SSA form of the crate
88 Ssa,
89 /// print the MIR of the crate
90 Mir,
91 /// print the MIR of the crate in dot format
92 DotMir,
93}