@@ -14,6 +14,7 @@ package llvm
14
14
15
15
/*
16
16
#include "IRBindings.h"
17
+ #include "backports.h"
17
18
#include <stdlib.h>
18
19
*/
19
20
import "C"
@@ -220,6 +221,43 @@ func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata {
220
221
return Metadata {C : result }
221
222
}
222
223
224
+ // DIGlobalVariableExpression holds the values for creating global variable
225
+ // debug metadata.
226
+ type DIGlobalVariableExpression struct {
227
+ Name string // Name of the variable.
228
+ LinkageName string // Mangled name of the variable
229
+ File Metadata // File where this variable is defined.
230
+ Line int // Line number.
231
+ Type Metadata // Variable Type.
232
+ LocalToUnit bool // Flag indicating whether this variable is externally visible or not.
233
+ Expr Metadata // The location of the global relative to the attached GlobalVariable.
234
+ Decl Metadata // Reference to the corresponding declaration.
235
+ AlignInBits uint32 // Variable alignment(or 0 if no alignment attr was specified).
236
+ }
237
+
238
+ // CreateGlobalVariableExpression creates a new descriptor for the specified
239
+ // global variable.
240
+ func (d * DIBuilder ) CreateGlobalVariableExpression (diScope Metadata , g DIGlobalVariableExpression ) Metadata {
241
+ name := C .CString (g .Name )
242
+ defer C .free (unsafe .Pointer (name ))
243
+ linkageName := C .CString (g .LinkageName )
244
+ defer C .free (unsafe .Pointer (linkageName ))
245
+ result := C .LLVMDIBuilderCreateGlobalVariableExpression (
246
+ d .ref , // Builder
247
+ diScope .C , // Scope
248
+ name , C .size_t (len (g .Name )), // Name, NameLen
249
+ linkageName , C .size_t (len (g .LinkageName )), // Linkage, LinkLen
250
+ g .File .C , // File
251
+ C .unsigned (g .Line ), // LineNo
252
+ g .Type .C , // Ty
253
+ C .LLVMBool (boolToCInt (g .LocalToUnit )), // LocalToUnit
254
+ g .Expr .C , // Expr
255
+ g .Decl .C , // Decl
256
+ C .uint32_t (g .AlignInBits ), // AlignInBits
257
+ )
258
+ return Metadata {C : result }
259
+ }
260
+
223
261
// DIAutoVariable holds the values for creating auto variable debug metadata.
224
262
type DIAutoVariable struct {
225
263
Name string
@@ -589,6 +627,11 @@ func (v Value) Subprogram() (md Metadata) {
589
627
return
590
628
}
591
629
630
+ // AddMetadata adds a metadata entry of the given kind to a global object.
631
+ func (v Value ) AddMetadata (kind int , md Metadata ) {
632
+ C .LLVMGlobalObjectAddMetadata (v .C , C .unsigned (kind ), md .C )
633
+ }
634
+
592
635
func boolToCInt (v bool ) C.int {
593
636
if v {
594
637
return 1
0 commit comments