Skip to content

Instantly share code, notes, and snippets.

@rrika
Created June 24, 2018 18:20
Show Gist options
  • Save rrika/a0d7cc5b0e11ca5147f7e5c638b578bc to your computer and use it in GitHub Desktop.
Save rrika/a0d7cc5b0e11ca5147f7e5c638b578bc to your computer and use it in GitHub Desktop.
extern crate llvm_sys;
use std::ffi::CStr;
use llvm_sys::core::*;
use llvm_sys::bit_reader::*;
fn main() {
unsafe {
let mut llvm_module = std::mem::uninitialized();
let mut buffer = std::mem::uninitialized();
let mut message = std::mem::uninitialized();
LLVMCreateMemoryBufferWithContentsOfFile(b"./test.bc\0" as *const u8 as *const i8, &mut buffer, &mut message);
LLVMParseBitcode2(buffer, &mut llvm_module);
let mut fun = LLVMGetFirstFunction(llvm_module);
while !fun.is_null() {
let name = LLVMGetValueName(fun);
println!("fn {}", CStr::from_ptr(name).to_string_lossy());
fun = LLVMGetNextFunction(fun);
}
LLVMDisposeModule(llvm_module);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment