OSDN Git Service

* config/bfin/bfin.c (n_regs_to_save): New static variable.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / scanasm.exp
1 #   Copyright (C) 2000, 2002, 2003, 2007 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 3 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 GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
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     if { [is_remote host] } {
48         remote_upload host "$output_file"
49     } 
50     set fd [open $output_file r]
51     set text [read $fd]
52     close $fd
53
54     set pattern [lindex $orig_args 0]
55     set printable_pattern [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern]
56
57     set match [regexp -- $pattern $text]
58     if { $match == $positive } {
59         pass "$testcase $name $printable_pattern"
60     } else {
61         fail "$testcase $name $printable_pattern"
62     }
63 }
64
65 # Look for a pattern in the .s file produced by the compiler.  See
66 # dg-scan for details.
67
68 proc scan-assembler { args } {
69     upvar 2 name testcase
70     set output_file "[file rootname [file tail $testcase]].s"
71
72     dg-scan "scan-assembler" 1 $testcase $output_file $args
73 }
74
75 # Check that a pattern is not present in the .s file produced by the
76 # compiler.  See dg-scan for details.
77
78 proc scan-assembler-not { args } {
79     upvar 2 name testcase
80     set output_file "[file rootname [file tail $testcase]].s"
81
82     dg-scan "scan-assembler-not" 0 $testcase $output_file $args
83 }
84
85 # Return the scan for the assembly for hidden visibility. 
86
87 proc hidden-scan-for { symbol } {
88
89     set objformat [gcc_target_object_format]
90
91     switch $objformat {
92         elf      { return "hidden\[ \t_\]*$symbol" }
93         mach-o   { return "private_extern\[ \t_\]*_?$symbol" }
94         default  { return "" }
95     }
96
97 }
98
99
100 # Check that a symbol is defined as a hidden symbol in the .s file
101 # produced by the compiler.
102
103 proc scan-hidden { args } {
104     upvar 2 name testcase
105     set output_file "[file rootname [file tail $testcase]].s"
106
107     set symbol [lindex $args 0]
108
109     set hidden_scan [hidden-scan-for $symbol]
110
111     set args [lreplace $args 0 0 "$hidden_scan"]
112
113     dg-scan "scan-hidden" 1 $testcase $output_file $args
114 }
115
116 # Check that a symbol is not defined as a hidden symbol in the .s file
117 # produced by the compiler.
118
119 proc scan-not-hidden { args } {
120     upvar 2 name testcase
121     set output_file "[file rootname [file tail $testcase]].s"
122
123     set symbol [lindex $args 0]
124     set hidden_scan [hidden-scan-for $symbol]
125
126     set args [lreplace $args 0 0 "$hidden_scan"]
127
128     dg-scan "scan-not-hidden" 0 $testcase $output_file $args
129 }
130
131 # Look for a pattern in OUTPUT_FILE.  See dg-scan for details.
132
133 proc scan-file { output_file args } {
134     upvar 2 name testcase
135     dg-scan "scan-file" 1 $testcase $output_file $args
136 }
137
138 # Check that a pattern is not present in the OUTPUT_FILE.  See dg-scan
139 # for details.
140
141 proc scan-file-not { output_file args } {
142     upvar 2 name testcase
143     dg-scan "scan-file-not" 0 $testcase $output_file $args
144 }
145
146 # Call pass if pattern is present given number of times, otherwise fail.
147 proc scan-assembler-times { args } {
148     if { [llength $args] < 2 } {
149         error "scan-assembler: too few arguments"
150         return
151     }
152     if { [llength $args] > 3 } {
153         error "scan-assembler: too many arguments"
154         return
155     }
156     if { [llength $args] >= 3 } {
157         switch [dg-process-target [lindex $args 2]] {
158             "S" { }
159             "N" { return }
160             "F" { setup_xfail "*-*-*" }
161             "P" { }
162         }
163     }
164
165     # This assumes that we are two frames down from dg-test, and that
166     # it still stores the filename of the testcase in a local variable "name".
167     # A cleaner solution would require a new dejagnu release.
168     upvar 2 name testcase
169
170     # This must match the rule in gcc-dg.exp.
171     set output_file "[file rootname [file tail $testcase]].s"
172
173     set fd [open $output_file r]
174     set text [read $fd]
175     close $fd
176
177     if { [llength [regexp -inline -all -- [lindex $args 0] $text]] == [lindex $args 1]} {
178         pass "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
179     } else {
180         fail "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
181     }
182 }
183
184 # Utility for scanning demangled compiler result, invoked via dg-final.
185 # Call pass if pattern is present, otherwise fail.
186 proc scan-assembler-dem { args } {
187     global cxxfilt
188     global base_dir
189
190     if { [llength $args] < 1 } {
191         error "scan-assembler-dem: too few arguments"
192         return
193     }
194     if { [llength $args] > 2 } {
195         error "scan-assembler-dem: too many arguments"
196         return
197     }
198     if { [llength $args] >= 2 } {
199         switch [dg-process-target [lindex $args 1]] {
200             "S" { }
201             "N" { return }
202             "F" { setup_xfail "*-*-*" }
203             "P" { }
204         }
205     }
206
207     # Find c++filt like we find g++ in g++.exp.
208     if ![info exists cxxfilt]  {
209         set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
210                      $base_dir/../../../binutils/cxxfilt \
211                      [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
212                       [findfile $base_dir/c++filt $base_dir/c++filt \
213                        [transform c++filt]]]]
214         verbose -log "c++filt is $cxxfilt"
215     }
216
217     upvar 2 name testcase
218     set output_file "[file rootname [file tail $testcase]].s"
219
220     set output [remote_exec host "$cxxfilt" "" "$output_file"]
221     set text [lindex $output 1]
222
223     if [regexp -- [lindex $args 0] $text] {
224         pass "$testcase scan-assembler-dem [lindex $args 0]"
225     } else {
226         fail "$testcase scan-assembler-dem [lindex $args 0]"
227     }
228 }
229
230 # Call pass if demangled pattern is not present, otherwise fail.
231 proc scan-assembler-dem-not { args } {
232     global cxxfilt
233     global base_dir
234
235     if { [llength $args] < 1 } {
236         error "scan-assembler-dem-not: too few arguments"
237         return
238     }
239     if { [llength $args] > 2 } {
240         error "scan-assembler-dem-not: too many arguments"
241         return
242     }
243     if { [llength $args] >= 2 } {
244         switch [dg-process-target [lindex $args 1]] {
245             "S" { }
246             "N" { return }
247             "F" { setup_xfail "*-*-*" }
248             "P" { }
249         }
250     }
251
252     # Find c++filt like we find g++ in g++.exp.
253     if ![info exists cxxfilt]  {
254         set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
255                      $base_dir/../../../binutils/cxxfilt \
256                      [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
257                       [findfile $base_dir/c++filt $base_dir/c++filt \
258                        [transform c++filt]]]]
259         verbose -log "c++filt is $cxxfilt"
260     }
261
262     upvar 2 name testcase
263     set output_file "[file rootname [file tail $testcase]].s"
264
265     set output [remote_exec host "$cxxfilt" "" "$output_file"]
266     set text [lindex $output 1]
267
268     if ![regexp -- [lindex $args 0] $text] {
269         pass "$testcase scan-assembler-dem-not [lindex $args 0]"
270     } else {
271         fail "$testcase scan-assembler-dem-not [lindex $args 0]"
272     }
273 }