1 |
12 |
jlechner |
# Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
|
2 |
|
|
|
3 |
|
|
# This program is free software; you can redistribute it and/or modify
|
4 |
|
|
# it under the terms of the GNU General Public License as published by
|
5 |
|
|
# the Free Software Foundation; either version 2 of the License, or
|
6 |
|
|
# (at your option) any later version.
|
7 |
|
|
#
|
8 |
|
|
# This program is distributed in the hope that it will be useful,
|
9 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11 |
|
|
# GNU General Public License for more details.
|
12 |
|
|
#
|
13 |
|
|
# You should have received a copy of the GNU General Public License
|
14 |
|
|
# along with this program; if not, write to the Free Software
|
15 |
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
16 |
|
|
|
17 |
|
|
# Various utilities for scanning assembler output, used by gcc-dg.exp and
|
18 |
|
|
# g++-dg.exp.
|
19 |
|
|
|
20 |
|
|
# Utility for scanning compiler result, invoked via dg-final.
|
21 |
|
|
|
22 |
|
|
# Scan the OUTPUT_FILE for a pattern. If it is present and POSITIVE
|
23 |
|
|
# is non-zero, or it is not present and POSITIVE is zero, the test
|
24 |
|
|
# passes. The ORIG_ARGS is the list of arguments provided by dg-final
|
25 |
|
|
# to scan-assembler. The first element in ORIG_ARGS is the regular
|
26 |
|
|
# expression to look for in the file. The second element, if present,
|
27 |
|
|
# is a DejaGNU target selector.
|
28 |
|
|
|
29 |
|
|
proc dg-scan { name positive testcase output_file orig_args } {
|
30 |
|
|
if { [llength $orig_args] < 1 } {
|
31 |
|
|
error "$name: too few arguments"
|
32 |
|
|
return
|
33 |
|
|
}
|
34 |
|
|
if { [llength $orig_args] > 2 } {
|
35 |
|
|
error "$name: too many arguments"
|
36 |
|
|
return
|
37 |
|
|
}
|
38 |
|
|
if { [llength $orig_args] >= 2 } {
|
39 |
|
|
switch [dg-process-target [lindex $orig_args 1]] {
|
40 |
|
|
"S" { }
|
41 |
|
|
"N" { return }
|
42 |
|
|
"F" { setup_xfail "*-*-*" }
|
43 |
|
|
"P" { }
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
set fd [open $output_file r]
|
48 |
|
|
set text [read $fd]
|
49 |
|
|
close $fd
|
50 |
|
|
|
51 |
|
|
set pattern [lindex $orig_args 0]
|
52 |
|
|
set printable_pattern [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern]
|
53 |
|
|
|
54 |
|
|
set match [regexp -- $pattern $text]
|
55 |
|
|
if { $match == $positive } {
|
56 |
|
|
pass "$testcase $name $printable_pattern"
|
57 |
|
|
} else {
|
58 |
|
|
fail "$testcase $name $printable_pattern"
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
# Look for a pattern in the .s file produced by the compiler. See
|
63 |
|
|
# dg-scan for details.
|
64 |
|
|
|
65 |
|
|
proc scan-assembler { args } {
|
66 |
|
|
upvar 2 name testcase
|
67 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
68 |
|
|
|
69 |
|
|
dg-scan "scan-assembler" 1 $testcase $output_file $args
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
# Check that a pattern is not present in the .s file produced by the
|
73 |
|
|
# compiler. See dg-scan for details.
|
74 |
|
|
|
75 |
|
|
proc scan-assembler-not { args } {
|
76 |
|
|
upvar 2 name testcase
|
77 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
78 |
|
|
|
79 |
|
|
dg-scan "scan-assembler-not" 0 $testcase $output_file $args
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
# Return the scan for the assembly for hidden visibility.
|
83 |
|
|
|
84 |
|
|
proc hidden-scan-for { symbol } {
|
85 |
|
|
|
86 |
|
|
set objformat [gcc_target_object_format]
|
87 |
|
|
|
88 |
|
|
switch $objformat {
|
89 |
|
|
elf { return "hidden\[ \t_\]*$symbol" }
|
90 |
|
|
mach-o { return "private_extern\[ \t_\]*_?$symbol" }
|
91 |
|
|
default { return "" }
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
# Check that a symbol is defined as a hidden symbol in the .s file
|
98 |
|
|
# produced by the compiler.
|
99 |
|
|
|
100 |
|
|
proc scan-hidden { args } {
|
101 |
|
|
upvar 2 name testcase
|
102 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
103 |
|
|
|
104 |
|
|
set symbol [lindex $args 0]
|
105 |
|
|
|
106 |
|
|
set hidden_scan [hidden-scan-for $symbol]
|
107 |
|
|
|
108 |
|
|
set args [lreplace $args 0 0 "$hidden_scan"]
|
109 |
|
|
|
110 |
|
|
dg-scan "scan-hidden" 1 $testcase $output_file $args
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
# Check that a symbol is not defined as a hidden symbol in the .s file
|
114 |
|
|
# produced by the compiler.
|
115 |
|
|
|
116 |
|
|
proc scan-not-hidden { args } {
|
117 |
|
|
upvar 2 name testcase
|
118 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
119 |
|
|
|
120 |
|
|
set symbol [lindex $args 0]
|
121 |
|
|
set hidden_scan [hidden-scan-for symbol]
|
122 |
|
|
|
123 |
|
|
set args [lreplace $args 0 0 "$hidden_scan"]
|
124 |
|
|
|
125 |
|
|
dg-scan "scan-not-hidden" 0 $testcase $output_file $args
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
# Look for a pattern in OUTPUT_FILE. See dg-scan for details.
|
129 |
|
|
|
130 |
|
|
proc scan-file { output_file args } {
|
131 |
|
|
upvar 2 name testcase
|
132 |
|
|
dg-scan "scan-file" 1 $testcase $output_file $args
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
# Check that a pattern is not present in the OUTPUT_FILE. See dg-scan
|
136 |
|
|
# for details.
|
137 |
|
|
|
138 |
|
|
proc scan-file-not { output_file args } {
|
139 |
|
|
upvar 2 name testcase
|
140 |
|
|
dg-scan "scan-file-not" 0 $testcase $output_file $args
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
# Call pass if pattern is present given number of times, otherwise fail.
|
144 |
|
|
proc scan-assembler-times { args } {
|
145 |
|
|
if { [llength $args] < 2 } {
|
146 |
|
|
error "scan-assembler: too few arguments"
|
147 |
|
|
return
|
148 |
|
|
}
|
149 |
|
|
if { [llength $args] > 3 } {
|
150 |
|
|
error "scan-assembler: too many arguments"
|
151 |
|
|
return
|
152 |
|
|
}
|
153 |
|
|
if { [llength $args] >= 3 } {
|
154 |
|
|
switch [dg-process-target [lindex $args 2]] {
|
155 |
|
|
"S" { }
|
156 |
|
|
"N" { return }
|
157 |
|
|
"F" { setup_xfail "*-*-*" }
|
158 |
|
|
"P" { }
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
# This assumes that we are two frames down from dg-test, and that
|
163 |
|
|
# it still stores the filename of the testcase in a local variable "name".
|
164 |
|
|
# A cleaner solution would require a new dejagnu release.
|
165 |
|
|
upvar 2 name testcase
|
166 |
|
|
|
167 |
|
|
# This must match the rule in gcc-dg.exp.
|
168 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
169 |
|
|
|
170 |
|
|
set fd [open $output_file r]
|
171 |
|
|
set text [read $fd]
|
172 |
|
|
close $fd
|
173 |
|
|
|
174 |
|
|
if { [llength [regexp -inline -all -- [lindex $args 0] $text]] == [lindex $args 1]} {
|
175 |
|
|
pass "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
|
176 |
|
|
} else {
|
177 |
|
|
fail "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
# Utility for scanning demangled compiler result, invoked via dg-final.
|
182 |
|
|
# Call pass if pattern is present, otherwise fail.
|
183 |
|
|
proc scan-assembler-dem { args } {
|
184 |
|
|
global cxxfilt
|
185 |
|
|
global base_dir
|
186 |
|
|
|
187 |
|
|
if { [llength $args] < 1 } {
|
188 |
|
|
error "scan-assembler-dem: too few arguments"
|
189 |
|
|
return
|
190 |
|
|
}
|
191 |
|
|
if { [llength $args] > 2 } {
|
192 |
|
|
error "scan-assembler-dem: too many arguments"
|
193 |
|
|
return
|
194 |
|
|
}
|
195 |
|
|
if { [llength $args] >= 2 } {
|
196 |
|
|
switch [dg-process-target [lindex $args 1]] {
|
197 |
|
|
"S" { }
|
198 |
|
|
"N" { return }
|
199 |
|
|
"F" { setup_xfail "*-*-*" }
|
200 |
|
|
"P" { }
|
201 |
|
|
}
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
# Find c++filt like we find g++ in g++.exp.
|
205 |
|
|
if ![info exists cxxfilt] {
|
206 |
|
|
set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
|
207 |
|
|
$base_dir/../../../binutils/cxxfilt \
|
208 |
|
|
[findfile $base_dir/../../c++filt $base_dir/../../c++filt \
|
209 |
|
|
[findfile $base_dir/c++filt $base_dir/c++filt \
|
210 |
|
|
[transform c++filt]]]]
|
211 |
|
|
verbose -log "c++filt is $cxxfilt"
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
upvar 2 name testcase
|
215 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
216 |
|
|
|
217 |
|
|
set fd [open "| $cxxfilt < $output_file" r]
|
218 |
|
|
set text [read $fd]
|
219 |
|
|
close $fd
|
220 |
|
|
|
221 |
|
|
if [regexp -- [lindex $args 0] $text] {
|
222 |
|
|
pass "$testcase scan-assembler-dem [lindex $args 0]"
|
223 |
|
|
} else {
|
224 |
|
|
fail "$testcase scan-assembler-dem [lindex $args 0]"
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
# Call pass if demangled pattern is not present, otherwise fail.
|
229 |
|
|
proc scan-assembler-dem-not { args } {
|
230 |
|
|
global cxxfilt
|
231 |
|
|
global base_dir
|
232 |
|
|
|
233 |
|
|
if { [llength $args] < 1 } {
|
234 |
|
|
error "scan-assembler-dem-not: too few arguments"
|
235 |
|
|
return
|
236 |
|
|
}
|
237 |
|
|
if { [llength $args] > 2 } {
|
238 |
|
|
error "scan-assembler-dem-not: too many arguments"
|
239 |
|
|
return
|
240 |
|
|
}
|
241 |
|
|
if { [llength $args] >= 2 } {
|
242 |
|
|
switch [dg-process-target [lindex $args 1]] {
|
243 |
|
|
"S" { }
|
244 |
|
|
"N" { return }
|
245 |
|
|
"F" { setup_xfail "*-*-*" }
|
246 |
|
|
"P" { }
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
# Find c++filt like we find g++ in g++.exp.
|
251 |
|
|
if ![info exists cxxfilt] {
|
252 |
|
|
set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
|
253 |
|
|
$base_dir/../../../binutils/cxxfilt \
|
254 |
|
|
[findfile $base_dir/../../c++filt $base_dir/../../c++filt \
|
255 |
|
|
[findfile $base_dir/c++filt $base_dir/c++filt \
|
256 |
|
|
[transform c++filt]]]]
|
257 |
|
|
verbose -log "c++filt is $cxxfilt"
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
upvar 2 name testcase
|
261 |
|
|
set output_file "[file rootname [file tail $testcase]].s"
|
262 |
|
|
|
263 |
|
|
set fd [open "| $cxxfilt < $output_file" r]
|
264 |
|
|
set text [read $fd]
|
265 |
|
|
close $fd
|
266 |
|
|
|
267 |
|
|
if ![regexp -- [lindex $args 0] $text] {
|
268 |
|
|
pass "$testcase scan-assembler-dem-not [lindex $args 0]"
|
269 |
|
|
} else {
|
270 |
|
|
fail "$testcase scan-assembler-dem-not [lindex $args 0]"
|
271 |
|
|
}
|
272 |
|
|
}
|