1 Star 1 Fork 0

zer0_xx/cxx2flow

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.rs 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
mgt 提交于 2021-08-19 18:35 +08:00 . chore: bump version
#[macro_use]
extern crate clap;
mod ast;
mod dot;
mod graph;
mod parser;
fn main() -> anyhow::Result<()> {
let matches = clap_app!(cxx2flow =>
(version: "0.1.6")
(author: "mgt. <mgt@oi-wiki.org>")
(about: "Convert your C/C++ code to control flow chart")
(@arg OUTPUT: -o --output +takes_value "Sets the output file.
If not specified, result will be directed to stdout.
e.g. graph.dot")
(@arg curved: -c --curved "Sets the style of the flow chart.
If specified, output flow chart will have curved connection line.")
(@arg INPUT: +required "Sets the input file. e.g. test.cpp")
(@arg FUNCTION: "The function you want to convert. e.g. main")
)
.after_help("Note that you need to manually compile the dot file using graphviz to get SVG or PNG files.
EXAMPLES:
cxx2flow test.cpp | dot -Tpng -o test.png
cxx2flow main.cpp my_custom_func | dot -Tsvg -o test.svg")
.setting(clap::AppSettings::ColoredHelp)
.get_matches();
let path = matches.value_of("INPUT").unwrap();
let func = matches.value_of("FUNCTION").map(|x| x.to_string());
let output = matches.value_of("OUTPUT");
let curved = matches.is_present("curved");
let ast_vec = parser::parse(path, func)?;
let graph = graph::from_ast(ast_vec)?;
let dot = dot::from_graph(&graph, curved)?;
if let Some(output) = output {
std::fs::write(output, dot)?;
} else {
print!("{}", dot);
}
Ok(())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/zer0-xx/cxx2flow.git
git@gitee.com:zer0-xx/cxx2flow.git
zer0-xx
cxx2flow
cxx2flow
master

搜索帮助