@@ -60,6 +60,18 @@ pub fn llvm_pdbutil() -> LlvmPdbutil {
60
60
LlvmPdbutil :: new ( )
61
61
}
62
62
63
+ /// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
64
+ /// at `$LLVM_BIN_DIR/llvm-dis`.
65
+ pub fn llvm_dis ( ) -> LlvmDis {
66
+ LlvmDis :: new ( )
67
+ }
68
+
69
+ /// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
70
+ /// at `$LLVM_BIN_DIR/llvm-objcopy`.
71
+ pub fn llvm_objcopy ( ) -> LlvmObjcopy {
72
+ LlvmObjcopy :: new ( )
73
+ }
74
+
63
75
/// A `llvm-readobj` invocation builder.
64
76
#[ derive( Debug ) ]
65
77
#[ must_use]
@@ -123,6 +135,20 @@ pub struct LlvmPdbutil {
123
135
cmd : Command ,
124
136
}
125
137
138
+ /// A `llvm-dis` invocation builder.
139
+ #[ derive( Debug ) ]
140
+ #[ must_use]
141
+ pub struct LlvmDis {
142
+ cmd : Command ,
143
+ }
144
+
145
+ /// A `llvm-objcopy` invocation builder.
146
+ #[ derive( Debug ) ]
147
+ #[ must_use]
148
+ pub struct LlvmObjcopy {
149
+ cmd : Command ,
150
+ }
151
+
126
152
crate :: macros:: impl_common_helpers!( LlvmReadobj ) ;
127
153
crate :: macros:: impl_common_helpers!( LlvmProfdata ) ;
128
154
crate :: macros:: impl_common_helpers!( LlvmFilecheck ) ;
@@ -132,6 +158,8 @@ crate::macros::impl_common_helpers!(LlvmNm);
132
158
crate :: macros:: impl_common_helpers!( LlvmBcanalyzer ) ;
133
159
crate :: macros:: impl_common_helpers!( LlvmDwarfdump ) ;
134
160
crate :: macros:: impl_common_helpers!( LlvmPdbutil ) ;
161
+ crate :: macros:: impl_common_helpers!( LlvmDis ) ;
162
+ crate :: macros:: impl_common_helpers!( LlvmObjcopy ) ;
135
163
136
164
/// Generate the path to the bin directory of LLVM.
137
165
#[ must_use]
@@ -390,3 +418,41 @@ impl LlvmPdbutil {
390
418
self
391
419
}
392
420
}
421
+
422
+ impl LlvmObjcopy {
423
+ /// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
424
+ /// at `$LLVM_BIN_DIR/llvm-objcopy`.
425
+ pub fn new ( ) -> Self {
426
+ let llvm_objcopy = llvm_bin_dir ( ) . join ( "llvm-objcopy" ) ;
427
+ let cmd = Command :: new ( llvm_objcopy) ;
428
+ Self { cmd }
429
+ }
430
+
431
+ /// Dump the contents of `section` into the file at `path`.
432
+ #[ track_caller]
433
+ pub fn dump_section < S : AsRef < str > , P : AsRef < Path > > (
434
+ & mut self ,
435
+ section_name : S ,
436
+ path : P ,
437
+ ) -> & mut Self {
438
+ self . cmd . arg ( "--dump-section" ) ;
439
+ self . cmd . arg ( format ! ( "{}={}" , section_name. as_ref( ) , path. as_ref( ) . to_str( ) . unwrap( ) ) ) ;
440
+ self
441
+ }
442
+ }
443
+
444
+ impl LlvmDis {
445
+ /// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
446
+ /// at `$LLVM_BIN_DIR/llvm-dis`.
447
+ pub fn new ( ) -> Self {
448
+ let llvm_dis = llvm_bin_dir ( ) . join ( "llvm-dis" ) ;
449
+ let cmd = Command :: new ( llvm_dis) ;
450
+ Self { cmd }
451
+ }
452
+
453
+ /// Provide an input file.
454
+ pub fn input < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Self {
455
+ self . cmd . arg ( path. as_ref ( ) ) ;
456
+ self
457
+ }
458
+ }
0 commit comments