Skip to content

Commit 13bb24c

Browse files
authored
Merge pull request #60 from CodaFi/target-locked
Add accessors for features and CPU type
2 parents f36fd54 + 962011b commit 13bb24c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Sources/LLVM/TargetMachine.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class TargetMachine {
8686
/// The target information associated with this target machine.
8787
public let target: Target
8888

89-
/// The data layout semantics associated with this target machine
89+
/// The data layout semantics associated with this target machine.
9090
public let dataLayout: TargetData
9191

9292
/// A string representing the target triple for this target machine. In the
@@ -99,6 +99,24 @@ public class TargetMachine {
9999
/// - abi = eabi, gnu, android, macho, elf, etc.
100100
public let triple: String
101101

102+
/// The CPU associated with this target machine.
103+
public var cpu: String {
104+
guard let str = LLVMGetTargetMachineCPU(self.llvm) else {
105+
return ""
106+
}
107+
defer { LLVMDisposeMessage(str) }
108+
return String(validatingUTF8: UnsafePointer<CChar>(str)) ?? ""
109+
}
110+
111+
/// The feature string associated with this target machine.
112+
public var features: String {
113+
guard let str = LLVMGetTargetMachineFeatureString(self.llvm) else {
114+
return ""
115+
}
116+
defer { LLVMDisposeMessage(str) }
117+
return String(validatingUTF8: UnsafePointer<CChar>(str)) ?? ""
118+
}
119+
102120
/// Creates a Target Machine with information about its target environment.
103121
///
104122
/// - parameter triple: An optional target triple to target. If this is not

0 commit comments

Comments
 (0)