run_make_support/external_deps/
llvm.rs1use std::path::{Path, PathBuf};
2
3use crate::command::Command;
4use crate::env::env_var;
5
6#[track_caller]
9pub fn llvm_readobj() -> LlvmReadobj {
10 LlvmReadobj::new()
11}
12
13#[track_caller]
16pub fn llvm_profdata() -> LlvmProfdata {
17 LlvmProfdata::new()
18}
19
20#[track_caller]
23pub fn llvm_filecheck() -> LlvmFilecheck {
24 LlvmFilecheck::new()
25}
26
27pub fn llvm_objdump() -> LlvmObjdump {
30 LlvmObjdump::new()
31}
32
33pub fn llvm_ar() -> LlvmAr {
36 LlvmAr::new()
37}
38
39pub fn llvm_nm() -> LlvmNm {
42 LlvmNm::new()
43}
44
45pub fn llvm_bcanalyzer() -> LlvmBcanalyzer {
48 LlvmBcanalyzer::new()
49}
50
51pub fn llvm_dwarfdump() -> LlvmDwarfdump {
54 LlvmDwarfdump::new()
55}
56
57pub fn llvm_pdbutil() -> LlvmPdbutil {
60 LlvmPdbutil::new()
61}
62
63pub fn llvm_as() -> LlvmAs {
66 LlvmAs::new()
67}
68
69pub fn llvm_dis() -> LlvmDis {
72 LlvmDis::new()
73}
74
75pub fn llvm_objcopy() -> LlvmObjcopy {
78 LlvmObjcopy::new()
79}
80
81#[derive(Debug)]
83#[must_use]
84pub struct LlvmReadobj {
85 cmd: Command,
86}
87
88#[derive(Debug)]
90#[must_use]
91pub struct LlvmProfdata {
92 cmd: Command,
93}
94
95#[derive(Debug)]
97#[must_use]
98pub struct LlvmFilecheck {
99 cmd: Command,
100}
101
102#[derive(Debug)]
104#[must_use]
105pub struct LlvmObjdump {
106 cmd: Command,
107}
108
109#[derive(Debug)]
111#[must_use]
112pub struct LlvmAr {
113 cmd: Command,
114}
115
116#[derive(Debug)]
118#[must_use]
119pub struct LlvmNm {
120 cmd: Command,
121}
122
123#[derive(Debug)]
125#[must_use]
126pub struct LlvmBcanalyzer {
127 cmd: Command,
128}
129
130#[derive(Debug)]
132#[must_use]
133pub struct LlvmDwarfdump {
134 cmd: Command,
135}
136
137#[derive(Debug)]
139#[must_use]
140pub struct LlvmPdbutil {
141 cmd: Command,
142}
143
144#[derive(Debug)]
146#[must_use]
147pub struct LlvmAs {
148 cmd: Command,
149}
150
151#[derive(Debug)]
153#[must_use]
154pub struct LlvmDis {
155 cmd: Command,
156}
157
158#[derive(Debug)]
160#[must_use]
161pub struct LlvmObjcopy {
162 cmd: Command,
163}
164
165crate::macros::impl_common_helpers!(LlvmReadobj);
166crate::macros::impl_common_helpers!(LlvmProfdata);
167crate::macros::impl_common_helpers!(LlvmFilecheck);
168crate::macros::impl_common_helpers!(LlvmObjdump);
169crate::macros::impl_common_helpers!(LlvmAr);
170crate::macros::impl_common_helpers!(LlvmNm);
171crate::macros::impl_common_helpers!(LlvmBcanalyzer);
172crate::macros::impl_common_helpers!(LlvmDwarfdump);
173crate::macros::impl_common_helpers!(LlvmPdbutil);
174crate::macros::impl_common_helpers!(LlvmAs);
175crate::macros::impl_common_helpers!(LlvmDis);
176crate::macros::impl_common_helpers!(LlvmObjcopy);
177
178#[must_use]
180pub fn llvm_bin_dir() -> PathBuf {
181 let llvm_bin_dir = env_var("LLVM_BIN_DIR");
182 PathBuf::from(llvm_bin_dir)
183}
184
185impl LlvmReadobj {
186 #[track_caller]
189 pub fn new() -> Self {
190 let llvm_readobj = llvm_bin_dir().join("llvm-readobj");
191 let cmd = Command::new(llvm_readobj);
192 let mut readobj = Self { cmd };
193 readobj.elf_output_style("GNU");
194 readobj
195 }
196
197 pub fn elf_output_style(&mut self, style: &str) -> &mut Self {
201 self.cmd.arg("--elf-output-style");
202 self.cmd.arg(style);
203 self
204 }
205
206 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
208 self.cmd.arg(path.as_ref());
209 self
210 }
211
212 pub fn file_header(&mut self) -> &mut Self {
214 self.cmd.arg("--file-header");
215 self
216 }
217
218 pub fn program_headers(&mut self) -> &mut Self {
220 self.cmd.arg("--program-headers");
221 self
222 }
223
224 pub fn symbols(&mut self) -> &mut Self {
227 self.cmd.arg("--symbols");
228 self
229 }
230
231 pub fn dynamic_table(&mut self) -> &mut Self {
233 self.cmd.arg("--dynamic-table");
234 self
235 }
236
237 pub fn section(&mut self, section: &str) -> &mut Self {
239 self.cmd.arg("--string-dump");
240 self.cmd.arg(section);
241 self
242 }
243}
244
245impl LlvmProfdata {
246 #[track_caller]
249 pub fn new() -> Self {
250 let llvm_profdata = llvm_bin_dir().join("llvm-profdata");
251 let cmd = Command::new(llvm_profdata);
252 Self { cmd }
253 }
254
255 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
257 self.cmd.arg(path.as_ref());
258 self
259 }
260
261 pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
263 self.cmd.arg("-o");
264 self.cmd.arg(path.as_ref());
265 self
266 }
267
268 pub fn merge(&mut self) -> &mut Self {
271 self.cmd.arg("merge");
272 self
273 }
274}
275
276impl LlvmFilecheck {
277 #[track_caller]
280 pub fn new() -> Self {
281 let llvm_filecheck = env_var("LLVM_FILECHECK");
282 let cmd = Command::new(llvm_filecheck);
283 Self { cmd }
284 }
285
286 pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
289 self.cmd.stdin_buf(input);
290 self
291 }
292
293 pub fn patterns<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
295 self.cmd.arg(path.as_ref());
296 self
297 }
298
299 pub fn input_file<P: AsRef<Path>>(&mut self, input_file: P) -> &mut Self {
301 self.cmd.arg("--input-file");
302 self.cmd.arg(input_file.as_ref());
303 self
304 }
305
306 pub fn check_prefix<S: AsRef<str>>(&mut self, prefix: S) -> &mut Self {
308 self.cmd.arg(format!("--check-prefix={}", prefix.as_ref()));
309 self
310 }
311}
312
313impl LlvmObjdump {
314 pub fn new() -> Self {
317 let llvm_objdump = llvm_bin_dir().join("llvm-objdump");
318 let cmd = Command::new(llvm_objdump);
319 Self { cmd }
320 }
321
322 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
324 self.cmd.arg(path.as_ref());
325 self
326 }
327
328 pub fn disassemble(&mut self) -> &mut Self {
330 self.cmd.arg("-d");
331 self
332 }
333
334 pub fn demangle(&mut self) -> &mut Self {
336 self.cmd.arg("--demangle");
337 self
338 }
339}
340
341impl LlvmAr {
342 pub fn new() -> Self {
345 let llvm_ar = llvm_bin_dir().join("llvm-ar");
346 let cmd = Command::new(llvm_ar);
347 Self { cmd }
348 }
349
350 pub fn obj_to_ar(&mut self) -> &mut Self {
353 self.cmd.arg("rcus");
354 self
355 }
356
357 pub fn obj_to_thin_ar(&mut self) -> &mut Self {
359 self.cmd.arg("rcus").arg("--thin");
360 self
361 }
362
363 pub fn extract(&mut self) -> &mut Self {
365 self.cmd.arg("x");
366 self
367 }
368
369 pub fn table_of_contents(&mut self) -> &mut Self {
371 self.cmd.arg("t");
372 self
373 }
374
375 pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
378 self.cmd.arg(out.as_ref());
379 self.cmd.arg(input.as_ref());
380 self
381 }
382}
383
384impl LlvmNm {
385 pub fn new() -> Self {
388 let llvm_nm = llvm_bin_dir().join("llvm-nm");
389 let cmd = Command::new(llvm_nm);
390 Self { cmd }
391 }
392
393 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
395 self.cmd.arg(path.as_ref());
396 self
397 }
398}
399
400impl LlvmBcanalyzer {
401 pub fn new() -> Self {
404 let llvm_bcanalyzer = llvm_bin_dir().join("llvm-bcanalyzer");
405 let cmd = Command::new(llvm_bcanalyzer);
406 Self { cmd }
407 }
408
409 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
411 self.cmd.arg(path.as_ref());
412 self
413 }
414}
415
416impl LlvmDwarfdump {
417 pub fn new() -> Self {
420 let llvm_dwarfdump = llvm_bin_dir().join("llvm-dwarfdump");
421 let cmd = Command::new(llvm_dwarfdump);
422 Self { cmd }
423 }
424
425 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
427 self.cmd.arg(path.as_ref());
428 self
429 }
430}
431
432impl LlvmPdbutil {
433 pub fn new() -> Self {
436 let llvm_pdbutil = llvm_bin_dir().join("llvm-pdbutil");
437 let cmd = Command::new(llvm_pdbutil);
438 Self { cmd }
439 }
440
441 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
443 self.cmd.arg(path.as_ref());
444 self
445 }
446}
447
448impl LlvmObjcopy {
449 pub fn new() -> Self {
452 let llvm_objcopy = llvm_bin_dir().join("llvm-objcopy");
453 let cmd = Command::new(llvm_objcopy);
454 Self { cmd }
455 }
456
457 #[track_caller]
459 pub fn dump_section<S: AsRef<str>, P: AsRef<Path>>(
460 &mut self,
461 section_name: S,
462 path: P,
463 ) -> &mut Self {
464 self.cmd.arg("--dump-section");
465 self.cmd.arg(format!("{}={}", section_name.as_ref(), path.as_ref().to_str().unwrap()));
466 self
467 }
468}
469
470impl LlvmAs {
471 pub fn new() -> Self {
474 let llvm_as = llvm_bin_dir().join("llvm-as");
475 let cmd = Command::new(llvm_as);
476 Self { cmd }
477 }
478
479 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
481 self.cmd.arg(path.as_ref());
482 self
483 }
484}
485
486impl LlvmDis {
487 pub fn new() -> Self {
490 let llvm_dis = llvm_bin_dir().join("llvm-dis");
491 let cmd = Command::new(llvm_dis);
492 Self { cmd }
493 }
494
495 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
497 self.cmd.arg(path.as_ref());
498 self
499 }
500}