@@ -101,6 +101,8 @@ extension FileCheckSource: ExpressibleByStringLiteral {
101101/// - parameter FD: The file descriptor to override and read from.
102102/// - parameter prefixes: Specifies one or more prefixes to match. By default
103103/// these patterns are prefixed with "CHECK".
104+ /// - parameter globals: Specifies a dictionary of global variables whose
105+ /// names may be used in capture patterns.
104106/// - parameter checkNot: Specifies zero or more prefixes to implicitly reject
105107/// in the output stream. This can be used to implement LLVM-verifier-like
106108/// checks.
@@ -111,7 +113,15 @@ extension FileCheckSource: ExpressibleByStringLiteral {
111113/// file descriptor.
112114///
113115/// - returns: Whether or not FileCheck succeeded in verifying the file.
114- public func fileCheckOutput( of FD : FileCheckFD = . stdout, withPrefixes prefixes : [ String ] = [ " CHECK " ] , checkNot : [ String ] = [ ] , against source : FileCheckSource = #file, options: FileCheckOptions = [ ] , block : ( ) -> ( ) ) -> Bool {
116+ public func fileCheckOutput(
117+ of FD : FileCheckFD = . stdout,
118+ withPrefixes prefixes : [ String ] = [ " CHECK " ] ,
119+ withGlobals globals: [ String : String ] = [ : ] ,
120+ checkNot : [ String ] = [ ] ,
121+ against source : FileCheckSource = #file,
122+ options: FileCheckOptions = [ ] ,
123+ block : ( ) -> ( )
124+ ) -> Bool {
115125 guard let validPrefixes = validateCheckPrefixes ( prefixes) else {
116126 print ( " Supplied check-prefix is invalid! Prefixes must be unique and " ,
117127 " start with a letter and contain only alphanumeric characters, " ,
@@ -154,7 +164,7 @@ public func fileCheckOutput(of FD : FileCheckFD = .stdout, withPrefixes prefixes
154164 return false
155165 }
156166
157- return check ( input: input, against: checkStrings, options: options)
167+ return check ( input: input, against: checkStrings, withGlobals : globals , options: options)
158168}
159169
160170private func overrideFDAndCollectOutput( file : FileCheckFD , of block : ( ) -> ( ) ) -> String {
@@ -511,12 +521,17 @@ private func readCheckStrings(in buf : UnsafeBufferPointer<CChar>, withPrefixes
511521/// strings read from the check file.
512522///
513523/// Returns `false` if the input fails to satisfy the checks.
514- private func check( input b : String , against checkStrings : [ CheckString ] , options: FileCheckOptions ) -> Bool {
524+ private func check(
525+ input b : String ,
526+ against checkStrings : [ CheckString ] ,
527+ withGlobals globals: [ String : String ] ,
528+ options: FileCheckOptions
529+ ) -> Bool {
515530 var buffer = Substring ( b)
516531 var failedChecks = false
517532
518533 // This holds all the current filecheck variables.
519- var variableTable = [ String : String ] ( )
534+ var variableTable = globals
520535
521536 var i = 0
522537 var j = 0
0 commit comments