master
  1//! We do this instead of @cImport because the self-hosted compiler is easier
  2//! to bootstrap if it does not depend on translate-c.
  3
  4/// Do not compare directly to .True, use toBool() instead.
  5pub const Bool = enum(c_int) {
  6    False,
  7    True,
  8    _,
  9
 10    pub fn fromBool(b: bool) Bool {
 11        return @as(Bool, @enumFromInt(@intFromBool(b)));
 12    }
 13
 14    pub fn toBool(b: Bool) bool {
 15        return b != .False;
 16    }
 17};
 18
 19pub const MemoryBuffer = opaque {
 20    pub const createMemoryBufferWithMemoryRange = LLVMCreateMemoryBufferWithMemoryRange;
 21    pub const dispose = LLVMDisposeMemoryBuffer;
 22
 23    extern fn LLVMCreateMemoryBufferWithMemoryRange(InputData: [*]const u8, InputDataLength: usize, BufferName: ?[*:0]const u8, RequiresNullTerminator: Bool) *MemoryBuffer;
 24    extern fn LLVMDisposeMemoryBuffer(MemBuf: *MemoryBuffer) void;
 25};
 26
 27/// Make sure to use the *InContext functions instead of the global ones.
 28pub const Context = opaque {
 29    pub const create = LLVMContextCreate;
 30    extern fn LLVMContextCreate() *Context;
 31
 32    pub const dispose = LLVMContextDispose;
 33    extern fn LLVMContextDispose(C: *Context) void;
 34
 35    pub const parseBitcodeInContext2 = LLVMParseBitcodeInContext2;
 36    extern fn LLVMParseBitcodeInContext2(C: *Context, MemBuf: *MemoryBuffer, OutModule: **Module) Bool;
 37
 38    pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit;
 39    extern fn ZigLLVMSetOptBisectLimit(C: *Context, limit: c_int) void;
 40
 41    pub const enableBrokenDebugInfoCheck = ZigLLVMEnableBrokenDebugInfoCheck;
 42    extern fn ZigLLVMEnableBrokenDebugInfoCheck(C: *Context) void;
 43
 44    pub const getBrokenDebugInfo = ZigLLVMGetBrokenDebugInfo;
 45    extern fn ZigLLVMGetBrokenDebugInfo(C: *Context) bool;
 46
 47    pub const intType = LLVMIntTypeInContext;
 48    extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) *Type;
 49};
 50
 51pub const Module = opaque {
 52    pub const dispose = LLVMDisposeModule;
 53    extern fn LLVMDisposeModule(*Module) void;
 54};
 55
 56pub const disposeMessage = LLVMDisposeMessage;
 57extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;
 58
 59pub const TargetMachine = opaque {
 60    pub const FloatABI = enum(c_int) {
 61        /// Target-specific (either soft or hard depending on triple, etc).
 62        Default,
 63        /// Soft float.
 64        Soft,
 65        // Hard float.
 66        Hard,
 67    };
 68
 69    pub const create = ZigLLVMCreateTargetMachine;
 70    extern fn ZigLLVMCreateTargetMachine(
 71        T: *Target,
 72        Triple: [*:0]const u8,
 73        CPU: ?[*:0]const u8,
 74        Features: ?[*:0]const u8,
 75        Level: CodeGenOptLevel,
 76        Reloc: RelocMode,
 77        CodeModel: CodeModel,
 78        function_sections: bool,
 79        data_sections: bool,
 80        float_abi: FloatABI,
 81        abi_name: ?[*:0]const u8,
 82        emulated_tls: bool,
 83    ) *TargetMachine;
 84
 85    pub const dispose = LLVMDisposeTargetMachine;
 86    extern fn LLVMDisposeTargetMachine(T: *TargetMachine) void;
 87
 88    pub const EmitOptions = extern struct {
 89        is_debug: bool,
 90        is_small: bool,
 91        time_report_out: ?*[*:0]u8,
 92        tsan: bool,
 93        sancov: bool,
 94        lto: LtoPhase,
 95        allow_fast_isel: bool,
 96        allow_machine_outliner: bool,
 97        asm_filename: ?[*:0]const u8,
 98        bin_filename: ?[*:0]const u8,
 99        llvm_ir_filename: ?[*:0]const u8,
100        bitcode_filename: ?[*:0]const u8,
101        coverage: Coverage,
102
103        pub const LtoPhase = enum(c_int) {
104            None,
105            ThinPreLink,
106            ThinPostLink,
107            FullPreLink,
108            FullPostLink,
109        };
110
111        pub const Coverage = extern struct {
112            CoverageType: Coverage.Type,
113            IndirectCalls: bool,
114            TraceBB: bool,
115            TraceCmp: bool,
116            TraceDiv: bool,
117            TraceGep: bool,
118            Use8bitCounters: bool,
119            TracePC: bool,
120            TracePCGuard: bool,
121            Inline8bitCounters: bool,
122            InlineBoolFlag: bool,
123            PCTable: bool,
124            NoPrune: bool,
125            StackDepth: bool,
126            TraceLoads: bool,
127            TraceStores: bool,
128            CollectControlFlow: bool,
129
130            pub const Type = enum(c_int) {
131                None = 0,
132                Function,
133                BB,
134                Edge,
135            };
136        };
137    };
138
139    pub const emitToFile = ZigLLVMTargetMachineEmitToFile;
140    extern fn ZigLLVMTargetMachineEmitToFile(
141        T: *TargetMachine,
142        M: *Module,
143        ErrorMessage: *[*:0]const u8,
144        options: *const EmitOptions,
145    ) bool;
146
147    pub const createTargetDataLayout = LLVMCreateTargetDataLayout;
148    extern fn LLVMCreateTargetDataLayout(*TargetMachine) *TargetData;
149};
150
151pub const TargetData = opaque {
152    pub const dispose = LLVMDisposeTargetData;
153    extern fn LLVMDisposeTargetData(*TargetData) void;
154
155    pub const abiAlignmentOfType = LLVMABIAlignmentOfType;
156    extern fn LLVMABIAlignmentOfType(TD: *TargetData, Ty: *Type) c_uint;
157};
158
159pub const Type = opaque {};
160
161pub const CodeModel = enum(c_int) {
162    Default,
163    JITDefault,
164    Tiny,
165    Small,
166    Kernel,
167    Medium,
168    Large,
169};
170
171pub const CodeGenOptLevel = enum(c_int) {
172    None,
173    Less,
174    Default,
175    Aggressive,
176};
177
178pub const RelocMode = enum(c_int) {
179    Default,
180    Static,
181    PIC,
182    DynamicNoPIC,
183    ROPI,
184    RWPI,
185    ROPI_RWPI,
186};
187
188pub const Target = opaque {
189    pub const getFromTriple = LLVMGetTargetFromTriple;
190    extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: *[*:0]const u8) Bool;
191};
192
193pub extern fn LLVMInitializeAArch64TargetInfo() void;
194pub extern fn LLVMInitializeAMDGPUTargetInfo() void;
195pub extern fn LLVMInitializeARMTargetInfo() void;
196pub extern fn LLVMInitializeAVRTargetInfo() void;
197pub extern fn LLVMInitializeBPFTargetInfo() void;
198pub extern fn LLVMInitializeHexagonTargetInfo() void;
199pub extern fn LLVMInitializeLanaiTargetInfo() void;
200pub extern fn LLVMInitializeMipsTargetInfo() void;
201pub extern fn LLVMInitializeMSP430TargetInfo() void;
202pub extern fn LLVMInitializeNVPTXTargetInfo() void;
203pub extern fn LLVMInitializePowerPCTargetInfo() void;
204pub extern fn LLVMInitializeRISCVTargetInfo() void;
205pub extern fn LLVMInitializeSparcTargetInfo() void;
206pub extern fn LLVMInitializeSystemZTargetInfo() void;
207pub extern fn LLVMInitializeWebAssemblyTargetInfo() void;
208pub extern fn LLVMInitializeX86TargetInfo() void;
209pub extern fn LLVMInitializeXCoreTargetInfo() void;
210pub extern fn LLVMInitializeXtensaTargetInfo() void;
211pub extern fn LLVMInitializeM68kTargetInfo() void;
212pub extern fn LLVMInitializeCSKYTargetInfo() void;
213pub extern fn LLVMInitializeVETargetInfo() void;
214pub extern fn LLVMInitializeARCTargetInfo() void;
215pub extern fn LLVMInitializeLoongArchTargetInfo() void;
216pub extern fn LLVMInitializeSPIRVTargetInfo() void;
217
218pub extern fn LLVMInitializeAArch64Target() void;
219pub extern fn LLVMInitializeAMDGPUTarget() void;
220pub extern fn LLVMInitializeARMTarget() void;
221pub extern fn LLVMInitializeAVRTarget() void;
222pub extern fn LLVMInitializeBPFTarget() void;
223pub extern fn LLVMInitializeHexagonTarget() void;
224pub extern fn LLVMInitializeLanaiTarget() void;
225pub extern fn LLVMInitializeMipsTarget() void;
226pub extern fn LLVMInitializeMSP430Target() void;
227pub extern fn LLVMInitializeNVPTXTarget() void;
228pub extern fn LLVMInitializePowerPCTarget() void;
229pub extern fn LLVMInitializeRISCVTarget() void;
230pub extern fn LLVMInitializeSparcTarget() void;
231pub extern fn LLVMInitializeSystemZTarget() void;
232pub extern fn LLVMInitializeWebAssemblyTarget() void;
233pub extern fn LLVMInitializeX86Target() void;
234pub extern fn LLVMInitializeXCoreTarget() void;
235pub extern fn LLVMInitializeXtensaTarget() void;
236pub extern fn LLVMInitializeM68kTarget() void;
237pub extern fn LLVMInitializeVETarget() void;
238pub extern fn LLVMInitializeCSKYTarget() void;
239pub extern fn LLVMInitializeARCTarget() void;
240pub extern fn LLVMInitializeLoongArchTarget() void;
241pub extern fn LLVMInitializeSPIRVTarget() void;
242
243pub extern fn LLVMInitializeAArch64TargetMC() void;
244pub extern fn LLVMInitializeAMDGPUTargetMC() void;
245pub extern fn LLVMInitializeARMTargetMC() void;
246pub extern fn LLVMInitializeAVRTargetMC() void;
247pub extern fn LLVMInitializeBPFTargetMC() void;
248pub extern fn LLVMInitializeHexagonTargetMC() void;
249pub extern fn LLVMInitializeLanaiTargetMC() void;
250pub extern fn LLVMInitializeMipsTargetMC() void;
251pub extern fn LLVMInitializeMSP430TargetMC() void;
252pub extern fn LLVMInitializeNVPTXTargetMC() void;
253pub extern fn LLVMInitializePowerPCTargetMC() void;
254pub extern fn LLVMInitializeRISCVTargetMC() void;
255pub extern fn LLVMInitializeSparcTargetMC() void;
256pub extern fn LLVMInitializeSystemZTargetMC() void;
257pub extern fn LLVMInitializeWebAssemblyTargetMC() void;
258pub extern fn LLVMInitializeX86TargetMC() void;
259pub extern fn LLVMInitializeXCoreTargetMC() void;
260pub extern fn LLVMInitializeXtensaTargetMC() void;
261pub extern fn LLVMInitializeM68kTargetMC() void;
262pub extern fn LLVMInitializeCSKYTargetMC() void;
263pub extern fn LLVMInitializeVETargetMC() void;
264pub extern fn LLVMInitializeARCTargetMC() void;
265pub extern fn LLVMInitializeLoongArchTargetMC() void;
266pub extern fn LLVMInitializeSPIRVTargetMC() void;
267
268pub extern fn LLVMInitializeAArch64AsmPrinter() void;
269pub extern fn LLVMInitializeAMDGPUAsmPrinter() void;
270pub extern fn LLVMInitializeARMAsmPrinter() void;
271pub extern fn LLVMInitializeAVRAsmPrinter() void;
272pub extern fn LLVMInitializeBPFAsmPrinter() void;
273pub extern fn LLVMInitializeHexagonAsmPrinter() void;
274pub extern fn LLVMInitializeLanaiAsmPrinter() void;
275pub extern fn LLVMInitializeMipsAsmPrinter() void;
276pub extern fn LLVMInitializeMSP430AsmPrinter() void;
277pub extern fn LLVMInitializeNVPTXAsmPrinter() void;
278pub extern fn LLVMInitializePowerPCAsmPrinter() void;
279pub extern fn LLVMInitializeRISCVAsmPrinter() void;
280pub extern fn LLVMInitializeSparcAsmPrinter() void;
281pub extern fn LLVMInitializeSystemZAsmPrinter() void;
282pub extern fn LLVMInitializeWebAssemblyAsmPrinter() void;
283pub extern fn LLVMInitializeX86AsmPrinter() void;
284pub extern fn LLVMInitializeXCoreAsmPrinter() void;
285pub extern fn LLVMInitializeM68kAsmPrinter() void;
286pub extern fn LLVMInitializeVEAsmPrinter() void;
287pub extern fn LLVMInitializeARCAsmPrinter() void;
288pub extern fn LLVMInitializeLoongArchAsmPrinter() void;
289pub extern fn LLVMInitializeSPIRVAsmPrinter() void;
290
291pub extern fn LLVMInitializeAArch64AsmParser() void;
292pub extern fn LLVMInitializeAMDGPUAsmParser() void;
293pub extern fn LLVMInitializeARMAsmParser() void;
294pub extern fn LLVMInitializeAVRAsmParser() void;
295pub extern fn LLVMInitializeBPFAsmParser() void;
296pub extern fn LLVMInitializeHexagonAsmParser() void;
297pub extern fn LLVMInitializeLanaiAsmParser() void;
298pub extern fn LLVMInitializeMipsAsmParser() void;
299pub extern fn LLVMInitializeMSP430AsmParser() void;
300pub extern fn LLVMInitializePowerPCAsmParser() void;
301pub extern fn LLVMInitializeRISCVAsmParser() void;
302pub extern fn LLVMInitializeSparcAsmParser() void;
303pub extern fn LLVMInitializeSystemZAsmParser() void;
304pub extern fn LLVMInitializeWebAssemblyAsmParser() void;
305pub extern fn LLVMInitializeX86AsmParser() void;
306pub extern fn LLVMInitializeXtensaAsmParser() void;
307pub extern fn LLVMInitializeM68kAsmParser() void;
308pub extern fn LLVMInitializeCSKYAsmParser() void;
309pub extern fn LLVMInitializeVEAsmParser() void;
310pub extern fn LLVMInitializeLoongArchAsmParser() void;
311
312extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
313extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
314extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
315
316pub const LinkCOFF = ZigLLDLinkCOFF;
317pub const LinkELF = ZigLLDLinkELF;
318pub const LinkWasm = ZigLLDLinkWasm;
319
320pub const ArchiveKind = enum(c_int) {
321    GNU,
322    GNU64,
323    BSD,
324    DARWIN,
325    DARWIN64,
326    COFF,
327    AIXBIG,
328};
329
330pub const WriteArchive = ZigLLVMWriteArchive;
331extern fn ZigLLVMWriteArchive(
332    archive_name: [*:0]const u8,
333    file_names_ptr: [*]const [*:0]const u8,
334    file_names_len: usize,
335    archive_kind: ArchiveKind,
336) bool;
337
338pub const ParseCommandLineOptions = ZigLLVMParseCommandLineOptions;
339extern fn ZigLLVMParseCommandLineOptions(argc: usize, argv: [*]const [*:0]const u8) void;
340
341pub const GetHostCPUName = LLVMGetHostCPUName;
342extern fn LLVMGetHostCPUName() ?[*:0]u8;
343
344pub const GetHostCPUFeatures = LLVMGetHostCPUFeatures;
345extern fn LLVMGetHostCPUFeatures() ?[*:0]u8;