Skip to content

Commit f46136e

Browse files
committed
Clarify documentation
1 parent af9c257 commit f46136e

File tree

13 files changed

+64
-49
lines changed

13 files changed

+64
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use util;
77
pub struct BasicBlock;
88
native_ref!(&BasicBlock = LLVMBasicBlockRef);
99
impl BasicBlock {
10-
/// Return the enclosing method, or `None` if it is non-existant.
10+
/// Return the enclosing method, or `None` if it is not attached to a method.
1111
pub fn get_parent(&self) -> Option<&Value> {
1212
unsafe { util::ptr_to_null(core::LLVMGetBasicBlockParent(self.into())) }
1313
}
@@ -26,7 +26,7 @@ impl BasicBlock {
2626
/// Delete this basic block.
2727
///
2828
/// This is unsafe because there should be no other reference to this, but
29-
/// this can't be guranteed.
29+
/// this can't be guranteed using Rust semantics.
3030
pub unsafe fn delete(&self) {
3131
core::LLVMDeleteBasicBlock(self.into())
3232
}

src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Builder {
114114
pub fn build_bit_cast(&self, value: &Value, dest: &Type) -> &Value {
115115
unsafe { core::LLVMBuildBitCast(self.into(), value.into(), dest.into(), NULL_NAME.as_ptr()).into() }
116116
}
117-
/// Build an instruction that inserts a value into an aggregate type.
117+
/// Build an instruction that inserts a value into an aggregate data value.
118118
pub fn build_insert_value(&self, agg: &Value, elem: &Value, index: usize) -> &Value {
119119
unsafe { core::LLVMBuildInsertValue(self.into(), agg.into(), elem.into(), index as c_uint, NULL_NAME.as_ptr()).into() }
120120
}
@@ -145,7 +145,7 @@ impl Builder {
145145
bin_op!{build_ashr, LLVMBuildAShr}
146146
bin_op!{build_and, LLVMBuildAnd}
147147
bin_op!{build_or, LLVMBuildOr}
148-
/// Build an instruction to compare two values with the predicate
148+
/// Build an instruction to compare two values with the predicate given.
149149
pub fn build_cmp(&self, a: &Value, b: &Value, pred: Predicate) -> &Value {
150150
let (at, bt) = (a.get_type(), b.get_type());
151151
assert_eq!(at, bt);

src/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use ty::{StructType, Type};
88
use std::mem;
99
use std::ffi::CStr;
1010

11-
/// Implemented for any type that can be represented as a constant in IR.
11+
/// A type that can be represented as a constant in LLVM IR.
1212
pub trait Compile<'a> {
13-
/// Compile this value in the context given.
13+
/// Compile this value into a constant in the context given.
1414
fn compile(self, context: &'a Context) -> &'a Value;
1515
/// Get the type descriptor for this type in the context given.
1616
fn get_type(context: &'a Context) -> &'a Type;

src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use ffi::prelude::LLVMContextRef;
22
use ffi::{core, LLVMContext};
33
use cbox::CBox;
44

5-
/// Contains all the LLVM entities such as modules.
5+
/// Contains all the LLVM entities - mainly modules.
66
///
77
/// Every single entity attached to it has its lifetime to enforce the
8-
/// rule that things from different contexts cannot interact and to keep
9-
/// their pointer safety intact.
8+
/// rule that things from different contexts cannot interact and to
9+
/// preserve pointer safety.
1010
pub struct Context;
1111
native_ref!(&Context = LLVMContextRef);
1212
impl Context {
@@ -17,7 +17,7 @@ impl Context {
1717
pub unsafe fn get_global() -> &'static Context {
1818
core::LLVMGetGlobalContext().into()
1919
}
20-
/// Create a new context, owned by the block that calls it.
20+
/// Create a new context, which is owned by the callee block.
2121
pub fn new() -> CBox<Self> {
2222
CBox::new(unsafe { core::LLVMContextCreate() })
2323
}

src/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use value::{Function, Value};
1818
///
1919
/// This is designed to support both interpreter and just-in-time (JIT) compiler implementations.
2020
pub trait ExecutionEngine<'a, 'b:'a> where LLVMExecutionEngineRef:From<&'b Self> {
21-
/// The options given to this upon creation.
21+
/// The options given to the engine upon creation.
2222
type Options : Copy;
2323
/// Create a new execution engine with the given `Module` and options, or return a
2424
/// description of the error.

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
//! This library provides wrappers for LLVM that are (mostly) memory-safe and follow
1+
//! This library provides wrappers for LLVM that are memory-safe and follow
22
//! Rust idioms.
3+
//!
4+
//! The original LLVM reference is available [here](http://llvm.org/doxygen/)
5+
//! but take note that this isn't as thorough as this documentation.
36
47
extern crate llvm_sys as ffi;
58
extern crate libc;

src/module.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use value::{Function, Value};
2020
use ty::Type;
2121
use util;
2222

23-
/// Represents a single translation unit of code.
23+
/// Represents a single compilation unit of code.
2424
///
2525
/// This is attached to the lifetime of the context that constructs it, but is owned by the `CSemiBox`.
2626
pub struct Module;
@@ -91,15 +91,15 @@ impl Module {
9191
let c_name = CString::new(name).unwrap();
9292
unsafe { core::LLVMAddFunction(self.into(), c_name.as_ptr(), sig.into()) }.into()
9393
}
94-
/// Returns the function with the name given if it exists.
94+
/// Returns the function with the name given, or `None` if no function with that name exists.
9595
pub fn get_function<'a>(&'a self, name: &str) -> Option<&'a Function> {
9696
let c_name = CString::new(name).unwrap();
9797
unsafe {
9898
let ty = core::LLVMGetNamedFunction(self.into(), c_name.as_ptr());
9999
util::ptr_to_null(ty)
100100
}
101101
}
102-
/// Returns the type with the name given if it exists.
102+
/// Returns the type with the name given, or `None`` if no type with that name exists.
103103
pub fn get_type<'a>(&'a self, name: &str) -> Option<&'a Type> {
104104
let c_name = CString::new(name).unwrap();
105105
unsafe {
@@ -113,6 +113,8 @@ impl Module {
113113
}
114114

115115
/// Optimize this module with the given optimization level and size level.
116+
///
117+
/// This runs passes depending on the levels given.
116118
pub fn optimize(&self, opt_level: usize, size_level: usize) {
117119
unsafe {
118120
let builder = builder::LLVMPassManagerBuilderCreate();
@@ -133,13 +135,14 @@ impl Module {
133135
}
134136
}
135137

136-
/// Set the target data of this module
138+
/// Set the target data of this module to the target data string given.
137139
pub fn set_target(&self, target: &str) {
138140
let c_target = CString::new(target).unwrap();
139141
unsafe { core::LLVMSetTarget(self.into(), c_target.as_ptr()) }
140142
}
141143

142-
/// Verify that the module is safe to run.
144+
/// Verify that the module is safe to run, returning a string detailing the error
145+
/// when an error occurs.
143146
pub fn verify(&self) -> Result<(), CBox<str>> {
144147
unsafe {
145148
let mut error = mem::uninitialized();
@@ -171,7 +174,9 @@ impl Module {
171174
.map(|_| ())
172175
}
173176

174-
/// Link a module into this module
177+
/// Link a module into this module, returning an error string if an error occurs.
178+
///
179+
/// This *does not* destroy the source module.
175180
pub fn link(&self, src: &Module) -> Result<(), CBox<str>> {
176181
unsafe {
177182
let dest = self.into();
@@ -185,7 +190,9 @@ impl Module {
185190
}
186191
}
187192

188-
/// Link a module into this module
193+
/// Link a module into this module, returning an error string if an error occurs.
194+
///
195+
/// This *does* destroy the source module.
189196
pub fn link_destroy(&self, src: CSemiBox<Module>) -> Result<(), CBox<str>> {
190197
unsafe {
191198
let dest = self.into();

src/object.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use std::mem;
88
use buffer::MemoryBuffer;
99
use util;
1010

11-
/// An external object file that has been parsed by LLVLM
11+
/// An external object file that has been parsed by LLVM.
1212
pub struct ObjectFile {
1313
obj: LLVMObjectFileRef
1414
}
1515
native_ref!(ObjectFile, obj: LLVMObjectFileRef);
1616
impl ObjectFile {
17-
/// Attempt to parse the object file at the path given
17+
/// Parse the object file at the path given, or return an error string if an error occurs.
1818
pub fn read(path: &str) -> Result<ObjectFile, CBox<str>> {
1919
let buf = try!(MemoryBuffer::new_from_file(path));
2020
unsafe {
@@ -26,7 +26,7 @@ impl ObjectFile {
2626
}
2727
}
2828
}
29-
/// Iterate through the symbols in this object fil
29+
/// Iterate through the symbols in this object file.
3030
pub fn symbols(&self) -> Symbols {
3131
Symbols {
3232
iter: unsafe { object::LLVMGetSymbols(self.obj) },
@@ -61,7 +61,9 @@ impl<'a> Drop for Symbols<'a> {
6161
}
6262
}
6363
pub struct Symbol<'a> {
64+
/// The name of this symbol.
6465
pub name: &'a str,
66+
/// The address that this symbol is at.
6567
pub address: *const c_void,
6668
pub size: usize
6769
}
@@ -77,7 +79,7 @@ impl<'a> fmt::Debug for Symbol<'a> {
7779
}
7880
}
7981
impl<'a> Symbol<'a> {
80-
/// Get the pointer for this symbol
82+
/// Get the pointer for this symbol.
8183
pub unsafe fn get<T>(self) -> &'a T {
8284
mem::transmute(self.address)
8385
}

src/target.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ use std::fmt;
77
use ty::Type;
88
use util;
99

10+
/// Represents an LLVM Target
1011
pub struct TargetData;
1112
native_ref!(&TargetData = LLVMTargetDataRef);
1213

1314
impl TargetData {
14-
/// Creates target data from a target layout string.
15+
/// Create a target data from a target layout string.
1516
pub fn new(rep: &str) -> CBox<TargetData> {
1617
let c_rep = CString::new(rep).unwrap();
1718
CBox::new(unsafe {
1819
target::LLVMCreateTargetData(c_rep.as_ptr())
19-
}.into())
20+
}.Returns truento())
2021
}
2122
/// Returns true if the target is big endian.
2223
pub fn is_big_endian(&self) -> bool {
@@ -47,7 +48,7 @@ impl TargetData {
4748
pub fn offset_of(&self, struct_ty: &Type, element: usize) -> u64 {
4849
unsafe { target::LLVMOffsetOfElement(self.into(), struct_ty.into(), element as c_uint) }
4950
}
50-
/// Converts this to a target layout string and returns it.
51+
/// Returns the string representation of this target data.
5152
pub fn as_str(&self) -> CBox<str> {
5253
unsafe {
5354
CBox::new(target::LLVMCopyStringRepOfTargetData(self.into()))
@@ -78,15 +79,15 @@ impl Target {
7879
pub fn get_description(&self) -> &str {
7980
unsafe { util::to_str(target_machine::LLVMGetTargetDescription(self.into()) as *mut c_char) }
8081
}
81-
/// Returns `true` if this target has an assembly generation backend in LLVM.
82+
/// Returns true if this target has an assembly generation backend implemented.
8283
pub fn has_asm_backend(&self) -> bool {
8384
unsafe { target_machine::LLVMTargetHasAsmBackend(self.into()) != 0 }
8485
}
85-
/// Returns `true` if this target supports JIT compilation.
86+
/// Returns true if this target supports JIT compilation.
8687
pub fn has_jit(&self) -> bool {
8788
unsafe { target_machine::LLVMTargetHasJIT(self.into()) != 0 }
8889
}
89-
/// Returns `true` if this target has a target machine.
90+
/// Returns true if this target has a target machine.
9091
pub fn has_target_machine(&self) -> bool {
9192
unsafe { target_machine::LLVMTargetHasTargetMachine(self.into()) != 0 }
9293
}

0 commit comments

Comments
 (0)