1 //===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines C bindings for the DIBuilder class.
12 //===----------------------------------------------------------------------===//
14 #include "DIBuilderBindings.h"
15 #include "IRBindings.h"
16 #include "llvm/IR/DIBuilder.h"
17 #include "llvm/IR/IRBuilder.h"
18 #include "llvm/IR/Module.h"
22 LLVMDIBuilderRef
LLVMNewDIBuilder(LLVMModuleRef mref
) {
23 Module
*m
= unwrap(mref
);
24 return wrap(new DIBuilder(*m
));
27 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref
) {
28 DIBuilder
*d
= unwrap(dref
);
32 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref
) { unwrap(dref
)->finalize(); }
34 LLVMMetadataRef
LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref
,
35 unsigned Lang
, const char *File
,
38 int Optimized
, const char *Flags
,
39 unsigned RuntimeVersion
) {
40 DIBuilder
*D
= unwrap(Dref
);
41 return wrap(D
->createCompileUnit(Lang
, D
->createFile(File
, Dir
), Producer
,
42 Optimized
, Flags
, RuntimeVersion
));
45 LLVMMetadataRef
LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref
, const char *File
,
47 DIBuilder
*D
= unwrap(Dref
);
48 return wrap(D
->createFile(File
, Dir
));
51 LLVMMetadataRef
LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref
,
52 LLVMMetadataRef Scope
,
56 DIBuilder
*D
= unwrap(Dref
);
57 auto *LB
= D
->createLexicalBlock(unwrap
<DILocalScope
>(Scope
),
58 unwrap
<DIFile
>(File
), Line
, Column
);
62 LLVMMetadataRef
LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref
,
63 LLVMMetadataRef Scope
,
65 unsigned Discriminator
) {
66 DIBuilder
*D
= unwrap(Dref
);
67 return wrap(D
->createLexicalBlockFile(unwrap
<DILocalScope
>(Scope
),
68 unwrap
<DIFile
>(File
), Discriminator
));
71 LLVMMetadataRef
LLVMDIBuilderCreateFunction(
72 LLVMDIBuilderRef Dref
, LLVMMetadataRef Scope
, const char *Name
,
73 const char *LinkageName
, LLVMMetadataRef File
, unsigned Line
,
74 LLVMMetadataRef CompositeType
, int IsLocalToUnit
, int IsDefinition
,
75 unsigned ScopeLine
, unsigned Flags
, int IsOptimized
) {
76 DIBuilder
*D
= unwrap(Dref
);
77 return wrap(D
->createFunction(
78 unwrap
<DIScope
>(Scope
), Name
, LinkageName
,
79 File
? unwrap
<DIFile
>(File
) : nullptr, Line
,
80 unwrap
<DISubroutineType
>(CompositeType
), IsLocalToUnit
, IsDefinition
,
81 ScopeLine
, static_cast<DINode::DIFlags
>(Flags
), IsOptimized
));
84 LLVMMetadataRef
LLVMDIBuilderCreateAutoVariable(
85 LLVMDIBuilderRef Dref
, LLVMMetadataRef Scope
, const char *Name
,
86 LLVMMetadataRef File
, unsigned Line
, LLVMMetadataRef Ty
, int AlwaysPreserve
,
87 unsigned Flags
, uint32_t AlignInBits
) {
88 DIBuilder
*D
= unwrap(Dref
);
90 D
->createAutoVariable(unwrap
<DIScope
>(Scope
), Name
, unwrap
<DIFile
>(File
),
91 Line
, unwrap
<DIType
>(Ty
), AlwaysPreserve
,
92 static_cast<DINode::DIFlags
>(Flags
), AlignInBits
));
95 LLVMMetadataRef
LLVMDIBuilderCreateParameterVariable(
96 LLVMDIBuilderRef Dref
, LLVMMetadataRef Scope
, const char *Name
,
97 unsigned ArgNo
, LLVMMetadataRef File
, unsigned Line
, LLVMMetadataRef Ty
,
98 int AlwaysPreserve
, unsigned Flags
) {
99 DIBuilder
*D
= unwrap(Dref
);
100 return wrap(D
->createParameterVariable(
101 unwrap
<DIScope
>(Scope
), Name
, ArgNo
, unwrap
<DIFile
>(File
), Line
,
102 unwrap
<DIType
>(Ty
), AlwaysPreserve
, static_cast<DINode::DIFlags
>(Flags
)));
105 LLVMMetadataRef
LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref
,
109 DIBuilder
*D
= unwrap(Dref
);
110 return wrap(D
->createBasicType(Name
, SizeInBits
, Encoding
));
113 LLVMMetadataRef
LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref
,
114 LLVMMetadataRef PointeeType
,
116 uint32_t AlignInBits
,
118 DIBuilder
*D
= unwrap(Dref
);
119 return wrap(D
->createPointerType(unwrap
<DIType
>(PointeeType
), SizeInBits
,
120 AlignInBits
, /* DWARFAddressSpace */ None
,
125 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref
, LLVMMetadataRef File
,
126 LLVMMetadataRef ParameterTypes
) {
127 DIBuilder
*D
= unwrap(Dref
);
129 D
->createSubroutineType(DITypeRefArray(unwrap
<MDTuple
>(ParameterTypes
))));
132 LLVMMetadataRef
LLVMDIBuilderCreateStructType(
133 LLVMDIBuilderRef Dref
, LLVMMetadataRef Scope
, const char *Name
,
134 LLVMMetadataRef File
, unsigned Line
, uint64_t SizeInBits
,
135 uint32_t AlignInBits
, unsigned Flags
, LLVMMetadataRef DerivedFrom
,
136 LLVMMetadataRef ElementTypes
) {
137 DIBuilder
*D
= unwrap(Dref
);
138 return wrap(D
->createStructType(
139 unwrap
<DIScope
>(Scope
), Name
, File
? unwrap
<DIFile
>(File
) : nullptr, Line
,
140 SizeInBits
, AlignInBits
, static_cast<DINode::DIFlags
>(Flags
),
141 DerivedFrom
? unwrap
<DIType
>(DerivedFrom
) : nullptr,
142 ElementTypes
? DINodeArray(unwrap
<MDTuple
>(ElementTypes
)) : nullptr));
145 LLVMMetadataRef
LLVMDIBuilderCreateReplaceableCompositeType(
146 LLVMDIBuilderRef Dref
, unsigned Tag
, const char *Name
,
147 LLVMMetadataRef Scope
, LLVMMetadataRef File
, unsigned Line
,
148 unsigned RuntimeLang
, uint64_t SizeInBits
, uint32_t AlignInBits
,
150 DIBuilder
*D
= unwrap(Dref
);
151 return wrap(D
->createReplaceableCompositeType(
152 Tag
, Name
, unwrap
<DIScope
>(Scope
), File
? unwrap
<DIFile
>(File
) : nullptr,
153 Line
, RuntimeLang
, SizeInBits
, AlignInBits
,
154 static_cast<DINode::DIFlags
>(Flags
)));
158 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref
, LLVMMetadataRef Scope
,
159 const char *Name
, LLVMMetadataRef File
,
160 unsigned Line
, uint64_t SizeInBits
,
161 uint32_t AlignInBits
, uint64_t OffsetInBits
,
162 unsigned Flags
, LLVMMetadataRef Ty
) {
163 DIBuilder
*D
= unwrap(Dref
);
164 return wrap(D
->createMemberType(
165 unwrap
<DIScope
>(Scope
), Name
, File
? unwrap
<DIFile
>(File
) : nullptr, Line
,
166 SizeInBits
, AlignInBits
, OffsetInBits
,
167 static_cast<DINode::DIFlags
>(Flags
), unwrap
<DIType
>(Ty
)));
170 LLVMMetadataRef
LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref
,
172 uint32_t AlignInBits
,
173 LLVMMetadataRef ElementType
,
174 LLVMMetadataRef Subscripts
) {
175 DIBuilder
*D
= unwrap(Dref
);
176 return wrap(D
->createArrayType(SizeInBits
, AlignInBits
,
177 unwrap
<DIType
>(ElementType
),
178 DINodeArray(unwrap
<MDTuple
>(Subscripts
))));
181 LLVMMetadataRef
LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref
,
182 LLVMMetadataRef Ty
, const char *Name
,
183 LLVMMetadataRef File
, unsigned Line
,
184 LLVMMetadataRef Context
) {
185 DIBuilder
*D
= unwrap(Dref
);
186 return wrap(D
->createTypedef(unwrap
<DIType
>(Ty
), Name
,
187 File
? unwrap
<DIFile
>(File
) : nullptr, Line
,
188 Context
? unwrap
<DIScope
>(Context
) : nullptr));
191 LLVMMetadataRef
LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref
,
192 int64_t Lo
, int64_t Count
) {
193 DIBuilder
*D
= unwrap(Dref
);
194 return wrap(D
->getOrCreateSubrange(Lo
, Count
));
197 LLVMMetadataRef
LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref
,
198 LLVMMetadataRef
*Data
,
200 DIBuilder
*D
= unwrap(Dref
);
201 Metadata
**DataValue
= unwrap(Data
);
202 ArrayRef
<Metadata
*> Elements(DataValue
, Length
);
203 DINodeArray A
= D
->getOrCreateArray(Elements
);
204 return wrap(A
.get());
207 LLVMMetadataRef
LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref
,
208 LLVMMetadataRef
*Data
,
210 DIBuilder
*D
= unwrap(Dref
);
211 Metadata
**DataValue
= unwrap(Data
);
212 ArrayRef
<Metadata
*> Elements(DataValue
, Length
);
213 DITypeRefArray A
= D
->getOrCreateTypeArray(Elements
);
214 return wrap(A
.get());
217 LLVMMetadataRef
LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref
,
218 int64_t *Addr
, size_t Length
) {
219 DIBuilder
*D
= unwrap(Dref
);
220 return wrap(D
->createExpression(ArrayRef
<int64_t>(Addr
, Length
)));
223 LLVMValueRef
LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref
,
224 LLVMValueRef Storage
,
225 LLVMMetadataRef VarInfo
,
226 LLVMMetadataRef Expr
,
227 LLVMBasicBlockRef Block
) {
228 // Fail immediately here until the llgo folks update their bindings. The
229 // called function is going to assert out anyway.
230 llvm_unreachable("DIBuilder API change requires a DebugLoc");
232 DIBuilder
*D
= unwrap(Dref
);
233 Instruction
*Instr
= D
->insertDeclare(
234 unwrap(Storage
), unwrap
<DILocalVariable
>(VarInfo
),
235 unwrap
<DIExpression
>(Expr
), /* DebugLoc */ nullptr, unwrap(Block
));
239 LLVMValueRef
LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref
,
241 LLVMMetadataRef VarInfo
,
242 LLVMMetadataRef Expr
,
243 LLVMBasicBlockRef Block
) {
244 // Fail immediately here until the llgo folks update their bindings. The
245 // called function is going to assert out anyway.
246 llvm_unreachable("DIBuilder API change requires a DebugLoc");
248 DIBuilder
*D
= unwrap(Dref
);
249 Instruction
*Instr
= D
->insertDbgValueIntrinsic(
250 unwrap(Val
), unwrap
<DILocalVariable
>(VarInfo
), unwrap
<DIExpression
>(Expr
),
251 /* DebugLoc */ nullptr, unwrap(Block
));