private static Type GetMsilType(LLVMSharp.API.Type typeRef) { switch (typeRef) { case IntegerType t: var intTypeWidth = t.BitWidth; switch (intTypeWidth) { case 1: case 32: return(typeof(int)); case 8: return(typeof(byte)); default: throw new NotImplementedException(); } case VoidType _: return(typeof(void)); case PointerType t: var elementType = GetMsilType(t.ElementType); return(elementType.IsArray ? elementType : elementType.MakeArrayType()); case ArrayType t: return(GetMsilType(t.ElementType).MakeArrayType()); default: throw new NotImplementedException(); } }
public static VectorType Get(Type elementType, uint numElements) => LLVM.VectorType(elementType.Unwrap(), numElements).WrapAs <VectorType>();
public static bool IsValidElementType(Type type) => type is IntegerType || type is FPType || type is PointerType;
public static ConstantExpr GetNull(Type type) => LLVM.ConstNull(type.MustHaveConstants().Unwrap()).WrapAs <ConstantExpr>();
public static ConstantExpr GetSizeOf(Type type) => LLVM.SizeOf(type.MustBeSized().Unwrap()).WrapAs <ConstantExpr>();
public static ConstantExpr GetInlineAsm(Type ty, string asmString, string constraints, bool hasSideEffects, bool isAlignStack) => LLVM.ConstInlineAsm(ty.MustHaveConstants().Unwrap(), asmString, constraints, hasSideEffects, isAlignStack).WrapAs <ConstantExpr>();
public static ConstantExpr GetFPCast(Constant constantVal, Type toType) => LLVM.ConstFPCast(constantVal.Unwrap(), toType.MustHaveConstants().Unwrap()).WrapAs <ConstantExpr>();
public static ConstantExpr GetIntCast(Constant constantVal, Type toType, bool isSigned) => LLVM.ConstIntCast(constantVal.Unwrap(), toType.MustHaveConstants().Unwrap(), isSigned).WrapAs <ConstantExpr>();
public static ConstantFP Get(Type type, string text) => LLVM.ConstRealOfString(type.Unwrap(), text).WrapAs <ConstantFP>();