OSDN Git Service

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