| ... | ... | @@ -7,85 +7,85 @@ const assert = std.debug.assert; |
| 7 | 7 | const LLVMBool = bool; |
| 8 | 8 | pub const LLVMAttributeIndex = c_uint; |
| 9 | 9 | |
| 10 | | pub const ValueRef = opaque { |
| 10 | pub const Value = opaque { |
| 11 | 11 | pub const addAttributeAtIndex = LLVMAddAttributeAtIndex; |
| 12 | | extern fn LLVMAddAttributeAtIndex(*const ValueRef, Idx: LLVMAttributeIndex, A: *const AttributeRef) void; |
| 12 | extern fn LLVMAddAttributeAtIndex(*const Value, Idx: LLVMAttributeIndex, A: *const Attribute) void; |
| 13 | 13 | |
| 14 | 14 | pub const appendBasicBlock = LLVMAppendBasicBlock; |
| 15 | | extern fn LLVMAppendBasicBlock(Fn: *const ValueRef, Name: [*:0]const u8) *const BasicBlockRef; |
| 15 | extern fn LLVMAppendBasicBlock(Fn: *const Value, Name: [*:0]const u8) *const BasicBlock; |
| 16 | 16 | |
| 17 | 17 | pub const getFirstBasicBlock = LLVMGetFirstBasicBlock; |
| 18 | | extern fn LLVMGetFirstBasicBlock(Fn: *const ValueRef) ?*const BasicBlockRef; |
| 18 | extern fn LLVMGetFirstBasicBlock(Fn: *const Value) ?*const BasicBlock; |
| 19 | 19 | |
| 20 | 20 | // Helper functions |
| 21 | 21 | // TODO: Do we want to put these functions here? It allows for convienient function calls |
| 22 | | // on ValueRef: llvm_fn.addFnAttr("noreturn") |
| 23 | | fn addAttr(val: *const ValueRef, index: LLVMAttributeIndex, name: []const u8) void { |
| 22 | // on Value: llvm_fn.addFnAttr("noreturn") |
| 23 | fn addAttr(val: *const Value, index: LLVMAttributeIndex, name: []const u8) void { |
| 24 | 24 | const kind_id = getEnumAttributeKindForName(name.ptr, name.len); |
| 25 | 25 | assert(kind_id != 0); |
| 26 | | const llvm_attr = ContextRef.getGlobal().createEnumAttribute(kind_id, 0); |
| 26 | const llvm_attr = Context.getGlobal().createEnumAttribute(kind_id, 0); |
| 27 | 27 | val.addAttributeAtIndex(index, llvm_attr); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | | pub fn addFnAttr(val: *const ValueRef, attr_name: []const u8) void { |
| 30 | pub fn addFnAttr(val: *const Value, attr_name: []const u8) void { |
| 31 | 31 | // TODO: improve this API, `addAttr(-1, attr_name)` |
| 32 | 32 | val.addAttr(std.math.maxInt(LLVMAttributeIndex), attr_name); |
| 33 | 33 | } |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | | pub const TypeRef = opaque { |
| 36 | pub const Type = opaque { |
| 37 | 37 | pub const functionType = LLVMFunctionType; |
| 38 | | extern fn LLVMFunctionType(ReturnType: *const TypeRef, ParamTypes: ?[*]*const TypeRef, ParamCount: c_uint, IsVarArg: LLVMBool) *const TypeRef; |
| 38 | extern fn LLVMFunctionType(ReturnType: *const Type, ParamTypes: ?[*]*const Type, ParamCount: c_uint, IsVarArg: LLVMBool) *const Type; |
| 39 | 39 | |
| 40 | 40 | pub const constNull = LLVMConstNull; |
| 41 | | extern fn LLVMConstNull(Ty: *const TypeRef) *const ValueRef; |
| 41 | extern fn LLVMConstNull(Ty: *const Type) *const Value; |
| 42 | 42 | |
| 43 | 43 | pub const constAllOnes = LLVMConstAllOnes; |
| 44 | | extern fn LLVMConstAllOnes(Ty: *const TypeRef) *const ValueRef; |
| 44 | extern fn LLVMConstAllOnes(Ty: *const Type) *const Value; |
| 45 | 45 | |
| 46 | 46 | pub const constInt = LLVMConstInt; |
| 47 | | extern fn LLVMConstInt(IntTy: *const TypeRef, N: c_ulonglong, SignExtend: LLVMBool) *const ValueRef; |
| 47 | extern fn LLVMConstInt(IntTy: *const Type, N: c_ulonglong, SignExtend: LLVMBool) *const Value; |
| 48 | 48 | |
| 49 | 49 | pub const constArray = LLVMConstArray; |
| 50 | | extern fn LLVMConstArray(ElementTy: *const TypeRef, ConstantVals: ?[*]*const ValueRef, Length: c_uint) *const ValueRef; |
| 50 | extern fn LLVMConstArray(ElementTy: *const Type, ConstantVals: ?[*]*const Value, Length: c_uint) *const Value; |
| 51 | 51 | |
| 52 | 52 | pub const getUndef = LLVMGetUndef; |
| 53 | | extern fn LLVMGetUndef(Ty: *const TypeRef) *const ValueRef; |
| 53 | extern fn LLVMGetUndef(Ty: *const Type) *const Value; |
| 54 | 54 | |
| 55 | 55 | pub const pointerType = LLVMPointerType; |
| 56 | | extern fn LLVMPointerType(ElementType: *const TypeRef, AddressSpace: c_uint) *const TypeRef; |
| 56 | extern fn LLVMPointerType(ElementType: *const Type, AddressSpace: c_uint) *const Type; |
| 57 | 57 | |
| 58 | 58 | pub const arrayType = LLVMArrayType; |
| 59 | | extern fn LLVMArrayType(ElementType: *const TypeRef, ElementCount: c_uint) *const TypeRef; |
| 59 | extern fn LLVMArrayType(ElementType: *const Type, ElementCount: c_uint) *const Type; |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | | pub const ModuleRef = opaque { |
| 62 | pub const Module = opaque { |
| 63 | 63 | pub const createWithName = LLVMModuleCreateWithName; |
| 64 | | extern fn LLVMModuleCreateWithName(ModuleID: [*:0]const u8) *const ModuleRef; |
| 64 | extern fn LLVMModuleCreateWithName(ModuleID: [*:0]const u8) *const Module; |
| 65 | 65 | |
| 66 | 66 | pub const disposeModule = LLVMDisposeModule; |
| 67 | | extern fn LLVMDisposeModule(*const ModuleRef) void; |
| 67 | extern fn LLVMDisposeModule(*const Module) void; |
| 68 | 68 | |
| 69 | 69 | pub const verifyModule = LLVMVerifyModule; |
| 70 | | extern fn LLVMVerifyModule(*const ModuleRef, Action: VerifierFailureAction, OutMessage: *[*:0]const u8) LLVMBool; |
| 70 | extern fn LLVMVerifyModule(*const Module, Action: VerifierFailureAction, OutMessage: *[*:0]const u8) LLVMBool; |
| 71 | 71 | |
| 72 | 72 | pub const addFunction = LLVMAddFunction; |
| 73 | | extern fn LLVMAddFunction(*const ModuleRef, Name: [*:0]const u8, FunctionTy: *const TypeRef) *const ValueRef; |
| 73 | extern fn LLVMAddFunction(*const Module, Name: [*:0]const u8, FunctionTy: *const Type) *const Value; |
| 74 | 74 | |
| 75 | 75 | pub const getNamedFunction = LLVMGetNamedFunction; |
| 76 | | extern fn LLVMGetNamedFunction(*const ModuleRef, Name: [*:0]const u8) ?*const ValueRef; |
| 76 | extern fn LLVMGetNamedFunction(*const Module, Name: [*:0]const u8) ?*const Value; |
| 77 | 77 | |
| 78 | 78 | pub const getIntrinsicDeclaration = LLVMGetIntrinsicDeclaration; |
| 79 | | extern fn LLVMGetIntrinsicDeclaration(Mod: *const ModuleRef, ID: c_uint, ParamTypes: ?[*]*const TypeRef, ParamCount: usize) *const ValueRef; |
| 79 | extern fn LLVMGetIntrinsicDeclaration(Mod: *const Module, ID: c_uint, ParamTypes: ?[*]*const Type, ParamCount: usize) *const Value; |
| 80 | 80 | |
| 81 | 81 | pub const printToString = LLVMPrintModuleToString; |
| 82 | | extern fn LLVMPrintModuleToString(*const ModuleRef) [*:0]const u8; |
| 82 | extern fn LLVMPrintModuleToString(*const Module) [*:0]const u8; |
| 83 | 83 | |
| 84 | 84 | pub const addGlobal = LLVMAddGlobal; |
| 85 | | extern fn LLVMAddGlobal(M: *const ModuleRef, Ty: *const TypeRef, Name: [*:0]const u8) *const ValueRef; |
| 85 | extern fn LLVMAddGlobal(M: *const Module, Ty: *const Type, Name: [*:0]const u8) *const Value; |
| 86 | 86 | |
| 87 | 87 | pub const getNamedGlobal = LLVMGetNamedGlobal; |
| 88 | | extern fn LLVMGetNamedGlobal(M: *const ModuleRef, Name: [*:0]const u8) ?*const ValueRef; |
| 88 | extern fn LLVMGetNamedGlobal(M: *const Module, Name: [*:0]const u8) ?*const Value; |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | pub const lookupIntrinsicID = LLVMLookupIntrinsicID; |
| ... | ... | @@ -101,120 +101,120 @@ pub const VerifierFailureAction = extern enum { |
| 101 | 101 | }; |
| 102 | 102 | |
| 103 | 103 | pub const constNeg = LLVMConstNeg; |
| 104 | | extern fn LLVMConstNeg(ConstantVal: *const ValueRef) *const ValueRef; |
| 104 | extern fn LLVMConstNeg(ConstantVal: *const Value) *const Value; |
| 105 | 105 | |
| 106 | 106 | pub const constString = LLVMConstString; |
| 107 | | extern fn LLVMConstString(Str: [*]const u8, Length: c_uint, DontNullTerminate: LLVMBool) *const ValueRef; |
| 107 | extern fn LLVMConstString(Str: [*]const u8, Length: c_uint, DontNullTerminate: LLVMBool) *const Value; |
| 108 | 108 | |
| 109 | 109 | pub const setInitializer = LLVMSetInitializer; |
| 110 | | extern fn LLVMSetInitializer(GlobalVar: *const ValueRef, ConstantVal: *const ValueRef) void; |
| 110 | extern fn LLVMSetInitializer(GlobalVar: *const Value, ConstantVal: *const Value) void; |
| 111 | 111 | |
| 112 | 112 | pub const voidType = LLVMVoidType; |
| 113 | | extern fn LLVMVoidType() *const TypeRef; |
| 113 | extern fn LLVMVoidType() *const Type; |
| 114 | 114 | |
| 115 | 115 | pub const getParam = LLVMGetParam; |
| 116 | | extern fn LLVMGetParam(Fn: *const ValueRef, Index: c_uint) *const ValueRef; |
| 116 | extern fn LLVMGetParam(Fn: *const Value, Index: c_uint) *const Value; |
| 117 | 117 | |
| 118 | 118 | pub const getEnumAttributeKindForName = LLVMGetEnumAttributeKindForName; |
| 119 | 119 | extern fn LLVMGetEnumAttributeKindForName(Name: [*]const u8, SLen: usize) c_uint; |
| 120 | 120 | |
| 121 | | pub const AttributeRef = opaque {}; |
| 121 | pub const Attribute = opaque {}; |
| 122 | 122 | |
| 123 | | pub const ContextRef = opaque { |
| 123 | pub const Context = opaque { |
| 124 | 124 | pub const createEnumAttribute = LLVMCreateEnumAttribute; |
| 125 | | extern fn LLVMCreateEnumAttribute(*const ContextRef, KindID: c_uint, Val: u64) *const AttributeRef; |
| 125 | extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute; |
| 126 | 126 | |
| 127 | 127 | pub const getGlobal = LLVMGetGlobalContext; |
| 128 | | extern fn LLVMGetGlobalContext() *const ContextRef; |
| 128 | extern fn LLVMGetGlobalContext() *const Context; |
| 129 | 129 | }; |
| 130 | 130 | |
| 131 | 131 | pub const intType = LLVMIntType; |
| 132 | | extern fn LLVMIntType(NumBits: c_uint) *const TypeRef; |
| 132 | extern fn LLVMIntType(NumBits: c_uint) *const Type; |
| 133 | 133 | |
| 134 | | pub const BuilderRef = opaque { |
| 134 | pub const Builder = opaque { |
| 135 | 135 | pub const createBuilder = LLVMCreateBuilder; |
| 136 | | extern fn LLVMCreateBuilder() *const BuilderRef; |
| 136 | extern fn LLVMCreateBuilder() *const Builder; |
| 137 | 137 | |
| 138 | 138 | pub const disposeBuilder = LLVMDisposeBuilder; |
| 139 | | extern fn LLVMDisposeBuilder(Builder: *const BuilderRef) void; |
| 139 | extern fn LLVMDisposeBuilder(Builder: *const Builder) void; |
| 140 | 140 | |
| 141 | 141 | pub const positionBuilderAtEnd = LLVMPositionBuilderAtEnd; |
| 142 | | extern fn LLVMPositionBuilderAtEnd(Builder: *const BuilderRef, Block: *const BasicBlockRef) void; |
| 142 | extern fn LLVMPositionBuilderAtEnd(Builder: *const Builder, Block: *const BasicBlock) void; |
| 143 | 143 | |
| 144 | 144 | pub const getInsertBlock = LLVMGetInsertBlock; |
| 145 | | extern fn LLVMGetInsertBlock(Builder: *const BuilderRef) *const BasicBlockRef; |
| 145 | extern fn LLVMGetInsertBlock(Builder: *const Builder) *const BasicBlock; |
| 146 | 146 | |
| 147 | 147 | pub const buildCall = LLVMBuildCall; |
| 148 | | extern fn LLVMBuildCall(*const BuilderRef, Fn: *const ValueRef, Args: ?[*]*const ValueRef, NumArgs: c_uint, Name: [*:0]const u8) *const ValueRef; |
| 148 | extern fn LLVMBuildCall(*const Builder, Fn: *const Value, Args: ?[*]*const Value, NumArgs: c_uint, Name: [*:0]const u8) *const Value; |
| 149 | 149 | |
| 150 | 150 | pub const buildCall2 = LLVMBuildCall2; |
| 151 | | extern fn LLVMBuildCall2(*const BuilderRef, *const TypeRef, Fn: *const ValueRef, Args: [*]*const ValueRef, NumArgs: c_uint, Name: [*:0]const u8) *const ValueRef; |
| 151 | extern fn LLVMBuildCall2(*const Builder, *const Type, Fn: *const Value, Args: [*]*const Value, NumArgs: c_uint, Name: [*:0]const u8) *const Value; |
| 152 | 152 | |
| 153 | 153 | pub const buildRetVoid = LLVMBuildRetVoid; |
| 154 | | extern fn LLVMBuildRetVoid(*const BuilderRef) *const ValueRef; |
| 154 | extern fn LLVMBuildRetVoid(*const Builder) *const Value; |
| 155 | 155 | |
| 156 | 156 | pub const buildRet = LLVMBuildRet; |
| 157 | | extern fn LLVMBuildRet(*const BuilderRef, V: *const ValueRef) *const ValueRef; |
| 157 | extern fn LLVMBuildRet(*const Builder, V: *const Value) *const Value; |
| 158 | 158 | |
| 159 | 159 | pub const buildUnreachable = LLVMBuildUnreachable; |
| 160 | | extern fn LLVMBuildUnreachable(*const BuilderRef) *const ValueRef; |
| 160 | extern fn LLVMBuildUnreachable(*const Builder) *const Value; |
| 161 | 161 | |
| 162 | 162 | pub const buildAlloca = LLVMBuildAlloca; |
| 163 | | extern fn LLVMBuildAlloca(*const BuilderRef, Ty: *const TypeRef, Name: [*:0]const u8) *const ValueRef; |
| 163 | extern fn LLVMBuildAlloca(*const Builder, Ty: *const Type, Name: [*:0]const u8) *const Value; |
| 164 | 164 | |
| 165 | 165 | pub const buildStore = LLVMBuildStore; |
| 166 | | extern fn LLVMBuildStore(*const BuilderRef, Val: *const ValueRef, Ptr: *const ValueRef) *const ValueRef; |
| 166 | extern fn LLVMBuildStore(*const Builder, Val: *const Value, Ptr: *const Value) *const Value; |
| 167 | 167 | |
| 168 | 168 | pub const buildLoad = LLVMBuildLoad; |
| 169 | | extern fn LLVMBuildLoad(*const BuilderRef, PointerVal: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 169 | extern fn LLVMBuildLoad(*const Builder, PointerVal: *const Value, Name: [*:0]const u8) *const Value; |
| 170 | 170 | |
| 171 | 171 | pub const buildNot = LLVMBuildNot; |
| 172 | | extern fn LLVMBuildNot(*const BuilderRef, V: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 172 | extern fn LLVMBuildNot(*const Builder, V: *const Value, Name: [*:0]const u8) *const Value; |
| 173 | 173 | |
| 174 | 174 | pub const buildNSWAdd = LLVMBuildNSWAdd; |
| 175 | | extern fn LLVMBuildNSWAdd(*const BuilderRef, LHS: *const ValueRef, RHS: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 175 | extern fn LLVMBuildNSWAdd(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; |
| 176 | 176 | |
| 177 | 177 | pub const buildNUWAdd = LLVMBuildNUWAdd; |
| 178 | | extern fn LLVMBuildNUWAdd(*const BuilderRef, LHS: *const ValueRef, RHS: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 178 | extern fn LLVMBuildNUWAdd(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; |
| 179 | 179 | |
| 180 | 180 | pub const buildNSWSub = LLVMBuildNSWSub; |
| 181 | | extern fn LLVMBuildNSWSub(*const BuilderRef, LHS: *const ValueRef, RHS: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 181 | extern fn LLVMBuildNSWSub(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; |
| 182 | 182 | |
| 183 | 183 | pub const buildNUWSub = LLVMBuildNUWSub; |
| 184 | | extern fn LLVMBuildNUWSub(*const BuilderRef, LHS: *const ValueRef, RHS: *const ValueRef, Name: [*:0]const u8) *const ValueRef; |
| 184 | extern fn LLVMBuildNUWSub(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; |
| 185 | 185 | |
| 186 | 186 | pub const buildIntCast2 = LLVMBuildIntCast2; |
| 187 | | extern fn LLVMBuildIntCast2(*const BuilderRef, Val: *const ValueRef, DestTy: *const TypeRef, IsSigned: LLVMBool, Name: [*:0]const u8) *const ValueRef; |
| 187 | extern fn LLVMBuildIntCast2(*const Builder, Val: *const Value, DestTy: *const Type, IsSigned: LLVMBool, Name: [*:0]const u8) *const Value; |
| 188 | 188 | |
| 189 | 189 | pub const buildBitCast = LLVMBuildBitCast; |
| 190 | | extern fn LLVMBuildBitCast(*const BuilderRef, Val: *const ValueRef, DestTy: *const TypeRef, Name: [*:0]const u8) *const ValueRef; |
| 190 | extern fn LLVMBuildBitCast(*const Builder, Val: *const Value, DestTy: *const Type, Name: [*:0]const u8) *const Value; |
| 191 | 191 | |
| 192 | 192 | pub const buildInBoundsGEP = LLVMBuildInBoundsGEP; |
| 193 | | extern fn LLVMBuildInBoundsGEP(B: *const BuilderRef, Pointer: *const ValueRef, Indices: [*]*const ValueRef, NumIndices: c_uint, Name: [*:0]const u8) *const ValueRef; |
| 193 | extern fn LLVMBuildInBoundsGEP(B: *const Builder, Pointer: *const Value, Indices: [*]*const Value, NumIndices: c_uint, Name: [*:0]const u8) *const Value; |
| 194 | 194 | }; |
| 195 | 195 | |
| 196 | | pub const BasicBlockRef = opaque { |
| 196 | pub const BasicBlock = opaque { |
| 197 | 197 | pub const deleteBasicBlock = LLVMDeleteBasicBlock; |
| 198 | | extern fn LLVMDeleteBasicBlock(BB: *const BasicBlockRef) void; |
| 198 | extern fn LLVMDeleteBasicBlock(BB: *const BasicBlock) void; |
| 199 | 199 | }; |
| 200 | 200 | |
| 201 | | pub const TargetMachineRef = opaque { |
| 201 | pub const TargetMachine = opaque { |
| 202 | 202 | pub const createTargetMachine = LLVMCreateTargetMachine; |
| 203 | 203 | extern fn LLVMCreateTargetMachine( |
| 204 | | T: *const TargetRef, |
| 204 | T: *const Target, |
| 205 | 205 | Triple: [*:0]const u8, |
| 206 | 206 | CPU: [*:0]const u8, |
| 207 | 207 | Features: [*:0]const u8, |
| 208 | 208 | Level: CodeGenOptLevel, |
| 209 | 209 | Reloc: RelocMode, |
| 210 | 210 | CodeModel: CodeMode, |
| 211 | | ) *const TargetMachineRef; |
| 211 | ) *const TargetMachine; |
| 212 | 212 | |
| 213 | 213 | pub const disposeTargetMachine = LLVMDisposeTargetMachine; |
| 214 | | extern fn LLVMDisposeTargetMachine(T: *const TargetMachineRef) void; |
| 214 | extern fn LLVMDisposeTargetMachine(T: *const TargetMachine) void; |
| 215 | 215 | |
| 216 | 216 | pub const emitToFile = LLVMTargetMachineEmitToFile; |
| 217 | | extern fn LLVMTargetMachineEmitToFile(*const TargetMachineRef, M: *const ModuleRef, Filename: [*:0]const u8, codegen: CodeGenFileType, ErrorMessage: *[*:0]const u8) LLVMBool; |
| 217 | extern fn LLVMTargetMachineEmitToFile(*const TargetMachine, M: *const Module, Filename: [*:0]const u8, codegen: CodeGenFileType, ErrorMessage: *[*:0]const u8) LLVMBool; |
| 218 | 218 | }; |
| 219 | 219 | |
| 220 | 220 | pub const CodeMode = extern enum { |
| ... | ... | @@ -249,9 +249,9 @@ pub const CodeGenFileType = extern enum { |
| 249 | 249 | ObjectFile, |
| 250 | 250 | }; |
| 251 | 251 | |
| 252 | | pub const TargetRef = opaque { |
| 252 | pub const Target = opaque { |
| 253 | 253 | pub const getTargetFromTriple = LLVMGetTargetFromTriple; |
| 254 | | extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **const TargetRef, ErrorMessage: *[*:0]const u8) LLVMBool; |
| 254 | extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **const Target, ErrorMessage: *[*:0]const u8) LLVMBool; |
| 255 | 255 | }; |
| 256 | 256 | |
| 257 | 257 | extern fn LLVMInitializeAArch64TargetInfo() void; |