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