Skip to content

Metadata -> IRMetadata #166

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 8, 2018
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
4 changes: 2 additions & 2 deletions Sources/LLVM/DIBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ extension DIBuilder {
/// - line: Line number of the declaration.
/// - name: The name of the imported declaration.
public func buildImportedDeclaration(
in context: DIScope, declaration: Metadata,
in context: DIScope, declaration: IRMetadata,
file: FileMetadata, line: Int, name: String = ""
) -> ImportedEntityMetadata {
guard let mod = LLVMDIBuilderCreateImportedDeclaration(
Expand Down Expand Up @@ -1111,7 +1111,7 @@ extension DIBuilder {
scope: DIScope, file: FileMetadata, line: Int,
isLocal: Bool = true,
expression: ExpressionMetadata? = nil,
declaration: Metadata? = nil,
declaration: IRMetadata? = nil,
alignment: Alignment = .zero
) -> ExpressionMetadata {
let radix = UInt32(self.module.dataLayout.intPointerType().width)
Expand Down
22 changes: 11 additions & 11 deletions Sources/LLVM/Metadata.swift → Sources/LLVM/IRMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ public protocol _IRMetadataInitializerHack {
/// to compile a program to native machine code and standard debugging
/// formats. This allows compatibility with traditional machine-code level
/// debuggers, like GDB, DBX, or CodeView.
public protocol Metadata: _IRMetadataInitializerHack {
public protocol IRMetadata: _IRMetadataInitializerHack {
/// Retrieves the underlying LLVM metadata object.
func asMetadata() -> LLVMMetadataRef
}

extension Metadata {
extension IRMetadata {
/// Replaces all uses of the this metadata with the given metadata.
///
/// - parameter metadata: The new value to swap in.
public func replaceAllUses(with metadata: Metadata) {
public func replaceAllUses(with metadata: IRMetadata) {
LLVMMetadataReplaceAllUsesWith(self.asMetadata(), metadata.asMetadata())
}
}

extension Metadata {
extension IRMetadata {
/// Dumps a representation of this metadata to stderr.
public func dump() {
LLVMDumpValue(LLVMMetadataAsValue(LLVMGetGlobalContext(), self.asMetadata()))
Expand All @@ -66,13 +66,13 @@ extension Metadata {
/// - warning: In general, use of this method is discouraged and can
/// lead to unpredictable results or undefined behavior. No checks are
/// performed before, during, or after the cast.
public func forceCast<DestTy: Metadata>(to: DestTy.Type) -> DestTy {
public func forceCast<DestTy: IRMetadata>(to: DestTy.Type) -> DestTy {
return DestTy(llvm: self.asMetadata())
}
}

/// Denotes a scope in which child metadata nodes can be inserted.
public protocol DIScope: Metadata {}
public protocol DIScope: IRMetadata {}

/// Denotes metadata for a type.
public protocol DIType: DIScope {}
Expand Down Expand Up @@ -113,7 +113,7 @@ extension DIType {
}

/// A `DebugLocation` represents a location in source.
public struct DebugLocation: Metadata {
public struct DebugLocation: IRMetadata {
internal let llvm: LLVMMetadataRef

public func asMetadata() -> LLVMMetadataRef {
Expand All @@ -140,7 +140,7 @@ public struct DebugLocation: Metadata {
}
}

struct AnyMetadata: Metadata {
struct AnyMetadata: IRMetadata {
let llvm: LLVMMetadataRef

func asMetadata() -> LLVMMetadataRef {
Expand Down Expand Up @@ -271,7 +271,7 @@ public struct LexicalBlockFileMetadata: DIScope {

/// `LocalVariableMetadata` nodes represent local variables and function
/// parameters in the source language.
public struct LocalVariableMetadata: Metadata {
public struct LocalVariableMetadata: IRMetadata {
internal let llvm: LLVMMetadataRef

public func asMetadata() -> LLVMMetadataRef {
Expand All @@ -284,7 +284,7 @@ public struct LocalVariableMetadata: Metadata {
}

/// `ObjectiveCPropertyMetadata` nodes represent Objective-C property nodes.
public struct ObjectiveCPropertyMetadata: Metadata {
public struct ObjectiveCPropertyMetadata: IRMetadata {
internal let llvm: LLVMMetadataRef

public func asMetadata() -> LLVMMetadataRef {
Expand Down Expand Up @@ -362,7 +362,7 @@ public struct NameSpaceMetadata: DIScope {
///
/// Though DWARF supports hundreds of expressions, LLVM currently implements
/// a very limited subset.
public struct ExpressionMetadata: Metadata {
public struct ExpressionMetadata: IRMetadata {
internal let llvm: LLVMMetadataRef

public func asMetadata() -> LLVMMetadataRef {
Expand Down
6 changes: 3 additions & 3 deletions Sources/LLVM/NamedMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class NamedMetadata {
}

/// Computes the operands of a named metadata node.
public var operands: [Metadata] {
public var operands: [IRMetadata] {
let count = Int(LLVMGetNamedMetadataNumOperands(self.module.llvm, name))
let operands = UnsafeMutablePointer<LLVMValueRef?>.allocate(capacity: count)
LLVMGetNamedMetadataOperands(self.module.llvm, name, operands)

var ops = [Metadata]()
var ops = [IRMetadata]()
ops.reserveCapacity(count)
for i in 0..<count {
guard let rawOperand = operands[i] else {
Expand All @@ -37,7 +37,7 @@ public class NamedMetadata {
}

/// Appends a metadata node as an operand.
public func addOperand(_ op: Metadata) {
public func addOperand(_ op: IRMetadata) {
let metaVal = LLVMMetadataAsValue(self.module.context.llvm, op.asMetadata())
LLVMAddNamedMetadataOperand(self.module.llvm, self.name, metaVal)
}
Expand Down