41
41
module FileCheck
42
42
import LLVM_jll
43
43
import IOCapture
44
+ using InteractiveUtils
44
45
45
46
export filecheck
46
47
@@ -63,26 +64,46 @@ module FileCheck
63
64
return Cmd (Cmd ([filecheck_path]); env)
64
65
end
65
66
67
+ const julia_typed_pointers = let
68
+ ir = sprint (io-> code_llvm (io, unsafe_load, Tuple{Ptr{Int}}))
69
+ if occursin (r" load i64, i64\* .+, align 1" , ir)
70
+ true
71
+ elseif occursin (r" load i64, ptr .+, align 1" , ir)
72
+ false
73
+ else
74
+ error (" could not determine whether Julia uses typed pointers" )
75
+ end
76
+ end
77
+
66
78
function filecheck (f, input)
67
79
# FileCheck assumes that the input is available as a file
68
- path, io = mktemp ()
69
- write (io, input)
70
- close (io)
80
+ mktemp () do path, io
81
+ write (io, input)
82
+ close (io)
71
83
72
- # Now execute `f` with IOCapture
73
- # XXX : See if Suppressor is a better fit
74
- value, output, error, backtrace = IOCapture. capture (()-> f (input); rethrow= Union{})
84
+ # Now execute `f` with IOCapture
85
+ # XXX : See if Suppressor is a better fit
86
+ value, output, error, backtrace = IOCapture. capture (()-> f (input); rethrow= Union{})
75
87
76
- io = IOBuffer ()
77
- write (io, output)
78
- println (io)
88
+ io = IOBuffer ()
89
+ write (io, output)
90
+ println (io)
79
91
80
- if error
81
- showerror (io, value, backtrace)
82
- end
92
+ if error
93
+ showerror (io, value, backtrace)
94
+ end
83
95
84
- seekstart (io)
85
- cmd = ` $(filecheck_exe ()) $path `
86
- value, success (pipeline (cmd; stdin = io, stdout , stderr ))
96
+ # Determine some useful prefixes for FileCheck
97
+ prefixes = [" CHECK" ]
98
+ if julia_typed_pointers
99
+ push! (prefixes, " OPAQUE" )
100
+ else
101
+ push! (prefixes, " TYPED" )
102
+ end
103
+
104
+ seekstart (io)
105
+ cmd = ` $(filecheck_exe ()) --allow-unused-prefixes --check-prefixes $(join (prefixes, ' ,' )) $path `
106
+ value, success (pipeline (cmd; stdin = io, stdout , stderr ))
107
+ end
87
108
end
88
- end
109
+ end
0 commit comments