@@ -1055,3 +1055,77 @@ extension DIBuilder {
1055
1055
return ObjectiveCPropertyMetadata ( llvm: ty)
1056
1056
}
1057
1057
}
1058
+
1059
+ extension DIBuilder {
1060
+ /// Create a new descriptor for the specified variable which has a complex
1061
+ /// address expression for its address.
1062
+ ///
1063
+ /// - Parameters:
1064
+ /// - expression: An array of complex address operations.
1065
+ public func buildExpression( _ expression: [ DWARFExpression ] ) -> ExpressionMetadata {
1066
+ var expr = expression. flatMap { $0. rawValue }
1067
+ let count = expr. count
1068
+ return expr. withUnsafeMutableBytes { raw in
1069
+ let rawVal = raw. bindMemory ( to: Int64 . self)
1070
+ guard let expr = LLVMDIBuilderCreateExpression (
1071
+ self . llvm, rawVal. baseAddress!, count)
1072
+ else {
1073
+ fatalError ( " Failed to allocate metadata " )
1074
+ }
1075
+ return ExpressionMetadata ( llvm: expr)
1076
+ }
1077
+ }
1078
+
1079
+ /// Create a new descriptor for the specified variable that does not have an
1080
+ /// address, but does have a constant value.
1081
+ ///
1082
+ /// - Parameters:
1083
+ /// - value: The constant value.
1084
+ public func buildConstantExpresion( _ value: Int ) -> ExpressionMetadata {
1085
+ guard let expr = LLVMDIBuilderCreateConstantValueExpression (
1086
+ self . llvm, Int64 ( value) )
1087
+ else {
1088
+ fatalError ( " Failed to allocate metadata " )
1089
+ }
1090
+ return ExpressionMetadata ( llvm: expr)
1091
+ }
1092
+
1093
+ /// Create a new descriptor for the specified variable.
1094
+ ///
1095
+ /// - Parameters:
1096
+ /// - name: Name of the variable.
1097
+ /// - linkageName: Mangled name of the variable.
1098
+ /// - type: Variable Type.
1099
+ /// - scope: Variable scope.
1100
+ /// - file: File where this variable is defined.
1101
+ /// - line: Line number.
1102
+ /// - isLocal: Boolean flag indicate whether this variable is
1103
+ /// externally visible or not.
1104
+ /// - expression: The location of the global relative to the attached
1105
+ /// GlobalVariable.
1106
+ /// - declaration: Reference to the corresponding declaration.
1107
+ /// - alignment: Variable alignment(or 0 if no alignment attr was
1108
+ /// specified)
1109
+ public func buildGlobalExpression(
1110
+ named name: String , linkageName: String , type: DIType ,
1111
+ scope: DIScope , file: FileMetadata , line: Int ,
1112
+ isLocal: Bool = true ,
1113
+ expression: ExpressionMetadata ? = nil ,
1114
+ declaration: Metadata ? = nil ,
1115
+ alignment: Alignment = . zero
1116
+ ) -> ExpressionMetadata {
1117
+ let radix = UInt32 ( self . module. dataLayout. intPointerType ( ) . width)
1118
+ guard let ty = LLVMDIBuilderCreateGlobalVariableExpression (
1119
+ self . llvm, scope. asMetadata ( ) ,
1120
+ name, name. count, linkageName, linkageName. count,
1121
+ file. asMetadata ( ) , UInt32 ( line) ,
1122
+ type. asMetadata ( ) ,
1123
+ isLocal. llvm,
1124
+ expression? . asMetadata ( ) , declaration? . asMetadata ( ) ,
1125
+ alignment. rawValue * radix)
1126
+ else {
1127
+ fatalError ( " Failed to allocate metadata " )
1128
+ }
1129
+ return ExpressionMetadata ( llvm: ty)
1130
+ }
1131
+ }
0 commit comments