Skip to content

Add missing docs #179

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 1 commit into from
Mar 21, 2019
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
19 changes: 19 additions & 0 deletions Sources/LLVM/Arbitrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cllvm
/// supports both the typical integer arithmetic and comparison operations as
/// well as bitwise manipulation.
public struct APInt: IRConstant {
/// The underlying word size.
public typealias Word = UInt64

private enum Impl {
Expand All @@ -20,6 +21,8 @@ public struct APInt: IRConstant {
}

private var value: Impl

/// The bitwidth of this integer.
public private(set) var bitWidth: Int

fileprivate init(raw values: [Word], _ bits: Int) {
Expand Down Expand Up @@ -166,12 +169,16 @@ extension APInt: Numeric {
self.init(integerLiteral: val)
}

/// Returns the result of performing a bitwise AND operation on the two
/// given values.
public static func & (lhs: APInt, rhs: APInt) -> APInt {
var lhs = lhs
lhs &= rhs
return lhs
}

/// Stores the result of performing a bitwise AND operation on the two given
/// values in the left-hand-side variable.
public static func &= (lhs: inout APInt, rhs: APInt) {
precondition(lhs.bitWidth == rhs.bitWidth)
switch (lhs.value, rhs.value) {
Expand All @@ -188,12 +195,16 @@ extension APInt: Numeric {
}
}

/// Returns the result of performing a bitwise OR operation on the two
/// given values.
public static func | (lhs: APInt, rhs: APInt) -> APInt {
var lhs = lhs
lhs |= rhs
return lhs
}

/// Stores the result of performing a bitwise OR operation on the two given
/// values in the left-hand-side variable.
public static func |= (lhs: inout APInt, rhs: APInt) {
precondition(lhs.bitWidth == rhs.bitWidth)
switch (lhs.value, rhs.value) {
Expand All @@ -210,12 +221,16 @@ extension APInt: Numeric {
}
}

/// Returns the result of performing a bitwise XOR operation on the two
/// given values.
public static func ^ (lhs: APInt, rhs: APInt) -> APInt {
var lhs = lhs
lhs ^= rhs
return lhs
}

/// Stores the result of performing a bitwise XOR operation on the two given
/// values in the left-hand-side variable.
public static func ^= (lhs: inout APInt, rhs: APInt) {
precondition(lhs.bitWidth == rhs.bitWidth)
switch (lhs.value, rhs.value) {
Expand Down Expand Up @@ -388,12 +403,16 @@ extension APInt: Numeric {
}
}

/// Returns the result of shifting a value’s binary representation the
/// specified number of digits to the left.
public static func << (lhs: APInt, amount: UInt64) -> APInt {
var lhs = lhs
lhs <<= amount
return lhs
}

/// Stores the result of shifting a value’s binary representation the
/// specified number of digits to the left in the left-hand-side variable.
public static func <<= (lhs: inout APInt, amount: UInt64) {
precondition(amount <= lhs.bitWidth)
switch lhs.value {
Expand Down
2 changes: 2 additions & 0 deletions Sources/LLVM/AttachedMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ public class AttachedMetadata {
self.bounds = bounds
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard let ptr = llvm else { return }
LLVMDisposeValueMetadataEntries(ptr)
Expand All @@ -700,6 +701,7 @@ public class AttachedMetadata {
return Entry(base: self, index: UInt32(index))
}

/// Returns the number of metadata entries.
public var count: Int {
return self.bounds
}
Expand Down
1 change: 1 addition & 0 deletions Sources/LLVM/DIBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class DIBuilder {
LLVMDIBuilderFinalize(self.llvm)
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeDIBuilder(self.llvm)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class IRBuilder {
self.llvm = LLVMCreateBuilderInContext(module.context.llvm)
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeBuilder(llvm)
}
Expand Down
31 changes: 31 additions & 0 deletions Sources/LLVM/IRMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,36 +385,67 @@ public struct ExpressionMetadata: IRMetadata {

/// Enumerates the kind of metadata nodes.
public enum IRMetadataKind {
/// The metadata is a string.
case mdString
/// The metadata is a constant-as-metadata node.
case constantAsMetadata
/// The metadata is a local-as-metadata node.
case localAsMetadata
/// The metadata is a disctint metadata operand placeholder.
case distinctMDOperandPlaceholder
/// The metadata is a tuple.
case mdTuple
/// The metadata is a location.
case location
/// The metadata is an expression.
case expression
/// The metadata is a global variable expression.
case globalVariableExpression
/// The metadata is a generic DI node.
case genericDINode
/// The metadata is a subrange.
case subrange
/// The metadata is an enumerator.
case enumerator
/// The metadata is a basic type.
case basicType
/// The metadata is a derived type.
case derivedType
/// The metadata is a composite type.
case compositeType
/// The metadata is a subroutine type.
case subroutineType
/// The metadata is a file.
case file
/// The metadata is a compile unit.
case compileUnit
/// The metadata is a subprogram.
case subprogram
/// The metadata is a lexical block.
case lexicalBlock
/// The metadata is a lexical block file.
case lexicalBlockFile
/// The metadata is a namespace.
case namespace
/// The metadata is a module.
case module
/// The metadata is a template type parameter.
case templateTypeParameter
/// The metadata is a template value parameter.
case templateValueParameter
/// The metadata is a global variable.
case globalVariable
/// The metadata is a local variable.
case localVariable
/// The metadata is a label.
case label
/// The metadata is an Objective-C property.
case objCProperty
/// The metadata is an imported entity.
case importedEntity
/// The metadata is a macro.
case macro
/// The metadata is a macro file.
case macroFile

fileprivate init(raw: LLVMMetadataKind) {
Expand Down
1 change: 1 addition & 0 deletions Sources/LLVM/JIT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public final class JIT {
self.init(llvm: LLVMOrcCreateInstance(machine.llvm), ownsContext: true)
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard self.ownsContext else {
return
Expand Down
1 change: 1 addition & 0 deletions Sources/LLVM/MemoryBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class MemoryBuffer: Sequence {
return UnsafeBufferPointer(start: start, count: size).makeIterator()
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard self.ownsContext else {
return
Expand Down
9 changes: 7 additions & 2 deletions Sources/LLVM/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public class Context {
set { LLVMContextSetDiscardValueNames(self.llvm, newValue.llvm) }
}

/// Deinitialize this value and dispose of its resources.
deinit {
if ownsContext {
LLVMContextDispose(llvm)
guard self.ownsContext else {
return
}
LLVMContextDispose(self.llvm)
}
}

Expand Down Expand Up @@ -329,6 +331,7 @@ public final class Module: CustomStringConvertible {
return String(cString: cStr)
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard self.ownsContext else {
return
Expand Down Expand Up @@ -587,6 +590,7 @@ extension Module {
self.bounds = bounds
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard let ptr = llvm else { return }
LLVMDisposeModuleFlagsMetadata(ptr)
Expand All @@ -602,6 +606,7 @@ extension Module {
return Entry(base: self, index: UInt32(index))
}

/// Returns the number of module flag metadata entries.
public var count: Int {
return self.bounds
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/LLVM/ObjectFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ObjectFile {
return SymbolSequence(llvm: LLVMGetSymbols(llvm), object: self)
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeObjectFile(llvm)
}
Expand Down Expand Up @@ -100,6 +101,7 @@ public class SectionSequence: Sequence {
}
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeSectionIterator(llvm)
}
Expand Down Expand Up @@ -171,6 +173,7 @@ public class RelocationSequence: Sequence {
}
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeSectionIterator(llvm)
}
Expand Down Expand Up @@ -198,6 +201,7 @@ public class SymbolSequence: Sequence {
}
}

/// Deinitialize this value and dispose of its resources.
deinit {
LLVMDisposeSymbolIterator(llvm)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/LLVM/TargetMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public class TargetMachine {
return MemoryBuffer(llvm: llvm)
}

/// Deinitialize this value and dispose of its resources.
deinit {
guard self.ownsContext else {
return
Expand Down