@@ -108,6 +108,43 @@ public enum RealPredicate {
108
108
}
109
109
}
110
110
111
+ extension Module {
112
+ /// Searches for and retrieves a global variable with the given name in this
113
+ /// module if that name references an existing global variable.
114
+ ///
115
+ /// - parameter name: The name of the global to reference.
116
+ ///
117
+ /// - returns: A value representing the referenced global if it exists.
118
+ public func global( named name: String ) -> Global ? {
119
+ guard let ref = LLVMGetNamedGlobal ( llvm, name) else { return nil }
120
+ return Global ( llvm: ref)
121
+ }
122
+
123
+ /// Searches for and retrieves a type with the given name in this module if
124
+ /// that name references an existing type.
125
+ ///
126
+ /// - parameter name: The name of the type to create.
127
+ ///
128
+ /// - returns: A representation of the newly created type with the given name
129
+ /// or nil if such a representation could not be created.
130
+ public func type( named name: String ) -> IRType ? {
131
+ guard let type = LLVMGetTypeByName ( llvm, name) else { return nil }
132
+ return convertType ( type)
133
+ }
134
+
135
+ /// Searches for and retrieves a function with the given name in this module
136
+ /// if that name references an existing function.
137
+ ///
138
+ /// - parameter name: The name of the function to create.
139
+ ///
140
+ /// - returns: A representation of the newly created function with the given
141
+ /// name or nil if such a representation could not be created.
142
+ public func function( named name: String ) -> Function ? {
143
+ guard let fn = LLVMGetNamedFunction ( llvm, name) else { return nil }
144
+ return Function ( llvm: fn)
145
+ }
146
+ }
147
+
111
148
/// An `IRBuilder` is a helper object that generates LLVM instructions. IR
112
149
/// Builders keep track of a position within a function or basic block and has
113
150
/// methods to insert instructions at that position.
@@ -935,7 +972,7 @@ public class IRBuilder {
935
972
return LLVMBuildInsertElement ( llvm, vector. asLLVM ( ) , element. asLLVM ( ) , index. asLLVM ( ) , name)
936
973
}
937
974
938
- // MARK: Global Variable Creation Instructions
975
+ // MARK: Global Variable Instructions
939
976
940
977
/// Build a named global of the given type.
941
978
///
@@ -974,8 +1011,8 @@ public class IRBuilder {
974
1011
/// - parameter name: The name for the newly inserted instruction.
975
1012
///
976
1013
/// - returns: A value representing the newly inserted global string variable.
977
- public func buildGlobalString( _ string: String , name: String = " " ) -> IRValue {
978
- return LLVMBuildGlobalString ( llvm, string, name)
1014
+ public func buildGlobalString( _ string: String , name: String = " " ) -> Global {
1015
+ return Global ( llvm : LLVMBuildGlobalString ( llvm, string, name) )
979
1016
}
980
1017
981
1018
/// Builds a named global variable containing a pointer to the contents of the
0 commit comments