@@ -101,6 +101,8 @@ extension FileCheckSource: ExpressibleByStringLiteral {
101
101
/// - parameter FD: The file descriptor to override and read from.
102
102
/// - parameter prefixes: Specifies one or more prefixes to match. By default
103
103
/// these patterns are prefixed with "CHECK".
104
+ /// - parameter globals: Specifies a dictionary of global variables whose
105
+ /// names may be used in capture patterns.
104
106
/// - parameter checkNot: Specifies zero or more prefixes to implicitly reject
105
107
/// in the output stream. This can be used to implement LLVM-verifier-like
106
108
/// checks.
@@ -111,7 +113,15 @@ extension FileCheckSource: ExpressibleByStringLiteral {
111
113
/// file descriptor.
112
114
///
113
115
/// - 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 {
115
125
guard let validPrefixes = validateCheckPrefixes ( prefixes) else {
116
126
print ( " Supplied check-prefix is invalid! Prefixes must be unique and " ,
117
127
" start with a letter and contain only alphanumeric characters, " ,
@@ -154,7 +164,7 @@ public func fileCheckOutput(of FD : FileCheckFD = .stdout, withPrefixes prefixes
154
164
return false
155
165
}
156
166
157
- return check ( input: input, against: checkStrings, options: options)
167
+ return check ( input: input, against: checkStrings, withGlobals : globals , options: options)
158
168
}
159
169
160
170
private func overrideFDAndCollectOutput( file : FileCheckFD , of block : ( ) -> ( ) ) -> String {
@@ -511,12 +521,17 @@ private func readCheckStrings(in buf : UnsafeBufferPointer<CChar>, withPrefixes
511
521
/// strings read from the check file.
512
522
///
513
523
/// 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 {
515
530
var buffer = Substring ( b)
516
531
var failedChecks = false
517
532
518
533
// This holds all the current filecheck variables.
519
- var variableTable = [ String : String ] ( )
534
+ var variableTable = globals
520
535
521
536
var i = 0
522
537
var j = 0
0 commit comments