MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / extract_llfns

Function extract_llfns

xtask/src/extract_llfns.rs:24–64  ·  view source on GitHub ↗
(file: &Path, dir: &Path)

Source from the content-addressed store, hash-verified

22// ------------------------------------------------
23
24pub(crate) fn extract_llfns(file: &Path, dir: &Path) {
25 let contents = std::fs::read_to_string(file).unwrap();
26 let re = Regex::new(r#"define .*(_Z.*?)(\(|")"#).unwrap();
27 let names = re
28 .captures_iter(&contents)
29 .map(|x| x.get(1).unwrap().as_str())
30 .collect::<Vec<_>>();
31
32 let mut contents = names
33 .par_iter()
34 .filter_map(|name| {
35 let out_file = format!("{}/{}.ll", dir.display(), name);
36 let _ = Command::new("llvm-extract")
37 .arg(file)
38 .arg(&format!("--func={}", name))
39 .arg("-S")
40 .arg("--recursive")
41 .arg("-o")
42 .arg(&out_file)
43 .spawn();
44
45 let read = std::fs::read_to_string(format!("{}/{}.ll", dir.display(), name)).ok()?;
46 Some((name, read, true))
47 })
48 .collect::<Vec<_>>();
49
50 // sort things by length so that we try the shortest functions first.
51 contents.sort_by_key(|x| x.1.len());
52
53 for (name, content, failed) in &mut contents {
54 if PRINT_EVERY_EXECUTION {
55 println!("Running command over `{}.ll`", name);
56 }
57
58 *failed = !run_command_for_each_fn(name, content);
59 }
60
61 for (name, _, _) in contents.into_iter().filter(|x| !x.2).take(30) {
62 println!("Err: {}", name);
63 }
64}

Callers 1

mainFunction · 0.85

Calls 4

newFunction · 0.85
run_command_for_each_fnFunction · 0.85
getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected