Skip to content

Commit f00ce43

Browse files
author
bors-servo
authored
Auto merge of #264 - fitzgen:emit-ir, r=emilio
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. This can wait to land until after #204 is merged. r? @emilio
2 parents 09dc05c + 3bb07b6 commit f00ce43

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

libbindgen/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

libbindgen/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ impl Builder {
225225
self
226226
}
227227

228+
/// Emit IR.
229+
pub fn emit_ir(mut self) -> Builder {
230+
self.options.emit_ir = true;
231+
self
232+
}
233+
228234
/// Enable C++ namespaces.
229235
pub fn enable_cxx_namespaces(mut self) -> Builder {
230236
self.options.enable_cxx_namespaces = true;
@@ -314,6 +320,9 @@ pub struct BindgenOptions {
314320
/// True if we should dump the Clang AST for debugging purposes.
315321
pub emit_ast: bool,
316322

323+
/// True if we should dump our internal IR for debugging purposes.
324+
pub emit_ir: bool,
325+
317326
/// True if we should ignore functions and only generate bindings for
318327
/// structures, types, and methods.
319328
pub ignore_functions: bool,
@@ -380,6 +389,7 @@ impl Default for BindgenOptions {
380389
builtins: false,
381390
links: vec![],
382391
emit_ast: false,
392+
emit_ir: false,
383393
ignore_functions: false,
384394
ignore_methods: false,
385395
derive_debug: true,

src/options.rs

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub fn builder_from_flags<I>(args: I)
5252
Arg::with_name("emit-clang-ast")
5353
.long("emit-clang-ast")
5454
.help("Output the Clang AST for debugging purposes."),
55+
Arg::with_name("emit-ir")
56+
.long("emit-ir")
57+
.help("Output our internal IR for debugging purposes."),
5558
Arg::with_name("enable-cxx-namespaces")
5659
.long("enable-cxx-namespaces")
5760
.help("Enable support for C++ namespaces."),
@@ -183,6 +186,10 @@ pub fn builder_from_flags<I>(args: I)
183186
builder = builder.emit_clang_ast();
184187
}
185188

189+
if matches.is_present("emit-ir") {
190+
builder = builder.emit_ir();
191+
}
192+
186193
if matches.is_present("enable-cxx-namespaces") {
187194
builder = builder.enable_cxx_namespaces();
188195
}

0 commit comments

Comments
 (0)