1 /*===-- debuginfo_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
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. *|
13 |* Note that these functions intentionally take liberties with the CAMLparamX *|
14 |* macros, since most of the parameters are not GC heap objects. *|
16 \*===----------------------------------------------------------------------===*/
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
41 i_DIFlagObjcClassComplete
,
42 i_DIFlagObjectPointer
,
45 i_DIFlagLValueReference
,
46 i_DIFlagRValueReference
,
48 i_DIFlagSingleInheritance
,
49 i_DIFlagMultipleInheritance
,
50 i_DIFlagVirtualInheritance
,
51 i_DIFlagIntroducedVirtual
,
54 i_DIFlagTypePassByValue
,
55 i_DIFlagTypePassByReference
,
62 i_DIFlagIndirectVirtualBase
,
63 i_DIFlagAccessibility
,
64 i_DIFlagPtrToMemberRep
67 static LLVMDIFlags
map_DIFlag(LLVMDIFlag_i DIF
) {
70 return LLVMDIFlagZero
;
72 return LLVMDIFlagPrivate
;
73 case i_DIFlagProtected
:
74 return LLVMDIFlagProtected
;
76 return LLVMDIFlagPublic
;
78 return LLVMDIFlagFwdDecl
;
79 case i_DIFlagAppleBlock
:
80 return LLVMDIFlagAppleBlock
;
81 case i_DIFlagReservedBit4
:
82 return LLVMDIFlagReservedBit4
;
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
;
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
;
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
;
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
;
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
;
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
));
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
,
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(
231 argv
[4], // IsOptimized
233 argv
[6], // RuntimeVer
234 argv
[7], // SplitName
237 argv
[10], // SplitDebugInline
238 argv
[11], // DebugInfoForProfiling
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
266 argv
[3], // ConfigMacros
267 argv
[4], // IncludePath
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
,
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,
297 argv
[3], // LinkageName
301 argv
[7], // IsLocalUnit
302 argv
[8], // IsDefinition
303 argv
[9], // ScopeLine
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
) {
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
) {
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
) {
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
);
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
);
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
));
389 return to_val(Metadata
);
392 value
llvm_dibuild_create_enumerator(value Builder
, value Name
, value Value
,
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
));
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
418 argv
[4], // LineNumber
419 argv
[5], // SizeInBits
420 argv
[6], // AlignInBits
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
));
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
446 argv
[4], // LineNumber
447 argv
[5], // SizeInBits
448 argv
[6], // AlignInBits
451 argv
[9], // RunTimeLanguage
456 value
llvm_dibuild_create_array_type(value Builder
, value Size
,
457 value AlignInBits
, value Ty
,
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
));
464 return to_val(Metadata
);
467 value
llvm_dibuild_create_vector_type(value Builder
, value Size
,
468 value AlignInBits
, value Ty
,
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
));
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
,
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
,
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
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
));
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
535 argv
[4], // LineNumber
536 argv
[5], // SizeInBits
537 argv
[6], // AlignInBits
539 argv
[8], // DeriviedFrom
541 argv
[10], // RunTimeLanguage
542 argv
[11], // VTableHolder
547 value
llvm_dibuild_create_member_type_native(value Builder
, value Scope
,
548 value Name
, value File
,
549 value LineNumber
, value SizeInBits
,
551 value OffsetInBits
, value Flags
,
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
566 argv
[4], // LineNumber
567 argv
[5], // SizeInBits
568 argv
[6], // AlignInBits
569 argv
[7], // OffsetInBits
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
591 argv
[4], // LineNumber
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
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
,
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
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
676 argv
[3], // BaseOffset
677 argv
[4], // VBPtrOffset
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
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
,
726 return llvm_dibuild_create_replaceable_composite_type_native(
733 argv
[6], // RuntimeLang
734 argv
[7], // SizeInBits
735 argv
[8], // AlignInBits
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
),
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(
762 argv
[5], // SizeInBits
763 argv
[6], // OffsetInBits
764 argv
[7], // StorageOffsetInBits
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
));
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
794 argv
[4], // LineNumber
795 argv
[5], // SizeInBits
796 argv
[6], // AlignInBits
797 argv
[7], // OffsetInBits
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
) {
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
));
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
));
866 value
llvm_dibuild_create_constant_value_expression(value Builder
,
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
,
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
,
889 return llvm_dibuild_create_global_variable_expression_native(
897 argv
[7], // LocalToUnit
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
941 argv
[6], // AlwaysPreserve
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
),
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(
967 argv
[7], // AlwaysPreserve
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
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
1006 argv
[4], // DebugLoc
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
)));