Skip to content

Commit 5d8ea13

Browse files
committed
Started doc tests for context.rs; Code cleanup
1 parent 11bdf37 commit 5d8ea13

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/context.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ impl Context {
3030
}
3131
}
3232

33+
/// Creates a new `Context`.
34+
///
35+
/// # Example
36+
///
37+
/// ```
38+
/// use inkwell::context::Context;
39+
///
40+
/// let context = Context::create();
41+
/// ```
3342
pub fn create() -> Self {
3443
let context = unsafe {
3544
LLVMContextCreate()
@@ -38,6 +47,15 @@ impl Context {
3847
Context::new(context)
3948
}
4049

50+
/// Creates a `ContextRef` which references the global context singleton.
51+
///
52+
/// # Example
53+
///
54+
/// ```
55+
/// use inkwell::context::Context;
56+
///
57+
/// let context = Context::get_global();
58+
/// ```
4159
pub fn get_global() -> ContextRef {
4260
let context = unsafe {
4361
LLVMGetGlobalContext()
@@ -46,6 +64,16 @@ impl Context {
4664
ContextRef::new(Context::new(context))
4765
}
4866

67+
/// Creates a new `Builder` for a `Context`.
68+
///
69+
/// # Example
70+
///
71+
/// ```
72+
/// use inkwell::context::Context;
73+
///
74+
/// let context = Context::create();
75+
/// let builder = context.create_builder();
76+
/// ```
4977
pub fn create_builder(&self) -> Builder {
5078
let builder = unsafe {
5179
LLVMCreateBuilderInContext(self.context)
@@ -54,6 +82,16 @@ impl Context {
5482
Builder::new(builder)
5583
}
5684

85+
/// Creates a new `Module` for a `Context`.
86+
///
87+
/// # Example
88+
///
89+
/// ```
90+
/// use inkwell::context::Context;
91+
///
92+
/// let context = Context::create();
93+
/// let module = context.create_module("my_module");
94+
/// ```
5795
pub fn create_module(&self, name: &str) -> Module {
5896
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
5997

src/data_layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl PartialEq for DataLayout {
3737
impl fmt::Debug for DataLayout {
3838
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3939
write!(f, "DataLayout {{\n ")?;
40-
write!(f, "address: {:?}\n ", self.data_layout.get());
40+
write!(f, "address: {:?}\n ", self.data_layout.get())?;
4141
write!(f, "repr: {:?}\n}}", self.as_str())
4242
}
4343
}

src/module.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use llvm_sys::analysis::{LLVMVerifyModule, LLVMVerifierFailureAction};
22
use llvm_sys::bit_writer::{LLVMWriteBitcodeToFile, LLVMWriteBitcodeToMemoryBuffer, LLVMWriteBitcodeToFD};
3-
use llvm_sys::core::{LLVMAddFunction, LLVMAddGlobal, LLVMDisposeMessage, LLVMDumpModule, LLVMGetNamedFunction, LLVMGetTypeByName, LLVMSetDataLayout, LLVMSetInitializer, LLVMSetTarget, LLVMCloneModule, LLVMDisposeModule, LLVMGetTarget, LLVMGetDataLayout, LLVMModuleCreateWithName, LLVMGetModuleContext, LLVMGetFirstFunction, LLVMGetLastFunction, LLVMSetLinkage, LLVMAddGlobalInAddressSpace, LLVMPrintModuleToString, LLVMGetNamedMetadataNumOperands, LLVMAddNamedMetadataOperand, LLVMGetNamedMetadataOperands, LLVMDisposeModuleProvider, LLVMCreateModuleProviderForExistingModule};
3+
use llvm_sys::core::{LLVMAddFunction, LLVMAddGlobal, LLVMDisposeMessage, LLVMDumpModule, LLVMGetNamedFunction, LLVMGetTypeByName, LLVMSetDataLayout, LLVMSetInitializer, LLVMSetTarget, LLVMCloneModule, LLVMDisposeModule, LLVMGetTarget, LLVMGetDataLayout, LLVMModuleCreateWithName, LLVMGetModuleContext, LLVMGetFirstFunction, LLVMGetLastFunction, LLVMSetLinkage, LLVMAddGlobalInAddressSpace, LLVMPrintModuleToString, LLVMGetNamedMetadataNumOperands, LLVMAddNamedMetadataOperand, LLVMGetNamedMetadataOperands};
44
use llvm_sys::execution_engine::{LLVMCreateJITCompilerForModule, LLVMCreateMCJITCompilerForModule};
55
use llvm_sys::prelude::{LLVMValueRef, LLVMModuleRef};
66
use llvm_sys::LLVMLinkage;
@@ -16,7 +16,6 @@ use context::{Context, ContextRef};
1616
use data_layout::DataLayout;
1717
use execution_engine::ExecutionEngine;
1818
use memory_buffer::MemoryBuffer;
19-
use passes::PassManager;
2019
use types::{AsTypeRef, BasicType, FunctionType, BasicTypeEnum};
2120
use values::{AsValueRef, BasicValue, FunctionValue, PointerValue, MetadataValue, BasicMetadataValueEnum};
2221

src/values/instruction_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use basic_block::BasicBlock;
66
use values::traits::AsValueRef;
77
use values::Value;
88

9-
// REVIEW: Metadata on instructions?
9+
// REVIEW: Split up into structs for SubTypes on InstructionValues?
1010
// REVIEW: This should maybe be split up into InstructionOpcode and ConstOpcode?
1111
// see LLVMGetConstOpcode
1212
#[derive(Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)