summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-11-15 10:26:26 -0800
committerNick Fitzgerald <fitzgen@gmail.com>2016-11-15 11:33:05 -0800
commit3bb07b6ea4e60a30a774d41819b63a85de096a1e (patch)
tree72dcfcc53bbbb4f98fbe9e6296241fa34764ce55
parent6b285e617ede6d3dbd6d2d0129ac81bc992a1593 (diff)
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.
-rw-r--r--libbindgen/src/codegen/mod.rs7
-rw-r--r--libbindgen/src/lib.rs10
-rw-r--r--src/options.rs7
3 files changed, 24 insertions, 0 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index 8e04fd7c..009d8819 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -1892,6 +1892,13 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> {
let whitelisted_items: ItemSet = context.whitelisted_items().collect();
+ if context.options().emit_ir {
+ for &id in whitelisted_items.iter() {
+ let item = context.resolve_item(id);
+ println!("ir: {:?} = {:#?}", id, item);
+ }
+ }
+
for &id in whitelisted_items.iter() {
let item = context.resolve_item(id);
diff --git a/libbindgen/src/lib.rs b/libbindgen/src/lib.rs
index d0ca7b03..e4923b77 100644
--- a/libbindgen/src/lib.rs
+++ b/libbindgen/src/lib.rs
@@ -225,6 +225,12 @@ impl Builder {
self
}
+ /// Emit IR.
+ pub fn emit_ir(mut self) -> Builder {
+ self.options.emit_ir = true;
+ self
+ }
+
/// Enable C++ namespaces.
pub fn enable_cxx_namespaces(mut self) -> Builder {
self.options.enable_cxx_namespaces = true;
@@ -314,6 +320,9 @@ pub struct BindgenOptions {
/// True if we should dump the Clang AST for debugging purposes.
pub emit_ast: bool,
+ /// True if we should dump our internal IR for debugging purposes.
+ pub emit_ir: bool,
+
/// True if we should ignore functions and only generate bindings for
/// structures, types, and methods.
pub ignore_functions: bool,
@@ -380,6 +389,7 @@ impl Default for BindgenOptions {
builtins: false,
links: vec![],
emit_ast: false,
+ emit_ir: false,
ignore_functions: false,
ignore_methods: false,
derive_debug: true,
diff --git a/src/options.rs b/src/options.rs
index c3c6a1f2..2ea74a27 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -52,6 +52,9 @@ pub fn builder_from_flags<I>(args: I)
Arg::with_name("emit-clang-ast")
.long("emit-clang-ast")
.help("Output the Clang AST for debugging purposes."),
+ Arg::with_name("emit-ir")
+ .long("emit-ir")
+ .help("Output our internal IR for debugging purposes."),
Arg::with_name("enable-cxx-namespaces")
.long("enable-cxx-namespaces")
.help("Enable support for C++ namespaces."),
@@ -183,6 +186,10 @@ pub fn builder_from_flags<I>(args: I)
builder = builder.emit_clang_ast();
}
+ if matches.is_present("emit-ir") {
+ builder = builder.emit_ir();
+ }
+
if matches.is_present("enable-cxx-namespaces") {
builder = builder.enable_cxx_namespaces();
}