[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / llvm / bindings / ocaml / debuginfo / debuginfo_ocaml.c
blob510244b32c290099e754f0fb11eb5103e999fc10
1 /*===-- debuginfo_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file glues LLVM's OCaml interface to its C interface. These functions *|
11 |* are by and large transparent wrappers to the corresponding C functions. *|
12 |* *|
13 |* Note that these functions intentionally take liberties with the CAMLparamX *|
14 |* macros, since most of the parameters are not GC heap objects. *|
15 |* *|
16 \*===----------------------------------------------------------------------===*/
18 #include <string.h>
20 #include "caml/memory.h"
21 #include "caml/mlvalues.h"
22 #include "llvm-c/Core.h"
23 #include "llvm-c/DebugInfo.h"
24 #include "llvm-c/Support.h"
26 #include "llvm_ocaml.h"
28 // This is identical to the definition in llvm_debuginfo.ml:DIFlag.t
29 typedef enum {
30 i_DIFlagZero,
31 i_DIFlagPrivate,
32 i_DIFlagProtected,
33 i_DIFlagPublic,
34 i_DIFlagFwdDecl,
35 i_DIFlagAppleBlock,
36 i_DIFlagReservedBit4,
37 i_DIFlagVirtual,
38 i_DIFlagArtificial,
39 i_DIFlagExplicit,
40 i_DIFlagPrototyped,
41 i_DIFlagObjcClassComplete,
42 i_DIFlagObjectPointer,
43 i_DIFlagVector,
44 i_DIFlagStaticMember,
45 i_DIFlagLValueReference,
46 i_DIFlagRValueReference,
47 i_DIFlagReserved,
48 i_DIFlagSingleInheritance,
49 i_DIFlagMultipleInheritance,
50 i_DIFlagVirtualInheritance,
51 i_DIFlagIntroducedVirtual,
52 i_DIFlagBitField,
53 i_DIFlagNoReturn,
54 i_DIFlagTypePassByValue,
55 i_DIFlagTypePassByReference,
56 i_DIFlagEnumClass,
57 i_DIFlagFixedEnum,
58 i_DIFlagThunk,
59 i_DIFlagNonTrivial,
60 i_DIFlagBigEndian,
61 i_DIFlagLittleEndian,
62 i_DIFlagIndirectVirtualBase,
63 i_DIFlagAccessibility,
64 i_DIFlagPtrToMemberRep
65 } LLVMDIFlag_i;
67 static LLVMDIFlags map_DIFlag(LLVMDIFlag_i DIF) {
68 switch (DIF) {
69 case i_DIFlagZero:
70 return LLVMDIFlagZero;
71 case i_DIFlagPrivate:
72 return LLVMDIFlagPrivate;
73 case i_DIFlagProtected:
74 return LLVMDIFlagProtected;
75 case i_DIFlagPublic:
76 return LLVMDIFlagPublic;
77 case i_DIFlagFwdDecl:
78 return LLVMDIFlagFwdDecl;
79 case i_DIFlagAppleBlock:
80 return LLVMDIFlagAppleBlock;
81 case i_DIFlagReservedBit4:
82 return LLVMDIFlagReservedBit4;
83 case i_DIFlagVirtual:
84 return LLVMDIFlagVirtual;
85 case i_DIFlagArtificial:
86 return LLVMDIFlagArtificial;
87 case i_DIFlagExplicit:
88 return LLVMDIFlagExplicit;
89 case i_DIFlagPrototyped:
90 return LLVMDIFlagPrototyped;
91 case i_DIFlagObjcClassComplete:
92 return LLVMDIFlagObjcClassComplete;
93 case i_DIFlagObjectPointer:
94 return LLVMDIFlagObjectPointer;
95 case i_DIFlagVector:
96 return LLVMDIFlagVector;
97 case i_DIFlagStaticMember:
98 return LLVMDIFlagStaticMember;
99 case i_DIFlagLValueReference:
100 return LLVMDIFlagLValueReference;
101 case i_DIFlagRValueReference:
102 return LLVMDIFlagRValueReference;
103 case i_DIFlagReserved:
104 return LLVMDIFlagReserved;
105 case i_DIFlagSingleInheritance:
106 return LLVMDIFlagSingleInheritance;
107 case i_DIFlagMultipleInheritance:
108 return LLVMDIFlagMultipleInheritance;
109 case i_DIFlagVirtualInheritance:
110 return LLVMDIFlagVirtualInheritance;
111 case i_DIFlagIntroducedVirtual:
112 return LLVMDIFlagIntroducedVirtual;
113 case i_DIFlagBitField:
114 return LLVMDIFlagBitField;
115 case i_DIFlagNoReturn:
116 return LLVMDIFlagNoReturn;
117 case i_DIFlagTypePassByValue:
118 return LLVMDIFlagTypePassByValue;
119 case i_DIFlagTypePassByReference:
120 return LLVMDIFlagTypePassByReference;
121 case i_DIFlagEnumClass:
122 return LLVMDIFlagEnumClass;
123 case i_DIFlagFixedEnum:
124 return LLVMDIFlagFixedEnum;
125 case i_DIFlagThunk:
126 return LLVMDIFlagThunk;
127 case i_DIFlagNonTrivial:
128 return LLVMDIFlagNonTrivial;
129 case i_DIFlagBigEndian:
130 return LLVMDIFlagBigEndian;
131 case i_DIFlagLittleEndian:
132 return LLVMDIFlagLittleEndian;
133 case i_DIFlagIndirectVirtualBase:
134 return LLVMDIFlagIndirectVirtualBase;
135 case i_DIFlagAccessibility:
136 return LLVMDIFlagAccessibility;
137 case i_DIFlagPtrToMemberRep:
138 return LLVMDIFlagPtrToMemberRep;
142 /* unit -> int */
143 value llvm_debug_metadata_version(value Unit) {
144 return Val_int(LLVMDebugMetadataVersion());
147 /* llmodule -> int */
148 value llvm_get_module_debug_metadata_version(value Module) {
149 return Val_int(LLVMGetModuleDebugMetadataVersion(Module_val(Module)));
152 #define DIFlags_val(v) (*(LLVMDIFlags *)(Data_custom_val(v)))
154 static struct custom_operations diflags_ops = {
155 (char *)"DebugInfo.lldiflags", custom_finalize_default,
156 custom_compare_default, custom_hash_default,
157 custom_serialize_default, custom_deserialize_default,
158 custom_compare_ext_default};
160 static value alloc_diflags(LLVMDIFlags Flags) {
161 value V = caml_alloc_custom(&diflags_ops, sizeof(LLVMDIFlags), 0, 1);
162 DIFlags_val(V) = Flags;
163 return V;
166 LLVMDIFlags llvm_diflags_get(value i_Flag) {
167 LLVMDIFlags Flags = map_DIFlag(Int_val(i_Flag));
168 return alloc_diflags(Flags);
171 LLVMDIFlags llvm_diflags_set(value Flags, value i_Flag) {
172 LLVMDIFlags FlagsNew = DIFlags_val(Flags) | map_DIFlag(Int_val(i_Flag));
173 return alloc_diflags(FlagsNew);
176 value llvm_diflags_test(value Flags, value i_Flag) {
177 LLVMDIFlags Flag = map_DIFlag(Int_val(i_Flag));
178 return Val_bool((DIFlags_val(Flags) & Flag) == Flag);
181 #define DIBuilder_val(v) (*(LLVMDIBuilderRef *)(Data_custom_val(v)))
183 static void llvm_finalize_dibuilder(value B) {
184 LLVMDIBuilderFinalize(DIBuilder_val(B));
185 LLVMDisposeDIBuilder(DIBuilder_val(B));
188 static struct custom_operations dibuilder_ops = {
189 (char *)"DebugInfo.lldibuilder", llvm_finalize_dibuilder,
190 custom_compare_default, custom_hash_default,
191 custom_serialize_default, custom_deserialize_default,
192 custom_compare_ext_default};
194 static value alloc_dibuilder(LLVMDIBuilderRef B) {
195 value V = caml_alloc_custom(&dibuilder_ops, sizeof(LLVMDIBuilderRef), 0, 1);
196 DIBuilder_val(V) = B;
197 return V;
200 /* llmodule -> lldibuilder */
201 value llvm_dibuilder(value M) {
202 return alloc_dibuilder(LLVMCreateDIBuilder(Module_val(M)));
205 value llvm_dibuild_finalize(value Builder) {
206 LLVMDIBuilderFinalize(DIBuilder_val(Builder));
207 return Val_unit;
210 value llvm_dibuild_create_compile_unit_native(
211 value Builder, value Lang, value FileRef, value Producer, value IsOptimized,
212 value Flags, value RuntimeVer, value SplitName, value Kind, value DWOId,
213 value SplitDebugInline, value DebugInfoForProfiling, value SysRoot,
214 value SDK) {
215 return to_val(LLVMDIBuilderCreateCompileUnit(
216 DIBuilder_val(Builder), Int_val(Lang), Metadata_val(FileRef),
217 String_val(Producer), caml_string_length(Producer), Bool_val(IsOptimized),
218 String_val(Flags), caml_string_length(Flags), Int_val(RuntimeVer),
219 String_val(SplitName), caml_string_length(SplitName), Int_val(Kind),
220 Int_val(DWOId), Bool_val(SplitDebugInline),
221 Bool_val(DebugInfoForProfiling), String_val(SysRoot),
222 caml_string_length(SysRoot), String_val(SDK), caml_string_length(SDK)));
225 value llvm_dibuild_create_compile_unit_bytecode(value *argv, int argn) {
226 return llvm_dibuild_create_compile_unit_native(
227 argv[0], // Builder
228 argv[1], // Lang
229 argv[2], // FileRef
230 argv[3], // Producer
231 argv[4], // IsOptimized
232 argv[5], // Flags
233 argv[6], // RuntimeVer
234 argv[7], // SplitName
235 argv[8], // Kind
236 argv[9], // DWOId
237 argv[10], // SplitDebugInline
238 argv[11], // DebugInfoForProfiling
239 argv[12], // SysRoot
240 argv[13] // SDK
244 value llvm_dibuild_create_file(value Builder, value Filename, value Directory) {
245 return to_val(LLVMDIBuilderCreateFile(
246 DIBuilder_val(Builder), String_val(Filename),
247 caml_string_length(Filename), String_val(Directory),
248 caml_string_length(Directory)));
251 value llvm_dibuild_create_module_native(value Builder, value ParentScope,
252 value Name, value ConfigMacros,
253 value IncludePath, value SysRoot) {
254 return to_val(LLVMDIBuilderCreateModule(
255 DIBuilder_val(Builder), Metadata_val(ParentScope), String_val(Name),
256 caml_string_length(Name), String_val(ConfigMacros),
257 caml_string_length(ConfigMacros), String_val(IncludePath),
258 caml_string_length(IncludePath), String_val(SysRoot),
259 caml_string_length(SysRoot)));
262 value llvm_dibuild_create_module_bytecode(value *argv, int argn) {
263 return llvm_dibuild_create_module_native(argv[0], // Builder
264 argv[1], // ParentScope
265 argv[2], // Name
266 argv[3], // ConfigMacros
267 argv[4], // IncludePath
268 argv[5] // SysRoot
272 value llvm_dibuild_create_namespace(value Builder, value ParentScope,
273 value Name, value ExportSymbols) {
274 return to_val(LLVMDIBuilderCreateNameSpace(
275 DIBuilder_val(Builder), Metadata_val(ParentScope), String_val(Name),
276 caml_string_length(Name), Bool_val(ExportSymbols)));
279 value llvm_dibuild_create_function_native(value Builder, value Scope,
280 value Name, value LinkageName,
281 value File, value LineNo, value Ty,
282 value IsLocalToUnit,
283 value IsDefinition, value ScopeLine,
284 value Flags, value IsOptimized) {
285 return to_val(LLVMDIBuilderCreateFunction(
286 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
287 caml_string_length(Name), String_val(LinkageName),
288 caml_string_length(LinkageName), Metadata_val(File), Int_val(LineNo),
289 Metadata_val(Ty), Bool_val(IsLocalToUnit), Bool_val(IsDefinition),
290 Int_val(ScopeLine), DIFlags_val(Flags), Bool_val(IsOptimized)));
293 value llvm_dibuild_create_function_bytecode(value *argv, int argn) {
294 return llvm_dibuild_create_function_native(argv[0], // Builder,
295 argv[1], // Scope
296 argv[2], // Name
297 argv[3], // LinkageName
298 argv[4], // File
299 argv[5], // LineNo
300 argv[6], // Ty
301 argv[7], // IsLocalUnit
302 argv[8], // IsDefinition
303 argv[9], // ScopeLine
304 argv[10], // Flags
305 argv[11] // IsOptimized
309 value llvm_dibuild_create_lexical_block(value Builder, value Scope, value File,
310 value Line, value Column) {
311 return to_val(LLVMDIBuilderCreateLexicalBlock(
312 DIBuilder_val(Builder), Metadata_val(Scope), Metadata_val(File),
313 Int_val(Line), Int_val(Column)));
316 value llvm_metadata_null(value Unit) { return to_val(NULL); }
318 value llvm_dibuild_create_debug_location(value Ctx, value Line, value Column,
319 value Scope, value InlinedAt) {
320 return to_val(LLVMDIBuilderCreateDebugLocation(
321 Context_val(Ctx), Int_val(Line), Int_val(Column), Metadata_val(Scope),
322 Metadata_val(InlinedAt)));
325 value llvm_di_location_get_line(value Location) {
326 return Val_int(LLVMDILocationGetLine(Metadata_val(Location)));
329 value llvm_di_location_get_column(value Location) {
330 return Val_int(LLVMDILocationGetColumn(Metadata_val(Location)));
333 value llvm_di_location_get_scope(value Location) {
334 return to_val(LLVMDILocationGetScope(Metadata_val(Location)));
337 value llvm_di_location_get_inlined_at(value Location) {
338 return ptr_to_option(LLVMDILocationGetInlinedAt(Metadata_val(Location)));
341 value llvm_di_scope_get_file(value Scope) {
342 return ptr_to_option(LLVMDIScopeGetFile(Metadata_val(Scope)));
345 value llvm_di_file_get_directory(value File) {
346 unsigned Len;
347 const char *Directory = LLVMDIFileGetDirectory(Metadata_val(File), &Len);
348 return cstr_to_string(Directory, Len);
351 value llvm_di_file_get_filename(value File) {
352 unsigned Len;
353 const char *Filename = LLVMDIFileGetFilename(Metadata_val(File), &Len);
354 return cstr_to_string(Filename, Len);
357 value llvm_di_file_get_source(value File) {
358 unsigned Len;
359 const char *Source = LLVMDIFileGetSource(Metadata_val(File), &Len);
360 return cstr_to_string(Source, Len);
363 value llvm_dibuild_get_or_create_type_array(value Builder, value Data) {
364 mlsize_t Count = Wosize_val(Data);
365 LLVMMetadataRef *Temp = from_val_array(Data);
366 LLVMMetadataRef Metadata =
367 LLVMDIBuilderGetOrCreateTypeArray(DIBuilder_val(Builder), Temp, Count);
368 free(Temp);
369 return to_val(Metadata);
372 value llvm_dibuild_get_or_create_array(value Builder, value Data) {
373 mlsize_t Count = Wosize_val(Data);
374 LLVMMetadataRef *Temp = from_val_array(Data);
375 LLVMMetadataRef Metadata =
376 LLVMDIBuilderGetOrCreateArray(DIBuilder_val(Builder), Temp, Count);
377 free(Temp);
378 return to_val(Metadata);
381 value llvm_dibuild_create_subroutine_type(value Builder, value File,
382 value ParameterTypes, value Flags) {
383 mlsize_t Count = Wosize_val(ParameterTypes);
384 LLVMMetadataRef *Temp = from_val_array(ParameterTypes);
385 LLVMMetadataRef Metadata = LLVMDIBuilderCreateSubroutineType(
386 DIBuilder_val(Builder), Metadata_val(File), Temp,
387 Wosize_val(ParameterTypes), DIFlags_val(Flags));
388 free(Temp);
389 return to_val(Metadata);
392 value llvm_dibuild_create_enumerator(value Builder, value Name, value Value,
393 value IsUnsigned) {
394 return to_val(LLVMDIBuilderCreateEnumerator(
395 DIBuilder_val(Builder), String_val(Name), caml_string_length(Name),
396 (int64_t)Int_val(Value), Bool_val(IsUnsigned)));
399 value llvm_dibuild_create_enumeration_type_native(
400 value Builder, value Scope, value Name, value File, value LineNumber,
401 value SizeInBits, value AlignInBits, value Elements, value ClassTy) {
402 mlsize_t Count = Wosize_val(Elements);
403 LLVMMetadataRef *Temp = from_val_array(Elements);
404 LLVMMetadataRef Metadata = LLVMDIBuilderCreateEnumerationType(
405 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
406 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
407 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits), Temp, Count,
408 Metadata_val(ClassTy));
409 free(Temp);
410 return to_val(Metadata);
413 value llvm_dibuild_create_enumeration_type_bytecode(value *argv, int argn) {
414 return llvm_dibuild_create_enumeration_type_native(argv[0], // Builder
415 argv[1], // Scope
416 argv[2], // Name
417 argv[3], // File
418 argv[4], // LineNumber
419 argv[5], // SizeInBits
420 argv[6], // AlignInBits
421 argv[7], // Elements
422 argv[8] // ClassTy
426 value llvm_dibuild_create_union_type_native(
427 value Builder, value Scope, value Name, value File, value LineNumber,
428 value SizeInBits, value AlignInBits, value Flags, value Elements,
429 value RunTimeLanguage, value UniqueId) {
430 LLVMMetadataRef *Temp = from_val_array(Elements);
431 LLVMMetadataRef Metadata = LLVMDIBuilderCreateUnionType(
432 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
433 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
434 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits), DIFlags_val(Flags),
435 Temp, Wosize_val(Elements), Int_val(RunTimeLanguage),
436 String_val(UniqueId), caml_string_length(UniqueId));
437 free(Temp);
438 return to_val(Metadata);
441 value llvm_dibuild_create_union_type_bytecode(value *argv, int argn) {
442 return llvm_dibuild_create_union_type_native(argv[0], // Builder
443 argv[1], // Scope
444 argv[2], // Name
445 argv[3], // File
446 argv[4], // LineNumber
447 argv[5], // SizeInBits
448 argv[6], // AlignInBits
449 argv[7], // Flags
450 argv[8], // Elements
451 argv[9], // RunTimeLanguage
452 argv[10] // UniqueId
456 value llvm_dibuild_create_array_type(value Builder, value Size,
457 value AlignInBits, value Ty,
458 value Subscripts) {
459 LLVMMetadataRef *Temp = from_val_array(Subscripts);
460 LLVMMetadataRef Metadata = LLVMDIBuilderCreateArrayType(
461 DIBuilder_val(Builder), (uint64_t)Int_val(Size), Int_val(AlignInBits),
462 Metadata_val(Ty), Temp, Wosize_val(Subscripts));
463 free(Temp);
464 return to_val(Metadata);
467 value llvm_dibuild_create_vector_type(value Builder, value Size,
468 value AlignInBits, value Ty,
469 value Subscripts) {
470 LLVMMetadataRef *Temp = from_val_array(Subscripts);
471 LLVMMetadataRef Metadata = LLVMDIBuilderCreateVectorType(
472 DIBuilder_val(Builder), (uint64_t)Int_val(Size), Int_val(AlignInBits),
473 Metadata_val(Ty), Temp, Wosize_val(Subscripts));
474 free(Temp);
475 return to_val(Metadata);
478 value llvm_dibuild_create_unspecified_type(value Builder, value Name) {
479 LLVMMetadataRef Metadata = LLVMDIBuilderCreateUnspecifiedType(
480 DIBuilder_val(Builder), String_val(Name), caml_string_length(Name));
481 return to_val(Metadata);
484 value llvm_dibuild_create_basic_type(value Builder, value Name,
485 value SizeInBits, value Encoding,
486 value Flags) {
487 LLVMMetadataRef Metadata = LLVMDIBuilderCreateBasicType(
488 DIBuilder_val(Builder), String_val(Name), caml_string_length(Name),
489 (uint64_t)Int_val(SizeInBits), Int_val(Encoding), DIFlags_val(Flags));
490 return to_val(Metadata);
493 value llvm_dibuild_create_pointer_type_native(value Builder, value PointeeTy,
494 value SizeInBits,
495 value AlignInBits,
496 value AddressSpace, value Name) {
497 LLVMMetadataRef Metadata = LLVMDIBuilderCreatePointerType(
498 DIBuilder_val(Builder), Metadata_val(PointeeTy),
499 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits),
500 Int_val(AddressSpace), String_val(Name), caml_string_length(Name));
501 return to_val(Metadata);
504 value llvm_dibuild_create_pointer_type_bytecode(value *argv, int argn) {
505 return llvm_dibuild_create_pointer_type_native(argv[0], // Builder
506 argv[1], // PointeeTy
507 argv[2], // SizeInBits
508 argv[3], // AlignInBits
509 argv[4], // AddressSpace
510 argv[5] // Name
514 value llvm_dibuild_create_struct_type_native(
515 value Builder, value Scope, value Name, value File, value LineNumber,
516 value SizeInBits, value AlignInBits, value Flags, value DerivedFrom,
517 value Elements, value RunTimeLanguage, value VTableHolder, value UniqueId) {
518 LLVMMetadataRef *Temp = from_val_array(Elements);
519 LLVMMetadataRef Metadata = LLVMDIBuilderCreateStructType(
520 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
521 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
522 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits), DIFlags_val(Flags),
523 Metadata_val(DerivedFrom), Temp, Wosize_val(Elements),
524 Int_val(RunTimeLanguage), Metadata_val(VTableHolder),
525 String_val(UniqueId), caml_string_length(UniqueId));
526 free(Temp);
527 return to_val(Metadata);
530 value llvm_dibuild_create_struct_type_bytecode(value *argv, int argn) {
531 return llvm_dibuild_create_struct_type_native(argv[0], // Builder
532 argv[1], // Scope
533 argv[2], // Name
534 argv[3], // File
535 argv[4], // LineNumber
536 argv[5], // SizeInBits
537 argv[6], // AlignInBits
538 argv[7], // Flags
539 argv[8], // DeriviedFrom
540 argv[9], // Elements
541 argv[10], // RunTimeLanguage
542 argv[11], // VTableHolder
543 argv[12] // UniqueId
547 value llvm_dibuild_create_member_type_native(value Builder, value Scope,
548 value Name, value File,
549 value LineNumber, value SizeInBits,
550 value AlignInBits,
551 value OffsetInBits, value Flags,
552 value Ty) {
553 LLVMMetadataRef Metadata = LLVMDIBuilderCreateMemberType(
554 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
555 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
556 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits),
557 (uint64_t)Int_val(OffsetInBits), DIFlags_val(Flags), Metadata_val(Ty));
558 return to_val(Metadata);
561 value llvm_dibuild_create_member_type_bytecode(value *argv, int argn) {
562 return llvm_dibuild_create_member_type_native(argv[0], // Builder
563 argv[1], // Scope
564 argv[2], // Name
565 argv[3], // File
566 argv[4], // LineNumber
567 argv[5], // SizeInBits
568 argv[6], // AlignInBits
569 argv[7], // OffsetInBits
570 argv[8], // Flags
571 argv[9] // Ty
575 value llvm_dibuild_create_static_member_type_native(
576 value Builder, value Scope, value Name, value File, value LineNumber,
577 value Type, value Flags, value ConstantVal, value AlignInBits) {
578 LLVMMetadataRef Metadata = LLVMDIBuilderCreateStaticMemberType(
579 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
580 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
581 Metadata_val(Type), DIFlags_val(Flags), Value_val(ConstantVal),
582 Int_val(AlignInBits));
583 return to_val(Metadata);
586 value llvm_dibuild_create_static_member_type_bytecode(value *argv, int argn) {
587 return llvm_dibuild_create_static_member_type_native(argv[0], // Builder
588 argv[1], // Scope
589 argv[2], // Name
590 argv[3], // File
591 argv[4], // LineNumber
592 argv[5], // Type
593 argv[6], // Flags,
594 argv[7], // ConstantVal
595 argv[8] // AlignInBits
599 value llvm_dibuild_create_member_pointer_type_native(
600 value Builder, value PointeeType, value ClassType, value SizeInBits,
601 value AlignInBits, value Flags) {
602 LLVMMetadataRef Metadata = LLVMDIBuilderCreateMemberPointerType(
603 DIBuilder_val(Builder), Metadata_val(PointeeType),
604 Metadata_val(ClassType), (uint64_t)Int_val(SizeInBits),
605 Int_val(AlignInBits), llvm_diflags_get(Flags));
606 return to_val(Metadata);
609 value llvm_dibuild_create_member_pointer_type_bytecode(value *argv, int argn) {
610 return llvm_dibuild_create_member_pointer_type_native(argv[0], // Builder
611 argv[1], // PointeeType
612 argv[2], // ClassType
613 argv[3], // SizeInBits
614 argv[4], // AlignInBits
615 argv[5] // Flags
619 value llvm_dibuild_create_object_pointer_type(value Builder, value Type) {
620 LLVMMetadataRef Metadata = LLVMDIBuilderCreateObjectPointerType(
621 DIBuilder_val(Builder), Metadata_val(Type));
622 return to_val(Metadata);
625 value llvm_dibuild_create_qualified_type(value Builder, value Tag, value Type) {
626 LLVMMetadataRef Metadata = LLVMDIBuilderCreateQualifiedType(
627 DIBuilder_val(Builder), Int_val(Tag), Metadata_val(Type));
628 return to_val(Metadata);
631 value llvm_dibuild_create_reference_type(value Builder, value Tag, value Type) {
632 LLVMMetadataRef Metadata = LLVMDIBuilderCreateReferenceType(
633 DIBuilder_val(Builder), Int_val(Tag), Metadata_val(Type));
634 return to_val(Metadata);
637 value llvm_dibuild_create_null_ptr_type(value Builder) {
638 return to_val(LLVMDIBuilderCreateNullPtrType(DIBuilder_val(Builder)));
641 value llvm_dibuild_create_typedef_native(value Builder, value Type, value Name,
642 value File, value LineNo, value Scope,
643 value AlignInBits) {
644 LLVMMetadataRef Metadata = LLVMDIBuilderCreateTypedef(
645 DIBuilder_val(Builder), Metadata_val(Type), String_val(Name),
646 caml_string_length(Name), Metadata_val(File), Int_val(LineNo),
647 Metadata_val(Scope), Int_val(AlignInBits));
648 return to_val(Metadata);
651 value llvm_dibuild_create_typedef_bytecode(value *argv, int argn) {
653 return llvm_dibuild_create_typedef_native(argv[0], // Builder
654 argv[1], // Type
655 argv[2], // Name
656 argv[3], // File
657 argv[4], // LineNo
658 argv[5], // Scope
659 argv[6] // AlignInBits
663 value llvm_dibuild_create_inheritance_native(value Builder, value Ty,
664 value BaseTy, value BaseOffset,
665 value VBPtrOffset, value Flags) {
666 LLVMMetadataRef Metadata = LLVMDIBuilderCreateInheritance(
667 DIBuilder_val(Builder), Metadata_val(Ty), Metadata_val(BaseTy),
668 (uint64_t)Int_val(BaseOffset), Int_val(VBPtrOffset), DIFlags_val(Flags));
669 return to_val(Metadata);
672 value llvm_dibuild_create_inheritance_bytecode(value *argv, int arg) {
673 return llvm_dibuild_create_inheritance_native(argv[0], // Builder
674 argv[1], // Ty
675 argv[2], // BaseTy
676 argv[3], // BaseOffset
677 argv[4], // VBPtrOffset
678 argv[5] // Flags
682 value llvm_dibuild_create_forward_decl_native(
683 value Builder, value Tag, value Name, value Scope, value File, value Line,
684 value RuntimeLang, value SizeInBits, value AlignInBits,
685 value UniqueIdentifier) {
686 LLVMMetadataRef Metadata = LLVMDIBuilderCreateForwardDecl(
687 DIBuilder_val(Builder), Int_val(Tag), String_val(Name),
688 caml_string_length(Name), Metadata_val(Scope), Metadata_val(File),
689 Int_val(Line), Int_val(RuntimeLang), (uint64_t)Int_val(SizeInBits),
690 Int_val(AlignInBits), String_val(UniqueIdentifier),
691 caml_string_length(UniqueIdentifier));
692 return to_val(Metadata);
695 value llvm_dibuild_create_forward_decl_bytecode(value *argv, int arg) {
697 return llvm_dibuild_create_forward_decl_native(argv[0], // Builder
698 argv[1], // Tag
699 argv[2], // Name
700 argv[3], // Scope
701 argv[4], // File
702 argv[5], // Line
703 argv[6], // RuntimeLang
704 argv[7], // SizeInBits
705 argv[8], // AlignInBits
706 argv[9] // UniqueIdentifier
710 value llvm_dibuild_create_replaceable_composite_type_native(
711 value Builder, value Tag, value Name, value Scope, value File, value Line,
712 value RuntimeLang, value SizeInBits, value AlignInBits, value Flags,
713 value UniqueIdentifier) {
714 LLVMMetadataRef Metadata = LLVMDIBuilderCreateReplaceableCompositeType(
715 DIBuilder_val(Builder), Int_val(Tag), String_val(Name),
716 caml_string_length(Name), Metadata_val(Scope), Metadata_val(File),
717 Int_val(Line), Int_val(RuntimeLang), (uint64_t)Int_val(SizeInBits),
718 Int_val(AlignInBits), DIFlags_val(Flags), String_val(UniqueIdentifier),
719 caml_string_length(UniqueIdentifier));
720 return to_val(Metadata);
723 value llvm_dibuild_create_replaceable_composite_type_bytecode(value *argv,
724 int arg) {
726 return llvm_dibuild_create_replaceable_composite_type_native(
727 argv[0], // Builder
728 argv[1], // Tag
729 argv[2], // Name
730 argv[3], // Scope
731 argv[4], // File
732 argv[5], // Line
733 argv[6], // RuntimeLang
734 argv[7], // SizeInBits
735 argv[8], // AlignInBits
736 argv[9], // Flags
737 argv[10] // UniqueIdentifier
741 value llvm_dibuild_create_bit_field_member_type_native(
742 value Builder, value Scope, value Name, value File, value LineNum,
743 value SizeInBits, value OffsetInBits, value StorageOffsetInBits,
744 value Flags, value Ty) {
745 LLVMMetadataRef Metadata = LLVMDIBuilderCreateBitFieldMemberType(
746 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
747 caml_string_length(Name), Metadata_val(File), Int_val(LineNum),
748 (uint64_t)Int_val(SizeInBits), (uint64_t)Int_val(OffsetInBits),
749 (uint64_t)Int_val(StorageOffsetInBits), DIFlags_val(Flags),
750 Metadata_val(Ty));
751 return to_val(Metadata);
754 value llvm_dibuild_create_bit_field_member_type_bytecode(value *argv, int arg) {
756 return llvm_dibuild_create_bit_field_member_type_native(
757 argv[0], // Builder
758 argv[1], // Scope
759 argv[2], // Name
760 argv[3], // File
761 argv[4], // LineNum
762 argv[5], // SizeInBits
763 argv[6], // OffsetInBits
764 argv[7], // StorageOffsetInBits
765 argv[8], // Flags
766 argv[9] // Ty
770 value llvm_dibuild_create_class_type_native(
771 value Builder, value Scope, value Name, value File, value LineNumber,
772 value SizeInBits, value AlignInBits, value OffsetInBits, value Flags,
773 value DerivedFrom, value Elements, value VTableHolder,
774 value TemplateParamsNode, value UniqueIdentifier) {
775 LLVMMetadataRef *Temp = from_val_array(Elements);
776 LLVMMetadataRef Metadata = LLVMDIBuilderCreateClassType(
777 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
778 caml_string_length(Name), Metadata_val(File), Int_val(LineNumber),
779 (uint64_t)Int_val(SizeInBits), Int_val(AlignInBits),
780 (uint64_t)Int_val(OffsetInBits), DIFlags_val(Flags),
781 Metadata_val(DerivedFrom), Temp, Wosize_val(Elements),
782 Metadata_val(VTableHolder), Metadata_val(TemplateParamsNode),
783 String_val(UniqueIdentifier), caml_string_length(UniqueIdentifier));
784 free(Temp);
785 return to_val(Metadata);
788 value llvm_dibuild_create_class_type_bytecode(value *argv, int arg) {
790 return llvm_dibuild_create_class_type_native(argv[0], // Builder
791 argv[1], // Scope
792 argv[2], // Name
793 argv[3], // File
794 argv[4], // LineNumber
795 argv[5], // SizeInBits
796 argv[6], // AlignInBits
797 argv[7], // OffsetInBits
798 argv[8], // Flags
799 argv[9], // DerivedFrom
800 argv[10], // Elements
801 argv[11], // VTableHolder
802 argv[12], // TemplateParamsNode
803 argv[13] // UniqueIdentifier
807 value llvm_dibuild_create_artificial_type(value Builder, value Type) {
808 LLVMMetadataRef Metadata = LLVMDIBuilderCreateArtificialType(
809 DIBuilder_val(Builder), Metadata_val(Type));
810 return to_val(Metadata);
813 value llvm_di_type_get_name(value DType) {
814 size_t Len;
815 const char *Name = LLVMDITypeGetName(Metadata_val(DType), &Len);
816 return cstr_to_string(Name, Len);
819 value llvm_di_type_get_size_in_bits(value DType) {
820 uint64_t Size = LLVMDITypeGetSizeInBits(Metadata_val(DType));
821 return Val_int((int)Size);
824 value llvm_di_type_get_offset_in_bits(value DType) {
825 uint64_t Size = LLVMDITypeGetOffsetInBits(Metadata_val(DType));
826 return Val_int((int)Size);
829 value llvm_di_type_get_align_in_bits(value DType) {
830 uint32_t Size = LLVMDITypeGetAlignInBits(Metadata_val(DType));
831 return Val_int(Size);
834 value llvm_di_type_get_line(value DType) {
835 unsigned Line = LLVMDITypeGetLine(Metadata_val(DType));
836 return Val_int(Line);
839 value llvm_di_type_get_flags(value DType) {
840 LLVMDIFlags Flags = LLVMDITypeGetLine(Metadata_val(DType));
841 return alloc_diflags(Flags);
844 value llvm_get_subprogram(value Func) {
845 return ptr_to_option(LLVMGetSubprogram(Value_val(Func)));
848 value llvm_set_subprogram(value Func, value SP) {
849 LLVMSetSubprogram(Value_val(Func), Metadata_val(SP));
850 return Val_unit;
853 value llvm_di_subprogram_get_line(value Subprogram) {
854 return Val_int(LLVMDISubprogramGetLine(Metadata_val(Subprogram)));
857 value llvm_instr_get_debug_loc(value Inst) {
858 return ptr_to_option(LLVMInstructionGetDebugLoc(Value_val(Inst)));
861 value llvm_instr_set_debug_loc(value Inst, value Loc) {
862 LLVMInstructionSetDebugLoc(Value_val(Inst), Metadata_val(Loc));
863 return Val_unit;
866 value llvm_dibuild_create_constant_value_expression(value Builder,
867 value Value) {
868 LLVMMetadataRef Metadata = LLVMDIBuilderCreateConstantValueExpression(
869 DIBuilder_val(Builder), (uint64_t)Int_val(Value));
870 return to_val(Metadata);
873 value llvm_dibuild_create_global_variable_expression_native(
874 value Builder, value Scope, value Name, value Linkage, value File,
875 value Line, value Ty, value LocalToUnit, value Expr, value Decl,
876 value AlignInBits) {
877 LLVMMetadataRef Metadata = LLVMDIBuilderCreateGlobalVariableExpression(
878 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
879 caml_string_length(Name), String_val(Linkage),
880 caml_string_length(Linkage), Metadata_val(File), Int_val(Line),
881 Metadata_val(Ty), Bool_val(LocalToUnit), Metadata_val(Expr),
882 Metadata_val(Decl), Int_val(AlignInBits));
883 return to_val(Metadata);
886 value llvm_dibuild_create_global_variable_expression_bytecode(value *argv,
887 int arg) {
889 return llvm_dibuild_create_global_variable_expression_native(
890 argv[0], // Builder
891 argv[1], // Scope
892 argv[2], // Name
893 argv[3], // Linkage
894 argv[4], // File
895 argv[5], // Line
896 argv[6], // Ty
897 argv[7], // LocalToUnit
898 argv[8], // Expr
899 argv[9], // Decl
900 argv[10] // AlignInBits
904 value llvm_di_global_variable_expression_get_variable(value GVE) {
905 return ptr_to_option(
906 LLVMDIGlobalVariableExpressionGetVariable(Metadata_val(GVE)));
909 value llvm_di_variable_get_line(value Variable) {
910 return Val_int(LLVMDIVariableGetLine(Metadata_val(Variable)));
913 value llvm_di_variable_get_file(value Variable) {
914 return ptr_to_option(LLVMDIVariableGetFile(Metadata_val(Variable)));
917 value llvm_get_metadata_kind(value Metadata) {
918 return Val_int(LLVMGetMetadataKind(Metadata_val(Metadata)));
921 value llvm_dibuild_create_auto_variable_native(value Builder, value Scope,
922 value Name, value File,
923 value Line, value Ty,
924 value AlwaysPreserve,
925 value Flags, value AlignInBits) {
926 return to_val(LLVMDIBuilderCreateAutoVariable(
927 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
928 caml_string_length(Name), Metadata_val(File), Int_val(Line),
929 Metadata_val(Ty), Bool_val(AlwaysPreserve), DIFlags_val(Flags),
930 Int_val(AlignInBits)));
933 value llvm_dibuild_create_auto_variable_bytecode(value *argv, int arg) {
935 return llvm_dibuild_create_auto_variable_native(argv[0], // Builder
936 argv[1], // Scope
937 argv[2], // Name
938 argv[3], // File
939 argv[4], // Line
940 argv[5], // Ty
941 argv[6], // AlwaysPreserve
942 argv[7], // Flags
943 argv[8] // AlignInBits
947 value llvm_dibuild_create_parameter_variable_native(
948 value Builder, value Scope, value Name, value ArgNo, value File, value Line,
949 value Ty, value AlwaysPreserve, value Flags) {
950 LLVMMetadataRef Metadata = LLVMDIBuilderCreateParameterVariable(
951 DIBuilder_val(Builder), Metadata_val(Scope), String_val(Name),
952 caml_string_length(Name), (unsigned)Int_val(ArgNo), Metadata_val(File),
953 Int_val(Line), Metadata_val(Ty), Bool_val(AlwaysPreserve),
954 DIFlags_val(Flags));
955 return to_val(Metadata);
958 value llvm_dibuild_create_parameter_variable_bytecode(value *argv, int arg) {
959 return llvm_dibuild_create_parameter_variable_native(
960 argv[0], // Builder
961 argv[1], // Scope
962 argv[2], // Name
963 argv[3], // ArgNo
964 argv[4], // File
965 argv[5], // Line
966 argv[6], // Ty
967 argv[7], // AlwaysPreserve
968 argv[8] // Flags
972 value llvm_dibuild_insert_declare_before_native(value Builder, value Storage,
973 value VarInfo, value Expr,
974 value DebugLoc, value Instr) {
975 LLVMValueRef Value = LLVMDIBuilderInsertDeclareBefore(
976 DIBuilder_val(Builder), Value_val(Storage), Metadata_val(VarInfo),
977 Metadata_val(Expr), Metadata_val(DebugLoc), Value_val(Instr));
978 return to_val(Value);
981 value llvm_dibuild_insert_declare_before_bytecode(value *argv, int arg) {
983 return llvm_dibuild_insert_declare_before_native(argv[0], // Builder
984 argv[1], // Storage
985 argv[2], // VarInfo
986 argv[3], // Expr
987 argv[4], // DebugLoc
988 argv[5] // Instr
992 value llvm_dibuild_insert_declare_at_end_native(value Builder, value Storage,
993 value VarInfo, value Expr,
994 value DebugLoc, value Block) {
995 LLVMValueRef Value = LLVMDIBuilderInsertDeclareAtEnd(
996 DIBuilder_val(Builder), Value_val(Storage), Metadata_val(VarInfo),
997 Metadata_val(Expr), Metadata_val(DebugLoc), BasicBlock_val(Block));
998 return to_val(Value);
1001 value llvm_dibuild_insert_declare_at_end_bytecode(value *argv, int arg) {
1002 return llvm_dibuild_insert_declare_at_end_native(argv[0], // Builder
1003 argv[1], // Storage
1004 argv[2], // VarInfo
1005 argv[3], // Expr
1006 argv[4], // DebugLoc
1007 argv[5] // Block
1011 value llvm_dibuild_expression(value Builder, value Addr) {
1012 return to_val(LLVMDIBuilderCreateExpression(
1013 DIBuilder_val(Builder), (uint64_t *)Op_val(Addr), Wosize_val(Addr)));