Skip to content

Commit 1a36aba

Browse files
committed
Added LLVMOpcode. Changed LLVMTypeKind
1 parent 6759dc7 commit 1a36aba

File tree

1 file changed

+151
-73
lines changed

1 file changed

+151
-73
lines changed

llvm-api/LLVM/Core/Types/Types.swift

Lines changed: 151 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public extension TypeRef {
9696
var getConcreteTypeInContext: TypeRef {
9797
let ty = Types(typeRef: self)
9898
switch ty.getTypeKind {
99-
case .integerTypeKind:
99+
case .IntegerTypeKind:
100100
let intWidth = IntType.getIntTypeWidth(ty: self)
101101
return switch intWidth {
102102
case 1: Int1Type(typeRef: self, context: ty.getTypeContext)
@@ -107,33 +107,33 @@ public extension TypeRef {
107107
case 128: Int128Type(typeRef: self, context: ty.getTypeContext)
108108
default: IntType(bits: intWidth, in: ty.getTypeContext)
109109
}
110-
case .voidTypeKind: return VoidType(typeRef: self, context: ty.getTypeContext)
111-
case .halfTypeKind: return HalfType(typeRef: self, context: ty.getTypeContext)
112-
case .floatTypeKind: return FloatType(typeRef: self, context: ty.getTypeContext)
113-
case .doubleTypeKind: return DoubleType(typeRef: self, context: ty.getTypeContext)
114-
case .x86_FP80TypeKind: return X86FP80Type(typeRef: self, context: ty.getTypeContext)
115-
case .fp128TypeKind: return FP128Type(typeRef: self, context: ty.getTypeContext)
116-
case .ppc_FP128TypeKind: return PPCFP128Type(typeRef: self, context: ty.getTypeContext)
117-
case .labelTypeKind: return LabelType(typeRef: self, context: ty.getTypeContext)
118-
case .functionTypeKind:
110+
case .VoidTypeKind: return VoidType(typeRef: self, context: ty.getTypeContext)
111+
case .HalfTypeKind: return HalfType(typeRef: self, context: ty.getTypeContext)
112+
case .FloatTypeKind: return FloatType(typeRef: self, context: ty.getTypeContext)
113+
case .DoubleTypeKind: return DoubleType(typeRef: self, context: ty.getTypeContext)
114+
case .X86_FP80TypeKind: return X86FP80Type(typeRef: self, context: ty.getTypeContext)
115+
case .FP128TypeKind: return FP128Type(typeRef: self, context: ty.getTypeContext)
116+
case .PPC_FP128TypeKind: return PPCFP128Type(typeRef: self, context: ty.getTypeContext)
117+
case .LabelTypeKind: return LabelType(typeRef: self, context: ty.getTypeContext)
118+
case .FunctionTypeKind:
119119
let paramTypes = FunctionType.getParamTypes(funcType: self)
120120
let returnTy = FunctionType.getReturnType(funcType: self)
121121
let isVarArg = FunctionType.isFunctionVarArg(funcType: self)
122122
return FunctionType(returnType: returnTy, parameterTypes: paramTypes, isVariadic: isVarArg)
123-
case .structTypeKind: return StructType(typeRef: self)
124-
case .arrayTypeKind: return ArrayType(typeRef: self)
125-
case .pointerTypeKind:
123+
case .StructTypeKind: return StructType(typeRef: self)
124+
case .ArrayTypeKind: return ArrayType(typeRef: self)
125+
case .PointerTypeKind:
126126
let pointee = PointerType.getElementType(typeRef: self)!
127127
let addressSpace = PointerType.getPointerAddressSpace(typeRef: self)
128128
return PointerType(pointee: pointee, addressSpace: addressSpace)
129-
case .vectorTypeKind: return VectorType(typeRef: self)
130-
case .metadataTypeKind: return MetadataType(typeRef: self, context: ty.getTypeContext)
131-
case .x86_MMXTypeKind: return X86MMXType(typeRef: self, context: ty.getTypeContext)
132-
case .tokenTypeKind: return TokenType(typeRef: self, context: ty.getTypeContext)
133-
case .scalableVectorTypeKind: return ScalableVectorType(typeRef: self)
134-
case .bFloatTypeKind: return BFloatType(typeRef: self, context: ty.getTypeContext)
135-
case .x86_AMXTypeKind: return X86AMXType(typeRef: self, context: ty.getTypeContext)
136-
case .targetExtTypeKind: return TargetExtType(typeRef: self, context: ty.getTypeContext)
129+
case .VectorTypeKind: return VectorType(typeRef: self)
130+
case .MetadataTypeKind: return MetadataType(typeRef: self, context: ty.getTypeContext)
131+
case .X86_MMXTypeKind: return X86MMXType(typeRef: self, context: ty.getTypeContext)
132+
case .TokenTypeKind: return TokenType(typeRef: self, context: ty.getTypeContext)
133+
case .ScalableVectorTypeKind: return ScalableVectorType(typeRef: self)
134+
case .BFloatTypeKind: return BFloatType(typeRef: self, context: ty.getTypeContext)
135+
case .X86_AMXTypeKind: return X86AMXType(typeRef: self, context: ty.getTypeContext)
136+
case .TargetExtTypeKind: return TargetExtType(typeRef: self, context: ty.getTypeContext)
137137
}
138138
}
139139
}
@@ -155,57 +155,6 @@ public protocol ValueRef {
155155
var valueRef: LLVMValueRef { get }
156156
}
157157

158-
public enum TypeKind {
159-
case voidTypeKind /** < type with no size */
160-
case halfTypeKind /** < 16 bit floating point type */
161-
case floatTypeKind /** < 32 bit floating point type */
162-
case doubleTypeKind /** < 64 bit floating point type */
163-
case x86_FP80TypeKind /** < 80 bit floating point type (X87) */
164-
case fp128TypeKind /** < 128 bit floating point type (112-bit mantissa) */
165-
case ppc_FP128TypeKind /** < 128 bit floating point type (two 64-bits) */
166-
case labelTypeKind /** < Labels */
167-
case integerTypeKind /** < Arbitrary bit width integers */
168-
case functionTypeKind /** < Functions */
169-
case structTypeKind /** < Structures */
170-
case arrayTypeKind /** < Arrays */
171-
case pointerTypeKind /** < Pointers */
172-
case vectorTypeKind /** < Fixed width SIMD vector type */
173-
case metadataTypeKind /** < Metadata */
174-
case x86_MMXTypeKind /** < X86 MMX */
175-
case tokenTypeKind /** < Tokens */
176-
case scalableVectorTypeKind /** < Scalable SIMD vector type */
177-
case bFloatTypeKind /** < 16 bit brain floating point type */
178-
case x86_AMXTypeKind /** < X86 AMX */
179-
case targetExtTypeKind /** < Target extension type */
180-
181-
public init?(ty: LLVMTypeKind) {
182-
switch ty {
183-
case LLVMVoidTypeKind: self = .voidTypeKind
184-
case LLVMHalfTypeKind: self = .halfTypeKind
185-
case LLVMFloatTypeKind: self = .floatTypeKind
186-
case LLVMDoubleTypeKind: self = .doubleTypeKind
187-
case LLVMX86_FP80TypeKind: self = .x86_FP80TypeKind
188-
case LLVMFP128TypeKind: self = .fp128TypeKind
189-
case LLVMPPC_FP128TypeKind: self = .ppc_FP128TypeKind
190-
case LLVMLabelTypeKind: self = .labelTypeKind
191-
case LLVMIntegerTypeKind: self = .integerTypeKind
192-
case LLVMFunctionTypeKind: self = .functionTypeKind
193-
case LLVMStructTypeKind: self = .structTypeKind
194-
case LLVMArrayTypeKind: self = .arrayTypeKind
195-
case LLVMPointerTypeKind: self = .pointerTypeKind
196-
case LLVMVectorTypeKind: self = .vectorTypeKind
197-
case LLVMMetadataTypeKind: self = .metadataTypeKind
198-
case LLVMX86_MMXTypeKind: self = .x86_MMXTypeKind
199-
case LLVMTokenTypeKind: self = .tokenTypeKind
200-
case LLVMScalableVectorTypeKind: self = .scalableVectorTypeKind
201-
case LLVMBFloatTypeKind: self = .bFloatTypeKind
202-
case LLVMX86_AMXTypeKind: self = .x86_AMXTypeKind
203-
case LLVMTargetExtTypeKind: self = .targetExtTypeKind
204-
default: return nil
205-
}
206-
}
207-
}
208-
209158
public struct Types: TypeRef {
210159
let llvm: LLVMTypeRef
211160

@@ -224,7 +173,7 @@ public struct Types: TypeRef {
224173

225174
/// Obtain the enumerated type of a Type instance.
226175
public var getTypeKind: TypeKind {
227-
TypeKind(ty: LLVMGetTypeKind(typeRef))!
176+
TypeKind(from: LLVMGetTypeKind(typeRef))!
228177
}
229178

230179
/// Whether the type has a known size.
@@ -253,3 +202,132 @@ public extension Bool {
253202
/// Get `LLVM` representation for Boolean type
254203
var llvm: Int32 { self ? 1 : 0 }
255204
}
205+
206+
/// Declarations for `LLVMOpcode`
207+
public enum Opcode: UInt32 {
208+
/* Terminator Instructions */
209+
case Ret = 1
210+
case Br = 2
211+
case Switch = 3
212+
case IndirectBr = 4
213+
case Invoke = 5
214+
/* removed 6 due to API changes */
215+
case Unreachable = 7
216+
case CallBr = 67
217+
218+
/* Standard Unary Operators */
219+
case FNeg = 66
220+
221+
/* Standard Binary Operators */
222+
case Add = 8
223+
case FAdd = 9
224+
case Sub = 10
225+
case FSub = 11
226+
case Mul = 12
227+
case FMul = 13
228+
case UDiv = 14
229+
case SDiv = 15
230+
case FDiv = 16
231+
case URem = 17
232+
case SRem = 18
233+
case FRem = 19
234+
235+
/* Logical Operators */
236+
case Shl = 20
237+
case LShr = 21
238+
case AShr = 22
239+
case And = 23
240+
case Or = 24
241+
case Xor = 25
242+
243+
/* Memory Operators */
244+
case Alloca = 26
245+
case Load = 27
246+
case Store = 28
247+
case GetElementPtr = 29
248+
249+
/* Cast Operators */
250+
case Trunc = 30
251+
case ZExt = 31
252+
case SExt = 32
253+
case FPToUI = 33
254+
case FPToSI = 34
255+
case UIToFP = 35
256+
case SIToFP = 36
257+
case FPTrunc = 37
258+
case FPExt = 38
259+
case PtrToInt = 39
260+
case IntToPtr = 40
261+
case BitCast = 41
262+
case AddrSpaceCast = 60
263+
264+
/* Other Operators */
265+
case ICmp = 42
266+
case FCmp = 43
267+
case PHI = 44
268+
case Call = 45
269+
case Select = 46
270+
case UserOp1 = 47
271+
case UserOp2 = 48
272+
case AArg = 49
273+
case ExtractElement = 50
274+
case InsertElement = 51
275+
case ShuffleVector = 52
276+
case ExtractValue = 53
277+
case InsertValue = 54
278+
case Freeze = 68
279+
280+
/* Atomic operators */
281+
case Fence = 55
282+
case AtomicCmpXchg = 56
283+
case AtomicRMW = 57
284+
285+
/* Exception Handling Operators */
286+
case Resume = 58
287+
case LandingPad = 59
288+
case CleanupRet = 61
289+
case CatchRet = 62
290+
case CatchPad = 63
291+
case CleanupPad = 64
292+
case CatchSwitch = 65
293+
294+
/// Init enum from `LLVMOpcode`
295+
public init?(from val: LLVMOpcode) {
296+
self.init(rawValue: val.rawValue)
297+
}
298+
299+
/// Get `LLVMOpcode` from current type
300+
public var llvm: LLVMOpcode { LLVMOpcode(rawValue: rawValue) }
301+
}
302+
303+
public enum TypeKind: UInt32 {
304+
case VoidTypeKind = 0 /** < type with no size */
305+
case HalfTypeKind /** < 16 bit floating point type */
306+
case FloatTypeKind /** < 32 bit floating point type */
307+
case DoubleTypeKind /** < 64 bit floating point type */
308+
case X86_FP80TypeKind /** < 80 bit floating point type (X87) */
309+
case FP128TypeKind /** < 128 bit floating point type (112-bit mantissa) */
310+
case PPC_FP128TypeKind /** < 128 bit floating point type (two 64-bits) */
311+
case LabelTypeKind /** < Labels */
312+
case IntegerTypeKind /** < Arbitrary bit width integers */
313+
case FunctionTypeKind /** < Functions */
314+
case StructTypeKind /** < Structures */
315+
case ArrayTypeKind /** < Arrays */
316+
case PointerTypeKind /** < Pointers */
317+
case VectorTypeKind /** < Fixed width SIMD vector type */
318+
case MetadataTypeKind /** < Metadata */
319+
case X86_MMXTypeKind /** < X86 MMX */
320+
case TokenTypeKind /** < Tokens */
321+
case ScalableVectorTypeKind /** < Scalable SIMD vector type */
322+
case BFloatTypeKind /** < 16 bit brain floating point type */
323+
case X86_AMXTypeKind /** < X86 AMX */
324+
case TargetExtTypeKind /** < Target extension type */
325+
326+
/// Init enum from `LLVMTypeKind`
327+
public init?(from ty: LLVMTypeKind) {
328+
self.init(rawValue: ty.rawValue)
329+
}
330+
331+
/// Get `LLVMTypeKind` from current type
332+
public var llvm: LLVMTypeKind { LLVMTypeKind(rawValue: rawValue) }
333+
}

0 commit comments

Comments
 (0)