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