Skip to content

Fill out Target's API #161

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
Nov 6, 2018
Merged
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
55 changes: 55 additions & 0 deletions Sources/LLVM/TargetMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,61 @@ public class Target {
public init(llvm: LLVMTargetRef) {
self.llvm = llvm
}

/// Returns `true` if this target has a JIT.
var hasJIT: Bool {
return LLVMTargetHasJIT(self.llvm) != 0
}

/// The name of this target.
public var name: String {
guard let str = LLVMGetTargetName(self.llvm) else {
return ""
}
return String(validatingUTF8: UnsafePointer<CChar>(str)) ?? ""
}

/// The description of this target.
public var targetDescription: String {
guard let str = LLVMGetTargetDescription(self.llvm) else {
return ""
}
return String(validatingUTF8: UnsafePointer<CChar>(str)) ?? ""
}

/// Returns `true` if this target has a `TargetMachine` associated with it.
var hasTargetMachine: Bool {
return LLVMTargetHasTargetMachine(self.llvm) != 0
}

/// Returns `true` if this target has an ASM backend
var hasASMBackend: Bool {
return LLVMTargetHasTargetMachine(self.llvm) != 0
}

/// Returns a sequence of all targets in the global list of targets.
public static var allTargets: AnySequence<Target> {
var current = firstTarget
return AnySequence<Target> {
return AnyIterator<Target> {
defer { current = current?.next() }
return current
}
}
}

/// Returns the first target in the global target list, if it exists.
public static var firstTarget: Target? {
guard let targetRef = LLVMGetFirstTarget() else { return nil }
return Target(llvm: targetRef)
}

/// Returns the target following this target in the global target list,
/// if it exists.
public func next() -> Target? {
guard let targetRef = LLVMGetNextTarget(self.llvm) else { return nil }
return Target(llvm: targetRef)
}
}

/// A `TargetMachine` object represents an object that encapsulates information
Expand Down