2017-12-22 21:29:39 -08:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
const c = @import("c.zig");
|
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2018-07-16 17:52:50 -07:00
|
|
|
// we wrap the c module for 3 reasons:
|
|
|
|
// 1. to avoid accidentally calling the non-thread-safe functions
|
|
|
|
// 2. patch up some of the types to remove nullability
|
|
|
|
// 3. some functions have been augmented by zig_llvm.cpp to be more powerful,
|
|
|
|
// such as ZigLLVMTargetMachineEmitToFile
|
|
|
|
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const AttributeIndex = c_uint;
|
|
|
|
pub const Bool = c_int;
|
|
|
|
|
2017-12-22 21:29:39 -08:00
|
|
|
pub const BuilderRef = removeNullability(c.LLVMBuilderRef);
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const ContextRef = removeNullability(c.LLVMContextRef);
|
|
|
|
pub const ModuleRef = removeNullability(c.LLVMModuleRef);
|
|
|
|
pub const ValueRef = removeNullability(c.LLVMValueRef);
|
|
|
|
pub const TypeRef = removeNullability(c.LLVMTypeRef);
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const BasicBlockRef = removeNullability(c.LLVMBasicBlockRef);
|
|
|
|
pub const AttributeRef = removeNullability(c.LLVMAttributeRef);
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const TargetRef = removeNullability(c.LLVMTargetRef);
|
|
|
|
pub const TargetMachineRef = removeNullability(c.LLVMTargetMachineRef);
|
|
|
|
pub const TargetDataRef = removeNullability(c.LLVMTargetDataRef);
|
|
|
|
pub const DIBuilder = c.ZigLLVMDIBuilder;
|
2018-07-14 12:45:15 -07:00
|
|
|
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const ABIAlignmentOfType = c.LLVMABIAlignmentOfType;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const AddAttributeAtIndex = c.LLVMAddAttributeAtIndex;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const AddFunction = c.LLVMAddFunction;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const AddGlobal = c.LLVMAddGlobal;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const AddModuleCodeViewFlag = c.ZigLLVMAddModuleCodeViewFlag;
|
|
|
|
pub const AddModuleDebugInfoFlag = c.ZigLLVMAddModuleDebugInfoFlag;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const ArrayType = c.LLVMArrayType;
|
2018-07-24 17:24:05 -07:00
|
|
|
pub const BuildLoad = c.LLVMBuildLoad;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const ClearCurrentDebugLocation = c.ZigLLVMClearCurrentDebugLocation;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const ConstAllOnes = c.LLVMConstAllOnes;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const ConstArray = c.LLVMConstArray;
|
|
|
|
pub const ConstBitCast = c.LLVMConstBitCast;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const ConstInt = c.LLVMConstInt;
|
2018-07-18 21:08:47 -07:00
|
|
|
pub const ConstIntOfArbitraryPrecision = c.LLVMConstIntOfArbitraryPrecision;
|
|
|
|
pub const ConstNeg = c.LLVMConstNeg;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const ConstNull = c.LLVMConstNull;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const ConstStringInContext = c.LLVMConstStringInContext;
|
|
|
|
pub const ConstStructInContext = c.LLVMConstStructInContext;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const CopyStringRepOfTargetData = c.LLVMCopyStringRepOfTargetData;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const CreateBuilderInContext = c.LLVMCreateBuilderInContext;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const CreateCompileUnit = c.ZigLLVMCreateCompileUnit;
|
|
|
|
pub const CreateDIBuilder = c.ZigLLVMCreateDIBuilder;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const CreateEnumAttribute = c.LLVMCreateEnumAttribute;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const CreateFile = c.ZigLLVMCreateFile;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const CreateStringAttribute = c.LLVMCreateStringAttribute;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const CreateTargetDataLayout = c.LLVMCreateTargetDataLayout;
|
|
|
|
pub const CreateTargetMachine = c.LLVMCreateTargetMachine;
|
|
|
|
pub const DIBuilderFinalize = c.ZigLLVMDIBuilderFinalize;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const DisposeBuilder = c.LLVMDisposeBuilder;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const DisposeDIBuilder = c.ZigLLVMDisposeDIBuilder;
|
|
|
|
pub const DisposeMessage = c.LLVMDisposeMessage;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const DisposeModule = c.LLVMDisposeModule;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const DisposeTargetData = c.LLVMDisposeTargetData;
|
|
|
|
pub const DisposeTargetMachine = c.LLVMDisposeTargetMachine;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const DoubleTypeInContext = c.LLVMDoubleTypeInContext;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const DumpModule = c.LLVMDumpModule;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const FP128TypeInContext = c.LLVMFP128TypeInContext;
|
|
|
|
pub const FloatTypeInContext = c.LLVMFloatTypeInContext;
|
|
|
|
pub const GetEnumAttributeKindForName = c.LLVMGetEnumAttributeKindForName;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const GetHostCPUName = c.ZigLLVMGetHostCPUName;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const GetMDKindIDInContext = c.LLVMGetMDKindIDInContext;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const GetNativeFeatures = c.ZigLLVMGetNativeFeatures;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const GetUndef = c.LLVMGetUndef;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const HalfTypeInContext = c.LLVMHalfTypeInContext;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const InitializeAllAsmParsers = c.LLVMInitializeAllAsmParsers;
|
|
|
|
pub const InitializeAllAsmPrinters = c.LLVMInitializeAllAsmPrinters;
|
|
|
|
pub const InitializeAllTargetInfos = c.LLVMInitializeAllTargetInfos;
|
|
|
|
pub const InitializeAllTargetMCs = c.LLVMInitializeAllTargetMCs;
|
|
|
|
pub const InitializeAllTargets = c.LLVMInitializeAllTargets;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const InsertBasicBlockInContext = c.LLVMInsertBasicBlockInContext;
|
|
|
|
pub const Int128TypeInContext = c.LLVMInt128TypeInContext;
|
|
|
|
pub const Int16TypeInContext = c.LLVMInt16TypeInContext;
|
|
|
|
pub const Int1TypeInContext = c.LLVMInt1TypeInContext;
|
|
|
|
pub const Int32TypeInContext = c.LLVMInt32TypeInContext;
|
|
|
|
pub const Int64TypeInContext = c.LLVMInt64TypeInContext;
|
|
|
|
pub const Int8TypeInContext = c.LLVMInt8TypeInContext;
|
|
|
|
pub const IntPtrTypeForASInContext = c.LLVMIntPtrTypeForASInContext;
|
|
|
|
pub const IntPtrTypeInContext = c.LLVMIntPtrTypeInContext;
|
|
|
|
pub const IntTypeInContext = c.LLVMIntTypeInContext;
|
|
|
|
pub const LabelTypeInContext = c.LLVMLabelTypeInContext;
|
|
|
|
pub const MDNodeInContext = c.LLVMMDNodeInContext;
|
|
|
|
pub const MDStringInContext = c.LLVMMDStringInContext;
|
|
|
|
pub const MetadataTypeInContext = c.LLVMMetadataTypeInContext;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const ModuleCreateWithNameInContext = c.LLVMModuleCreateWithNameInContext;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const PPCFP128TypeInContext = c.LLVMPPCFP128TypeInContext;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const PointerType = c.LLVMPointerType;
|
|
|
|
pub const SetAlignment = c.LLVMSetAlignment;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const SetDataLayout = c.LLVMSetDataLayout;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const SetGlobalConstant = c.LLVMSetGlobalConstant;
|
|
|
|
pub const SetInitializer = c.LLVMSetInitializer;
|
|
|
|
pub const SetLinkage = c.LLVMSetLinkage;
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const SetTarget = c.LLVMSetTarget;
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const SetUnnamedAddr = c.LLVMSetUnnamedAddr;
|
2018-07-24 17:24:05 -07:00
|
|
|
pub const SetVolatile = c.LLVMSetVolatile;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const StructTypeInContext = c.LLVMStructTypeInContext;
|
|
|
|
pub const TokenTypeInContext = c.LLVMTokenTypeInContext;
|
2018-07-14 12:45:15 -07:00
|
|
|
pub const VoidTypeInContext = c.LLVMVoidTypeInContext;
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext;
|
|
|
|
pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext;
|
2018-07-16 17:52:50 -07:00
|
|
|
|
2018-07-24 17:24:05 -07:00
|
|
|
pub const GetElementType = LLVMGetElementType;
|
|
|
|
extern fn LLVMGetElementType(Ty: TypeRef) TypeRef;
|
|
|
|
|
|
|
|
pub const TypeOf = LLVMTypeOf;
|
|
|
|
extern fn LLVMTypeOf(Val: ValueRef) TypeRef;
|
|
|
|
|
|
|
|
pub const BuildStore = LLVMBuildStore;
|
|
|
|
extern fn LLVMBuildStore(arg0: BuilderRef, Val: ValueRef, Ptr: ValueRef) ?ValueRef;
|
|
|
|
|
|
|
|
pub const BuildAlloca = LLVMBuildAlloca;
|
|
|
|
extern fn LLVMBuildAlloca(arg0: BuilderRef, Ty: TypeRef, Name: ?[*]const u8) ?ValueRef;
|
|
|
|
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const ConstInBoundsGEP = LLVMConstInBoundsGEP;
|
|
|
|
pub extern fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, ConstantIndices: [*]ValueRef, NumIndices: c_uint) ?ValueRef;
|
|
|
|
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const GetTargetFromTriple = LLVMGetTargetFromTriple;
|
|
|
|
extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: *TargetRef, ErrorMessage: ?*[*]u8) Bool;
|
2018-07-14 21:04:12 -07:00
|
|
|
|
|
|
|
pub const VerifyModule = LLVMVerifyModule;
|
|
|
|
extern fn LLVMVerifyModule(M: ModuleRef, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool;
|
|
|
|
|
|
|
|
pub const GetInsertBlock = LLVMGetInsertBlock;
|
|
|
|
extern fn LLVMGetInsertBlock(Builder: BuilderRef) BasicBlockRef;
|
2018-07-14 12:45:15 -07:00
|
|
|
|
|
|
|
pub const FunctionType = LLVMFunctionType;
|
|
|
|
extern fn LLVMFunctionType(
|
|
|
|
ReturnType: TypeRef,
|
|
|
|
ParamTypes: [*]TypeRef,
|
|
|
|
ParamCount: c_uint,
|
2018-07-14 21:04:12 -07:00
|
|
|
IsVarArg: Bool,
|
2018-07-14 12:45:15 -07:00
|
|
|
) ?TypeRef;
|
2017-12-22 21:29:39 -08:00
|
|
|
|
2018-07-14 21:04:12 -07:00
|
|
|
pub const GetParam = LLVMGetParam;
|
|
|
|
extern fn LLVMGetParam(Fn: ValueRef, Index: c_uint) ValueRef;
|
|
|
|
|
|
|
|
pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext;
|
|
|
|
extern fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef, Name: [*]const u8) ?BasicBlockRef;
|
|
|
|
|
|
|
|
pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd;
|
|
|
|
extern fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef) void;
|
|
|
|
|
|
|
|
pub const AbortProcessAction = VerifierFailureAction.LLVMAbortProcessAction;
|
|
|
|
pub const PrintMessageAction = VerifierFailureAction.LLVMPrintMessageAction;
|
|
|
|
pub const ReturnStatusAction = VerifierFailureAction.LLVMReturnStatusAction;
|
|
|
|
pub const VerifierFailureAction = c.LLVMVerifierFailureAction;
|
|
|
|
|
2018-07-16 17:52:50 -07:00
|
|
|
pub const CodeGenLevelNone = c.LLVMCodeGenOptLevel.LLVMCodeGenLevelNone;
|
|
|
|
pub const CodeGenLevelLess = c.LLVMCodeGenOptLevel.LLVMCodeGenLevelLess;
|
|
|
|
pub const CodeGenLevelDefault = c.LLVMCodeGenOptLevel.LLVMCodeGenLevelDefault;
|
|
|
|
pub const CodeGenLevelAggressive = c.LLVMCodeGenOptLevel.LLVMCodeGenLevelAggressive;
|
|
|
|
pub const CodeGenOptLevel = c.LLVMCodeGenOptLevel;
|
|
|
|
|
|
|
|
pub const RelocDefault = c.LLVMRelocMode.LLVMRelocDefault;
|
|
|
|
pub const RelocStatic = c.LLVMRelocMode.LLVMRelocStatic;
|
|
|
|
pub const RelocPIC = c.LLVMRelocMode.LLVMRelocPIC;
|
|
|
|
pub const RelocDynamicNoPic = c.LLVMRelocMode.LLVMRelocDynamicNoPic;
|
|
|
|
pub const RelocMode = c.LLVMRelocMode;
|
|
|
|
|
|
|
|
pub const CodeModelDefault = c.LLVMCodeModel.LLVMCodeModelDefault;
|
|
|
|
pub const CodeModelJITDefault = c.LLVMCodeModel.LLVMCodeModelJITDefault;
|
|
|
|
pub const CodeModelSmall = c.LLVMCodeModel.LLVMCodeModelSmall;
|
|
|
|
pub const CodeModelKernel = c.LLVMCodeModel.LLVMCodeModelKernel;
|
|
|
|
pub const CodeModelMedium = c.LLVMCodeModel.LLVMCodeModelMedium;
|
|
|
|
pub const CodeModelLarge = c.LLVMCodeModel.LLVMCodeModelLarge;
|
|
|
|
pub const CodeModel = c.LLVMCodeModel;
|
|
|
|
|
|
|
|
pub const EmitAssembly = EmitOutputType.ZigLLVM_EmitAssembly;
|
|
|
|
pub const EmitBinary = EmitOutputType.ZigLLVM_EmitBinary;
|
|
|
|
pub const EmitLLVMIr = EmitOutputType.ZigLLVM_EmitLLVMIr;
|
|
|
|
pub const EmitOutputType = c.ZigLLVM_EmitOutputType;
|
|
|
|
|
2018-07-22 20:27:58 -07:00
|
|
|
pub const CCallConv = c.LLVMCCallConv;
|
|
|
|
pub const FastCallConv = c.LLVMFastCallConv;
|
|
|
|
pub const ColdCallConv = c.LLVMColdCallConv;
|
|
|
|
pub const WebKitJSCallConv = c.LLVMWebKitJSCallConv;
|
|
|
|
pub const AnyRegCallConv = c.LLVMAnyRegCallConv;
|
|
|
|
pub const X86StdcallCallConv = c.LLVMX86StdcallCallConv;
|
|
|
|
pub const X86FastcallCallConv = c.LLVMX86FastcallCallConv;
|
|
|
|
pub const CallConv = c.LLVMCallConv;
|
|
|
|
|
|
|
|
pub const FnInline = extern enum {
|
|
|
|
Auto,
|
|
|
|
Always,
|
|
|
|
Never,
|
|
|
|
};
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
fn removeNullability(comptime T: type) type {
|
2018-06-09 20:42:14 -07:00
|
|
|
comptime assert(@typeId(T) == builtin.TypeId.Optional);
|
2017-12-22 21:29:39 -08:00
|
|
|
return T.Child;
|
|
|
|
}
|
2018-07-14 21:04:12 -07:00
|
|
|
|
|
|
|
pub const BuildRet = LLVMBuildRet;
|
2018-07-22 20:27:58 -07:00
|
|
|
extern fn LLVMBuildRet(arg0: BuilderRef, V: ?ValueRef) ?ValueRef;
|
2018-07-16 17:52:50 -07:00
|
|
|
|
|
|
|
pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile;
|
|
|
|
extern fn ZigLLVMTargetMachineEmitToFile(
|
|
|
|
targ_machine_ref: TargetMachineRef,
|
|
|
|
module_ref: ModuleRef,
|
|
|
|
filename: [*]const u8,
|
|
|
|
output_type: EmitOutputType,
|
|
|
|
error_message: *[*]u8,
|
|
|
|
is_debug: bool,
|
|
|
|
is_small: bool,
|
|
|
|
) bool;
|
2018-07-22 20:27:58 -07:00
|
|
|
|
|
|
|
pub const BuildCall = ZigLLVMBuildCall;
|
|
|
|
extern fn ZigLLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: [*]ValueRef, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?ValueRef;
|
|
|
|
|
|
|
|
pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage;
|