extern { pub type BasicBlock; }
extern { pub type Builder; }
extern { pub type MemoryBuffer; }
-pub type MemoryBufferRef = *mut MemoryBuffer;
extern { pub type PassManager; }
pub type PassManagerRef = *mut PassManager;
extern { pub type PassManagerBuilder; }
pub type PassManagerBuilderRef = *mut PassManagerBuilder;
extern { pub type ObjectFile; }
-pub type ObjectFileRef = *mut ObjectFile;
extern { pub type SectionIterator; }
pub type SectionIteratorRef = *mut SectionIterator;
extern { pub type Pass; }
// Stuff that's in rustllvm/ because it's not upstream yet.
/// Opens an object file.
- pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
+ pub fn LLVMCreateObjectFile(
+ MemBuf: &'static mut MemoryBuffer,
+ ) -> Option<&'static mut ObjectFile>;
/// Closes an object file.
- pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
+ pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
/// Enumerates the sections in an object file.
- pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
+ pub fn LLVMGetSections(ObjFile: &ObjectFile) -> SectionIteratorRef;
/// Destroys a section iterator.
pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
/// Returns true if the section iterator is at the end of the section
/// list:
- pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef, SI: SectionIteratorRef) -> Bool;
+ pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &ObjectFile, SI: SectionIteratorRef) -> Bool;
/// Moves the section iterator to point to the next section.
pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
/// Returns the current section size.
/// Reads the given file and returns it as a memory buffer. Use
/// LLVMDisposeMemoryBuffer() to get rid of it.
- pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char) -> MemoryBufferRef;
+ pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
+ Path: *const c_char,
+ ) -> Option<&'static mut MemoryBuffer>;
pub fn LLVMStartMultithreaded() -> Bool;
// Memory-managed interface to object files.
pub struct ObjectFile {
- pub llof: ObjectFileRef,
+ pub llof: &'static mut ffi::ObjectFile,
}
unsafe impl Send for ObjectFile {}
impl ObjectFile {
// This will take ownership of llmb
- pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
+ pub fn new(llmb: &'static mut MemoryBuffer) -> Option<ObjectFile> {
unsafe {
- let llof = LLVMCreateObjectFile(llmb);
- if llof as isize == 0 {
- // LLVMCreateObjectFile took ownership of llmb
- return None;
- }
-
+ let llof = LLVMCreateObjectFile(llmb)?;
Some(ObjectFile { llof: llof })
}
}
impl Drop for ObjectFile {
fn drop(&mut self) {
unsafe {
- LLVMDisposeObjectFile(self.llof);
+ LLVMDisposeObjectFile(&mut *(self.llof as *mut _));
}
}
}
}
}
-pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
+pub fn mk_section_iter(llof: &ffi::ObjectFile) -> SectionIter {
unsafe { SectionIter { llsi: LLVMGetSections(llof) } }
}
-> Result<MetadataRef, String> {
unsafe {
let buf = common::path2cstr(filename);
- let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr());
- if mb as isize == 0 {
- return Err(format!("error reading library: '{}'", filename.display()));
- }
+ let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr())
+ .ok_or_else(|| format!("error reading library: '{}'", filename.display()))?;
let of = ObjectFile::new(mb)
.map(|of| OwningRef::new(box of))
.ok_or_else(|| format!("provided path not an object file: '{}'",