Skip to content

Commit

Permalink
Support for LLVM 11 (#220)
Browse files Browse the repository at this point in the history
* supporting LLVM11

* Bump package version in Readme

* bump to 11

Co-authored-by: Alex Reilly <[email protected]>
  • Loading branch information
twof and twof authored Jan 3, 2021
1 parent 47b7fba commit 7bfd465
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ There are a couple annoying steps you need to accomplish before building
LLVMSwift:

- Install LLVM 8.0+ using your favorite package manager. For example:
- `brew install llvm`
- `brew install llvm@11`
- Ensure `llvm-config` is in your `PATH`
- That will reside in the `/bin` folder wherever your package manager
installed LLVM.
Expand All @@ -198,7 +198,7 @@ compiler projects!
### Installation with Swift Package Manager

```swift
.package(url: "https://github.com/llvm-swift/LLVMSwift.git", from: "0.4.0")
.package(url: "https://github.com/llvm-swift/LLVMSwift.git", from: "0.8.0")
```

### Installation without Swift Package Manager
Expand Down
23 changes: 19 additions & 4 deletions Sources/LLVM/DIBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ extension DIBuilder {
/// by third-party tools.
/// - splitDWARFPath: The path to the split DWARF file.
/// - identity: The identity of the tool that is compiling this source file.
/// - sysRoot: The Clang system root (the value of the `-isysroot` that's passed to clang).
/// - sdkRoot: The SDK root -- on Darwin platforms, this is the last component of the sysroot.
/// - Returns: A value representing a compilation-unit level scope.
public func buildCompileUnit(
for language: DWARFSourceLanguage,
Expand All @@ -208,7 +210,9 @@ extension DIBuilder {
flags: [String] = [],
runtimeVersion: Int = 0,
splitDWARFPath: String = "",
identity: String = ""
identity: String = "",
sysRoot: String = "",
sdkRoot: String = ""
) -> CompileUnitMetadata {
let allFlags = flags.joined(separator: " ")
guard let cu = LLVMDIBuilderCreateCompileUnit(
Expand All @@ -220,7 +224,11 @@ extension DIBuilder {
kind.llvm,
/*DWOId*/0,
splitDebugInlining.llvm,
debugInfoForProfiling.llvm
debugInfoForProfiling.llvm,
sysRoot,
sysRoot.count,
sdkRoot,
sdkRoot.count
) else {
fatalError()
}
Expand Down Expand Up @@ -860,15 +868,22 @@ extension DIBuilder {
/// - Parameters:
/// - type: Original type.
/// - name: Typedef name.
/// - alignment: Alignment of the type
/// - scope: The surrounding context for the typedef.
/// - file: File where this type is defined.
/// - line: Line number.
public func buildTypedef(
of type: DIType, name: String, scope: DIScope, file: FileMetadata, line: Int
of type: DIType,
name: String,
alignment: Alignment = .one,
scope: DIScope,
file: FileMetadata,
line: Int
) -> DIType {
guard let ty = LLVMDIBuilderCreateTypedef(
self.llvm, type.asMetadata(), name, name.count,
file.asMetadata(), UInt32(line), scope.asMetadata())
file.asMetadata(), UInt32(line), scope.asMetadata(),
alignment.rawValue * 8)
else {
fatalError("Failed to allocate metadata")
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/LLVM/MetadataAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,6 @@ public struct DIFlags : OptionSet {
public static let forwardDeclaration = DIFlags(rawValue: LLVMDIFlagFwdDecl.rawValue)
/// Denotes a block object.
public static let appleBlock = DIFlags(rawValue: LLVMDIFlagAppleBlock.rawValue)
/// Denotes the structure containing a variable captured by reference in a
/// block object.
public static let blockByrefStruct = DIFlags(rawValue: LLVMDIFlagBlockByrefStruct.rawValue)
/// Denotes a virtual function or dynamic dispatch.
public static let virtual = DIFlags(rawValue: LLVMDIFlagVirtual.rawValue)
/// Denotes a compiler-generated declaration that may not appear in source.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LLVM/TargetMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class TargetMachine {
}
var err: UnsafeMutablePointer<Int8>?
let status = path.withCString { cStr -> LLVMBool in
var mutable = strdup(cStr)
let mutable = strdup(cStr)
defer { free(mutable) }
return LLVMTargetMachineEmitToFile(llvm, module.llvm, mutable, type.asLLVM(), &err)
}
Expand Down
6 changes: 3 additions & 3 deletions utils/make-pkgconfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func makeFile() throws {
}

/// Ensure we have llvm-config in the PATH
guard let llvmConfig = which("llvm-config-9") ?? which("llvm-config") ?? brewLLVMConfig() else {
guard let llvmConfig = which("llvm-config-11") ?? which("llvm-config") ?? brewLLVMConfig() else {
throw "Failed to find llvm-config. Ensure llvm-config is installed and " +
"in your PATH"
}
Expand All @@ -84,8 +84,8 @@ func makeFile() throws {

let version = (components[0], components[1], components[2])

guard version >= (9, 0, 0) else {
throw "LLVMSwift requires LLVM version >=9.0.0, but you have \(versionStr)"
guard version >= (11, 0, 0) else {
throw "LLVMSwift requires LLVM version >=11.0.0, but you have \(versionStr)"
}

print("LLVM version is \(versionStr)")
Expand Down

0 comments on commit 7bfd465

Please sign in to comment.