Skip to content

Commit e997eb1

Browse files
committed
Add an option to emit our ir for debugging
Similar to our ability to emit the clang AST, this adds an option to emit our IR for debugging purposes.
1 parent 6e78bb8 commit e997eb1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/bin/options.rs

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub fn builder_from_flags<I>(args: I)
5555
Arg::with_name("emit-clang-ast")
5656
.long("emit-clang-ast")
5757
.help("Output the Clang AST for debugging purposes."),
58+
Arg::with_name("emit-ir")
59+
.long("emit-ir")
60+
.help("Output our internal IR for debugging purposes."),
5861
Arg::with_name("enable-cxx-namespaces")
5962
.long("enable-cxx-namespaces")
6063
.help("Enable support for C++ namespaces."),
@@ -186,6 +189,10 @@ pub fn builder_from_flags<I>(args: I)
186189
builder = builder.emit_clang_ast();
187190
}
188191

192+
if matches.is_present("emit-ir") {
193+
builder = builder.emit_ir();
194+
}
195+
189196
if matches.is_present("enable-cxx-namespaces") {
190197
builder = builder.enable_cxx_namespaces();
191198
}

src/codegen/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,13 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> {
18921892

18931893
let whitelisted_items: ItemSet = context.whitelisted_items().collect();
18941894

1895+
if context.options().emit_ir {
1896+
for &id in whitelisted_items.iter() {
1897+
let item = context.resolve_item(id);
1898+
println!("ir: {:?} = {:#?}", id, item);
1899+
}
1900+
}
1901+
18951902
for &id in whitelisted_items.iter() {
18961903
let item = context.resolve_item(id);
18971904

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ impl Builder {
228228
self
229229
}
230230

231+
/// Emit IR.
232+
pub fn emit_ir(mut self) -> Builder {
233+
self.options.emit_ir = true;
234+
self
235+
}
236+
231237
/// Enable C++ namespaces.
232238
pub fn enable_cxx_namespaces(mut self) -> Builder {
233239
self.options.enable_cxx_namespaces = true;
@@ -317,6 +323,9 @@ pub struct BindgenOptions {
317323
/// True if we should dump the Clang AST for debugging purposes.
318324
pub emit_ast: bool,
319325

326+
/// True if we should dump our internal IR for debugging purposes.
327+
pub emit_ir: bool,
328+
320329
/// True if we should ignore functions and only generate bindings for
321330
/// structures, types, and methods.
322331
pub ignore_functions: bool,
@@ -383,6 +392,7 @@ impl Default for BindgenOptions {
383392
builtins: false,
384393
links: vec![],
385394
emit_ast: false,
395+
emit_ir: false,
386396
ignore_functions: false,
387397
ignore_methods: false,
388398
derive_debug: true,

0 commit comments

Comments
 (0)