File tree 3 files changed +34
-0
lines changed
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ public struct BasicBlock: IRValue {
59
59
return BasicBlock ( llvm: blockRef)
60
60
}
61
61
62
+ /// Returns the basic block before this basic block, if it exists.
63
+ public func previous( ) -> BasicBlock ? {
64
+ guard let blockRef = LLVMGetPreviousBasicBlock ( llvm) else { return nil }
65
+ return BasicBlock ( llvm: blockRef)
66
+ }
67
+
62
68
/// Returns a sequence of the Instructions that make up this basic block.
63
69
public var instructions : AnySequence < Instruction > {
64
70
var current = firstInstruction
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ public struct Instruction: IRValue {
33
33
return Instruction ( llvm: val)
34
34
}
35
35
36
+ /// Retrieves the parent basic block that contains this instruction, if it
37
+ /// exists.
38
+ public var parentBlock : BasicBlock ? {
39
+ guard let parent = LLVMGetInstructionParent ( self . llvm) else { return nil }
40
+ return BasicBlock ( llvm: parent)
41
+ }
42
+
36
43
/// Retrieves the first use of this instruction.
37
44
public var firstUse : Use ? {
38
45
guard let use = LLVMGetFirstUse ( llvm) else { return nil }
Original file line number Diff line number Diff line change @@ -69,6 +69,27 @@ public struct StructType: IRType {
69
69
}
70
70
}
71
71
72
+ /// Retrieves the name associated with this structure type, or the empty
73
+ /// string if this type is unnamed.
74
+ public var name : String {
75
+ guard let sname = LLVMGetStructName ( self . llvm) else { return " " }
76
+ return String ( cString: sname)
77
+ }
78
+
79
+ /// Retrieves the element types associated with this structure type.
80
+ public var elementTypes : [ IRType ] {
81
+ var params = [ IRType] ( )
82
+ let count = Int ( LLVMCountStructElementTypes ( self . llvm) )
83
+ let paramsPtr = UnsafeMutablePointer< LLVMTypeRef?> . allocate( capacity: count)
84
+ defer { free ( paramsPtr) }
85
+ LLVMGetStructElementTypes ( self . llvm, paramsPtr)
86
+ for i in 0 ..< count {
87
+ let ty = paramsPtr [ i] !
88
+ params. append ( convertType ( ty) )
89
+ }
90
+ return params
91
+ }
92
+
72
93
/// Retrieves the underlying LLVM type object.
73
94
public func asLLVM( ) -> LLVMTypeRef {
74
95
return llvm
You can’t perform that action at this time.
0 commit comments