Skip to content

Add an option to emit our ir for debugging #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ os:

rust:
- stable
- nightly

env:
- LLVM_VERSION=3.8 BINDGEN_FEATURES=llvm_stable
Expand Down
7 changes: 7 additions & 0 deletions libbindgen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions libbindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down Expand Up @@ -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();
}
Expand Down