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
;
142 value
llvm_debug_metadata_version(value Unit
) {
143 return Val_int(LLVMDebugMetadataVersion());
146 value
llvm_get_module_debug_metadata_version(LLVMModuleRef Module
) {
147 return Val_int(LLVMGetModuleDebugMetadataVersion(Module
));
150 #define DIFlags_val(v) (*(LLVMDIFlags *)(Data_custom_val(v)))
152 static struct custom_operations diflags_ops
= {
153 (char *)"DebugInfo.lldiflags", custom_finalize_default
,
154 custom_compare_default
, custom_hash_default
,
155 custom_serialize_default
, custom_deserialize_default
,
156 custom_compare_ext_default
};
158 static value
alloc_diflags(LLVMDIFlags Flags
) {
159 value V
= alloc_custom(&diflags_ops
, sizeof(LLVMDIFlags
), 0, 1);
160 DIFlags_val(V
) = Flags
;
164 LLVMDIFlags
llvm_diflags_get(value i_Flag
) {
165 LLVMDIFlags Flags
= map_DIFlag(Int_val(i_Flag
));
166 return alloc_diflags(Flags
);
169 LLVMDIFlags
llvm_diflags_set(value Flags
, value i_Flag
) {
170 LLVMDIFlags FlagsNew
= DIFlags_val(Flags
) | map_DIFlag(Int_val(i_Flag
));
171 return alloc_diflags(FlagsNew
);
174 value
llvm_diflags_test(value Flags
, value i_Flag
) {
175 LLVMDIFlags Flag
= map_DIFlag(Int_val(i_Flag
));
176 return Val_bool((DIFlags_val(Flags
) & Flag
) == Flag
);
179 #define DIBuilder_val(v) (*(LLVMDIBuilderRef *)(Data_custom_val(v)))
181 static void llvm_finalize_dibuilder(value B
) {
182 LLVMDIBuilderFinalize(DIBuilder_val(B
));
183 LLVMDisposeDIBuilder(DIBuilder_val(B
));
186 static struct custom_operations dibuilder_ops
= {
187 (char *)"DebugInfo.lldibuilder", llvm_finalize_dibuilder
,
188 custom_compare_default
, custom_hash_default
,
189 custom_serialize_default
, custom_deserialize_default
,
190 custom_compare_ext_default
};
192 static value
alloc_dibuilder(LLVMDIBuilderRef B
) {
193 value V
= alloc_custom(&dibuilder_ops
, sizeof(LLVMDIBuilderRef
), 0, 1);
194 DIBuilder_val(V
) = B
;
198 /* llmodule -> lldibuilder */
199 value
llvm_dibuilder(LLVMModuleRef M
) {
200 return alloc_dibuilder(LLVMCreateDIBuilder(M
));
203 value
llvm_dibuild_finalize(value Builder
) {
204 LLVMDIBuilderFinalize(DIBuilder_val(Builder
));
208 LLVMMetadataRef
llvm_dibuild_create_compile_unit_native(
209 value Builder
, value Lang
, LLVMMetadataRef FileRef
, value Producer
,
210 value IsOptimized
, value Flags
, value RuntimeVer
, value SplitName
,
211 value Kind
, value DWOId
, value SplitDebugInline
,
212 value DebugInfoForProfiling
, value SysRoot
, value SDK
) {
213 return LLVMDIBuilderCreateCompileUnit(
214 DIBuilder_val(Builder
), Int_val(Lang
), FileRef
, String_val(Producer
),
215 caml_string_length(Producer
), Bool_val(IsOptimized
), String_val(Flags
),
216 caml_string_length(Flags
), Int_val(RuntimeVer
), String_val(SplitName
),
217 caml_string_length(SplitName
), Int_val(Kind
), Int_val(DWOId
),
218 Bool_val(SplitDebugInline
), Bool_val(DebugInfoForProfiling
),
219 String_val(SysRoot
), caml_string_length(SysRoot
), String_val(SDK
),
220 caml_string_length(SDK
));
223 LLVMMetadataRef
llvm_dibuild_create_compile_unit_bytecode(value
*argv
,
225 return llvm_dibuild_create_compile_unit_native(
228 (LLVMMetadataRef
)argv
[2], // FileRef
230 argv
[4], // IsOptimized
232 argv
[6], // RuntimeVer
233 argv
[7], // SplitName
236 argv
[10], // SplitDebugInline
237 argv
[11], // DebugInfoForProfiling
243 LLVMMetadataRef
llvm_dibuild_create_file(value Builder
, value Filename
,
245 return LLVMDIBuilderCreateFile(DIBuilder_val(Builder
), String_val(Filename
),
246 caml_string_length(Filename
),
247 String_val(Directory
),
248 caml_string_length(Directory
));
252 llvm_dibuild_create_module_native(value Builder
, LLVMMetadataRef ParentScope
,
253 value Name
, value ConfigMacros
,
254 value IncludePath
, value SysRoot
) {
255 return LLVMDIBuilderCreateModule(
256 DIBuilder_val(Builder
), ParentScope
, String_val(Name
),
257 caml_string_length(Name
), String_val(ConfigMacros
),
258 caml_string_length(ConfigMacros
), String_val(IncludePath
),
259 caml_string_length(IncludePath
), String_val(SysRoot
),
260 caml_string_length(SysRoot
));
263 LLVMMetadataRef
llvm_dibuild_create_module_bytecode(value
*argv
, int argn
) {
264 return llvm_dibuild_create_module_native(
266 (LLVMMetadataRef
)argv
[1], // ParentScope
268 argv
[3], // ConfigMacros
269 argv
[4], // IncludePath
274 LLVMMetadataRef
llvm_dibuild_create_namespace(value Builder
,
275 LLVMMetadataRef ParentScope
,
276 value Name
, value ExportSymbols
) {
277 return LLVMDIBuilderCreateNameSpace(
278 DIBuilder_val(Builder
), ParentScope
, String_val(Name
),
279 caml_string_length(Name
), Bool_val(ExportSymbols
));
282 LLVMMetadataRef
llvm_dibuild_create_function_native(
283 value Builder
, LLVMMetadataRef Scope
, value Name
, value LinkageName
,
284 LLVMMetadataRef File
, value LineNo
, LLVMMetadataRef Ty
, value IsLocalToUnit
,
285 value IsDefinition
, value ScopeLine
, value Flags
, value IsOptimized
) {
286 return LLVMDIBuilderCreateFunction(
287 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
288 String_val(LinkageName
), caml_string_length(LinkageName
), File
,
289 Int_val(LineNo
), Ty
, Bool_val(IsLocalToUnit
), Bool_val(IsDefinition
),
290 Int_val(ScopeLine
), DIFlags_val(Flags
), Bool_val(IsOptimized
));
293 LLVMMetadataRef
llvm_dibuild_create_function_bytecode(value
*argv
, int argn
) {
294 return llvm_dibuild_create_function_native(argv
[0], // Builder,
295 (LLVMMetadataRef
)argv
[1], // Scope
297 argv
[3], // LinkageName
298 (LLVMMetadataRef
)argv
[4], // File
300 (LLVMMetadataRef
)argv
[6], // Ty
301 argv
[7], // IsLocalUnit
302 argv
[8], // IsDefinition
303 argv
[9], // ScopeLine
305 argv
[11] // IsOptimized
309 LLVMMetadataRef
llvm_dibuild_create_lexical_block(value Builder
,
310 LLVMMetadataRef Scope
,
311 LLVMMetadataRef File
,
312 value Line
, value Column
) {
313 return LLVMDIBuilderCreateLexicalBlock(DIBuilder_val(Builder
), Scope
, File
,
314 Int_val(Line
), Int_val(Column
));
317 LLVMMetadataRef
llvm_metadata_null() { return (LLVMMetadataRef
)NULL
; }
319 LLVMMetadataRef
llvm_dibuild_create_debug_location(LLVMContextRef Ctx
,
320 value Line
, value Column
,
321 LLVMMetadataRef Scope
,
322 LLVMMetadataRef InlinedAt
) {
323 return LLVMDIBuilderCreateDebugLocation(Ctx
, Int_val(Line
), Int_val(Column
),
327 value
llvm_di_location_get_line(LLVMMetadataRef Location
) {
328 return Val_int(LLVMDILocationGetLine(Location
));
331 value
llvm_di_location_get_column(LLVMMetadataRef Location
) {
332 return Val_int(LLVMDILocationGetColumn(Location
));
335 LLVMMetadataRef
llvm_di_location_get_scope(LLVMMetadataRef Location
) {
336 return LLVMDILocationGetScope(Location
);
339 value
llvm_di_location_get_inlined_at(LLVMMetadataRef Location
) {
340 return (ptr_to_option(LLVMDILocationGetInlinedAt(Location
)));
343 value
llvm_di_scope_get_file(LLVMMetadataRef Scope
) {
344 return (ptr_to_option(LLVMDIScopeGetFile(Scope
)));
347 value
llvm_di_file_get_directory(LLVMMetadataRef File
) {
349 const char *Directory
= LLVMDIFileGetDirectory(File
, &Len
);
350 return cstr_to_string(Directory
, Len
);
353 value
llvm_di_file_get_filename(LLVMMetadataRef File
) {
355 const char *Filename
= LLVMDIFileGetFilename(File
, &Len
);
356 return cstr_to_string(Filename
, Len
);
359 value
llvm_di_file_get_source(LLVMMetadataRef File
) {
361 const char *Source
= LLVMDIFileGetSource(File
, &Len
);
362 return cstr_to_string(Source
, Len
);
365 LLVMMetadataRef
llvm_dibuild_get_or_create_type_array(value Builder
,
368 return LLVMDIBuilderGetOrCreateTypeArray(DIBuilder_val(Builder
),
369 (LLVMMetadataRef
*)Op_val(Data
),
373 LLVMMetadataRef
llvm_dibuild_get_or_create_array(value Builder
, value Data
) {
375 return LLVMDIBuilderGetOrCreateArray(DIBuilder_val(Builder
),
376 (LLVMMetadataRef
*)Op_val(Data
),
380 LLVMMetadataRef
llvm_dibuild_create_subroutine_type(value Builder
,
381 LLVMMetadataRef File
,
382 value ParameterTypes
,
385 return LLVMDIBuilderCreateSubroutineType(
386 DIBuilder_val(Builder
), File
, (LLVMMetadataRef
*)Op_val(ParameterTypes
),
387 Wosize_val(ParameterTypes
), DIFlags_val(Flags
));
390 LLVMMetadataRef
llvm_dibuild_create_enumerator(value Builder
, value Name
,
391 value Value
, value IsUnsigned
) {
392 return LLVMDIBuilderCreateEnumerator(
393 DIBuilder_val(Builder
), String_val(Name
), caml_string_length(Name
),
394 (int64_t)Int_val(Value
), Bool_val(IsUnsigned
));
397 LLVMMetadataRef
llvm_dibuild_create_enumeration_type_native(
398 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
399 value LineNumber
, value SizeInBits
, value AlignInBits
, value Elements
,
400 LLVMMetadataRef ClassTy
) {
401 return LLVMDIBuilderCreateEnumerationType(
402 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
403 File
, Int_val(LineNumber
), (uint64_t)Int_val(SizeInBits
),
404 Int_val(AlignInBits
), (LLVMMetadataRef
*)Op_val(Elements
),
405 Wosize_val(Elements
), ClassTy
);
408 LLVMMetadataRef
llvm_dibuild_create_enumeration_type_bytecode(value
*argv
,
410 return llvm_dibuild_create_enumeration_type_native(
412 (LLVMMetadataRef
)argv
[1], // Scope
414 (LLVMMetadataRef
)argv
[3], // File
415 argv
[4], // LineNumber
416 argv
[5], // SizeInBits
417 argv
[6], // AlignInBits
419 (LLVMMetadataRef
)argv
[8] // ClassTy
423 LLVMMetadataRef
llvm_dibuild_create_union_type_native(
424 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
425 value LineNumber
, value SizeInBits
, value AlignInBits
, value Flags
,
426 value Elements
, value RunTimeLanguage
, value UniqueId
) {
428 return LLVMDIBuilderCreateUnionType(
429 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
430 File
, Int_val(LineNumber
), (uint64_t)Int_val(SizeInBits
),
431 Int_val(AlignInBits
), DIFlags_val(Flags
),
432 (LLVMMetadataRef
*)Op_val(Elements
), Wosize_val(Elements
),
433 Int_val(RunTimeLanguage
), String_val(UniqueId
),
434 caml_string_length(UniqueId
));
437 LLVMMetadataRef
llvm_dibuild_create_union_type_bytecode(value
*argv
, int argn
) {
438 return llvm_dibuild_create_union_type_native(
440 (LLVMMetadataRef
)argv
[1], // Scope
442 (LLVMMetadataRef
)argv
[3], // File
443 argv
[4], // LineNumber
444 argv
[5], // SizeInBits
445 argv
[6], // AlignInBits
448 argv
[9], // RunTimeLanguage
453 LLVMMetadataRef
llvm_dibuild_create_array_type(value Builder
, value Size
,
457 return LLVMDIBuilderCreateArrayType(
458 DIBuilder_val(Builder
), (uint64_t)Int_val(Size
), Int_val(AlignInBits
), Ty
,
459 (LLVMMetadataRef
*)Op_val(Subscripts
), Wosize_val(Subscripts
));
462 LLVMMetadataRef
llvm_dibuild_create_vector_type(value Builder
, value Size
,
466 return LLVMDIBuilderCreateVectorType(
467 DIBuilder_val(Builder
), (uint64_t)Int_val(Size
), Int_val(AlignInBits
), Ty
,
468 (LLVMMetadataRef
*)Op_val(Subscripts
), Wosize_val(Subscripts
));
471 LLVMMetadataRef
llvm_dibuild_create_unspecified_type(value Builder
,
473 return LLVMDIBuilderCreateUnspecifiedType(
474 DIBuilder_val(Builder
), String_val(Name
), caml_string_length(Name
));
477 LLVMMetadataRef
llvm_dibuild_create_basic_type(value Builder
, value Name
,
478 value SizeInBits
, value Encoding
,
481 return LLVMDIBuilderCreateBasicType(
482 DIBuilder_val(Builder
), String_val(Name
), caml_string_length(Name
),
483 (uint64_t)Int_val(SizeInBits
), Int_val(Encoding
), DIFlags_val(Flags
));
486 LLVMMetadataRef
llvm_dibuild_create_pointer_type_native(
487 value Builder
, LLVMMetadataRef PointeeTy
, value SizeInBits
,
488 value AlignInBits
, value AddressSpace
, value Name
) {
489 return LLVMDIBuilderCreatePointerType(
490 DIBuilder_val(Builder
), PointeeTy
, (uint64_t)Int_val(SizeInBits
),
491 Int_val(AlignInBits
), Int_val(AddressSpace
), String_val(Name
),
492 caml_string_length(Name
));
495 LLVMMetadataRef
llvm_dibuild_create_pointer_type_bytecode(value
*argv
,
497 return llvm_dibuild_create_pointer_type_native(
499 (LLVMMetadataRef
)argv
[1], // PointeeTy
500 argv
[2], // SizeInBits
501 argv
[3], // AlignInBits
502 argv
[4], // AddressSpace
507 LLVMMetadataRef
llvm_dibuild_create_struct_type_native(
508 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
509 value LineNumber
, value SizeInBits
, value AlignInBits
, value Flags
,
510 LLVMMetadataRef DerivedFrom
, value Elements
, value RunTimeLanguage
,
511 LLVMMetadataRef VTableHolder
, value UniqueId
) {
513 return LLVMDIBuilderCreateStructType(
514 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
515 File
, Int_val(LineNumber
), (uint64_t)Int_val(SizeInBits
),
516 Int_val(AlignInBits
), DIFlags_val(Flags
), DerivedFrom
,
517 (LLVMMetadataRef
*)Op_val(Elements
), Wosize_val(Elements
),
518 Int_val(RunTimeLanguage
), VTableHolder
, String_val(UniqueId
),
519 caml_string_length(UniqueId
));
522 LLVMMetadataRef
llvm_dibuild_create_struct_type_bytecode(value
*argv
,
524 return llvm_dibuild_create_struct_type_native(
526 (LLVMMetadataRef
)argv
[1], // Scope
528 (LLVMMetadataRef
)argv
[3], // File
529 argv
[4], // LineNumber
530 argv
[5], // SizeInBits
531 argv
[6], // AlignInBits
533 (LLVMMetadataRef
)argv
[8], // DeriviedFrom
535 argv
[10], // RunTimeLanguage
536 (LLVMMetadataRef
)argv
[11], // VTableHolder
541 LLVMMetadataRef
llvm_dibuild_create_member_type_native(
542 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
543 value LineNumber
, value SizeInBits
, value AlignInBits
, value OffsetInBits
,
544 value Flags
, LLVMMetadataRef Ty
) {
546 return LLVMDIBuilderCreateMemberType(
547 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
548 File
, Int_val(LineNumber
), (uint64_t)Int_val(SizeInBits
),
549 Int_val(AlignInBits
), (uint64_t)Int_val(OffsetInBits
), DIFlags_val(Flags
),
553 LLVMMetadataRef
llvm_dibuild_create_member_type_bytecode(value
*argv
,
555 return llvm_dibuild_create_member_type_native(
557 (LLVMMetadataRef
)argv
[1], // Scope
559 (LLVMMetadataRef
)argv
[3], // File
560 argv
[4], // LineNumber
561 argv
[5], // SizeInBits
562 argv
[6], // AlignInBits
563 argv
[7], // OffsetInBits
565 (LLVMMetadataRef
)argv
[9] // Ty
569 LLVMMetadataRef
llvm_dibuild_create_static_member_type_native(
570 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
571 value LineNumber
, LLVMMetadataRef Type
, value Flags
,
572 LLVMValueRef ConstantVal
, value AlignInBits
) {
574 return LLVMDIBuilderCreateStaticMemberType(
575 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
576 File
, Int_val(LineNumber
), Type
, DIFlags_val(Flags
), ConstantVal
,
577 Int_val(AlignInBits
));
580 LLVMMetadataRef
llvm_dibuild_create_static_member_type_bytecode(value
*argv
,
582 return llvm_dibuild_create_static_member_type_native(
584 (LLVMMetadataRef
)argv
[1], // Scope
586 (LLVMMetadataRef
)argv
[3], // File
587 argv
[4], // LineNumber
588 (LLVMMetadataRef
)argv
[5], // Type
590 (LLVMValueRef
)argv
[7], // ConstantVal
591 argv
[8] // AlignInBits
595 LLVMMetadataRef
llvm_dibuild_create_member_pointer_type_native(
596 value Builder
, LLVMMetadataRef PointeeType
, LLVMMetadataRef ClassType
,
597 uint64_t SizeInBits
, uint32_t AlignInBits
, LLVMDIFlags Flags
) {
599 return LLVMDIBuilderCreateMemberPointerType(
600 DIBuilder_val(Builder
), PointeeType
, ClassType
,
601 (uint64_t)Int_val(SizeInBits
), Int_val(AlignInBits
), Flags
);
604 LLVMMetadataRef
llvm_dibuild_create_member_pointer_type_bytecode(value
*argv
,
606 return llvm_dibuild_create_member_pointer_type_native(
608 (LLVMMetadataRef
)argv
[1], // PointeeType
609 (LLVMMetadataRef
)argv
[2], // ClassType
610 argv
[3], // SizeInBits
611 argv
[4], // AlignInBits
616 LLVMMetadataRef
llvm_dibuild_create_object_pointer_type(value Builder
,
617 LLVMMetadataRef Type
) {
618 return LLVMDIBuilderCreateObjectPointerType(DIBuilder_val(Builder
), Type
);
621 LLVMMetadataRef
llvm_dibuild_create_qualified_type(value Builder
, value Tag
,
622 LLVMMetadataRef Type
) {
624 return LLVMDIBuilderCreateQualifiedType(DIBuilder_val(Builder
), Int_val(Tag
),
628 LLVMMetadataRef
llvm_dibuild_create_reference_type(value Builder
, value Tag
,
629 LLVMMetadataRef Type
) {
631 return LLVMDIBuilderCreateReferenceType(DIBuilder_val(Builder
), Int_val(Tag
),
635 LLVMMetadataRef
llvm_dibuild_create_null_ptr_type(value Builder
) {
637 return LLVMDIBuilderCreateNullPtrType(DIBuilder_val(Builder
));
640 LLVMMetadataRef
llvm_dibuild_create_typedef_native(
641 value Builder
, LLVMMetadataRef Type
, value Name
, LLVMMetadataRef File
,
642 value LineNo
, LLVMMetadataRef Scope
, value AlignInBits
) {
644 return LLVMDIBuilderCreateTypedef(
645 DIBuilder_val(Builder
), Type
, String_val(Name
), caml_string_length(Name
),
646 File
, Int_val(LineNo
), Scope
, Int_val(AlignInBits
));
649 LLVMMetadataRef
llvm_dibuild_create_typedef_bytecode(value
*argv
, int argn
) {
651 return llvm_dibuild_create_typedef_native(argv
[0], // Builder
652 (LLVMMetadataRef
)argv
[1], // Type
654 (LLVMMetadataRef
)argv
[3], // File
656 (LLVMMetadataRef
)argv
[5], // Scope
657 argv
[6] // AlignInBits
662 llvm_dibuild_create_inheritance_native(value Builder
, LLVMMetadataRef Ty
,
663 LLVMMetadataRef BaseTy
, value BaseOffset
,
664 value VBPtrOffset
, value Flags
) {
666 return LLVMDIBuilderCreateInheritance(DIBuilder_val(Builder
), Ty
, BaseTy
,
667 (uint64_t)Int_val(BaseOffset
),
668 Int_val(VBPtrOffset
), Flags
);
671 LLVMMetadataRef
llvm_dibuild_create_inheritance_bytecode(value
*argv
, int arg
) {
673 return llvm_dibuild_create_inheritance_native(
675 (LLVMMetadataRef
)argv
[1], // Ty
676 (LLVMMetadataRef
)argv
[2], // BaseTy
677 argv
[3], // BaseOffset
678 argv
[4], // VBPtrOffset
683 LLVMMetadataRef
llvm_dibuild_create_forward_decl_native(
684 value Builder
, value Tag
, value Name
, LLVMMetadataRef Scope
,
685 LLVMMetadataRef File
, value Line
, value RuntimeLang
, value SizeInBits
,
686 value AlignInBits
, value UniqueIdentifier
) {
687 return LLVMDIBuilderCreateForwardDecl(
688 DIBuilder_val(Builder
), Int_val(Tag
), String_val(Name
),
689 caml_string_length(Name
), Scope
, File
, Int_val(Line
),
690 Int_val(RuntimeLang
), (uint64_t)Int_val(SizeInBits
), Int_val(AlignInBits
),
691 String_val(UniqueIdentifier
), caml_string_length(UniqueIdentifier
));
694 LLVMMetadataRef
llvm_dibuild_create_forward_decl_bytecode(value
*argv
,
697 return llvm_dibuild_create_forward_decl_native(
701 (LLVMMetadataRef
)argv
[3], // Scope
702 (LLVMMetadataRef
)argv
[4], // File
704 argv
[6], // RuntimeLang
705 argv
[7], // SizeInBits
706 argv
[8], // AlignInBits
707 argv
[9] // UniqueIdentifier
711 LLVMMetadataRef
llvm_dibuild_create_replaceable_composite_type_native(
712 value Builder
, value Tag
, value Name
, LLVMMetadataRef Scope
,
713 LLVMMetadataRef File
, value Line
, value RuntimeLang
, value SizeInBits
,
714 value AlignInBits
, value Flags
, value UniqueIdentifier
) {
716 return LLVMDIBuilderCreateReplaceableCompositeType(
717 DIBuilder_val(Builder
), Int_val(Tag
), String_val(Name
),
718 caml_string_length(Name
), Scope
, File
, Int_val(Line
),
719 Int_val(RuntimeLang
), (uint64_t)Int_val(SizeInBits
), Int_val(AlignInBits
),
720 DIFlags_val(Flags
), String_val(UniqueIdentifier
),
721 caml_string_length(UniqueIdentifier
));
725 llvm_dibuild_create_replaceable_composite_type_bytecode(value
*argv
, int arg
) {
727 return llvm_dibuild_create_replaceable_composite_type_native(
731 (LLVMMetadataRef
)argv
[3], // Scope
732 (LLVMMetadataRef
)argv
[4], // File
734 argv
[6], // RuntimeLang
735 argv
[7], // SizeInBits
736 argv
[8], // AlignInBits
738 argv
[10] // UniqueIdentifier
742 LLVMMetadataRef
llvm_dibuild_create_bit_field_member_type_native(
743 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
744 value LineNum
, value SizeInBits
, value OffsetInBits
,
745 value StorageOffsetInBits
, value Flags
, LLVMMetadataRef Ty
) {
747 return LLVMDIBuilderCreateBitFieldMemberType(
748 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
749 File
, Int_val(LineNum
), (uint64_t)Int_val(SizeInBits
),
750 (uint64_t)Int_val(OffsetInBits
), (uint64_t)Int_val(StorageOffsetInBits
),
751 DIFlags_val(Flags
), Ty
);
754 LLVMMetadataRef
llvm_dibuild_create_bit_field_member_type_bytecode(value
*argv
,
757 return llvm_dibuild_create_bit_field_member_type_native(
759 (LLVMMetadataRef
)argv
[1], // Scope
761 (LLVMMetadataRef
)argv
[3], // File
763 argv
[5], // SizeInBits
764 argv
[6], // OffsetInBits
765 argv
[7], // StorageOffsetInBits
767 (LLVMMetadataRef
)argv
[9] // Ty
771 LLVMMetadataRef
llvm_dibuild_create_class_type_native(
772 value Builder
, LLVMMetadataRef Scope
, value Name
, LLVMMetadataRef File
,
773 value LineNumber
, value SizeInBits
, value AlignInBits
, value OffsetInBits
,
774 value Flags
, LLVMMetadataRef DerivedFrom
, value Elements
,
775 LLVMMetadataRef VTableHolder
, LLVMMetadataRef TemplateParamsNode
,
776 value UniqueIdentifier
) {
778 return LLVMDIBuilderCreateClassType(
779 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
780 File
, Int_val(LineNumber
), (uint64_t)Int_val(SizeInBits
),
781 Int_val(AlignInBits
), (uint64_t)Int_val(OffsetInBits
), DIFlags_val(Flags
),
782 DerivedFrom
, (LLVMMetadataRef
*)Op_val(Elements
), Wosize_val(Elements
),
783 VTableHolder
, TemplateParamsNode
, String_val(UniqueIdentifier
),
784 caml_string_length(UniqueIdentifier
));
787 LLVMMetadataRef
llvm_dibuild_create_class_type_bytecode(value
*argv
, int arg
) {
789 return llvm_dibuild_create_class_type_native(
791 (LLVMMetadataRef
)argv
[1], // Scope
793 (LLVMMetadataRef
)argv
[3], // File
794 argv
[4], // LineNumber
795 argv
[5], // SizeInBits
796 argv
[6], // AlignInBits
797 argv
[7], // OffsetInBits
799 (LLVMMetadataRef
)argv
[9], // DerivedFrom
800 argv
[10], // Elements
801 (LLVMMetadataRef
)argv
[11], // VTableHolder
802 (LLVMMetadataRef
)argv
[12], // TemplateParamsNode
803 argv
[13] // UniqueIdentifier
807 LLVMMetadataRef
llvm_dibuild_create_artificial_type(value Builder
,
808 LLVMMetadataRef Type
) {
809 return LLVMDIBuilderCreateArtificialType(DIBuilder_val(Builder
), Type
);
812 value
llvm_di_type_get_name(LLVMMetadataRef DType
) {
814 const char *Name
= LLVMDITypeGetName(DType
, &Len
);
815 return cstr_to_string(Name
, Len
);
818 value
llvm_di_type_get_size_in_bits(LLVMMetadataRef DType
) {
819 uint64_t Size
= LLVMDITypeGetSizeInBits(DType
);
820 return Val_int((int)Size
);
823 value
llvm_di_type_get_offset_in_bits(LLVMMetadataRef DType
) {
824 uint64_t Size
= LLVMDITypeGetOffsetInBits(DType
);
825 return Val_int((int)Size
);
828 value
llvm_di_type_get_align_in_bits(LLVMMetadataRef DType
) {
829 uint32_t Size
= LLVMDITypeGetAlignInBits(DType
);
830 return Val_int(Size
);
833 value
llvm_di_type_get_line(LLVMMetadataRef DType
) {
834 unsigned Line
= LLVMDITypeGetLine(DType
);
835 return Val_int(Line
);
838 value
llvm_di_type_get_flags(LLVMMetadataRef DType
) {
839 LLVMDIFlags Flags
= LLVMDITypeGetLine(DType
);
840 return alloc_diflags(Flags
);
843 value
llvm_get_subprogram(LLVMValueRef Func
) {
844 return (ptr_to_option(LLVMGetSubprogram(Func
)));
847 value
llvm_set_subprogram(LLVMValueRef Func
, LLVMMetadataRef SP
) {
848 LLVMSetSubprogram(Func
, SP
);
852 value
llvm_di_subprogram_get_line(LLVMMetadataRef Subprogram
) {
853 return Val_int(LLVMDISubprogramGetLine(Subprogram
));
856 value
llvm_instr_get_debug_loc(LLVMValueRef Inst
) {
857 return (ptr_to_option(LLVMInstructionGetDebugLoc(Inst
)));
860 value
llvm_instr_set_debug_loc(LLVMValueRef Inst
, LLVMMetadataRef Loc
) {
861 LLVMInstructionSetDebugLoc(Inst
, Loc
);
865 LLVMMetadataRef
llvm_dibuild_create_constant_value_expression(value Builder
,
867 return LLVMDIBuilderCreateConstantValueExpression(DIBuilder_val(Builder
),
868 (uint64_t)Int_val(Value
));
871 LLVMMetadataRef
llvm_dibuild_create_global_variable_expression_native(
872 value Builder
, LLVMMetadataRef Scope
, value Name
, value Linkage
,
873 LLVMMetadataRef File
, value Line
, LLVMMetadataRef Ty
, value LocalToUnit
,
874 LLVMMetadataRef Expr
, LLVMMetadataRef Decl
, value AlignInBits
) {
875 return LLVMDIBuilderCreateGlobalVariableExpression(
876 DIBuilder_val(Builder
), Scope
, String_val(Name
), caml_string_length(Name
),
877 String_val(Linkage
), caml_string_length(Linkage
), File
, Int_val(Line
), Ty
,
878 Bool_val(LocalToUnit
), Expr
, Decl
, Int_val(AlignInBits
));
882 llvm_dibuild_create_global_variable_expression_bytecode(value
*argv
, int arg
) {
884 return llvm_dibuild_create_global_variable_expression_native(
886 (LLVMMetadataRef
)argv
[1], // Scope
889 (LLVMMetadataRef
)argv
[4], // File
891 (LLVMMetadataRef
)argv
[6], // Ty
892 argv
[7], // LocalToUnit
893 (LLVMMetadataRef
)argv
[8], // Expr
894 (LLVMMetadataRef
)argv
[9], // Decl
895 argv
[10] // AlignInBits
899 value
llvm_di_global_variable_expression_get_variable(LLVMMetadataRef GVE
) {
900 return (ptr_to_option(LLVMDIGlobalVariableExpressionGetVariable(GVE
)));
903 value
llvm_di_variable_get_line(LLVMMetadataRef Variable
) {
904 return Val_int(LLVMDIVariableGetLine(Variable
));
907 value
llvm_di_variable_get_file(LLVMMetadataRef Variable
) {
908 return (ptr_to_option(LLVMDIVariableGetFile(Variable
)));
911 value
llvm_get_metadata_kind(LLVMMetadataRef Metadata
) {
912 return Val_int(LLVMGetMetadataKind(Metadata
));