2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / mips / mips.exp
blob526bbdb14f22013b750010b44eaccb7692fe46a4
1 # Copyright (C) 1997, 2007 Free Software Foundation, Inc.
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.
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/>.
17 # GCC testsuite that uses the `dg.exp' driver.
19 # Exit immediately if this isn't a MIPS target.
20 if ![istarget mips*-*-*] {
21 return
24 # Load support procs.
25 load_lib gcc-dg.exp
27 # Find out which target is selected by the default compiler flags.
28 # Also remember which aspects of the target are forced on the command
29 # line (as opposed to being overridable defaults).
31 # $mips_isa: the ISA level specified by __mips
32 # $mips_isa_rev: the ISA revision specified by __mips_isa_rev
33 # $mips_arch: the architecture specified by _MIPS_ARCH
34 # $mips_mips16: true if MIPS16 output is selected
35 # $mips_gp: the number of bytes in a general register
36 # $mips_fp: the number of bytes in a floating-point register
37 # $mips_float: "hard" or "soft"
38 # $mips_abi: the ABI specified by _MIPS_SIM
40 # $mips_forced_isa: true if the command line uses -march=* or -mips*
41 # $mips_forced_abi: true if the command line uses -mabi=*
42 # $mips_forced_regs: true if the command line uses -mgp* or -mfp*
43 # $mips_forced_float: true if the command line uses -mhard/soft-float
44 # $mips_forced_be true if the command line uses -EB or -meb
45 # $mips_forced_le true if the command line uses -EL or -mel
46 # $mips_forced_gp true if the command line forces a particular GP mode
47 # $mips_forced_no_abicalls
48 # true if the command line contains -mno-abicalls
49 # $mips_forced_no_shared
50 # true if the command line contains -mno-shared
51 # $mips_forced_no_er true if the command line contains -mno-explicit-relocs
52 proc setup_mips_tests {} {
53 global mips_isa
54 global mips_isa_rev
55 global mips_arch
56 global mips_mips16
57 global mips_gp
58 global mips_fp
59 global mips_float
60 global mips_abi
62 global mips_forced_isa
63 global mips_forced_abi
64 global mips_forced_float
65 global mips_forced_be
66 global mips_forced_le
67 global mips_forced_gp
68 global mips_forced_no_abicalls
69 global mips_forced_no_shared
70 global mips_forced_no_er
71 global mips_forced_regs
73 global compiler_flags
74 global tool
76 set src dummy[pid].c
77 set f [open $src "w"]
78 puts $f {
79 int isa = __mips;
80 #ifdef __mips_isa_rev
81 int isa_rev = __mips_isa_rev;
82 #else
83 int isa_rev = 1;
84 #endif
85 const char *arch = _MIPS_ARCH;
86 #ifdef __mips16
87 int mips16 = 1;
88 #endif
89 #ifdef __mips64
90 int gp = 64;
91 #else
92 int gp = 32;
93 #endif
94 int fp = __mips_fpr;
95 #ifdef __mips_hard_float
96 const char *float = "hard";
97 #else
98 const char *float = "soft";
99 #endif
100 #if !defined _MIPS_SIM
101 const char *abi = "eabi";
102 #elif _MIPS_SIM==_ABIO32
103 const char *abi = "32";
104 #elif _MIPS_SIM==_ABIO64
105 const char *abi = "o64";
106 #elif _MIPS_SIM==_ABIN32
107 const char *abi = "n32";
108 #else
109 const char *abi = "64";
110 #endif
112 close $f
113 set output [${tool}_target_compile $src "" preprocess ""]
114 file delete $src
116 regexp {isa = ([^;]*)} $output dummy mips_isa
117 regexp {isa_rev = ([^;]*)} $output dummy mips_isa_rev
118 regexp {arch = "([^"]*)} $output dummy mips_arch
119 set mips_mips16 [regexp {mips16 = 1} $output]
120 regexp {gp = ([^;]*)} $output dummy mips_gp
121 regexp {fp = ([^;]*)} $output dummy mips_fp
122 regexp {float = "([^"]*)} $output dummy mips_float
123 regexp {abi = "([^"]*)} $output dummy mips_abi
125 set mips_forced_isa [regexp -- {(-mips[1-5][[:>:]]|-mips32*|-mips64*|-march)} $compiler_flags]
126 set mips_forced_abi [regexp -- {-mabi} $compiler_flags]
127 set mips_forced_regs [regexp -- {(-mgp|-mfp)} $compiler_flags]
128 set mips_forced_float [regexp -- {-m(hard|soft)-float} $compiler_flags]
129 set mips_forced_be [regexp -- {-(EB|meb)[[:>:]]} $compiler_flags]
130 set mips_forced_le [regexp -- {-(EL|mel)[[:>:]]} $compiler_flags]
131 set mips_forced_gp [regexp -- {-(G|m(|no-)((extern|local)-sdata|gpopt)|mabicalls|mrtp)} $compiler_flags]
132 set mips_forced_no_abicalls [regexp -- {-mno-abicalls} $compiler_flags]
133 set mips_forced_no_shared [regexp -- {-mno-shared} $compiler_flags]
134 set mips_forced_no_er [regexp -- {-mno-explicit-relocs} $compiler_flags]
136 if {$mips_forced_regs && $mips_gp == 32 && $mips_fp == 64} {
137 set mips_forced_abi 1
138 set mips_forced_isa 1
142 # Like dg-options, but treats certain MIPS-specific options specially:
144 # -mgp32
145 # -march=mips32*
146 # Force 32-bit code. Skip the test if the multilib flags force
147 # a 64-bit ABI.
149 # -mgp64
150 # Force 64-bit code. Also force a 64-bit target architecture
151 # if the other flags don't do so. Skip the test if the multilib
152 # flags force a 32-bit ABI or a 32-bit architecture.
154 # -mfp64
155 # Force the use of 64-bit floating-point registers, even on a
156 # 32-bit target. Also force -mhard-float and an architecture that
157 # supports such a combination, unless these things are already
158 # specified by other parts of the given flags.
160 # -mabi=*
161 # Force a particular ABI. Skip the test if the multilib flags
162 # force a specific ABI or a different register size. If testing
163 # MIPS16 multilibs, try to force -msoft-float for ABIs other than
164 # o32 and o64, and skip the test if this is not possible.
166 # -march=*
167 # -mips*
168 # Select the target architecture. Skip the test if the multilib
169 # flags force a different architecture.
171 # -msoft-float
172 # -mhard-float
173 # Select the given floating-point mode. Skip the test if the
174 # multilib flags force a different selection.
176 # -EB
177 # -EL
178 # Select the given endianness. Skip the test if the multilib flags
179 # force the opposite endianness.
181 # -G*
182 # -m(no-)extern-sdata
183 # -m(no-)local-sdata
184 # -m(no-)gpopt
185 # Select the small-data mode, and -mno-abcialls. Skip the test if
186 # the multilib flags already contain such an option, or specify
187 # something that might be incompatible with them.
189 # -mabicalls
190 # -mshared
191 # Select the form of SVR4 PIC. Skip the test if the multilib flags
192 # conflict with the required setting.
194 # -mexplicit-relocs
195 # Select explicit relocations. Skip the test if the multilib flags
196 # force -mno-explicit-relocs.
198 # -mpaired-single
199 # Select paired-single instructions. Also behave as for -mfp64.
200 proc dg-mips-options {args} {
201 upvar dg-extra-tool-flags extra_tool_flags
202 upvar dg-do-what do_what
204 global mips_isa
205 global mips_isa_rev
206 global mips_arch
207 global mips_mips16
208 global mips_gp
209 global mips_fp
210 global mips_float
211 global mips_abi
213 global mips_forced_isa
214 global mips_forced_abi
215 global mips_forced_regs
216 global mips_forced_float
217 global mips_forced_be
218 global mips_forced_le
219 global mips_forced_gp
220 global mips_forced_no_abicalls
221 global mips_forced_no_shared
222 global mips_forced_no_er
224 set flags [lindex $args 1]
225 set matches 1
227 # Add implied flags.
228 foreach flag $flags {
229 if {[string match -mpaired-single $flag]
230 && [lsearch $flags -mfp*] < 0} {
231 append flags " -mfp64"
232 } elseif {[regexp -- {^-mabi=(.*)} $flag dummy abi]
233 && $mips_mips16
234 && $abi != "32"
235 && $abi != "o64"} {
236 if {[lsearch $flags -mhard-float] >= 0} {
237 set matches 0
238 } else {
239 append flags " -msoft-float"
243 foreach flag $flags {
244 if {[string match -mfp* $flag]
245 && [lsearch -regexp $flags {^-m(hard|soft)-float$}] < 0} {
246 append flags " -mhard-float"
250 # Handle options that force a particular register size. Add
251 # architecture and ABI options if necessary.
252 set mips_new_gp $mips_gp
253 set mips_new_fp $mips_fp
254 foreach flag $flags {
255 switch -glob -- $flag {
256 -msmartmips -
257 -mips[12] -
258 -mips32* -
259 -march=mips32* -
260 -march=24k* -
261 -mabi=32 -
262 -mgp32 {
263 set mips_new_gp 32
265 -mabi=64 -
266 -mabi=o64 -
267 -mabi=n32 -
268 -mgp64 {
269 set mips_new_gp 64
271 -mfp64 {
272 set mips_new_fp 64
277 if {$mips_new_gp != $mips_gp || $mips_new_fp != $mips_fp} {
278 if {$mips_forced_regs} {
279 set matches 0
281 # Select an appropriate ABI.
282 if {[lsearch $flags "-mabi=*"] < 0} {
283 if {$mips_new_gp == 32} {
284 append flags " -mabi=32"
285 } else {
286 append flags " -mabi=o64"
289 # And an appropriate architecture.
290 if {[lsearch -regexp $flags {^(-mips|-march)}] < 0} {
291 if {$mips_new_gp == 64 && $mips_gp == 32} {
292 append flags " -mips3"
293 } elseif {$mips_new_gp == 32 && $mips_new_fp == 64} {
294 append flags " -mips32r2"
299 foreach flag $flags {
300 if {[string match -mabicalls $flag]} {
301 # EABI has no SVR4-style PIC mode, so try to force another ABI.
302 if {$mips_abi == "eabi" && [lsearch $flags "-mabi=*"] < 0} {
303 if {$mips_new_gp == 32} {
304 append flags " -mabi=32"
305 } else {
306 append flags " -mabi=n32"
309 # Turn off small data, if on by default.
310 append flags " -G0"
314 # Handle the other options.
315 foreach flag $flags {
316 if {[regexp -- {^-mabi=(.*)} $flag dummy abi]} {
317 if {$abi != $mips_abi && $mips_forced_abi} {
318 set matches 0
320 } elseif {[regexp -- {^-mips(.*)} $flag dummy isa]
321 || [regexp -- {^-march=mips(.*)} $flag dummy isa]} {
322 if {![regexp {(.*)r(.*)} $isa dummy isa isa_rev]} {
323 set isa_rev 1
325 if {($isa != $mips_isa || $isa_rev != $mips_isa_rev)
326 && $mips_forced_isa} {
327 set matches 0
329 } elseif {[regexp -- {^-march=(.*)} $flag dummy arch]} {
330 if {$arch != $mips_arch && $mips_forced_isa} {
331 set matches 0
333 } elseif {[regexp -- {^-m(hard|soft)-float} $flag dummy float]} {
334 if {$mips_float != $float && $mips_forced_float} {
335 set matches 0
337 } elseif {[regexp -- {^-(EB|meb)$} $flag]} {
338 if {$mips_forced_le} {
339 set matches 0
341 } elseif {[regexp -- {^-(EL|mel)$} $flag]} {
342 if {$mips_forced_be} {
343 set matches 0
345 } elseif {[regexp -- {^-(G|m(|no-)((extern|local)-sdata|gpopt))} $flag]} {
346 if {$flag != "-G0"} {
347 append flags " -mno-abicalls"
349 if {$mips_forced_gp} {
350 set matches 0
352 } elseif {[regexp -- {^-mabicalls$} $flag]} {
353 if {$mips_forced_no_abicalls} {
354 set matches 0
356 } elseif {[regexp -- {^-mshared$} $flag]} {
357 if {$mips_forced_no_shared} {
358 set matches 0
360 } elseif {[regexp -- {^-mexplicit-relocs$} $flag]} {
361 if {$mips_forced_no_er} {
362 set matches 0
366 if {$matches} {
367 append extra_tool_flags " " $flags
368 } else {
369 set do_what [list [lindex $do_what 0] "N" "P"]
373 setup_mips_tests
375 dg-init
376 # MIPS16 is defined in add_options_for_mips16_attribute.
377 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "" \
378 "-DNOMIPS16=__attribute__((nomips16))"
379 dg-finish