File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 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 {
5959 return BasicBlock ( llvm: blockRef)
6060 }
6161
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+
6268 /// Returns a sequence of the Instructions that make up this basic block.
6369 public var instructions : AnySequence < Instruction > {
6470 var current = firstInstruction
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ public struct Instruction: IRValue {
3333 return Instruction ( llvm: val)
3434 }
3535
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+
3643 /// Retrieves the first use of this instruction.
3744 public var firstUse : Use ? {
3845 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 {
6969 }
7070 }
7171
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+
7293 /// Retrieves the underlying LLVM type object.
7394 public func asLLVM( ) -> LLVMTypeRef {
7495 return llvm
You can’t perform that action at this time.
0 commit comments